[gtk+/wip/css: 99/125] styleproperty: Move parse/print vfuncs to GtkCssStyleProperty



commit 93e24c2f043532ba7494a3ea04c7b68e950c2a68
Author: Benjamin Otte <otte redhat com>
Date:   Mon Jan 2 18:05:06 2012 +0100

    styleproperty: Move parse/print vfuncs to GtkCssStyleProperty

 gtk/gtkcssstyleproperty.c        |   39 ++++++++++++++------
 gtk/gtkcssstylepropertyimpl.c    |   71 +++++++++++++++++++++----------------
 gtk/gtkcssstylepropertyprivate.h |    9 +++++
 gtk/gtkstylepropertyprivate.h    |    7 ----
 4 files changed, 76 insertions(+), 50 deletions(-)
---
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index e358077..03418dd 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -143,7 +143,7 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
                                     GtkCssParser     *parser,
                                     GFile            *base)
 {
-  gboolean success;
+  GtkCssStyleProperty *style_property = GTK_CSS_STYLE_PROPERTY (property);
 
   if (_gtk_css_parser_try (parser, "initial", TRUE))
     {
@@ -168,15 +168,13 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
     }
 
   g_value_init (value, _gtk_style_property_get_value_type (property));
-  if (property->parse_func)
-    success = (* property->parse_func) (parser, base, value);
-  else
-    success = _gtk_css_style_parse_value (value, parser, base);
-
-  if (!success)
-    g_value_unset (value);
+  if (!(* style_property->parse_value) (style_property, value, parser, base))
+    {
+      g_value_unset (value);
+      return FALSE;
+    }
 
-  return success;
+  return TRUE;
 }
 
 static void
@@ -218,6 +216,23 @@ _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
   klass->style_properties = g_ptr_array_new ();
 }
 
+static gboolean
+gtk_css_style_property_real_parse_value (GtkCssStyleProperty *property,
+                                         GValue              *value,
+                                         GtkCssParser        *parser,
+                                         GFile               *base)
+{
+  return _gtk_css_style_parse_value (value, parser, base);
+}
+
+static void
+gtk_css_style_property_real_print_value (GtkCssStyleProperty *property,
+                                         const GValue        *value,
+                                         GString             *string)
+{
+  _gtk_css_style_print_value (value, string);
+}
+
 static void
 gtk_css_style_property_real_compute_value (GtkCssStyleProperty *property,
                                            GValue              *computed,
@@ -231,6 +246,8 @@ gtk_css_style_property_real_compute_value (GtkCssStyleProperty *property,
 static void
 _gtk_css_style_property_init (GtkCssStyleProperty *property)
 {
+  property->parse_value = gtk_css_style_property_real_parse_value;
+  property->print_value = gtk_css_style_property_real_print_value;
   property->compute_value = gtk_css_style_property_real_compute_value;
 }
 
@@ -382,9 +399,7 @@ _gtk_css_style_property_print_value (GtkCssStyleProperty    *property,
 
       g_type_class_unref (enum_class);
     }
-  else if (GTK_STYLE_PROPERTY (property)->print_func)
-    (* GTK_STYLE_PROPERTY (property)->print_func) (value, string);
   else
-    _gtk_css_style_print_value (value, string);
+    property->print_value (property, value, string);
 }
 
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 9f520cb..6a59299 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -45,14 +45,14 @@
 /*** REGISTRATION ***/
 
 static void
-_gtk_style_property_register (const char *              name,
-                              GType                     value_type,
-                              GtkStylePropertyFlags     flags,
-                              GtkStyleParseFunc         parse_func,
-                              GtkStylePrintFunc         print_func,
-                              const GValue *            initial_value)
+_gtk_style_property_register (const char *                 name,
+                              GType                        value_type,
+                              GtkStylePropertyFlags        flags,
+                              GtkCssStylePropertyParseFunc parse_value,
+                              GtkCssStylePropertyPrintFunc print_value,
+                              const GValue *               initial_value)
 {
-  GtkStyleProperty *node;
+  GtkCssStyleProperty *node;
 
   node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
                        "inherit", (flags & GTK_STYLE_PROPERTY_INHERIT) ? TRUE : FALSE,
@@ -60,23 +60,26 @@ _gtk_style_property_register (const char *              name,
                        "name", name,
                        "value-type", value_type,
                        NULL);
-  node->parse_func = parse_func;
-  node->print_func = print_func;
+
+  if (parse_value)
+    node->parse_value = parse_value;
+  if (print_value)
+    node->print_value = print_value;
 }
 
 static void
-gtk_style_property_register (const char *              name,
-                             GType                     value_type,
-                             GtkStylePropertyFlags     flags,
-                             GtkStyleParseFunc         parse_func,
-                             GtkStylePrintFunc         print_func,
+gtk_style_property_register (const char *                 name,
+                             GType                        value_type,
+                             GtkStylePropertyFlags        flags,
+                             GtkCssStylePropertyParseFunc parse_value,
+                             GtkCssStylePropertyPrintFunc print_value,
                              ...)
 {
   GValue initial_value = G_VALUE_INIT;
   char *error = NULL;
   va_list args;
 
-  va_start (args, print_func);
+  va_start (args, print_value);
   G_VALUE_COLLECT_INIT (&initial_value, value_type,
                         args, 0, &error);
   if (error)
@@ -88,7 +91,7 @@ gtk_style_property_register (const char *              name,
 
   va_end (args);
 
-  _gtk_style_property_register (name, value_type, flags, parse_func, print_func, &initial_value);
+  _gtk_style_property_register (name, value_type, flags, parse_value, print_value, &initial_value);
 
   g_value_unset (&initial_value);
 }
@@ -145,9 +148,10 @@ string_append_string (GString    *str,
 /*** IMPLEMENTATIONS ***/
 
 static gboolean
-font_family_parse (GtkCssParser *parser,
-                   GFile        *base,
-                   GValue       *value)
+font_family_parse (GtkCssStyleProperty *property,
+                   GValue              *value,
+                   GtkCssParser        *parser,
+                   GFile               *base)
 {
   GPtrArray *names;
   char *name;
@@ -191,8 +195,9 @@ font_family_parse (GtkCssParser *parser,
 }
 
 static void
-font_family_value_print (const GValue *value,
-                         GString      *string)
+font_family_value_print (GtkCssStyleProperty *property,
+                         const GValue        *value,
+                         GString             *string)
 {
   const char **names = g_value_get_boxed (value);
 
@@ -213,9 +218,10 @@ font_family_value_print (const GValue *value,
 }
 
 static gboolean 
-bindings_value_parse (GtkCssParser *parser,
-                      GFile        *base,
-                      GValue       *value)
+bindings_value_parse (GtkCssStyleProperty *property,
+                      GValue              *value,
+                      GtkCssParser        *parser,
+                      GFile               *base)
 {
   GPtrArray *array;
   GtkBindingSet *binding_set;
@@ -252,8 +258,9 @@ bindings_value_parse (GtkCssParser *parser,
 }
 
 static void
-bindings_value_print (const GValue *value,
-                      GString      *string)
+bindings_value_print (GtkCssStyleProperty *property,
+                      const GValue        *value,
+                      GString             *string)
 {
   GPtrArray *array;
   guint i;
@@ -271,9 +278,10 @@ bindings_value_print (const GValue *value,
 }
 
 static gboolean 
-border_corner_radius_value_parse (GtkCssParser *parser,
-                                  GFile        *base,
-                                  GValue       *value)
+border_corner_radius_value_parse (GtkCssStyleProperty *property,
+                                  GValue              *value,
+                                  GtkCssParser        *parser,
+                                  GFile               *base)
 {
   GtkCssBorderCornerRadius corner;
 
@@ -299,8 +307,9 @@ negative:
 }
 
 static void
-border_corner_radius_value_print (const GValue *value,
-                                  GString      *string)
+border_corner_radius_value_print (GtkCssStyleProperty *property,
+                                  const GValue        *value,
+                                  GString             *string)
 {
   GtkCssBorderCornerRadius *corner;
 
diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h
index a8f6dce..ca86bc8 100644
--- a/gtk/gtkcssstylepropertyprivate.h
+++ b/gtk/gtkcssstylepropertyprivate.h
@@ -35,6 +35,13 @@ G_BEGIN_DECLS
 typedef struct _GtkCssStyleProperty           GtkCssStyleProperty;
 typedef struct _GtkCssStylePropertyClass      GtkCssStylePropertyClass;
 
+typedef gboolean         (* GtkCssStylePropertyParseFunc)  (GtkCssStyleProperty    *property,
+                                                            GValue                 *value,
+                                                            GtkCssParser           *parser,
+                                                            GFile                  *base);
+typedef void             (* GtkCssStylePropertyPrintFunc)  (GtkCssStyleProperty    *property,
+                                                            const GValue           *value,
+                                                            GString                *string);
 typedef void             (* GtkCssStylePropertyComputeFunc)(GtkCssStyleProperty    *property,
                                                             GValue                 *computed,
                                                             GtkStyleContext        *context,
@@ -47,6 +54,8 @@ struct _GtkCssStyleProperty
   guint id;
   guint inherit :1;
 
+  GtkCssStylePropertyParseFunc parse_value;
+  GtkCssStylePropertyPrintFunc print_value;
   GtkCssStylePropertyComputeFunc compute_value;
 };
 
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index b2c7b92..92cfb07 100644
--- a/gtk/gtkstylepropertyprivate.h
+++ b/gtk/gtkstylepropertyprivate.h
@@ -45,11 +45,6 @@ typedef void             (* GtkStylePackFunc)              (GValue
                                                             GtkStyleProperties     *props,
                                                             GtkStateFlags           state,
 							    GtkStylePropertyContext *context);
-typedef gboolean         (* GtkStyleParseFunc)             (GtkCssParser           *parser,
-                                                            GFile                  *base,
-                                                            GValue                 *value);
-typedef void             (* GtkStylePrintFunc)             (const GValue           *value,
-                                                            GString                *string);
 
 struct _GtkStyleProperty
 {
@@ -60,8 +55,6 @@ struct _GtkStyleProperty
 
   GtkStyleUnpackFunc        unpack_func;
   GtkStylePackFunc          pack_func;
-  GtkStyleParseFunc         parse_func;
-  GtkStylePrintFunc         print_func;
 };
 
 struct _GtkStylePropertyClass



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