[gtk+/gestures: 63/92] eventcontroller: Add propagation-phase property



commit b4dd1053f410a5b7a8e54c58b769afaa88167e6a
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue Apr 8 20:25:53 2014 +0200

    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 +++++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkeventcontroller.h |    9 ++++++
 2 files changed, 74 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkeventcontroller.c b/gtk/gtkeventcontroller.c
index cf89152..a4d294d 100644
--- a/gtk/gtkeventcontroller.c
+++ b/gtk/gtkeventcontroller.c
@@ -19,6 +19,7 @@
  */
 #include "config.h"
 #include <gtk/gtkeventcontroller.h>
+#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");
+}
diff --git a/gtk/gtkeventcontroller.h b/gtk/gtkeventcontroller.h
index 12c5d2a..bbefe1b 100644
--- a/gtk/gtkeventcontroller.h
+++ b/gtk/gtkeventcontroller.h
@@ -29,6 +29,7 @@ typedef struct _GtkEventControllerClass GtkEventControllerClass;
 
 #include <gdk/gdk.h>
 #include <gtk/gtktypes.h>
+#include <gtk/gtkenums.h>
 
 G_BEGIN_DECLS
 
@@ -74,6 +75,14 @@ gboolean     gtk_event_controller_handle_event   (GtkEventController *controller
 GDK_AVAILABLE_IN_3_14
 void         gtk_event_controller_reset          (GtkEventController *controller);
 
+GDK_AVAILABLE_IN_3_14
+GtkPropagationPhase
+             gtk_event_controller_get_propagation_phase (GtkEventController *controller);
+
+GDK_AVAILABLE_IN_3_14
+void         gtk_event_controller_set_propagation_phase (GtkEventController  *controller,
+                                                         GtkPropagationPhase  phase);
+
 G_END_DECLS
 
 #endif /* __GTK_EVENT_CONTROLLER_H__ */


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