[gtk+/gestures: 1/8] Add GtkEventController



commit 26189faa0c9a11d968e3005e35c5faf7a19421c0
Author: Carlos Garnacho <carlos lanedo com>
Date:   Thu Jan 17 20:55:24 2013 +0100

    Add GtkEventController
    
    This is a basic abstract type that handles GdkEvents.

 gtk/Makefile.am          |    2 +
 gtk/gtk.h                |    1 +
 gtk/gtkeventcontroller.c |   84 ++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkeventcontroller.h |   64 +++++++++++++++++++++++++++++++++++
 4 files changed, 151 insertions(+), 0 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 510021b..bb692ec 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -244,6 +244,7 @@ gtk_public_h_sources = 		\
 	gtkentrycompletion.h	\
 	gtkenums.h		\
 	gtkeventbox.h		\
+	gtkeventcontroller.h	\
 	gtkexpander.h		\
 	gtkfilechooser.h	\
 	gtkfilechooserbutton.h	\
@@ -707,6 +708,7 @@ gtk_base_c_sources = 		\
 	gtkentrybuffer.c	\
 	gtkentrycompletion.c	\
 	gtkeventbox.c		\
+	gtkeventcontroller.c	\
 	gtkexpander.c		\
 	gtkfilechooser.c	\
 	gtkfilechooserbutton.c	\
diff --git a/gtk/gtk.h b/gtk/gtk.h
index fbc06a3..27a61df 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -95,6 +95,7 @@
 #include <gtk/gtkentrycompletion.h>
 #include <gtk/gtkenums.h>
 #include <gtk/gtkeventbox.h>
+#include <gtk/gtkeventcontroller.h>
 #include <gtk/gtkexpander.h>
 #include <gtk/gtkfixed.h>
 #include <gtk/gtkfilechooser.h>
diff --git a/gtk/gtkeventcontroller.c b/gtk/gtkeventcontroller.c
new file mode 100644
index 0000000..e615bef
--- /dev/null
+++ b/gtk/gtkeventcontroller.c
@@ -0,0 +1,84 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2012, One Laptop Per Child.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): Carlos Garnacho <carlos lanedo com>
+ */
+#include <gtk/gtkeventcontroller.h>
+#include "gtkmarshalers.h"
+
+enum {
+  HANDLE_EVENT,
+  N_SIGNALS
+};
+
+guint signals[N_SIGNALS] = { 0 };
+
+G_DEFINE_ABSTRACT_TYPE (GtkEventController, gtk_event_controller, G_TYPE_OBJECT)
+
+static gboolean
+gtk_event_controller_handle_event_default (GtkEventController *controller,
+                                           GdkEvent           *event)
+{
+  return FALSE;
+}
+
+static void
+gtk_event_controller_class_init (GtkEventControllerClass *klass)
+{
+  klass->handle_event = gtk_event_controller_handle_event_default;
+
+  signals[HANDLE_EVENT] =
+    g_signal_new ("handle-event",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+                  G_STRUCT_OFFSET (GtkEventControllerClass, handle_event),
+                  g_signal_accumulator_true_handled, NULL,
+                  _gtk_marshal_BOOLEAN__BOXED,
+                  G_TYPE_BOOLEAN, 1,
+                  GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
+}
+
+static void
+gtk_event_controller_init (GtkEventController *controller)
+{
+}
+
+/**
+ * gtk_event_controller_handle_event:
+ * @controller: a #GtkEventController
+ * @event: a #GdkEvent
+ *
+ * Feeds an events into @controller, so it can be interpreted
+ * and the controller actions triggered.
+ *
+ * Returns: %TRUE if the event was potentially useful to construct
+ *          a gesture.
+ *
+ * Since: 3.8
+ **/
+gboolean
+gtk_event_controller_handle_event (GtkEventController *controller,
+                                   GdkEvent           *event)
+{
+  gboolean retval;
+
+  g_return_val_if_fail (GTK_IS_EVENT_CONTROLLER (controller), FALSE);
+  g_return_val_if_fail (event != NULL, FALSE);
+
+  g_signal_emit (controller, signals[HANDLE_EVENT], 0, event, &retval);
+
+  return retval;
+}
diff --git a/gtk/gtkeventcontroller.h b/gtk/gtkeventcontroller.h
new file mode 100644
index 0000000..56e2ab4
--- /dev/null
+++ b/gtk/gtkeventcontroller.h
@@ -0,0 +1,64 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2012, One Laptop Per Child.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author(s): Carlos Garnacho <carlos lanedo com>
+ */
+#ifndef __GTK_EVENT_CONTROLLER_H__
+#define __GTK_EVENT_CONTROLLER_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gdk/gdk.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_EVENT_CONTROLLER         (gtk_event_controller_get_type ())
+#define GTK_EVENT_CONTROLLER(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_EVENT_CONTROLLER, GtkEventController))
+#define GTK_EVENT_CONTROLLER_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_EVENT_CONTROLLER, GtkEventControllerClass))
+#define GTK_IS_EVENT_CONTROLLER(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_EVENT_CONTROLLER))
+#define GTK_IS_EVENT_CONTROLLER_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_EVENT_CONTROLLER))
+#define GTK_EVENT_CONTROLLER_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_EVENT_CONTROLLER, GtkEventControllerClass))
+
+typedef struct _GtkEventController GtkEventController;
+typedef struct _GtkEventControllerClass GtkEventControllerClass;
+typedef struct _GtkEventControllerPriv GtkEventControllerPriv;
+
+struct _GtkEventController
+{
+  GObject parent_instance;
+
+  /*< private >*/
+  GtkEventControllerPriv *_priv;
+};
+
+struct _GtkEventControllerClass
+{
+  GObjectClass parent_class;
+
+  gboolean (* handle_event) (GtkEventController *controller,
+                             GdkEvent           *event);
+};
+
+GType     gtk_event_controller_get_type     (void) G_GNUC_CONST;
+
+gboolean  gtk_event_controller_handle_event (GtkEventController *controller,
+                                             GdkEvent           *event);
+
+G_END_DECLS
+
+#endif /* __GTK_EVENT_CONTROLLER_H__ */



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