[gtk+/touch-for-3.4] Keep the capture phase private for now
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/touch-for-3.4] Keep the capture phase private for now
- Date: Sat, 25 Feb 2012 18:57:07 +0000 (UTC)
commit 4d01e5cb2d8551fd603a75820e6b7da663e2e5fa
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 25 11:38:06 2012 -0500
Keep the capture phase private for now
Instead of a public ::captured-event signal, use a private
api to register handlers for the capture phase. Use this in
GtkScrolledWindow, GtkMenu and GtkPaned.
gtk/gtkmenu.c | 4 +++-
gtk/gtkpaned.c | 6 ++++--
gtk/gtkscrolledwindow.c | 27 ++++++---------------------
gtk/gtkwidget.c | 46 +++++++++++++---------------------------------
gtk/gtkwidget.h | 3 ---
gtk/gtkwidgetprivate.h | 4 ++++
6 files changed, 30 insertions(+), 60 deletions(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 3f0d40d..98e1407 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -113,6 +113,7 @@
#include "gtkdnd.h"
#include "gtkintl.h"
#include "gtktypebuiltins.h"
+#include "gtkwidgetprivate.h"
#include "deprecated/gtktearoffmenuitem.h"
@@ -512,7 +513,6 @@ gtk_menu_class_init (GtkMenuClass *class)
widget_class->get_preferred_width = gtk_menu_get_preferred_width;
widget_class->get_preferred_height = gtk_menu_get_preferred_height;
widget_class->get_preferred_height_for_width = gtk_menu_get_preferred_height_for_width;
- widget_class->captured_event = gtk_menu_captured_event;
container_class->remove = gtk_menu_remove;
container_class->get_child_property = gtk_menu_get_child_property;
@@ -1064,6 +1064,8 @@ gtk_menu_init (GtkMenu *menu)
context = gtk_widget_get_style_context (GTK_WIDGET (menu));
gtk_style_context_add_class (context, GTK_STYLE_CLASS_MENU);
+
+ _gtk_widget_set_captured_event_handler (GTK_WIDGET (menu), gtk_menu_captured_event);
}
static void
diff --git a/gtk/gtkpaned.c b/gtk/gtkpaned.c
index 732890c..4eb5a56 100644
--- a/gtk/gtkpaned.c
+++ b/gtk/gtkpaned.c
@@ -37,6 +37,7 @@
#include "gtkprivate.h"
#include "gtkintl.h"
#include "gtkdnd.h"
+#include "gtkwidgetprivate.h"
#include "a11y/gtkpanedaccessible.h"
/**
@@ -338,7 +339,6 @@ gtk_paned_class_init (GtkPanedClass *class)
widget_class->grab_broken_event = gtk_paned_grab_broken;
widget_class->grab_notify = gtk_paned_grab_notify;
widget_class->state_flags_changed = gtk_paned_state_flags_changed;
- widget_class->captured_event = gtk_paned_captured_event;
container_class->add = gtk_paned_add;
container_class->remove = gtk_paned_remove;
@@ -728,6 +728,8 @@ gtk_paned_init (GtkPaned *paned)
priv->touches = g_array_sized_new (FALSE, FALSE,
sizeof (TouchInfo), 2);
+
+ _gtk_widget_set_captured_event_handler (GTK_WIDGET (paned), gtk_paned_captured_event);
}
static void
@@ -1894,7 +1896,7 @@ gtk_paned_release_captured_event (GtkPaned *paned,
static gboolean
gtk_paned_captured_event (GtkWidget *widget,
- GdkEvent *event)
+ GdkEvent *event)
{
GtkPaned *paned = GTK_PANED (widget);
GtkPanedPrivate *priv = paned->priv;
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 1ac0314..2315f4f 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -41,6 +41,7 @@
#include "gtktypebuiltins.h"
#include "gtkintl.h"
#include "gtkviewport.h"
+#include "gtkwidgetprivate.h"
#include "a11y/gtkscrolledwindowaccessible.h"
/**
@@ -159,7 +160,6 @@ struct _GtkScrolledWindowPrivate
guint capture_button_press : 1;
guint in_drag : 1;
guint last_button_event_valid : 1;
- guint captured_event_id;
guint release_timeout_id;
guint deceleration_id;
@@ -230,8 +230,7 @@ static void gtk_scrolled_window_size_allocate (GtkWidget *widge
static gboolean gtk_scrolled_window_scroll_event (GtkWidget *widget,
GdkEventScroll *event);
static gboolean gtk_scrolled_window_captured_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data);
+ GdkEvent *event);
static gboolean gtk_scrolled_window_focus (GtkWidget *widget,
GtkDirectionType direction);
static void gtk_scrolled_window_add (GtkContainer *container,
@@ -1132,18 +1131,12 @@ gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window,
priv->kinetic_scrolling = kinetic_scrolling;
if (priv->kinetic_scrolling)
{
- priv->captured_event_id =
- g_signal_connect (scrolled_window, "captured-event",
- G_CALLBACK (gtk_scrolled_window_captured_event),
- NULL);
+ _gtk_widget_set_captured_event_handler (GTK_WIDGET (scrolled_window),
+ gtk_scrolled_window_captured_event);
}
else
{
- if (priv->captured_event_id > 0)
- {
- g_signal_handler_disconnect (scrolled_window, priv->captured_event_id);
- priv->captured_event_id = 0;
- }
+ _gtk_widget_set_captured_event_handler (GTK_WIDGET (scrolled_window), NULL);
if (priv->release_timeout_id)
{
g_source_remove (priv->release_timeout_id);
@@ -1171,8 +1164,6 @@ gtk_scrolled_window_set_kinetic_scrolling (GtkScrolledWindow *scrolled_window,
gboolean
gtk_scrolled_window_get_kinetic_scrolling (GtkScrolledWindow *scrolled_window)
{
- GtkScrolledWindowPrivate *priv;
-
g_return_val_if_fail (GTK_IS_SCROLLED_WINDOW (scrolled_window), FALSE);
return scrolled_window->priv->kinetic_scrolling;
@@ -1223,11 +1214,6 @@ gtk_scrolled_window_destroy (GtkWidget *widget)
priv->vscrollbar = NULL;
}
- if (priv->captured_event_id > 0)
- {
- g_signal_handler_disconnect (scrolled_window, priv->captured_event_id);
- priv->captured_event_id = 0;
- }
if (priv->release_timeout_id)
{
g_source_remove (priv->release_timeout_id);
@@ -2752,8 +2738,7 @@ gtk_scrolled_window_captured_button_press (GtkWidget *widget,
static gboolean
gtk_scrolled_window_captured_event (GtkWidget *widget,
- GdkEvent *event,
- gpointer user_data)
+ GdkEvent *event)
{
gboolean retval = FALSE;
GtkScrolledWindowPrivate *priv = GTK_SCROLLED_WINDOW (widget)->priv;
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index e477a24..1393109 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -484,7 +484,6 @@ enum {
QUERY_TOOLTIP,
DRAG_FAILED,
STYLE_UPDATED,
- CAPTURED_EVENT,
TOUCH_EVENT,
LAST_SIGNAL
};
@@ -1801,9 +1800,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
* #GtkWidget::key-press-event) and finally a generic
* #GtkWidget::event-after signal.
*
- * An event can be captured before ::event signal is emitted by connecting to
- * ::captured-event event signal.
- *
* Returns: %TRUE to stop other handlers from being invoked for the event
* and to cancel the emission of the second specific ::event signal.
* %FALSE to propagate the event further and to allow the emission of
@@ -1841,34 +1837,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
/**
- * GtkWidget::captured-event:
- * @widget: the object which received the signal.
- * @event: the #GdkEvent which triggered this signal
- *
- * The #GtkWidget::captured-event signal is emitted before the
- * #GtkWidget::event signal to allow capturing an event before the
- * specialized events are emitted. The event is propagated starting
- * from the top-level container to the widget that received the event
- * going down the hierarchy.
- *
- * Returns: %TRUE to stop other handlers from being invoked for the event
- * and to cancel the emission of the ::event signal.
- * %FALSE to propagate the event further and to allow the emission of
- * the ::event signal.
- *
- * Since: 3.2
- */
- widget_signals[CAPTURED_EVENT] =
- g_signal_new (I_("captured-event"),
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GtkWidgetClass, captured_event),
- _gtk_boolean_handled_accumulator, NULL,
- _gtk_marshal_BOOLEAN__BOXED,
- G_TYPE_BOOLEAN, 1,
- GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
-
- /**
* GtkWidget::button-press-event:
* @widget: the object which received the signal.
* @event: (type Gdk.EventButton): the #GdkEventButton which triggered
@@ -5913,11 +5881,19 @@ gtk_widget_event (GtkWidget *widget,
return gtk_widget_event_internal (widget, event);
}
+void
+_gtk_widget_set_captured_event_handler (GtkWidget *widget,
+ GtkCapturedEventHandler callback)
+{
+ g_object_set_data (G_OBJECT (widget), "captured-event-handler", callback);
+}
+
gboolean
_gtk_widget_captured_event (GtkWidget *widget,
GdkEvent *event)
{
gboolean return_val = FALSE;
+ GtkCapturedEventHandler handler;
g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
@@ -5933,9 +5909,13 @@ _gtk_widget_captured_event (GtkWidget *widget,
if (!event_window_is_still_viewable (event))
return TRUE;
+ handler = g_object_get_data (G_OBJECT (widget), "captured-event-handler");
+ if (!handler)
+ return FALSE;
+
g_object_ref (widget);
- g_signal_emit (widget, widget_signals[CAPTURED_EVENT], 0, event, &return_val);
+ return_val = handler (widget, event);
return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
/* The widget that was originally to receive the event
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 442679b..7910ea2 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -425,9 +425,6 @@ struct _GtkWidgetClass
void (* style_updated) (GtkWidget *widget);
- gboolean (* captured_event) (GtkWidget *widget,
- GdkEvent *event);
-
gboolean (* touch_event) (GtkWidget *widget,
GdkEventTouch *event);
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index cbe659e..31ef1ff 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -167,6 +167,10 @@ GtkStyle * _gtk_widget_get_style (GtkWidget *widget);
void _gtk_widget_set_style (GtkWidget *widget,
GtkStyle *style);
+typedef gboolean (*GtkCapturedEventHandler) (GtkWidget *widget, GdkEvent *event);
+
+void _gtk_widget_set_captured_event_handler (GtkWidget *widget,
+ GtkCapturedEventHandler handler);
gboolean _gtk_widget_captured_event (GtkWidget *widget,
GdkEvent *event);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]