[gtk+/wip/css: 62/125] styleproperty: Move value printing to real properties



commit e07cfc5c74c15a33a86648d9e3fe7f980b5ca191
Author: Benjamin Otte <otte redhat com>
Date:   Sun Jan 1 18:28:27 2012 +0100

    styleproperty: Move value printing to real properties
    
    We can't print shorthands, so don't try.
    In particular, I want to get away from shorthands being representable
    using GValue, and this function kinda requires that.

 gtk/gtkcssprovider.c             |    6 ++--
 gtk/gtkcssstyleproperty.c        |   40 ++++++++++++++++++++++++++++++++++++++
 gtk/gtkcssstylepropertyprivate.h |    4 +++
 gtk/gtkstyleproperty.c           |   29 ---------------------------
 gtk/gtkstylepropertyprivate.h    |    3 --
 5 files changed, 47 insertions(+), 35 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index f6cdd9d..04f9493 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -3282,13 +3282,13 @@ gtk_css_ruleset_print (const GtkCssRuleset *ruleset,
 
       for (walk = keys; walk; walk = walk->next)
         {
-          GtkStyleProperty *prop = walk->data;
+          GtkCssStyleProperty *prop = walk->data;
           const PropertyValue *value = g_hash_table_lookup (ruleset->style, prop);
 
           g_string_append (str, "  ");
-          g_string_append (str, _gtk_style_property_get_name (prop));
+          g_string_append (str, _gtk_style_property_get_name (GTK_STYLE_PROPERTY (prop)));
           g_string_append (str, ": ");
-          _gtk_style_property_print_value (prop, &value->value, str);
+          _gtk_css_style_property_print_value (prop, &value->value, str);
           g_string_append (str, ";\n");
         }
 
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index 66ce7ff..da90227 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -22,7 +22,10 @@
 
 #include "gtkcssstylepropertyprivate.h"
 
+#include "gtkcssstylefuncsprivate.h"
+#include "gtkcsstypesprivate.h"
 #include "gtkintl.h"
+#include "gtkprivatetypebuiltins.h"
 
 enum {
   PROP_0,
@@ -227,3 +230,40 @@ _gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property)
   return &property->initial_value;
 }
 
+/**
+ * _gtk_css_style_property_print_value:
+ * @property: the property
+ * @value: the value to print
+ * @string: the string to print to
+ *
+ * Prints @value to the given @string in CSS format. The @value must be a
+ * valid specified value as parsed using the parse functions or as assigned
+ * via _gtk_style_property_assign().
+ **/
+void
+_gtk_css_style_property_print_value (GtkCssStyleProperty    *property,
+                                     const GValue           *value,
+                                     GString                *string)
+{
+  g_return_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property));
+  g_return_if_fail (value != NULL);
+  g_return_if_fail (string != NULL);
+
+  if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
+    {
+      GEnumClass *enum_class;
+      GEnumValue *enum_value;
+
+      enum_class = g_type_class_ref (GTK_TYPE_CSS_SPECIAL_VALUE);
+      enum_value = g_enum_get_value (enum_class, g_value_get_enum (value));
+
+      g_string_append (string, enum_value->value_nick);
+
+      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);
+}
+
diff --git a/gtk/gtkcssstylepropertyprivate.h b/gtk/gtkcssstylepropertyprivate.h
index 32ab48d..aba791c 100644
--- a/gtk/gtkcssstylepropertyprivate.h
+++ b/gtk/gtkcssstylepropertyprivate.h
@@ -61,6 +61,10 @@ guint                   _gtk_css_style_property_get_id          (GtkCssStyleProp
 const GValue *          _gtk_css_style_property_get_initial_value
                                                                 (GtkCssStyleProperty    *property);
 
+void                    _gtk_css_style_property_print_value     (GtkCssStyleProperty    *property,
+                                                                 const GValue           *value,
+                                                                 GString                *string);
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_STYLE_PROPERTY_PRIVATE_H__ */
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index d9cea0a..170b3ea 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -201,22 +201,6 @@ string_append_string (GString    *str,
 
 /*** IMPLEMENTATIONS ***/
 
-static void
-enum_print (int         value,
-	    GType       type,
-	    GString    *string)
-{
-  GEnumClass *enum_class;
-  GEnumValue *enum_value;
-
-  enum_class = g_type_class_ref (type);
-  enum_value = g_enum_get_value (enum_class, value);
-
-  g_string_append (string, enum_value->value_nick);
-
-  g_type_class_unref (enum_class);
-}
-
 static gboolean
 font_family_parse (GtkCssParser *parser,
                    GFile        *base,
@@ -453,19 +437,6 @@ _gtk_style_property_parse_value (GtkStyleProperty *property,
   return _gtk_css_style_parse_value (value, parser, base);
 }
 
-void
-_gtk_style_property_print_value (GtkStyleProperty *property,
-                                 const GValue     *value,
-                                 GString          *string)
-{
-  if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
-    enum_print (g_value_get_enum (value), GTK_TYPE_CSS_SPECIAL_VALUE, string);
-  else if (property && property->print_func)
-    (* property->print_func) (value, string);
-  else
-    _gtk_css_style_print_value (value, string);
-}
-
 static void
 _gtk_style_property_default_value (GtkStyleProperty   *property,
                                    GtkStyleProperties *properties,
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index e8d6e58..92c3fea 100644
--- a/gtk/gtkstylepropertyprivate.h
+++ b/gtk/gtkstylepropertyprivate.h
@@ -95,9 +95,6 @@ gboolean                 _gtk_style_property_parse_value   (GtkStyleProperty *
                                                             GValue                 *value,
                                                             GtkCssParser           *parser,
                                                             GFile                  *base);
-void                     _gtk_style_property_print_value   (GtkStyleProperty *      property,
-                                                            const GValue           *value,
-                                                            GString                *string);
 
 GType                    _gtk_style_property_get_value_type(GtkStyleProperty *      property);
 void                     _gtk_style_property_query         (GtkStyleProperty *      property,



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