From: Nickolay V. Shmyrev Date: Sun, 24 Apr 2005 20:40:54 +0000 (+0000) Subject: Horizontal scroll and zooming with mouse wheel X-Git-Tag: EVINCE_0_3_0~28 X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=commitdiff_plain;h=16a2c17ee1a0bb5659007a49b4d8e14b71fc415f;p=evince.git Horizontal scroll and zooming with mouse wheel --- diff --git a/ChangeLog b/ChangeLog index d3cb7327..32b223ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2005-04-25 Nickolay V. Shmyrev + + * shell/ev-view.c: (ev_view_scroll_event), (ev_view_class_init), + (ev_view_set_sizing_mode), + (ev_view_zoom_for_size_continuous_and_dual_page), + (ev_view_zoom_for_size_continuous): + * shell/ev-window.c: (ev_window_cmd_view_best_fit), + (ev_window_cmd_view_page_width), (ev_window_cmd_view_zoom_in), + (ev_window_cmd_view_zoom_out), (ev_window_sizing_mode_changed_cb), + (ev_window_init): + + Control + Scroll does zooming, Shift + Scroll scrolls horizontally + Fix for 165473 and 165472. + 2005-04-24 Nickolay V. Shmyrev * po/POTFILES.in: diff --git a/shell/ev-view.c b/shell/ev-view.c index 851b5e4d..ef7d2996 100644 --- a/shell/ev-view.c +++ b/shell/ev-view.c @@ -653,6 +653,37 @@ ev_view_unrealize (GtkWidget *widget) GTK_WIDGET_CLASS (ev_view_parent_class)->unrealize (widget); } +static gboolean +ev_view_scroll_event (GtkWidget *widget, GdkEventScroll *event) +{ + EvView *view = EV_VIEW (widget); + + if ((event->state & GDK_CONTROL_MASK) != 0) { + + ev_view_set_sizing_mode (view, EV_SIZING_FREE); + + if ((event->direction == GDK_SCROLL_DOWN || + event->direction == GDK_SCROLL_LEFT) && + ev_view_can_zoom_in (view)) { + ev_view_zoom_in (view); + } else if (ev_view_can_zoom_out (view)) { + ev_view_zoom_out (view); + } + + return TRUE; + } + + if ((event->state & GDK_SHIFT_MASK) != 0) { + if (event->direction == GDK_SCROLL_UP) + event->direction = GDK_SCROLL_LEFT; + if (event->direction == GDK_SCROLL_DOWN) + event->direction = GDK_SCROLL_RIGHT; + } + + return FALSE; +} + + #if 0 static guint32 ev_gdk_color_to_rgb (const GdkColor *color) @@ -1594,6 +1625,7 @@ ev_view_class_init (EvViewClass *class) widget_class->size_allocate = ev_view_size_allocate; widget_class->realize = ev_view_realize; widget_class->unrealize = ev_view_unrealize; + widget_class->scroll_event = ev_view_scroll_event; gtk_object_class->destroy = ev_view_destroy; class->set_scroll_adjustments = ev_view_set_scroll_adjustments; @@ -2061,7 +2093,6 @@ ev_view_set_sizing_mode (EvView *view, view->sizing_mode = sizing_mode; gtk_widget_queue_resize (GTK_WIDGET (view)); } - g_object_notify (G_OBJECT (view), "sizing-mode"); } @@ -2156,7 +2187,7 @@ ev_view_zoom_for_size_continuous_and_dual_page (EvView *view, doc_width = doc_width * 2; width -= (2 * (border.left + border.right) + 3 * view->spacing); - height -= (border.top + border.bottom + 2 * view->spacing); + height -= (border.top + border.bottom + 2 * view->spacing - 1); /* FIXME: We really need to calculate the overall height here, not the * page height. We assume there's always a vertical scrollbar for @@ -2191,7 +2222,7 @@ ev_view_zoom_for_size_continuous (EvView *view, compute_border (view, doc_width, doc_height, &border); width -= (border.left + border.right + 2 * view->spacing); - height -= (border.top + border.bottom + 2 * view->spacing); + height -= (border.top + border.bottom + 2 * view->spacing - 1); /* FIXME: We really need to calculate the overall height here, not the * page height. We assume there's always a vertical scrollbar for diff --git a/shell/ev-window.c b/shell/ev-window.c index b7b172dc..9f18753f 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -144,10 +144,8 @@ static void ev_window_set_page_mode (EvWindow *window, static gboolean start_loading_document (EvWindow *ev_window, EvDocument *document, const char *uri); -static void ev_window_set_sizing_mode (EvWindow *ev_window, - EvSizingMode sizing_mode, - gboolean first_time); - +static void ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec, + EvWindow *ev_window); static void ev_window_add_recent (EvWindow *window, const char *filename); static void ev_window_fullscreen (EvWindow *window); @@ -325,9 +323,9 @@ static void ev_window_cmd_view_best_fit (GtkAction *action, EvWindow *ev_window) { if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) { - ev_window_set_sizing_mode (ev_window, EV_SIZING_BEST_FIT, FALSE); + ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_BEST_FIT); } else { - ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE, FALSE); + ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FREE); } update_action_sensitivity (ev_window); } @@ -336,9 +334,9 @@ static void ev_window_cmd_view_page_width (GtkAction *action, EvWindow *ev_window) { if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) { - ev_window_set_sizing_mode (ev_window, EV_SIZING_FIT_WIDTH, FALSE); + ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FIT_WIDTH); } else { - ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE, FALSE); + ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FREE); } update_action_sensitivity (ev_window); } @@ -1514,7 +1512,7 @@ ev_window_cmd_view_zoom_in (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE, FALSE); + ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FREE); ev_view_zoom_in (EV_VIEW (ev_window->priv->view)); update_action_sensitivity (ev_window); } @@ -1524,7 +1522,7 @@ ev_window_cmd_view_zoom_out (GtkAction *action, EvWindow *ev_window) { g_return_if_fail (EV_IS_WINDOW (ev_window)); - ev_window_set_sizing_mode (ev_window, EV_SIZING_FREE, FALSE); + ev_view_set_sizing_mode (EV_VIEW (ev_window->priv->view), EV_SIZING_FREE); ev_view_zoom_out (EV_VIEW (ev_window->priv->view)); update_action_sensitivity (ev_window); } @@ -1664,37 +1662,29 @@ size_allocate_cb (GtkWidget *scrolled_window, update_view_size (window); } -static void -ev_window_set_sizing_mode (EvWindow *ev_window, - EvSizingMode sizing_mode, - gboolean first_time) +static void +ev_window_sizing_mode_changed_cb (EvView *view, GParamSpec *pspec, + EvWindow *ev_window) { GtkWidget *scrolled_window; + EvSizingMode sizing_mode; - /* Short circuit the call if it's not the first time we call this */ - if (!first_time) { - EvSizingMode old_sizing_mode; - - g_object_get (ev_window->priv->view, - "sizing-mode", &old_sizing_mode, - NULL); - if (old_sizing_mode == sizing_mode) - return; - } + g_object_get (ev_window->priv->view, + "sizing-mode", &sizing_mode, + NULL); scrolled_window = ev_window->priv->scrolled_window; - g_object_set (ev_window->priv->view, - "sizing-mode", sizing_mode, - NULL); + g_signal_handlers_disconnect_by_func (scrolled_window, size_allocate_cb, ev_window); - update_view_size (ev_window); + if (sizing_mode != EV_SIZING_FREE) + update_view_size (ev_window); switch (sizing_mode) { case EV_SIZING_BEST_FIT: g_object_set (G_OBJECT (scrolled_window), "hscrollbar-policy", GTK_POLICY_NEVER, - "vscrollbar-policy", GTK_POLICY_NEVER, + "vscrollbar-policy", GTK_POLICY_AUTOMATIC, NULL); g_signal_connect (scrolled_window, "size-allocate", G_CALLBACK (size_allocate_cb), @@ -2487,6 +2477,7 @@ ev_window_init (EvWindow *ev_window) gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window), ev_window->priv->view); + g_signal_connect (ev_window->priv->view, "notify::find-status", G_CALLBACK (view_find_status_changed_cb), @@ -2495,6 +2486,10 @@ ev_window_init (EvWindow *ev_window) "notify::status", G_CALLBACK (view_status_changed_cb), ev_window); + g_signal_connect (ev_window->priv->view, + "notify::sizing-mode", + G_CALLBACK (ev_window_sizing_mode_changed_cb), + ev_window); ev_window->priv->statusbar = gtk_statusbar_new (); gtk_box_pack_end (GTK_BOX (ev_window->priv->main_box), @@ -2559,6 +2554,7 @@ ev_window_init (EvWindow *ev_window) G_CALLBACK (drag_data_received_cb), NULL); /* Set it to something random to force a change */ - ev_window_set_sizing_mode (ev_window, EV_SIZING_FIT_WIDTH, TRUE); + + ev_window_sizing_mode_changed_cb (EV_VIEW (ev_window->priv->view), NULL, ev_window); update_action_sensitivity (ev_window); }