[gtk+/wip/events: 3/8] widget: Add API for adding recognizers



commit 9326bb66cda69bd34602e60e95c3cad8eb613edf
Author: Benjamin Otte <otte redhat com>
Date:   Sun Mar 4 02:06:19 2012 +0100

    widget: Add API for adding recognizers
    
    Apart from adding and removing them, nothing can be done with them.

 gtk/gtkwidget.c |  130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 gtk/gtkwidget.h |   10 ++++
 2 files changed, 139 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 23ab0d8..97387dd 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -411,6 +411,7 @@ struct _GtkWidgetClassPrivate
 {
   GType accessible_type;
   AtkRole accessible_role;
+  GPtrArray *recognizers;
 };
 
 enum {
@@ -792,8 +793,23 @@ static void
 gtk_widget_base_class_init (gpointer g_class)
 {
   GtkWidgetClass *klass = g_class;
+  GtkWidgetClassPrivate *priv;
+
+  priv = klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
 
-  klass->priv = G_TYPE_CLASS_GET_PRIVATE (g_class, GTK_TYPE_WIDGET, GtkWidgetClassPrivate);
+  if (priv->recognizers)
+    {
+      GPtrArray *copy;
+      guint i;
+      
+      copy = g_ptr_array_new_full (priv->recognizers->len, g_object_unref);
+      for (i = 0; i < priv->recognizers->len; i++)
+        {
+          g_ptr_array_add (copy, g_object_ref (g_ptr_array_index (priv->recognizers, i)));
+        }
+
+      priv->recognizers = copy;
+    }
 }
 
 static void
@@ -3203,8 +3219,15 @@ gtk_widget_class_init (GtkWidgetClass *klass)
 static void
 gtk_widget_base_class_finalize (GtkWidgetClass *klass)
 {
+  GtkWidgetClassPrivate *priv = klass->priv;
   GList *list, *node;
 
+  if (priv->recognizers)
+    {
+      g_ptr_array_free (priv->recognizers, TRUE);
+      priv->recognizers = NULL;
+    }
+
   list = g_param_spec_pool_list_owned (style_property_spec_pool, G_OBJECT_CLASS_TYPE (klass));
   for (node = list; node; node = node->next)
     {
@@ -13694,6 +13717,111 @@ gtk_widget_send_focus_change (GtkWidget *widget,
 }
 
 /**
+ * gtk_widget_class_add_recognizer:
+ * @widget_class: The widget class
+ * @recognizer: The recognizer to add
+ *
+ * Adds @recognizer to @widget_class. The @recognizer will be
+ * added at the end of the list of recognizers.
+ *
+ * After calling this function, the properties of @recognizer
+ * should not be modified anymore.
+ *
+ * This function should only be called in the class_init function
+ * of @widget_class.
+ **/
+void
+gtk_widget_class_add_recognizer (GtkWidgetClass     *widget_class,
+                                 GtkEventRecognizer *recognizer)
+{
+  GtkWidgetClassPrivate *priv;
+
+  g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
+  g_return_if_fail (GTK_IS_EVENT_RECOGNIZER (recognizer));
+
+  priv = widget_class->priv;
+
+  if (priv->recognizers == NULL)
+    priv->recognizers = g_ptr_array_new_with_free_func (g_object_unref);
+
+  g_object_ref (recognizer);
+  g_ptr_array_add (priv->recognizers, recognizer);
+}
+
+/**
+ * gtk_widget_class_remove_recognizer:
+ * @widget_class: The widget class to remove the recognizer from 
+ * @id: The index
+ *
+ * Removes the recognizer at @id from @idget_class.
+ *
+ * This function should only be called in the class_init function
+ * of @widget_class.
+ **/
+void
+gtk_widget_class_remove_recognizer (GtkWidgetClass     *widget_class,
+                                    guint               id)
+{
+  GtkWidgetClassPrivate *priv;
+
+  g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
+
+  priv = widget_class->priv;
+  g_return_if_fail (priv->recognizers != NULL);
+  g_return_if_fail (id < priv->recognizers->len);
+
+  g_ptr_array_remove_index (priv->recognizers, id);
+}
+
+/**
+ * gtk_widget_class_get_recognizer:
+ * @widget_class: The widget class
+ * @id: the index of the recognizer. Must be less then the number of
+ *   recognizers of @widget_class.
+ *
+ * Gets the recognizer @id in use by @widget class
+ *
+ * Returns: The recognizer
+ **/
+GtkEventRecognizer *
+gtk_widget_class_get_recognizer (GtkWidgetClass *widget_class,
+                                 guint           id)
+{
+  GtkWidgetClassPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_WIDGET_CLASS (widget_class), NULL);
+
+  priv = widget_class->priv;
+  g_return_val_if_fail (priv->recognizers != NULL, NULL);
+  g_return_val_if_fail (id < priv->recognizers->len, NULL);
+
+  return g_ptr_array_index (priv->recognizers, id);
+}
+
+/**
+ * gtk_widget_class_get_n_recognizers:
+ * @widget_class: the widget class
+ *
+ * Gets the number of recognizers in use by @widget_class.
+ *
+ * Returns: The number of recognizers currently in use by @widget_class
+ **/
+guint
+gtk_widget_class_get_n_recognizers (GtkWidgetClass *widget_class)
+{
+  GtkWidgetClassPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_WIDGET_CLASS (widget_class), 0);
+
+  priv = widget_class->priv;
+
+  if (priv->recognizers == NULL)
+    return 0;
+
+  return priv->recognizers->len;
+}
+
+/**
  * gtk_widget_in_destruction:
  * @widget: a #GtkWidget
  *
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 5a4ac4f..556ad92 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -526,6 +526,16 @@ gint       gtk_widget_send_expose         (GtkWidget           *widget,
 gboolean   gtk_widget_send_focus_change   (GtkWidget           *widget,
                                            GdkEvent            *event);
 
+void       gtk_widget_class_add_recognizer(GtkWidgetClass      *widget_class,
+                                           GtkEventRecognizer  *recognizer);
+void       gtk_widget_class_remove_recognizer
+                                          (GtkWidgetClass      *widget_class,
+                                           guint                id);
+GtkEventRecognizer *
+           gtk_widget_class_get_recognizer(GtkWidgetClass      *widget_class,
+                                           guint                id);
+guint      gtk_widget_class_get_n_recognizers (GtkWidgetClass  *widget_class);
+
 gboolean   gtk_widget_activate		     (GtkWidget	       *widget);
      
 void	   gtk_widget_reparent		  (GtkWidget	       *widget,



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