summaryrefslogtreecommitdiff
path: root/gtk/gtkgesturelongpress.c
diff options
context:
space:
mode:
authorCarlos Garnacho <carlosg@gnome.org>2014-03-21 18:57:32 +0100
committerCarlos Garnacho <carlosg@gnome.org>2014-05-23 19:54:23 +0200
commit3db87cb0b7a195edc3cda0cb8c8dabf18348f9ab (patch)
treeb32dc5cf7767e0986e3281da8dc9b6acc8e937b7 /gtk/gtkgesturelongpress.c
parent5f24d1a51943c1c066e47e5a9144520d242827cb (diff)
downloadgtk+-3db87cb0b7a195edc3cda0cb8c8dabf18348f9ab.tar.gz
longpress: Make a subclass of GtkGestureSingle
the redundant API here has been removed.
Diffstat (limited to 'gtk/gtkgesturelongpress.c')
-rw-r--r--gtk/gtkgesturelongpress.c136
1 files changed, 22 insertions, 114 deletions
diff --git a/gtk/gtkgesturelongpress.c b/gtk/gtkgesturelongpress.c
index 76143fb21e..7c67fc1548 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;
-}