[evince/wip/gestures] WIP: zoom/pinch gesture



commit d21c34872337619f8d7bee74558694bbad1b2e5e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 28 19:55:03 2014 +0100

    WIP: zoom/pinch gesture
    
    To be used together with the "gestures" GTK+ branch

 libview/ev-view-private.h |    4 +++
 libview/ev-view.c         |   51 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 1 deletions(-)
---
diff --git a/libview/ev-view-private.h b/libview/ev-view-private.h
index 4f1721a..82cc241 100644
--- a/libview/ev-view-private.h
+++ b/libview/ev-view-private.h
@@ -221,6 +221,10 @@ struct _EvView {
        gboolean cursor_visible;
        guint    cursor_blink_timeout_id;
        guint    cursor_blink_time;
+
+       /* Gestures */
+       GtkGesture *zoom_gesture;
+       gdouble prev_zoom_scale;
 };
 
 struct _EvViewClass {
diff --git a/libview/ev-view.c b/libview/ev-view.c
index acd9890..7cce37f 100644
--- a/libview/ev-view.c
+++ b/libview/ev-view.c
@@ -4626,7 +4626,10 @@ ev_view_button_press_event (GtkWidget      *widget,
 
        if (!view->document)
                return FALSE;
-       
+
+       if (gtk_gesture_is_recognized (view->zoom_gesture))
+               return TRUE;
+
        if (!gtk_widget_has_focus (widget)) {
                gtk_widget_grab_focus (widget);
        }
@@ -4941,6 +4944,9 @@ ev_view_motion_notify_event (GtkWidget      *widget,
        if (!view->document)
                return FALSE;
 
+       if (gtk_gesture_is_recognized (view->zoom_gesture))
+               return TRUE;
+
        window = gtk_widget_get_window (widget);
 
         if (event->is_hint || event->window != window) {
@@ -5096,6 +5102,9 @@ ev_view_button_release_event (GtkWidget      *widget,
 
        view->image_dnd_info.in_drag = FALSE;
 
+       if (gtk_gesture_is_recognized (view->zoom_gesture))
+               return TRUE;
+
        if (view->scroll_info.autoscrolling) {
                ev_view_autoscroll_stop (view);
                view->pressed_button = -1;
@@ -6183,6 +6192,10 @@ ev_view_finalize (GObject *object)
                g_object_unref (view->image_dnd_info.image);
        view->image_dnd_info.image = NULL;
 
+       gtk_widget_remove_controller (GTK_WIDGET (view),
+                                     GTK_EVENT_CONTROLLER (view->zoom_gesture));
+       g_object_unref (view->zoom_gesture);
+
        G_OBJECT_CLASS (ev_view_parent_class)->finalize (object);
 }
 
@@ -6702,6 +6715,33 @@ ev_view_class_init (EvViewClass *class)
 }
 
 static void
+zoom_gesture_begin_cb (GtkGesture       *gesture,
+                      GdkEventSequence *sequence,
+                      EvView           *view)
+{
+       view->prev_zoom_scale = 1;
+}
+
+static void
+zoom_scale_changed_cb (GtkGestureZoom *gesture,
+                      gdouble         scale,
+                      EvView         *view)
+{
+       gdouble factor;
+
+       view->drag_info.in_drag = FALSE;
+       view->image_dnd_info.in_drag = FALSE;
+
+       factor = scale - view->prev_zoom_scale + 1;
+       view->prev_zoom_scale = scale;
+       ev_document_model_set_sizing_mode (view->model, EV_SIZING_FREE);
+
+       if ((factor < 1.0 && ev_view_can_zoom_out (view)) ||
+           (factor >= 1.0 && ev_view_can_zoom_in (view)))
+               ev_view_zoom (view, factor);
+}
+
+static void
 ev_view_init (EvView *view)
 {
        GtkStyleContext *context;
@@ -6716,6 +6756,7 @@ ev_view_init (EvView *view)
        gtk_style_context_add_class (context, "view");
 
        gtk_widget_set_events (GTK_WIDGET (view),
+                              GDK_TOUCH_MASK |
                               GDK_EXPOSURE_MASK |
                               GDK_BUTTON_PRESS_MASK |
                               GDK_BUTTON_RELEASE_MASK |
@@ -6750,6 +6791,14 @@ ev_view_init (EvView *view)
        view->pixbuf_cache_size = DEFAULT_PIXBUF_CACHE_SIZE;
        view->caret_enabled = FALSE;
        view->cursor_page = 0;
+
+       view->zoom_gesture = gtk_gesture_zoom_new (GTK_WIDGET (view));
+       gtk_widget_add_controller (GTK_WIDGET (view),
+                                  GTK_EVENT_CONTROLLER (view->zoom_gesture));
+       g_signal_connect (view->zoom_gesture, "begin",
+                         G_CALLBACK (zoom_gesture_begin_cb), view);
+       g_signal_connect (view->zoom_gesture, "scale-changed",
+                         G_CALLBACK (zoom_scale_changed_cb), view);
 }
 
 /*** Callbacks ***/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]