[gtk+/gestures: 34/55] multipress: Make a subclass of GtkGestureSingle



commit e6c5ca4e33d6524dfc7f49d85e373e099088696e
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Mar 21 19:21:56 2014 +0100

    multipress: Make a subclass of GtkGestureSingle
    
    The redundant API has been removed here.

 gtk/gtkgesturemultipress.c |  166 +++++++-------------------------------------
 gtk/gtkgesturemultipress.h |   15 +---
 2 files changed, 29 insertions(+), 152 deletions(-)
---
diff --git a/gtk/gtkgesturemultipress.c b/gtk/gtkgesturemultipress.c
index 2ef3abf..a3a5540 100644
--- a/gtk/gtkgesturemultipress.c
+++ b/gtk/gtkgesturemultipress.c
@@ -31,16 +31,11 @@ struct _GtkGestureMultiPressPrivate
   gdouble initial_press_y;
   guint double_click_timeout_id;
   guint n_presses;
-  guint button;
   guint current_button;
   guint rect_is_set : 1;
 };
 
 enum {
-  PROP_BUTTON = 1
-};
-
-enum {
   PRESSED,
   STOPPED,
   LAST_SIGNAL
@@ -48,7 +43,7 @@ enum {
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkGestureMultiPress, gtk_gesture_multi_press, GTK_TYPE_GESTURE)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkGestureMultiPress, gtk_gesture_multi_press, GTK_TYPE_GESTURE_SINGLE)
 
 static void
 gtk_gesture_multi_press_finalize (GObject *object)
@@ -68,51 +63,6 @@ gtk_gesture_multi_press_finalize (GObject *object)
   G_OBJECT_CLASS (gtk_gesture_multi_press_parent_class)->finalize (object);
 }
 
-static void
-gtk_gesture_multi_press_set_property (GObject      *object,
-                                      guint         prop_id,
-                                      const GValue *value,
-                                      GParamSpec   *pspec)
-{
-  GtkGestureMultiPress *gesture;
-
-  gesture = GTK_GESTURE_MULTI_PRESS (object);
-
-  switch (prop_id)
-    {
-    case PROP_BUTTON:
-      gtk_gesture_multi_press_set_button (gesture,
-                                          g_value_get_uint (value));
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
-static void
-gtk_gesture_multi_press_get_property (GObject    *object,
-                                      guint       prop_id,
-                                      GValue     *value,
-                                      GParamSpec *pspec)
-{
-  GtkGestureMultiPressPrivate *priv;
-  GtkGestureMultiPress *gesture;
-
-  gesture = GTK_GESTURE_MULTI_PRESS (object);
-  priv = gtk_gesture_multi_press_get_instance_private (gesture);
-
-  switch (prop_id)
-    {
-    case PROP_BUTTON:
-      g_value_set_uint (value, priv->button);
-      break;
-    default:
-      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-      break;
-    }
-}
-
 static gboolean
 gtk_gesture_multi_press_check (GtkGesture *gesture)
 {
@@ -125,12 +75,30 @@ gtk_gesture_multi_press_check (GtkGesture *gesture)
   priv = gtk_gesture_multi_press_get_instance_private (multi_press);
   sequences = gtk_gesture_get_sequences (gesture);
 
-  active = sequences || priv->double_click_timeout_id;
+  active = g_list_length (sequences) == 1 || priv->double_click_timeout_id;
   g_list_free (sequences);
 
   return active;
 }
 
+static void
+_gtk_gesture_multi_press_stop (GtkGestureMultiPress *gesture)
+{
+  GtkGestureMultiPressPrivate *priv;
+
+  priv = gtk_gesture_multi_press_get_instance_private (gesture);
+
+  if (priv->n_presses == 0)
+    return;
+
+  if (priv->n_presses != 0)
+    g_signal_emit (gesture, signals[STOPPED], 0);
+
+  priv->current_button = 0;
+  priv->n_presses = 0;
+  gtk_gesture_check (GTK_GESTURE (gesture));
+}
+
 static gboolean
 _double_click_timeout_cb (gpointer user_data)
 {
@@ -139,8 +107,7 @@ _double_click_timeout_cb (gpointer user_data)
 
   priv = gtk_gesture_multi_press_get_instance_private (gesture);
   priv->double_click_timeout_id = 0;
-
-  gtk_gesture_multi_press_reset (gesture);
+  _gtk_gesture_multi_press_stop (gesture);
 
   return FALSE;
 }
@@ -215,27 +182,26 @@ gtk_gesture_multi_press_update (GtkGesture       *gesture,
   priv = gtk_gesture_multi_press_get_instance_private (multi_press);
   event = gtk_gesture_get_last_event (gesture, sequence);
 
+  if (!event)
+    return;
+
   switch (event->type)
     {
     case GDK_BUTTON_PRESS:
       button = event->button.button;
       /* Fall through */
     case GDK_TOUCH_BEGIN:
-      /* Ignore buttons we don't care about */
-      if (priv->button != 0 && button != priv->button)
-        break;
-
       /* Reset the gesture if the button number changes mid-recognition */
       if (priv->n_presses > 0 &&
           priv->current_button != button)
-        gtk_gesture_multi_press_reset (multi_press);
+        _gtk_gesture_multi_press_stop (multi_press);
 
       priv->current_button = button;
       _gtk_gesture_multi_press_update_timeout (multi_press);
       gtk_gesture_get_point (gesture, sequence, &x, &y);
 
       if (!_gtk_gesture_multi_press_check_within_threshold (multi_press, x, y))
-        gtk_gesture_multi_press_reset (multi_press);
+        _gtk_gesture_multi_press_stop (multi_press);
 
       /* Increment later the real counter, just if the gesture is
        * reset on the pressed handler */
@@ -319,86 +285,6 @@ gtk_gesture_multi_press_new (GtkWidget *widget)
 }
 
 /**
- * gtk_gesture_multi_press_reset:
- * @gesture: a #GtkGestureMultiPress
- *
- * Resets the gesture, so the press count is reset to 0.
- *
- * Note: If this happens within a #GtkGestureMultiPress::pressed handler,
- * the button press being currently handled will still increment the press
- * counter, so a subsequent press would count as the second press.
- *
- * Since: 3.14
- **/
-void
-gtk_gesture_multi_press_reset (GtkGestureMultiPress *gesture)
-{
-  GtkGestureMultiPressPrivate *priv;
-
-  g_return_if_fail (GTK_IS_GESTURE (gesture));
-
-  priv = gtk_gesture_multi_press_get_instance_private (gesture);
-
-  if (priv->n_presses != 0)
-    g_signal_emit (gesture, signals[STOPPED], 0);
-
-  priv->current_button = 0;
-  priv->n_presses = 0;
-  gtk_gesture_check (GTK_GESTURE (gesture));
-}
-
-/**
- * gtk_gesture_multi_press_set_button:
- * @gesture: a #GtkGestureMultiPress
- * @button: button number to listen to, or 0 for any button
- *
- * Sets the button number @gesture listens to. If non-0, every
- * button press from a different button number will be ignored.
- * Touch events implicitly match with button 1.
- *
- * Since: 3.14
- **/
-void
-gtk_gesture_multi_press_set_button (GtkGestureMultiPress *gesture,
-                                    guint                 button)
-{
-  GtkGestureMultiPressPrivate *priv;
-
-  g_return_if_fail (GTK_IS_GESTURE_MULTI_PRESS (gesture));
-
-  priv = gtk_gesture_multi_press_get_instance_private (gesture);
-
-  if (priv->button == button)
-    return;
-
-  priv->button = button;
-  g_object_notify (G_OBJECT (gesture), "button");
-}
-
-/**
- * gtk_gesture_multi_press_get_button:
- * @gesture: a #GtkgestureMultiPress
- *
- * Returns the button number @gesture listens for, or 0 if @gesture
- * reacts to any button press.
- *
- * Returns: The button number, or 0 for any button.
- *
- * Since: 3.14
- **/
-guint
-gtk_gesture_multi_press_get_button (GtkGestureMultiPress *gesture)
-{
-  GtkGestureMultiPressPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_GESTURE_MULTI_PRESS (gesture), 0);
-
-  priv = gtk_gesture_multi_press_get_instance_private (gesture);
-
-  return priv->button;
-}
-
-/**
  * gtk_gesture_multi_press_set_area:
  * @gesture: a #GtkGesture
  * @rect: (allow-none): rectangle to receive coordinates on.
diff --git a/gtk/gtkgesturemultipress.h b/gtk/gtkgesturemultipress.h
index f95f568..31c8b75 100644
--- a/gtk/gtkgesturemultipress.h
+++ b/gtk/gtkgesturemultipress.h
@@ -24,7 +24,7 @@
 #endif
 
 #include <gtk/gtkwidget.h>
-#include <gtk/gtkgesture.h>
+#include <gtk/gtkgesturesingle.h>
 
 G_BEGIN_DECLS
 
@@ -40,12 +40,12 @@ typedef struct _GtkGestureMultiPressClass GtkGestureMultiPressClass;
 
 struct _GtkGestureMultiPress
 {
-  GtkGesture parent_instance;
+  GtkGestureSingle parent_instance;
 };
 
 struct _GtkGestureMultiPressClass
 {
-  GtkGestureClass parent_class;
+  GtkGestureSingleClass parent_class;
 
   gboolean (* pressed) (GtkGestureMultiPress *gesture,
                         gint                  n_press,
@@ -65,15 +65,6 @@ GDK_AVAILABLE_IN_3_14
 GtkGesture * gtk_gesture_multi_press_new      (GtkWidget            *widget);
 
 GDK_AVAILABLE_IN_3_14
-void         gtk_gesture_multi_press_reset    (GtkGestureMultiPress *gesture);
-
-GDK_AVAILABLE_IN_3_14
-void         gtk_gesture_multi_press_set_button (GtkGestureMultiPress *gesture,
-                                                 guint                 button);
-GDK_AVAILABLE_IN_3_14
-guint        gtk_gesture_multi_press_get_button (GtkGestureMultiPress *gesture);
-
-GDK_AVAILABLE_IN_3_14
 void         gtk_gesture_multi_press_set_area (GtkGestureMultiPress *gesture,
                                               const GdkRectangle   *rect);
 GDK_AVAILABLE_IN_3_14


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