[gtk+] styleproperty: Move default value setting to styleproperty.c



commit 66396d2bab676ca80af32a379236b82983afb1d0
Author: Benjamin Otte <otte redhat com>
Date:   Sat May 28 05:43:07 2011 +0200

    styleproperty: Move default value setting to styleproperty.c

 gtk/gtkstyleproperties.c      |   27 ++----------------
 gtk/gtkstyleproperty.c        |   60 ++++++++++++++++++++++++++++++++--------
 gtk/gtkstylepropertyprivate.h |   22 ++++++++++-----
 3 files changed, 66 insertions(+), 43 deletions(-)
---
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index 2f15304..9a9e739 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -316,6 +316,7 @@ gtk_style_properties_register_property (GtkStylePropertyParser  parse_func,
                                 NULL,
                                 NULL,
                                 NULL,
+                                NULL,
                                 NULL);
 }
 
@@ -794,28 +795,6 @@ style_properties_resolve_type (GtkStyleProperties     *props,
   return TRUE;
 }
 
-static void
-lookup_default_value (const GtkStyleProperty *node,
-                      GValue                 *value)
-{
-  if (node->pspec->value_type == GTK_TYPE_THEMING_ENGINE)
-    g_value_set_object (value, gtk_theming_engine_load (NULL));
-  else if (node->pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
-    g_value_take_boxed (value, pango_font_description_from_string ("Sans 10"));
-  else if (node->pspec->value_type == GDK_TYPE_RGBA)
-    {
-      GdkRGBA color;
-      gdk_rgba_parse (&color, "pink");
-      g_value_set_boxed (value, &color);
-    }
-  else if (node->pspec->value_type == GTK_TYPE_BORDER)
-    {
-      g_value_take_boxed (value, gtk_border_new ());
-    }
-  else
-    g_param_value_set_default (node->pspec, value);
-}
-
 /* NB: Will return NULL for shorthands */
 const GValue *
 _gtk_style_properties_peek_property (GtkStyleProperties      *props,
@@ -895,7 +874,7 @@ gtk_style_properties_get_property (GtkStyleProperties *props,
   else if (_gtk_style_property_is_shorthand (node))
     _gtk_style_property_pack (node, props, state, value);
   else
-    lookup_default_value (node, value);
+    _gtk_style_property_default_value (node, props, value);
 
   return TRUE;
 }
@@ -949,7 +928,7 @@ gtk_style_properties_get_valist (GtkStyleProperties *props,
           GValue default_value = { 0 };
 
           g_value_init (&default_value, node->pspec->value_type);
-          lookup_default_value (node, &default_value);
+          _gtk_style_property_default_value (node, props, &default_value);
           G_VALUE_LCOPY (&default_value, args, 0, &error);
           g_value_unset (&default_value);
         }
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index ee5128f..e8cc02f 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -1729,6 +1729,31 @@ _gtk_style_property_print_value (const GtkStyleProperty *property,
   func (value, string);
 }
 
+void
+_gtk_style_property_default_value (const GtkStyleProperty *property,
+                                   GtkStyleProperties     *properties,
+                                   GValue                 *value)
+{
+  if (property->default_value_func)
+    property->default_value_func (properties, value);
+  else if (property->pspec->value_type == GTK_TYPE_THEMING_ENGINE)
+    g_value_set_object (value, gtk_theming_engine_load (NULL));
+  else if (property->pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
+    g_value_take_boxed (value, pango_font_description_from_string ("Sans 10"));
+  else if (property->pspec->value_type == GDK_TYPE_RGBA)
+    {
+      GdkRGBA color;
+      gdk_rgba_parse (&color, "pink");
+      g_value_set_boxed (value, &color);
+    }
+  else if (property->pspec->value_type == GTK_TYPE_BORDER)
+    {
+      g_value_take_boxed (value, gtk_border_new ());
+    }
+  else
+    g_param_value_set_default (property->pspec, value);
+}
+
 gboolean
 _gtk_style_property_is_shorthand  (const GtkStyleProperty *property)
 {
@@ -1833,6 +1858,7 @@ gtk_style_property_init (void)
                                           unpack_margin,
                                           pack_margin,
                                           NULL,
+                                          NULL,
                                           NULL);
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_int ("padding-top",
@@ -1862,6 +1888,7 @@ gtk_style_property_init (void)
                                           unpack_padding,
                                           pack_padding,
                                           NULL,
+                                          NULL,
                                           NULL);
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_int ("border-top-width",
@@ -1891,6 +1918,7 @@ gtk_style_property_init (void)
                                           unpack_border_width,
                                           pack_border_width,
                                           NULL,
+                                          NULL,
                                           NULL);
 
   _gtk_style_property_register           (g_param_spec_boxed ("border-top-left-radius",
@@ -1901,7 +1929,8 @@ gtk_style_property_init (void)
                                           NULL,
                                           NULL,
                                           border_corner_radius_value_parse,
-                                          border_corner_radius_value_print);
+                                          border_corner_radius_value_print,
+                                          NULL);
   _gtk_style_property_register           (g_param_spec_boxed ("border-top-right-radius",
                                                               "Border top right radius",
                                                               "Border radius of top right corner, in pixels",
@@ -1910,7 +1939,8 @@ gtk_style_property_init (void)
                                           NULL,
                                           NULL,
                                           border_corner_radius_value_parse,
-                                          border_corner_radius_value_print);
+                                          border_corner_radius_value_print,
+                                          NULL);
   _gtk_style_property_register           (g_param_spec_boxed ("border-bottom-right-radius",
                                                               "Border bottom right radius",
                                                               "Border radius of bottom right corner, in pixels",
@@ -1919,7 +1949,8 @@ gtk_style_property_init (void)
                                           NULL,
                                           NULL,
                                           border_corner_radius_value_parse,
-                                          border_corner_radius_value_print);
+                                          border_corner_radius_value_print,
+                                          NULL);
   _gtk_style_property_register           (g_param_spec_boxed ("border-bottom-left-radius",
                                                               "Border bottom left radius",
                                                               "Border radius of bottom left corner, in pixels",
@@ -1928,7 +1959,8 @@ gtk_style_property_init (void)
                                           NULL,
                                           NULL,
                                           border_corner_radius_value_parse,
-                                          border_corner_radius_value_print);
+                                          border_corner_radius_value_print,
+                                          NULL);
   _gtk_style_property_register           (g_param_spec_int ("border-radius",
                                                             "Border radius",
                                                             "Border radius, in pixels",
@@ -1937,7 +1969,8 @@ gtk_style_property_init (void)
                                           unpack_border_radius,
                                           pack_border_radius,
                                           border_radius_value_parse,
-                                          border_radius_value_print);
+                                          border_radius_value_print,
+                                          NULL);
 
   gtk_style_properties_register_property (NULL,
                                           g_param_spec_enum ("border-style",
@@ -1980,7 +2013,8 @@ gtk_style_property_init (void)
                                           NULL,
                                           NULL,
                                           bindings_value_parse,
-                                          bindings_value_print);
+                                          bindings_value_print,
+                                          NULL);
 }
 
 const GtkStyleProperty *
@@ -1992,12 +2026,13 @@ _gtk_style_property_lookup (const char *name)
 }
 
 void
-_gtk_style_property_register (GParamSpec             *pspec,
-                              GtkStylePropertyParser  property_parse_func,
-                              GtkStyleUnpackFunc      unpack_func,
-                              GtkStylePackFunc        pack_func,
-                              GtkStyleParseFunc       parse_func,
-                              GtkStylePrintFunc       print_func)
+_gtk_style_property_register (GParamSpec               *pspec,
+                              GtkStylePropertyParser    property_parse_func,
+                              GtkStyleUnpackFunc        unpack_func,
+                              GtkStylePackFunc          pack_func,
+                              GtkStyleParseFunc         parse_func,
+                              GtkStylePrintFunc         print_func,
+                              GtkStyleDefaultValueFunc  default_value_func)
 {
   const GtkStyleProperty *existing;
   GtkStyleProperty *node;
@@ -2021,6 +2056,7 @@ _gtk_style_property_register (GParamSpec             *pspec,
   node->unpack_func = unpack_func;
   node->parse_func = parse_func;
   node->print_func = print_func;
+  node->default_value_func = default_value_func;
 
   g_hash_table_insert (properties, pspec->name, node);
 }
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index 64789bc..30aa62f 100644
--- a/gtk/gtkstylepropertyprivate.h
+++ b/gtk/gtkstylepropertyprivate.h
@@ -36,16 +36,19 @@ typedef gboolean         (* GtkStyleParseFunc)             (GtkCssParser
                                                             GValue                 *value);
 typedef void             (* GtkStylePrintFunc)             (const GValue           *value,
                                                             GString                *string);
+typedef void             (* GtkStyleDefaultValueFunc)      (GtkStyleProperties     *props,
+                                                            GValue                 *value);
 
 
 struct _GtkStyleProperty
 {
-  GParamSpec             *pspec;
-  GtkStylePropertyParser  property_parse_func;
-  GtkStyleUnpackFunc      unpack_func;
-  GtkStylePackFunc        pack_func;
-  GtkStyleParseFunc       parse_func;
-  GtkStylePrintFunc       print_func;
+  GParamSpec               *pspec;
+  GtkStylePropertyParser    property_parse_func;
+  GtkStyleUnpackFunc        unpack_func;
+  GtkStylePackFunc          pack_func;
+  GtkStyleParseFunc         parse_func;
+  GtkStylePrintFunc         print_func;
+  GtkStyleDefaultValueFunc  default_value_func;
 };
 
 const GtkStyleProperty * _gtk_style_property_lookup        (const char             *name);
@@ -55,7 +58,12 @@ void                     _gtk_style_property_register      (GParamSpec
                                                             GtkStyleUnpackFunc      unpack_func,
                                                             GtkStylePackFunc        pack_func,
                                                             GtkStyleParseFunc       parse_func,
-                                                            GtkStylePrintFunc       print_func);
+                                                            GtkStylePrintFunc       print_func,
+                                                            GtkStyleDefaultValueFunc default_value_func);
+
+void                     _gtk_style_property_default_value (const GtkStyleProperty *property,
+                                                            GtkStyleProperties     *properties,
+                                                            GValue                 *value);
 
 gboolean                 _gtk_style_property_is_shorthand  (const GtkStyleProperty *property);
 GParameter *             _gtk_style_property_unpack        (const GtkStyleProperty *property,



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