[gtk+/gestures: 40/173] widget: Make helper gesture API take GtkGestures
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gestures: 40/173] widget: Make helper gesture API take GtkGestures
- Date: Fri, 16 May 2014 17:03:45 +0000 (UTC)
commit c51fca8b0ebee0813577c560574485d630140f83
Author: Carlos Garnacho <carlosg gnome org>
Date: Mon Mar 24 14:35:17 2014 +0100
widget: Make helper gesture API take GtkGestures
GtkEventController may be certainly useful to keep event
handling self-contained in other places than gestures, but
the current widget API is highly related to gestures, so
just using GtkGesture as the argument there will be quite
more convenient. The other places where GtkEventController
make sense as a base object will better provide their own
hooks.
gtk/gtkwidget.c | 99 ++++++++++++++++++++++++++----------------------------
gtk/gtkwidget.h | 12 +++---
2 files changed, 54 insertions(+), 57 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index e029c22..6efd31f 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -398,7 +398,7 @@ typedef struct {
} GtkWidgetTemplate;
typedef struct {
- GtkEventController *controller;
+ GtkGesture *controller;
guint evmask_notify_id;
guint propagation_phase : 2;
} EventControllerData;
@@ -7129,7 +7129,7 @@ _gtk_widget_get_controllers_evmask (GtkWidget *widget)
for (l = priv->event_controllers; l; l = l->next)
{
data = l->data;
- evmask |= gtk_event_controller_get_event_mask (data->controller);
+ evmask |= gtk_event_controller_get_event_mask (GTK_EVENT_CONTROLLER (data->controller));
}
return evmask;
@@ -7152,7 +7152,8 @@ _gtk_widget_run_controllers (GtkWidget *widget,
data = l->data;
if (data->propagation_phase == phase)
- handled |= gtk_event_controller_handle_event (data->controller, event);
+ handled |= gtk_event_controller_handle_event (GTK_EVENT_CONTROLLER (data->controller),
+ event);
}
return handled;
@@ -11858,7 +11859,7 @@ gtk_widget_finalize (GObject *object)
while (priv->event_controllers)
{
data = priv->event_controllers->data;
- gtk_widget_remove_controller (widget, data->controller);
+ gtk_widget_remove_gesture (widget, data->controller);
}
if (g_object_is_floating (object))
@@ -16532,75 +16533,82 @@ event_controller_notify_event_mask (GtkEventController *controller,
gtk_widget_add_events_internal (widget, NULL, evmask);
}
-void
-gtk_widget_add_controller (GtkWidget *widget,
- GtkEventController *controller,
- GtkPropagationPhase phase)
+EventControllerData *
+_gtk_widget_has_gesture (GtkWidget *widget,
+ GtkGesture *gesture)
{
EventControllerData *data;
GtkWidgetPrivate *priv;
GList *l;
- g_return_if_fail (GTK_IS_WIDGET (widget));
- g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
- g_return_if_fail (phase >= GTK_PHASE_NONE &&
- phase <= GTK_PHASE_BUBBLE);
-
priv = widget->priv;
for (l = priv->event_controllers; l; l = l->next)
{
data = l->data;
+ if (data->controller == gesture)
+ return data;
+ }
- if (data->controller != controller)
- continue;
+ return NULL;
+}
- data->propagation_phase = phase;
- return;
- }
+void
+gtk_widget_add_gesture (GtkWidget *widget,
+ GtkGesture *gesture,
+ GtkPropagationPhase phase)
+{
+ EventControllerData *data;
+ GtkWidgetPrivate *priv;
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (GTK_IS_GESTURE (gesture));
+ g_return_if_fail (phase >= GTK_PHASE_NONE &&
+ phase <= GTK_PHASE_BUBBLE);
+ g_return_if_fail (!_gtk_widget_has_gesture (widget, gesture));
+
+ priv = widget->priv;
data = g_new0 (EventControllerData, 1);
- data->controller = g_object_ref (controller);
+ data->controller = g_object_ref (gesture);
data->propagation_phase = phase;
data->evmask_notify_id =
- g_signal_connect (controller, "notify::event-mask",
+ g_signal_connect (gesture, "notify::event-mask",
G_CALLBACK (event_controller_notify_event_mask), widget);
priv->event_controllers = g_list_prepend (priv->event_controllers, data);
}
void
-gtk_widget_remove_controller (GtkWidget *widget,
- GtkEventController *controller)
+gtk_widget_remove_gesture (GtkWidget *widget,
+ GtkGesture *gesture)
{
EventControllerData *data;
GtkWidgetPrivate *priv;
- GList *l;
g_return_if_fail (GTK_IS_WIDGET (widget));
- g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller));
+ g_return_if_fail (GTK_IS_GESTURE (gesture));
priv = widget->priv;
+ data = _gtk_widget_has_gesture (widget, gesture);
- for (l = priv->event_controllers; l; l = l->next)
- {
- data = l->data;
+ if (!data)
+ return;
- if (data->controller != controller)
- continue;
+ priv->event_controllers = g_list_remove (priv->event_controllers, data);
- gtk_event_controller_reset (data->controller);
- g_signal_handler_disconnect (data->controller, data->evmask_notify_id);
- g_object_unref (data->controller);
- g_free (data);
- priv->event_controllers = g_list_delete_link (priv->event_controllers, l);
- return;
- }
+ if (g_signal_handler_is_connected (widget, data->grab_notify_id))
+ g_signal_handler_disconnect (widget, data->grab_notify_id);
+
+ g_signal_handler_disconnect (data->controller, data->evmask_notify_id);
+ gtk_event_controller_reset (GTK_EVENT_CONTROLLER (data->controller));
+ g_object_unref (data->controller);
+ g_free (data);
}
GList *
-gtk_widget_list_controllers (GtkWidget *widget,
- GtkPropagationPhase phase)
+gtk_widget_list_gestures (GtkWidget *widget,
+ GtkPropagationPhase phase)
{
EventControllerData *data;
GtkWidgetPrivate *priv;
@@ -16640,12 +16648,7 @@ gtk_widget_get_sequence_state (GtkWidget *widget,
for (l = priv->event_controllers; l; l = l->next)
{
data = l->data;
-
- if (!GTK_IS_GESTURE (data->controller))
- continue;
-
- state = gtk_gesture_get_sequence_state (GTK_GESTURE (data->controller),
- sequence);
+ state = gtk_gesture_get_sequence_state (data->controller, sequence);
if (state != GTK_EVENT_SEQUENCE_NONE)
return state;
}
@@ -16658,10 +16661,8 @@ gtk_widget_set_sequence_state (GtkWidget *widget,
GdkEventSequence *sequence,
GtkEventSequenceState state)
{
- EventControllerData *data;
gboolean handled = FALSE;
GtkWidget *event_widget;
- GtkWidgetPrivate *priv;
const GdkEvent *event;
g_return_if_fail (GTK_IS_WIDGET (widget));
@@ -16674,16 +16675,12 @@ gtk_widget_set_sequence_state (GtkWidget *widget,
if (!handled)
return;
- priv = widget->priv;
- data = priv->event_controllers->data;
- event = gtk_gesture_get_last_event (GTK_GESTURE (data->controller), sequence);
+ event = _gtk_widget_get_last_event (widget, sequence);
if (!event)
return;
event_widget = gtk_get_event_widget ((GdkEvent *) event);
- g_assert (widget == event_widget ||
- gtk_widget_is_ancestor (event_widget, widget));
while (event_widget)
{
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index c06fd41..bad8950 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -33,7 +33,7 @@
#include <gtk/gtkaccelgroup.h>
#include <gtk/gtkborder.h>
#include <gtk/gtktypes.h>
-#include <gtk/gtkeventcontroller.h>
+#include <gtk/gtkgesture.h>
#include <atk/atk.h>
G_BEGIN_DECLS
@@ -1471,14 +1471,14 @@ void gtk_widget_class_bind_template_child_full (GtkWidgetClass *
gssize struct_offset);
GDK_AVAILABLE_IN_3_14
-void gtk_widget_add_controller (GtkWidget *widget,
- GtkEventController *controller,
+void gtk_widget_add_gesture (GtkWidget *widget,
+ GtkGesture *gesture,
GtkPropagationPhase phase);
GDK_AVAILABLE_IN_3_14
-void gtk_widget_remove_controller (GtkWidget *widget,
- GtkEventController *controller);
+void gtk_widget_remove_gesture (GtkWidget *widget,
+ GtkGesture *gesture);
GDK_AVAILABLE_IN_3_14
-GList * gtk_widget_list_controllers (GtkWidget *widget,
+GList * gtk_widget_list_gestures (GtkWidget *widget,
GtkPropagationPhase phase);
GDK_AVAILABLE_IN_3_14
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]