+ view->adding_annot = TRUE;
+ view->adding_annot_type = annot_type;
+ ev_view_set_cursor (view, EV_VIEW_CURSOR_ADD);
+}
+
+void
+ev_view_cancel_add_annotation (EvView *view)
+{
+ gint x, y;
+
+ if (!view->adding_annot)
+ return;
+
+ view->adding_annot = FALSE;
+ gtk_widget_get_pointer (GTK_WIDGET (view), &x, &y);
+ ev_view_handle_cursor_over_xy (view, x, y);
+}
+
+static gboolean
+ev_view_synctex_backward_search (EvView *view,
+ gdouble x,
+ gdouble y)
+{
+ gint page = -1;
+ gint x_new = 0, y_new = 0;
+ EvSourceLink *link;
+
+ if (!ev_document_has_synctex (view->document))
+ return FALSE;
+
+ if (!get_doc_point_from_location (view, x, y, &page, &x_new, &y_new))
+ return FALSE;
+
+ link = ev_document_synctex_backward_search (view->document, page, x_new, y_new);
+ if (link) {
+ g_signal_emit (view, signals[SIGNAL_SYNC_SOURCE], 0, link);
+ g_free (link);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+/*** GtkWidget implementation ***/
+
+static void
+ev_view_size_request_continuous_dual_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ gint n_pages;
+
+ n_pages = ev_document_get_n_pages (view->document) + 1;
+ get_page_y_offset (view, n_pages, &requisition->height);
+
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
+ case EV_SIZING_BEST_FIT:
+ requisition->width = 1;
+
+ break;
+ case EV_SIZING_FREE: {
+ gint max_width;
+ GtkBorder border;
+
+ ev_view_get_max_page_size (view, &max_width, NULL);
+ compute_border (view, max_width, max_width, &border);
+ requisition->width = (max_width + border.left + border.right) * 2 + (view->spacing * 3);
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+ev_view_size_request_continuous (EvView *view,
+ GtkRequisition *requisition)
+{
+ gint n_pages;
+
+ n_pages = ev_document_get_n_pages (view->document);
+ get_page_y_offset (view, n_pages, &requisition->height);
+
+ switch (view->sizing_mode) {
+ case EV_SIZING_FIT_WIDTH:
+ case EV_SIZING_BEST_FIT:
+ requisition->width = 1;
+
+ break;
+ case EV_SIZING_FREE: {
+ gint max_width;
+ GtkBorder border;
+
+ ev_view_get_max_page_size (view, &max_width, NULL);
+ compute_border (view, max_width, max_width, &border);
+ requisition->width = max_width + (view->spacing * 2) + border.left + border.right;
+ }
+ break;
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static void
+ev_view_size_request_dual_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ GtkBorder border;
+ gint width, height;
+
+ if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+
+ return;
+ }
+
+ /* Find the largest of the two. */
+ ev_view_get_page_size (view,
+ view->current_page,
+ &width, &height);
+ if (view->current_page + 1 < ev_document_get_n_pages (view->document)) {
+ gint width_2, height_2;
+ ev_view_get_page_size (view,
+ view->current_page + 1,
+ &width_2, &height_2);
+ if (width_2 > width) {
+ width = width_2;
+ height = height_2;
+ }
+ }
+ compute_border (view, width, height, &border);
+
+ requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
+ ((width + border.left + border.right) * 2) + (view->spacing * 3);
+ requisition->height = (height + border.top + border.bottom) + (view->spacing * 2);
+}
+
+static void
+ev_view_size_request_single_page (EvView *view,
+ GtkRequisition *requisition)
+{
+ GtkBorder border;
+ gint width, height;
+
+ if (view->sizing_mode == EV_SIZING_BEST_FIT) {
+ requisition->width = 1;
+ requisition->height = 1;
+
+ return;
+ }
+
+ ev_view_get_page_size (view, view->current_page, &width, &height);
+ compute_border (view, width, height, &border);
+
+ requisition->width = view->sizing_mode == EV_SIZING_FIT_WIDTH ? 1 :
+ width + border.left + border.right + (2 * view->spacing);
+ requisition->height = height + border.top + border.bottom + (2 * view->spacing);
+}
+
+static void
+ev_view_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
+{
+ EvView *view = EV_VIEW (widget);
+
+ if (view->document == NULL) {
+ view->requisition.width = 1;
+ view->requisition.height = 1;
+
+ *requisition = view->requisition;
+
+ return;
+ }
+
+ /* Get zoom for size here when not called from
+ * ev_view_size_allocate()
+ */
+ if (!view->internal_size_request &&
+ (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
+ view->sizing_mode == EV_SIZING_BEST_FIT)) {
+ GtkAllocation allocation;
+
+ gtk_widget_get_allocation (widget, &allocation);
+ ev_view_zoom_for_size (view,
+ allocation.width,
+ allocation.height);
+ }
+
+ if (view->continuous && view->dual_page)
+ ev_view_size_request_continuous_dual_page (view, &view->requisition);
+ else if (view->continuous)
+ ev_view_size_request_continuous (view, &view->requisition);