[gtk+] Add the gtk-key-bindings CSS parser property.



commit d39f0411bea8a04d5ed8af6ca48a843133b4e2c4
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Jan 28 09:59:02 2011 +0100

    Add the gtk-key-bindings CSS parser property.
    
    This property takes a list of binding set names to have these
    stored as a GPtrArray containing GtkBindingSets. this property
    is handled so merging GtkStyleProperties will merge both
    GtkBindingSet lists.

 gtk/gtkcssprovider.c     |   32 ++++++++++++++++++++++++++++++++
 gtk/gtkstyleproperties.c |   22 ++++++++++++++++++++++
 2 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 70461e2..95e3807 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -2762,6 +2762,32 @@ border_parse_str (const gchar  *str,
   return border;
 }
 
+static void
+resolve_binding_sets (const gchar *value_str,
+                      GValue      *value)
+{
+  GPtrArray *array;
+  gchar **bindings, **str;
+
+  bindings = g_strsplit (value_str, ",", -1);
+  array = g_ptr_array_new ();
+
+  for (str = bindings; *str; str++)
+    {
+      GtkBindingSet *binding_set;
+
+      binding_set = gtk_binding_set_find (g_strstrip (*str));
+
+      if (!binding_set)
+        continue;
+
+      g_ptr_array_add (array, binding_set);
+    }
+
+  g_value_take_boxed (value, array);
+  g_strfreev (bindings);
+}
+
 static gboolean
 css_provider_parse_value (GtkCssProvider  *css_provider,
                           const gchar     *value_str,
@@ -3378,6 +3404,12 @@ parse_rule (GtkCssProvider  *css_provider,
               g_param_value_set_default (pspec, val);
               g_hash_table_insert (priv->cur_properties, prop, val);
             }
+          else if (strcmp (prop, "gtk-key-bindings") == 0)
+            {
+              /* Private property holding the binding sets */
+              resolve_binding_sets (value_str, val);
+              g_hash_table_insert (priv->cur_properties, prop, val);
+            }
           else if (pspec->value_type == G_TYPE_STRING)
             {
               g_value_set_string (val, value_str);
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index 0eff9cc..f3a325d 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -171,6 +171,13 @@ gtk_style_properties_class_init (GtkStylePropertiesClass *klass)
                                                               "Transition animation description",
                                                               GTK_TYPE_ANIMATION_DESCRIPTION, 0));
 
+  /* Private property holding the binding sets */
+  gtk_style_properties_register_property (NULL,
+                                          g_param_spec_boxed ("gtk-key-bindings",
+                                                              "Key bindings",
+                                                              "Key bindings",
+                                                              G_TYPE_PTR_ARRAY, 0));
+
   g_type_class_add_private (object_class, sizeof (GtkStylePropertiesPrivate));
 }
 
@@ -1239,6 +1246,21 @@ gtk_style_properties_merge (GtkStyleProperties       *props,
 
               pango_font_description_merge (font_desc, font_desc_to_merge, replace);
             }
+          else if (G_VALUE_TYPE (&data->value) == G_TYPE_PTR_ARRAY &&
+                   G_IS_VALUE (value))
+            {
+              GPtrArray *array, *array_to_merge;
+              gint i;
+
+              /* Append the array, mainly thought
+               * for the gtk-key-bindings property
+               */
+              array = g_value_get_boxed (value);
+              array_to_merge = g_value_get_boxed (&data->value);
+
+              for (i = 0; i < array_to_merge->len; i++)
+                g_ptr_array_add (array, g_ptr_array_index (array_to_merge, i));
+            }
           else if (replace || !G_IS_VALUE (value))
             {
               if (!G_IS_VALUE (value))



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