[gtk+/gestures: 87/140] range: Replace GtkPressAndHold with GtkGestureLongPress



commit 486d98d923012ecf141584f4259d73affa36e392
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Apr 8 21:21:14 2014 +0200

    range: Replace GtkPressAndHold with GtkGestureLongPress

 gtk/gtkrange.c |   60 ++++++++++++++++++++++++++++++-------------------------
 1 files changed, 33 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 99dcaec..cd14bd8 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -37,7 +37,6 @@
 #include "gtkmain.h"
 #include "gtkmarshalers.h"
 #include "gtkorientableprivate.h"
-#include "gtkpressandholdprivate.h"
 #include "gtkprivate.h"
 #include "gtkscale.h"
 #include "gtkscrollbar.h"
@@ -148,7 +147,7 @@ struct _GtkRangePrivate
   /* Whether we're doing fine adjustment */
   guint zoom                   : 1;
   guint zoom_set               : 1;
-  GtkPressAndHold *press_and_hold;
+  GtkGesture *long_press_gesture;
   GtkScrollType autoscroll_mode;
   guint autoscroll_id;
 
@@ -1508,7 +1507,11 @@ gtk_range_destroy (GtkWidget *widget)
 
   gtk_range_remove_step_timer (range);
 
-  g_clear_object (&priv->press_and_hold);
+  if (priv->long_press_gesture)
+    {
+      gtk_widget_remove_controller (widget, GTK_EVENT_CONTROLLER (priv->long_press_gesture));
+      g_clear_object (&priv->long_press_gesture);
+    }
 
   if (priv->adjustment)
     {
@@ -2379,7 +2382,11 @@ update_zoom_set (GtkRange *range,
                  gboolean  zoom_set)
 {
   if (zoom_set)
-    g_clear_object (&range->priv->press_and_hold);
+    {
+      gtk_widget_remove_controller (GTK_WIDGET (range),
+                                    GTK_EVENT_CONTROLLER (range->priv->long_press_gesture));
+      g_clear_object (&range->priv->long_press_gesture);
+    }
 
   range->priv->zoom_set = zoom_set;
 }
@@ -2551,10 +2558,10 @@ gtk_range_key_press (GtkWidget   *widget,
 }
 
 static void
-hold_action (GtkPressAndHold *pah,
-             gint             x,
-             gint             y,
-             GtkRange        *range)
+hold_action (GtkGestureLongPress *gesture,
+             gdouble              x,
+             gdouble              y,
+             GtkRange            *range)
 {
   update_zoom_state (range, TRUE);
   update_zoom_set (range, TRUE);
@@ -2712,25 +2719,22 @@ gtk_range_button_press (GtkWidget      *widget,
             }
           else
             {
-              if (!priv->press_and_hold)
+              if (!priv->long_press_gesture)
                 {
-                  gint drag_threshold;
-
-                  g_object_get (gtk_widget_get_settings (widget),
-                                "gtk-dnd-drag-threshold", &drag_threshold,
-                                NULL);
-                  priv->press_and_hold = gtk_press_and_hold_new ();
-
-                  g_object_set (priv->press_and_hold,
-                                "drag-threshold", drag_threshold,
-                                "hold-time", ZOOM_HOLD_TIME,
-                                NULL);
-
-                  g_signal_connect (priv->press_and_hold, "hold",
+                  priv->long_press_gesture =
+                    gtk_gesture_long_press_new (widget);
+                  gtk_gesture_single_set_touch_only (GTK_GESTURE_SINGLE (priv->long_press_gesture),
+                                                     FALSE);
+                  gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (priv->long_press_gesture), 1);
+                  gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER 
(priv->long_press_gesture),
+                                                              GTK_PHASE_NONE);
+
+                  g_signal_connect (priv->long_press_gesture, "pressed",
                                     G_CALLBACK (hold_action), range);
                 }
 
-              gtk_press_and_hold_process_event (priv->press_and_hold, (GdkEvent *)event);
+              gtk_event_controller_handle_event (GTK_EVENT_CONTROLLER (priv->long_press_gesture),
+                                                 (const GdkEvent*) event);
             }
         }
 
@@ -2943,8 +2947,9 @@ gtk_range_button_release (GtkWidget      *widget,
     {
       if (priv->grab_location == MOUSE_SLIDER)
         {
-          if (priv->press_and_hold)
-            gtk_press_and_hold_process_event (priv->press_and_hold, (GdkEvent *)event);
+          if (priv->long_press_gesture)
+            gtk_event_controller_handle_event (GTK_EVENT_CONTROLLER (priv->long_press_gesture),
+                                               (const GdkEvent*) event);
         }
 
       stop_scrolling (range);
@@ -3085,8 +3090,9 @@ gtk_range_motion_notify (GtkWidget      *widget,
 
   if (priv->grab_location == MOUSE_SLIDER)
     {
-      if (!priv->zoom_set && priv->press_and_hold != NULL)
-        gtk_press_and_hold_process_event (priv->press_and_hold, (GdkEvent *)event);
+      if (!priv->zoom_set && priv->long_press_gesture != NULL)
+        gtk_event_controller_handle_event (GTK_EVENT_CONTROLLER (priv->long_press_gesture),
+                                           (const GdkEvent*) event);
 
       update_autoscroll_mode (range);
       if (priv->autoscroll_mode == GTK_SCROLL_NONE)


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