]> www.fi.muni.cz Git - evince.git/blobdiff - shell/ev-view.c
Use common save function for backends.
[evince.git] / shell / ev-view.c
index 9c7779b2f5fb552289d33dfd243f1664a16d50bf..311504b147e4116a9e6b844ad92bfbbe709d11d6 100644 (file)
@@ -179,6 +179,7 @@ static gboolean   ev_view_scroll_event                       (GtkWidget
                                                              GdkEventScroll     *event);
 static gboolean   ev_view_expose_event                       (GtkWidget          *widget,
                                                              GdkEventExpose     *event);
+static gboolean   ev_view_popup_menu                         (GtkWidget         *widget);
 static gboolean   ev_view_button_press_event                 (GtkWidget          *widget,
                                                              GdkEventButton     *event);
 static gboolean   ev_view_motion_notify_event                (GtkWidget          *widget,
@@ -319,17 +320,23 @@ scroll_to_current_page (EvView *view, GtkOrientation orientation)
 
         doc_point_to_view_point (view, view->current_page, &view->pending_point, &view_point);
 
-       view->pending_point.x = 0;
-       view->pending_point.y = 0;
+       if (orientation == GTK_ORIENTATION_VERTICAL) {
+               view->pending_point.y = 0;
+       } else {
+               view->pending_point.x = 0;
+       }
 
        if (orientation == GTK_ORIENTATION_VERTICAL) {
                if (view->continuous) {
                        gtk_adjustment_clamp_page (view->vadjustment,
-                                                  view_point.y - view->spacing,
+                                                  view_point.y - view->spacing / 2,
                                                   view_point.y + view->vadjustment->page_size);
                } else {
                        gtk_adjustment_set_value (view->vadjustment,
-                                                 view_point.y);
+                                                 CLAMP (view_point.y,
+                                                 view->vadjustment->lower,
+                                                 view->vadjustment->upper -
+                                                 view->vadjustment->page_size));
                }
        } else {
                if (view->dual_page) {
@@ -413,6 +420,8 @@ view_set_adjustment_values (EvView         *view,
 static void
 view_update_range_and_current_page (EvView *view)
 {
+       gint current_page;
+       
        if (view->pending_scroll != SCROLL_TO_KEEP_POSITION)
                return;
 
@@ -423,7 +432,6 @@ view_update_range_and_current_page (EvView *view)
        } else if (view->continuous) {
                GdkRectangle current_area, unused, page_area;
                GtkBorder border;
-               gint current_page;
                gboolean found = FALSE;
                int i;
 
@@ -451,28 +459,33 @@ view_update_range_and_current_page (EvView *view)
                        }
                }
 
-               current_page = ev_page_cache_get_current_page (view->page_cache);
-
-               if (current_page < view->start_page || current_page > view->end_page) {
-                       view->current_page = view->start_page;
-                       ev_page_cache_set_current_page (view->page_cache, view->start_page);
-               }
        } else {
                if (view->dual_page) {
-                       if (view->current_page % 2 == 0) {
+                       if (view->current_page % 2 == DUAL_EVEN_LEFT) {
                                view->start_page = view->current_page;
                                if (view->current_page + 1 < ev_page_cache_get_n_pages (view->page_cache))
                                        view->end_page = view->start_page + 1;
                                else 
                                        view->end_page = view->start_page;
                        } else {
-                               view->start_page = view->current_page - 1;
+                               if (view->current_page - 1 < 0)
+                                       view->start_page = view->current_page;
+                               else
+                                       view->start_page = view->current_page - 1;
                                view->end_page = view->current_page;
                        }
                } else {
                        view->start_page = view->current_page;
                        view->end_page = view->current_page;
                }
+
+       }
+
+       current_page = ev_page_cache_get_current_page (view->page_cache);
+
+       if (current_page < view->start_page || current_page > view->end_page) {
+               view->current_page = view->start_page;
+               ev_page_cache_set_current_page (view->page_cache, view->start_page);
        }
 
        ev_pixbuf_cache_set_page_range (view->pixbuf_cache,
@@ -571,7 +584,7 @@ ev_view_scroll (EvView        *view,
                                /* At the top of a page, assign the upper bound limit of previous page */
                        } else if (value == (adjustment->lower)) {
                                value = adjustment->upper - adjustment->page_size;
-                               ev_page_cache_set_current_page (view->page_cache, view->current_page - 1);
+                               ev_view_previous_page (view);
                                /* Jump to the top */
                        } else {
                                value = MAX (value - increment, adjustment->lower);
@@ -584,7 +597,7 @@ ev_view_scroll (EvView        *view,
                        /* At the bottom of a page, assign the lower bound limit of next page */
                        } else if (value == (adjustment->upper - adjustment->page_size)) {
                                value = 0;
-                               ev_page_cache_set_current_page (view->page_cache, view->current_page + 1);
+                               ev_view_next_page (view);
                        /* Jump to the bottom */
                        } else {
                                value = MIN (value + increment, adjustment->upper - adjustment->page_size);
@@ -710,7 +723,7 @@ get_page_y_offset (EvView *view, int page, double zoom, int *y_offset)
        if (view->dual_page) {
                ev_page_cache_get_height_to_page (view->page_cache, page,
                                                  view->rotation, zoom, NULL, &offset);
-               offset += (page / 2 + 1) * view->spacing + (page / 2) * (border.top + border.bottom);
+               offset += ((page + DUAL_EVEN_LEFT) / 2 + 1) * view->spacing + ((page + DUAL_EVEN_LEFT) / 2 ) * (border.top + border.bottom);
        } else {
                ev_page_cache_get_height_to_page (view->page_cache, page,
                                                  view->rotation, zoom, &offset, NULL);
@@ -753,9 +766,9 @@ get_page_extents (EvView       *view,
                max_width = max_width + border->left + border->right;
                /* Get the location of the bounding box */
                if (view->dual_page) {
-                       x = view->spacing + (page % 2) * (max_width + view->spacing);
+                       x = view->spacing + ((page % 2 == DUAL_EVEN_LEFT) ? 0 : 1) * (max_width + view->spacing);
                        x = x + MAX (0, widget->allocation.width - (max_width * 2 + view->spacing * 3)) / 2;
-                       if (page % 2 == 0)
+                       if (page % 2 == DUAL_EVEN_LEFT)
                                x = x + (max_width - width - border->left - border->right);
                } else {
                        x = view->spacing;
@@ -775,10 +788,11 @@ get_page_extents (EvView       *view,
                        GtkBorder overall_border;
                        gint other_page;
 
-                       other_page = page ^ 1;
+                       other_page = (page % 2 == DUAL_EVEN_LEFT) ? page + 1: page - 1;
 
                        /* First, we get the bounding box of the two pages */
-                       if (other_page < ev_page_cache_get_n_pages (view->page_cache)) {
+                       if (other_page < ev_page_cache_get_n_pages (view->page_cache)
+                           && (0 <= other_page)) {
                                ev_page_cache_get_size (view->page_cache,
                                                        other_page,
                                                        view->rotation,
@@ -796,7 +810,7 @@ get_page_extents (EvView       *view,
                        y = view->spacing;
 
                        /* Adjust for being the left or right page */
-                       if (page % 2 == 0)
+                       if (page % 2 == DUAL_EVEN_LEFT)
                                x = x + max_width - width;
                        else
                                x = x + (max_width + overall_border.left + overall_border.right) + view->spacing;
@@ -1174,8 +1188,8 @@ goto_xyz_link (EvView *view, EvLink *link)
        page = ev_link_get_page (link);
        ev_page_cache_get_size (view->page_cache, page, 0, 1.0, NULL, &height);
 
-       ev_view_set_sizing_mode (view, EV_SIZING_FREE);
        if (zoom != 0) {
+               ev_view_set_sizing_mode (view, EV_SIZING_FREE);
                ev_view_set_zoom (view, zoom, FALSE);
        }
 
@@ -1619,6 +1633,19 @@ ev_view_expose_event (GtkWidget      *widget,
        return FALSE;
 }
 
+static gboolean
+ev_view_popup_menu (GtkWidget *widget)
+{
+    gint x, y;
+    EvLink *link;
+    EvView *view = EV_VIEW (widget);
+    
+    gtk_widget_get_pointer (widget, &x, &y);
+    link = ev_view_get_link_at_location (view, x, y);
+    g_signal_emit (view, signals[SIGNAL_POPUP_MENU], 0, link);
+    return TRUE;
+}
+
 static gboolean
 ev_view_button_press_event (GtkWidget      *widget,
                            GdkEventButton *event)
@@ -1703,10 +1730,10 @@ selection_update_idle_cb (EvView *view)
 static gboolean
 selection_scroll_timeout_cb (EvView *view)
 {      
-       gint y, shift = 0;
+       gint x, y, shift = 0;
        GtkWidget *widget = GTK_WIDGET (view);
        
-       gtk_widget_get_pointer (widget, NULL, &y);
+       gtk_widget_get_pointer (widget, &x, &y);
 
        if (y > widget->allocation.height) {
                shift = (y - widget->allocation.height) / 2;
@@ -1720,6 +1747,20 @@ selection_scroll_timeout_cb (EvView *view)
                                          view->vadjustment->lower,
                                          view->vadjustment->upper -
                                          view->vadjustment->page_size));       
+
+       if (x > widget->allocation.width) {
+               shift = (x - widget->allocation.width) / 2;
+       } else if (x < 0) {
+               shift = x / 2;
+       }
+
+       if (shift)
+               gtk_adjustment_set_value (view->hadjustment,
+                                         CLAMP (view->hadjustment->value + shift,
+                                         view->hadjustment->lower,
+                                         view->hadjustment->upper -
+                                         view->hadjustment->page_size));       
+
        return TRUE;
 }
 
@@ -2369,6 +2410,7 @@ ev_view_class_init (EvViewClass *class)
        widget_class->leave_notify_event = ev_view_leave_notify_event;
        widget_class->style_set = ev_view_style_set;
        widget_class->drag_data_get = ev_view_drag_data_get;
+       widget_class->popup_menu = ev_view_popup_menu;
        gtk_object_class->destroy = ev_view_destroy;
 
        class->set_scroll_adjustments = ev_view_set_scroll_adjustments;
@@ -3903,6 +3945,9 @@ ev_view_next_page (EvView *view)
        if (page < ev_page_cache_get_n_pages (view->page_cache)) {
                ev_page_cache_set_current_page (view->page_cache, page);
                return TRUE;
+       } else if (ev_view_get_dual_page (view) && page == ev_page_cache_get_n_pages (view->page_cache)) {
+               ev_page_cache_set_current_page (view->page_cache, page - 1);
+               return TRUE;
        } else {
                return FALSE;
        }
@@ -3921,7 +3966,10 @@ ev_view_previous_page (EvView *view)
        if (page >= 0) {
                ev_page_cache_set_current_page (view->page_cache, page);
                return TRUE;
-       } else {
+       } else if (ev_view_get_dual_page (view) && page == -1) {
+               ev_page_cache_set_current_page (view->page_cache, 0);
+               return TRUE;
+       } else {        
                return FALSE;
        }
 }