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.
This commit is contained in:
Carlos Garnacho 2014-04-08 20:25:53 +02:00
parent 2ed086748f
commit 759705d3e6
2 changed files with 74 additions and 1 deletions

View File

@ -19,6 +19,7 @@
*/ */
#include "config.h" #include "config.h"
#include <gtk/gtkeventcontroller.h> #include <gtk/gtkeventcontroller.h>
#include "gtktypebuiltins.h"
#include "gtkmarshalers.h" #include "gtkmarshalers.h"
#include "gtkprivate.h" #include "gtkprivate.h"
#include "gtkintl.h" #include "gtkintl.h"
@ -27,7 +28,8 @@ typedef struct _GtkEventControllerPrivate GtkEventControllerPrivate;
enum { enum {
PROP_WIDGET = 1, PROP_WIDGET = 1,
PROP_EVENT_MASK PROP_EVENT_MASK,
PROP_PROPAGATION_PHASE
}; };
enum { enum {
@ -40,6 +42,7 @@ struct _GtkEventControllerPrivate
{ {
GtkWidget *widget; GtkWidget *widget;
guint evmask; guint evmask;
guint propagation_phase : 2;
}; };
guint signals[N_SIGNALS] = { 0 }; guint signals[N_SIGNALS] = { 0 };
@ -125,6 +128,13 @@ gtk_event_controller_class_init (GtkEventControllerClass *klass)
P_("Event mask the controller handles"), P_("Event mask the controller handles"),
GDK_TYPE_EVENT_MASK, 0, GDK_TYPE_EVENT_MASK, 0,
GTK_PARAM_READWRITE)); 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] = signals[HANDLE_EVENT] =
g_signal_new ("handle-event", g_signal_new ("handle-event",
G_TYPE_FROM_CLASS (klass), G_TYPE_FROM_CLASS (klass),
@ -145,6 +155,10 @@ gtk_event_controller_class_init (GtkEventControllerClass *klass)
static void static void
gtk_event_controller_init (GtkEventController *controller) 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); 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");
}

View File

@ -29,6 +29,7 @@ typedef struct _GtkEventControllerClass GtkEventControllerClass;
#include <gdk/gdk.h> #include <gdk/gdk.h>
#include <gtk/gtktypes.h> #include <gtk/gtktypes.h>
#include <gtk/gtkenums.h>
G_BEGIN_DECLS G_BEGIN_DECLS
@ -74,6 +75,14 @@ gboolean gtk_event_controller_handle_event (GtkEventController *controller
GDK_AVAILABLE_IN_3_14 GDK_AVAILABLE_IN_3_14
void gtk_event_controller_reset (GtkEventController *controller); 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 G_END_DECLS
#endif /* __GTK_EVENT_CONTROLLER_H__ */ #endif /* __GTK_EVENT_CONTROLLER_H__ */