[gtk+/wip/css: 50/167] styleproperty: Add gtk_style_property_assign()



commit 8f0af927387e6ad6290fe1c99c200089c8816e5b
Author: Benjamin Otte <otte redhat com>
Date:   Sat Dec 31 19:03:53 2011 +0100

    styleproperty: Add gtk_style_property_assign()

 gtk/gtkstyleproperties.c      |   67 +++++++----------------------------------
 gtk/gtkstyleproperty.c        |   41 +++++++++++++++++++++++++
 gtk/gtkstylepropertyprivate.h |    4 ++
 3 files changed, 56 insertions(+), 56 deletions(-)
---
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index 1c39f0a..cb8a1b4 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -528,55 +528,8 @@ _gtk_style_properties_set_property_by_property (GtkStyleProperties *props,
 {
   GtkStylePropertiesPrivate *priv;
   PropertyData *prop;
-  GType value_type, style_prop_type;
   GValue *val;
 
-  value_type = G_VALUE_TYPE (value);
-  style_prop_type = _gtk_style_property_get_value_type (style_prop);
-
-  if (style_prop_type == GDK_TYPE_RGBA ||
-      style_prop_type == GDK_TYPE_COLOR)
-    {
-      /* Allow GtkSymbolicColor and special values as well */
-      g_return_if_fail (value_type == GDK_TYPE_RGBA ||
-                        value_type == GDK_TYPE_COLOR ||
-                        value_type == GTK_TYPE_CSS_SPECIAL_VALUE ||
-                        value_type == GTK_TYPE_SYMBOLIC_COLOR);
-    }
-  else if (style_prop_type == CAIRO_GOBJECT_TYPE_PATTERN)
-    {
-      /* Allow GtkGradient and theme part as a substitute */
-      g_return_if_fail (value_type == CAIRO_GOBJECT_TYPE_PATTERN ||
-                        value_type == GTK_TYPE_GRADIENT	||
-			value_type == GTK_TYPE_WIN32_THEME_PART);
-    }
-  else if (style_prop_type == G_TYPE_INT)
-    {
-      g_return_if_fail (value_type == G_TYPE_INT ||
-                        value_type == GTK_TYPE_CSS_BORDER_RADIUS);
-    }
-  else
-    g_return_if_fail (style_prop_type == value_type);
-
-  if (GTK_IS_CSS_SHORTHAND_PROPERTY (style_prop))
-    {
-      GParameter *parameters;
-      guint i, n_parameters;
-
-      parameters = _gtk_style_property_unpack (style_prop, value, &n_parameters);
-
-      for (i = 0; i < n_parameters; i++)
-        {
-          gtk_style_properties_set_property (props,
-                                             parameters[i].name,
-                                             state,
-                                             &parameters[i].value);
-          g_value_unset (&parameters[i].value);
-        }
-      g_free (parameters);
-      return;
-    }
-
   priv = props->priv;
   prop = g_hash_table_lookup (priv->properties, style_prop);
 
@@ -588,18 +541,18 @@ _gtk_style_properties_set_property_by_property (GtkStyleProperties *props,
 
   val = property_data_get_value (prop, state);
 
-  if (G_VALUE_TYPE (val) == value_type)
+  if (G_VALUE_TYPE (val) == G_VALUE_TYPE (value))
     g_value_reset (val);
   else
     {
       if (G_IS_VALUE (val))
         g_value_unset (val);
 
-      g_value_init (val, value_type);
+      g_value_init (val, G_VALUE_TYPE (value));
     }
 
   g_value_copy (value, val);
-  if (style_prop_type == value_type)
+  if (_gtk_style_property_get_value_type (style_prop) == G_VALUE_TYPE (value))
     g_param_value_validate (style_prop->pspec, val);
 }
 
@@ -633,11 +586,13 @@ gtk_style_properties_set_property (GtkStyleProperties *props,
       g_warning ("Style property \"%s\" is not registered", property);
       return;
     }
-
-  _gtk_style_properties_set_property_by_property (props,
-                                                  node,
-                                                  state,
-                                                  value);
+  if (_gtk_style_property_get_value_type (node) == G_TYPE_NONE)
+    {
+      g_warning ("Style property \"%s\" is not settable", property);
+      return;
+    }
+  
+  _gtk_style_property_assign (node, props, state, value);
 }
 
 /**
@@ -693,7 +648,7 @@ gtk_style_properties_set_valist (GtkStyleProperties *props,
           break;
         }
 
-      _gtk_style_properties_set_property_by_property (props, node, state, &val);
+      _gtk_style_property_assign (node, props, state, &val);
       g_value_unset (&val);
 
       property_name = va_arg (args, const gchar *);
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 646e5c8..69a16f2 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -2056,6 +2056,47 @@ _gtk_style_property_pack (GtkStyleProperty   *property,
 }
 
 void
+_gtk_style_property_assign (GtkStyleProperty   *property,
+                            GtkStyleProperties *props,
+                            GtkStateFlags       state,
+                            const GValue       *value)
+{
+  g_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+  g_return_if_fail (value != NULL);
+
+  if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
+    {
+      GParameter *parameters;
+      guint i, n_parameters;
+
+      parameters = _gtk_style_property_unpack (property, value, &n_parameters);
+
+      for (i = 0; i < n_parameters; i++)
+        {
+          _gtk_style_property_assign (_gtk_style_property_lookup (parameters[i].name),
+                                      props,
+                                      state,
+                                      &parameters[i].value);
+          g_value_unset (&parameters[i].value);
+        }
+      g_free (parameters);
+      return;
+    }
+  else if (GTK_IS_CSS_STYLE_PROPERTY (property))
+    {
+      _gtk_style_properties_set_property_by_property (props,
+                                                      property,
+                                                      state,
+                                                      value);
+    }
+  else
+    {
+      g_assert_not_reached ();
+    }
+}
+
+void
 _gtk_style_property_query (GtkStyleProperty        *property,
                            GtkStyleProperties      *props,
                            GtkStateFlags            state,
diff --git a/gtk/gtkstylepropertyprivate.h b/gtk/gtkstylepropertyprivate.h
index a7ca9da..cc03728 100644
--- a/gtk/gtkstylepropertyprivate.h
+++ b/gtk/gtkstylepropertyprivate.h
@@ -120,6 +120,10 @@ void                     _gtk_style_property_query         (GtkStyleProperty *
                                                             GtkStateFlags           state,
 							    GtkStylePropertyContext *context,
                                                             GValue                 *value);
+void                     _gtk_style_property_assign        (GtkStyleProperty       *property,
+                                                            GtkStyleProperties     *props,
+                                                            GtkStateFlags           state,
+                                                            const GValue           *value);
 
 G_END_DECLS
 



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