[gtk+/gestures: 33/117] longpress: Make a subclass of GtkGestureSingle
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gestures: 33/117] longpress: Make a subclass of GtkGestureSingle
- Date: Thu, 10 Apr 2014 20:27:28 +0000 (UTC)
commit d9c0729838c75e1d3ea8cbbabf3e2a941daf73ae
Author: Carlos Garnacho <carlosg gnome org>
Date: Fri Mar 21 18:57:32 2014 +0100
longpress: Make a subclass of GtkGestureSingle
the redundant API here has been removed.
gtk/gtkgesturelongpress.c | 136 +++++++-------------------------------------
gtk/gtkgesturelongpress.h | 12 +---
2 files changed, 25 insertions(+), 123 deletions(-)
---
diff --git a/gtk/gtkgesturelongpress.c b/gtk/gtkgesturelongpress.c
index 76143fb..7c67fc1 100644
--- a/gtk/gtkgesturelongpress.c
+++ b/gtk/gtkgesturelongpress.c
@@ -29,10 +29,6 @@
typedef struct _GtkGestureLongPressPrivate GtkGestureLongPressPrivate;
enum {
- PROP_BUTTON = 1
-};
-
-enum {
PRESSED,
CANCELLED,
N_SIGNALS
@@ -43,7 +39,6 @@ struct _GtkGestureLongPressPrivate
gdouble initial_x;
gdouble initial_y;
- guint button;
guint timeout_id;
guint delay;
guint cancelled : 1;
@@ -52,7 +47,7 @@ struct _GtkGestureLongPressPrivate
static guint signals[N_SIGNALS] = { 0 };
-G_DEFINE_TYPE_WITH_PRIVATE (GtkGestureLongPress, gtk_gesture_long_press, GTK_TYPE_GESTURE)
+G_DEFINE_TYPE_WITH_PRIVATE (GtkGestureLongPress, gtk_gesture_long_press, GTK_TYPE_GESTURE_SINGLE)
static void
gtk_gesture_long_press_init (GtkGestureLongPress *gesture)
@@ -96,20 +91,15 @@ gtk_gesture_long_press_begin (GtkGesture *gesture,
GdkEventSequence *sequence)
{
GtkGestureLongPressPrivate *priv;
- GdkEvent *event;
- guint button;
+ const GdkEvent *event;
priv = gtk_gesture_long_press_get_instance_private (GTK_GESTURE_LONG_PRESS (gesture));
+ sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
event = gtk_gesture_get_last_event (gesture, sequence);
- if (event->type == GDK_BUTTON_PRESS)
- button = event->button.button;
- else if (event->type == GDK_TOUCH_BEGIN)
- button = 1;
- else
- return;
-
- if (priv->button != 0 && priv->button != button)
+ if (!event ||
+ (event->type != GDK_BUTTON_PRESS &&
+ event->type != GDK_TOUCH_BEGIN))
return;
gtk_gesture_get_point (gesture, sequence,
@@ -165,57 +155,32 @@ gtk_gesture_long_press_end (GtkGesture *gesture,
}
static void
-gtk_gesture_long_press_finalize (GObject *object)
+gtk_gesture_long_press_sequence_state_changed (GtkGesture *gesture,
+ GdkEventSequence *sequence,
+ GtkEventSequenceState state)
{
GtkGestureLongPressPrivate *priv;
- priv = gtk_gesture_long_press_get_instance_private (GTK_GESTURE_LONG_PRESS (object));
-
- if (priv->timeout_id)
- g_source_remove (priv->timeout_id);
-
- G_OBJECT_CLASS (gtk_gesture_long_press_parent_class)->finalize (object);
-}
+ priv = gtk_gesture_long_press_get_instance_private (GTK_GESTURE_LONG_PRESS (gesture));
-static void
-gtk_gesture_long_press_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- switch (prop_id)
+ if (state == GTK_EVENT_SEQUENCE_DENIED)
{
- case PROP_BUTTON:
- gtk_gesture_long_press_set_button (GTK_GESTURE_LONG_PRESS (object),
- g_value_get_uint (value));
- break;
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
+ gtk_gesture_long_press_end (gesture, sequence);
+ priv->cancelled = TRUE;
}
}
static void
-gtk_gesture_long_press_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+gtk_gesture_long_press_finalize (GObject *object)
{
GtkGestureLongPressPrivate *priv;
- GtkGestureLongPress *gesture;
- gesture = GTK_GESTURE_LONG_PRESS (object);
- priv = gtk_gesture_long_press_get_instance_private (gesture);
+ priv = gtk_gesture_long_press_get_instance_private (GTK_GESTURE_LONG_PRESS (object));
- 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;
- }
+ if (priv->timeout_id)
+ g_source_remove (priv->timeout_id);
+
+ G_OBJECT_CLASS (gtk_gesture_long_press_parent_class)->finalize (object);
}
static void
@@ -225,21 +190,15 @@ gtk_gesture_long_press_class_init (GtkGestureLongPressClass *klass)
GtkGestureClass *gesture_class = GTK_GESTURE_CLASS (klass);
object_class->finalize = gtk_gesture_long_press_finalize;
- object_class->set_property = gtk_gesture_long_press_set_property;
- object_class->get_property = gtk_gesture_long_press_get_property;
gesture_class->check = gtk_gesture_long_press_check;
gesture_class->begin = gtk_gesture_long_press_begin;
gesture_class->update = gtk_gesture_long_press_update;
gesture_class->end = gtk_gesture_long_press_end;
+ gesture_class->cancel = gtk_gesture_long_press_end;
+ gesture_class->sequence_state_changed =
+ gtk_gesture_long_press_sequence_state_changed;
- g_object_class_install_property (object_class,
- PROP_BUTTON,
- g_param_spec_uint ("button",
- P_("Button number"),
- P_("Button number to listen to"),
- 0, G_MAXUINT, 0,
- GTK_PARAM_READWRITE));
signals[PRESSED] =
g_signal_new ("pressed",
G_TYPE_FROM_CLASS (klass),
@@ -273,54 +232,3 @@ gtk_gesture_long_press_new (GtkWidget *widget)
"widget", widget,
NULL);
}
-
-/**
- * gtk_gesture_long_press_set_button:
- * @gesture: a #GtkGestureLongPress
- * @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_long_press_set_button (GtkGestureLongPress *gesture,
- guint button)
-{
- GtkGestureLongPressPrivate *priv;
-
- g_return_if_fail (GTK_IS_GESTURE_LONG_PRESS (gesture));
-
- priv = gtk_gesture_long_press_get_instance_private (gesture);
-
- if (priv->button == button)
- return;
-
- priv->button = button;
- g_object_notify (G_OBJECT (gesture), "button");
-}
-
-/**
- * gtk_gesture_long_press_get_button:
- * @gesture: a #GtkGestureLongPress
- *
- * 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_long_press_get_button (GtkGestureLongPress *gesture)
-{
- GtkGestureLongPressPrivate *priv;
-
- g_return_val_if_fail (GTK_IS_GESTURE_LONG_PRESS (gesture), 0);
-
- priv = gtk_gesture_long_press_get_instance_private (gesture);
-
- return priv->button;
-}
diff --git a/gtk/gtkgesturelongpress.h b/gtk/gtkgesturelongpress.h
index 3560d36..d27f660 100644
--- a/gtk/gtkgesturelongpress.h
+++ b/gtk/gtkgesturelongpress.h
@@ -24,7 +24,7 @@
#error "Only <gtk/gtk.h> can be included directly."
#endif
-#include <gtk/gtkgesture.h>
+#include <gtk/gtkgesturesingle.h>
G_BEGIN_DECLS
@@ -40,12 +40,12 @@ typedef struct _GtkGestureLongPressClass GtkGestureLongPressClass;
struct _GtkGestureLongPress
{
- GtkGesture parent_instance;
+ GtkGestureSingle parent_instance;
};
struct _GtkGestureLongPressClass
{
- GtkGestureClass parent_class;
+ GtkGestureSingleClass parent_class;
void (* pressed) (GtkGestureLongPress *gesture,
gdouble x,
@@ -62,12 +62,6 @@ GType gtk_gesture_long_press_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_3_14
GtkGesture * gtk_gesture_long_press_new (GtkWidget *widget);
-GDK_AVAILABLE_IN_3_14
-void gtk_gesture_long_press_set_button (GtkGestureLongPress *gesture,
- guint button);
-GDK_AVAILABLE_IN_3_14
-guint gtk_gesture_long_press_get_button (GtkGestureLongPress *gesture);
-
G_END_DECLS
#endif /* __GTK_GESTURE_LONG_PRESS_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]