From 759705d3e67d4bcb85fbcc2c2244a3505a0fd78c Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Tue, 8 Apr 2014 20:25:53 +0200 Subject: eventcontroller: Add propagation-phase property This is so we don't have to specify the capture phase for every controller. The default "bubble" value will be sane on most situations. --- gtk/gtkeventcontroller.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 65 insertions(+), 1 deletion(-) (limited to 'gtk/gtkeventcontroller.c') diff --git a/gtk/gtkeventcontroller.c b/gtk/gtkeventcontroller.c index cf891524ea..a4d294d244 100644 --- a/gtk/gtkeventcontroller.c +++ b/gtk/gtkeventcontroller.c @@ -19,6 +19,7 @@ */ #include "config.h" #include +#include "gtktypebuiltins.h" #include "gtkmarshalers.h" #include "gtkprivate.h" #include "gtkintl.h" @@ -27,7 +28,8 @@ typedef struct _GtkEventControllerPrivate GtkEventControllerPrivate; enum { PROP_WIDGET = 1, - PROP_EVENT_MASK + PROP_EVENT_MASK, + PROP_PROPAGATION_PHASE }; enum { @@ -40,6 +42,7 @@ struct _GtkEventControllerPrivate { GtkWidget *widget; guint evmask; + guint propagation_phase : 2; }; guint signals[N_SIGNALS] = { 0 }; @@ -125,6 +128,13 @@ gtk_event_controller_class_init (GtkEventControllerClass *klass) P_("Event mask the controller handles"), GDK_TYPE_EVENT_MASK, 0, GTK_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_PROPAGATION_PHASE, + g_param_spec_enum ("propagation-phase", + P_("Propagation phase"), + P_("Phase in event propagation where this controller handles events"), + GTK_TYPE_PROPAGATION_PHASE, GTK_PHASE_BUBBLE, + GTK_PARAM_READWRITE)); signals[HANDLE_EVENT] = g_signal_new ("handle-event", G_TYPE_FROM_CLASS (klass), @@ -145,6 +155,10 @@ gtk_event_controller_class_init (GtkEventControllerClass *klass) static void gtk_event_controller_init (GtkEventController *controller) { + GtkEventControllerPrivate *priv; + + priv = gtk_event_controller_get_instance_private (controller); + priv->propagation_phase = GTK_PHASE_BUBBLE; } /** @@ -263,3 +277,53 @@ gtk_event_controller_reset (GtkEventController *controller) g_signal_emit (controller, signals[RESET], 0); } + +/** + * gtk_event_controller_get_propagation_phase: + * @controller: a #GtkEventController + * + * Gets the propagation phase at which this @controller is run. + * + * Returns: The propagation phase + * + * Since: 3.14 + **/ +GtkPropagationPhase +gtk_event_controller_get_propagation_phase (GtkEventController *controller) +{ + GtkEventControllerPrivate *priv; + + g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER (controller), GTK_PHASE_NONE); + + priv = gtk_event_controller_get_instance_private (controller); + + return priv->propagation_phase; +} + +/** + * gtk_event_controller_set_propagation_phase: + * @controller: a #GtkEventController + * @phase: the propagation phase + * + * Sets the propagation phase at which this @controller is run. Note that + * event controllers are run before the regular #GtkWidget::event handler. + * + * Since: 3.14 + **/ +void +gtk_event_controller_set_propagation_phase (GtkEventController *controller, + GtkPropagationPhase phase) +{ + GtkEventControllerPrivate *priv; + + g_return_if_fail (GTK_IS_EVENT_CONTROLLER (controller)); + g_return_if_fail (phase >= GTK_PHASE_NONE && phase <= GTK_PHASE_CAPTURE); + + priv = gtk_event_controller_get_instance_private (controller); + + if (priv->propagation_phase == phase) + return; + + priv->propagation_phase = phase; + g_object_notify (G_OBJECT (controller), "propagation-phase"); +} -- cgit v1.2.1