+ 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);
+ else if (view->dual_page)
+ ev_view_size_request_dual_page (view, &view->requisition);
+ else
+ ev_view_size_request_single_page (view, &view->requisition);
+
+ *requisition = view->requisition;
+}
+
+static void
+ev_view_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ EvView *view = EV_VIEW (widget);
+ GList *children, *l;
+ gint root_x, root_y;
+
+ GTK_WIDGET_CLASS (ev_view_parent_class)->size_allocate (widget, allocation);
+
+ if (!view->document)
+ return;
+
+ if (view->sizing_mode == EV_SIZING_FIT_WIDTH ||
+ view->sizing_mode == EV_SIZING_BEST_FIT) {
+ GtkRequisition req;
+
+ ev_view_zoom_for_size (view,
+ allocation->width,
+ allocation->height);
+ view->internal_size_request = TRUE;
+ ev_view_size_request (widget, &req);
+ view->internal_size_request = FALSE;
+ }
+
+ view_set_adjustment_values (view, GTK_ORIENTATION_HORIZONTAL);
+ view_set_adjustment_values (view, GTK_ORIENTATION_VERTICAL);
+
+ if (view->document)
+ view_update_range_and_current_page (view);
+
+ view->pending_scroll = SCROLL_TO_KEEP_POSITION;
+ view->pending_resize = FALSE;
+ view->pending_point.x = 0;
+ view->pending_point.y = 0;
+
+ children = gtk_container_get_children (GTK_CONTAINER (widget));
+ for (l = children; l && l->data; l = g_list_next (l)) {
+ EvFormField *field;
+ GdkRectangle view_area;
+ EvMappingList *form_field_mapping;
+ GtkAllocation child_allocation;
+ GtkRequisition child_requisition;
+ GtkWidget *child = (GtkWidget *)l->data;
+
+ field = g_object_get_data (G_OBJECT (child), "form-field");
+ if (!field)
+ continue;
+
+ form_field_mapping = ev_page_cache_get_form_field_mapping (view->page_cache,
+ field->page->index);
+ ev_view_get_area_from_mapping (view, field->page->index,
+ form_field_mapping,
+ field, &view_area);
+
+ gtk_widget_size_request (child, &child_requisition);
+ if (child_requisition.width != view_area.width ||
+ child_requisition.height != view_area.height)
+ gtk_widget_set_size_request (child, view_area.width, view_area.height);
+
+ gtk_container_child_get (GTK_CONTAINER (widget),
+ child,
+ "x", &child_allocation.x,
+ "y", &child_allocation.y,
+ NULL);
+ if (child_allocation.x != view_area.x ||
+ child_allocation.y != view_area.y) {
+ gtk_layout_move (GTK_LAYOUT (widget), child, view_area.x, view_area.y);
+ }
+ }
+ g_list_free (children);
+
+ if (view->window_children)
+ gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (view)),
+ &root_x, &root_y);
+
+ for (l = view->window_children; l && l->data; l = g_list_next (l)) {
+ EvViewWindowChild *child;
+ EvRectangle doc_rect;
+ GdkRectangle view_rect;
+
+ child = (EvViewWindowChild *)l->data;
+
+ ev_annotation_window_get_rectangle (EV_ANNOTATION_WINDOW (child->window), &doc_rect);
+ if (child->moved) {
+ doc_rect.x1 = child->orig_x;
+ doc_rect.y1 = child->orig_y;
+ }
+ doc_rect_to_view_rect (view, child->page, &doc_rect, &view_rect);
+ view_rect.x -= view->scroll_x;
+ view_rect.y -= view->scroll_y;
+
+ if (view_rect.x != child->orig_x || view_rect.y != child->orig_y) {
+ child->parent_x = root_x;
+ child->parent_y = root_y;
+ ev_view_window_child_move (view, child, view_rect.x + root_x, view_rect.y + root_y);
+ }
+ }
+}
+
+static void
+ev_view_realize (GtkWidget *widget)
+{
+ EvView *view = EV_VIEW (widget);
+ GdkWindow *bin_window;
+ GtkStyle *style;
+
+ if (GTK_WIDGET_CLASS (ev_view_parent_class)->realize)
+ (* GTK_WIDGET_CLASS (ev_view_parent_class)->realize) (widget);
+
+ bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (view));
+ gdk_window_set_events (bin_window,
+ (gdk_window_get_events (bin_window) |
+ GDK_EXPOSURE_MASK |
+ GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_SCROLL_MASK |
+ GDK_KEY_PRESS_MASK |
+ GDK_POINTER_MOTION_MASK |
+ GDK_POINTER_MOTION_HINT_MASK |
+ GDK_ENTER_NOTIFY_MASK |
+ GDK_LEAVE_NOTIFY_MASK));
+
+ style = gtk_widget_get_style (widget);
+ gdk_window_set_background (bin_window, &style->mid[GTK_STATE_NORMAL]);
+
+ on_adjustment_value_changed (NULL, view);
+}