[gtk+/gtk-style-context: 59/540] GtkStyleSet: Add method to lookup property default settings.



commit 4a03f9afc29618be96fe7fb017c95bdb82e52fb2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sun Apr 11 20:26:49 2010 +0200

    GtkStyleSet: Add method to lookup property default settings.

 gtk/gtkstyleset.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 gtk/gtkstyleset.h |    3 +++
 2 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/gtk/gtkstyleset.c b/gtk/gtkstyleset.c
index f91d332..19e1a97 100644
--- a/gtk/gtkstyleset.c
+++ b/gtk/gtkstyleset.c
@@ -218,6 +218,56 @@ gtk_style_set_register_property (const gchar  *property_name,
   g_array_insert_val (properties, i, new);
 }
 
+gboolean
+gtk_style_set_lookup_property (const gchar *property_name,
+                               GType       *type,
+                               GValue      *default_value)
+{
+  PropertyNode *node;
+  GtkStyleSetClass *klass;
+  GQuark quark;
+  GType t;
+  gint i;
+
+  g_return_val_if_fail (property_name != NULL, FALSE);
+
+  klass = g_type_class_ref (GTK_TYPE_STYLE_SET);
+  quark = g_quark_try_string (property_name);
+
+  if (quark == 0)
+    {
+      g_type_class_unref (klass);
+      return FALSE;
+    }
+
+  for (i = 0; i < properties->len; i++)
+    {
+      node = &g_array_index (properties, PropertyNode, i);
+
+      if (node->property_quark == quark)
+        {
+          if (type)
+            *type = node->property_type;
+
+          if (default_value)
+            {
+              g_value_init (default_value, G_VALUE_TYPE (&node->default_value));
+              g_value_copy (&node->default_value, default_value);
+            }
+
+          g_type_class_unref (klass);
+
+          return TRUE;
+        }
+      else if (node->property_quark > quark)
+        break;
+    }
+
+  g_type_class_unref (klass);
+
+  return FALSE;
+}
+
 void
 gtk_style_set_register_property_color (const gchar *property_name,
                                        GdkColor    *initial_value)
diff --git a/gtk/gtkstyleset.h b/gtk/gtkstyleset.h
index 642dd02..16fda3e 100644
--- a/gtk/gtkstyleset.h
+++ b/gtk/gtkstyleset.h
@@ -55,6 +55,9 @@ GType gtk_style_set_get_type (void) G_GNUC_CONST;
 void     gtk_style_set_register_property (const gchar  *property_name,
                                           GType         type,
                                           const GValue *default_value);
+gboolean gtk_style_set_lookup_property   (const gchar  *property_name,
+                                          GType        *type,
+                                          GValue       *default_value);
 
 void gtk_style_set_register_property_color  (const gchar *property_name,
                                              GdkColor    *default_value);



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