[gtk+] styleproperties: Add _gtk_style_properties_set_property_by_property()



commit 73c39f5b1681f2efe5ddf3fb3c7fa6e071ac6039
Author: Benjamin Otte <otte redhat com>
Date:   Sat May 21 21:17:08 2011 +0200

    styleproperties: Add _gtk_style_properties_set_property_by_property()
    
    ... as a replacement for _gtk_style_properties_set_property_by_pspec().
    We'll need that to handle shorthands.

 gtk/gtkcssprovider.c            |   41 ++++++++++++++++++++-------------------
 gtk/gtkstyleproperties.c        |   32 +++++++++++++++---------------
 gtk/gtkstylepropertiesprivate.h |   16 +++++++-------
 3 files changed, 45 insertions(+), 44 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 32a9642..4f09c5e 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -990,9 +990,9 @@ gtk_css_ruleset_add_style (GtkCssRuleset *ruleset,
 }
 
 static void
-gtk_css_ruleset_add (GtkCssRuleset *ruleset,
-                     GParamSpec    *pspec,
-                     GValue        *value)
+gtk_css_ruleset_add (GtkCssRuleset          *ruleset,
+                     const GtkStyleProperty *prop,
+                     GValue                 *value)
 {
   if (ruleset->style == NULL)
     ruleset->style = g_hash_table_new_full (g_direct_hash,
@@ -1000,8 +1000,8 @@ gtk_css_ruleset_add (GtkCssRuleset *ruleset,
                                             NULL,
                                             (GDestroyNotify) property_value_free);
 
-  ruleset->has_inherit |= gtk_style_param_get_inherit (pspec);
-  g_hash_table_insert (ruleset->style, pspec, value);
+  ruleset->has_inherit |= gtk_style_param_get_inherit (prop->pspec);
+  g_hash_table_insert (ruleset->style, (gpointer) prop, value);
 }
 
 static gboolean
@@ -1199,15 +1199,15 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
 
           while (g_hash_table_iter_next (&iter, &key, &value))
             {
-              GParamSpec *pspec = key;
+              GtkStyleProperty *prop = key;
 
-              if (l != length && !gtk_style_param_get_inherit (pspec))
+              if (l != length && !gtk_style_param_get_inherit (prop->pspec))
                 continue;
 
-              _gtk_style_properties_set_property_by_pspec (props,
-                                                           pspec,
-                                                           _gtk_css_selector_get_state_flags (ruleset->selector),
-                                                           value);
+              _gtk_style_properties_set_property_by_property (props,
+                                                              prop,
+                                                              _gtk_css_selector_get_state_flags (ruleset->selector),
+                                                              value);
             }
         }
     }
@@ -1992,7 +1992,7 @@ parse_declaration (GtkCssScanner *scanner,
            * to override other style providers when merged
            */
           g_param_value_set_default (property->pspec, val);
-          gtk_css_ruleset_add (ruleset, property->pspec, val);
+          gtk_css_ruleset_add (ruleset, property, val);
         }
       else if (property->parse_func)
         {
@@ -2007,7 +2007,7 @@ parse_declaration (GtkCssScanner *scanner,
             }
           
           if ((*property->parse_func) (value_str, val, &error))
-            gtk_css_ruleset_add (ruleset, property->pspec, val);
+            gtk_css_ruleset_add (ruleset, property, val);
           else
             gtk_css_provider_take_error (scanner->provider, scanner, error);
 
@@ -2023,7 +2023,7 @@ parse_declaration (GtkCssScanner *scanner,
                   _gtk_css_parser_begins_with (scanner->parser, '}') ||
                   _gtk_css_parser_is_eof (scanner->parser))
                 {
-                  gtk_css_ruleset_add (ruleset, property->pspec, val);
+                  gtk_css_ruleset_add (ruleset, property, val);
                 }
               else
                 {
@@ -2860,9 +2860,10 @@ gtk_css_provider_get_named (const gchar *name,
 }
 
 static int
-compare_pspecs (gconstpointer a, gconstpointer b)
+compare_properties (gconstpointer a, gconstpointer b)
 {
-  return strcmp (((const GParamSpec *) a)->name, ((const GParamSpec *) b)->name);
+  return strcmp (((const GtkStyleProperty *) a)->pspec->name,
+                 ((const GtkStyleProperty *) b)->pspec->name);
 }
 
 static void
@@ -2880,15 +2881,15 @@ gtk_css_ruleset_print (const GtkCssRuleset *ruleset,
     {
       keys = g_hash_table_get_keys (ruleset->style);
       /* so the output is identical for identical selector styles */
-      keys = g_list_sort (keys, compare_pspecs);
+      keys = g_list_sort (keys, compare_properties);
 
       for (walk = keys; walk; walk = walk->next)
         {
-          GParamSpec *pspec = walk->data;
-          const GValue *value = g_hash_table_lookup (ruleset->style, pspec);
+          GtkStyleProperty *prop = walk->data;
+          const GValue *value = g_hash_table_lookup (ruleset->style, prop);
 
           g_string_append (str, "  ");
-          g_string_append (str, pspec->name);
+          g_string_append (str, prop->pspec->name);
           g_string_append (str, ": ");
           s = _gtk_css_value_to_string (value);
           g_string_append (str, s);
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index afe7df5..946347f 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -482,10 +482,10 @@ gtk_style_properties_lookup_color (GtkStyleProperties *props,
 }
 
 void
-_gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
-                                             GParamSpec         *pspec,
-                                             GtkStateFlags       state,
-                                             const GValue       *value)
+_gtk_style_properties_set_property_by_property (GtkStyleProperties     *props,
+                                                const GtkStyleProperty *style_prop,
+                                                GtkStateFlags           state,
+                                                const GValue           *value)
 {
   GtkStylePropertiesPrivate *priv;
   PropertyData *prop;
@@ -494,30 +494,30 @@ _gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
 
   value_type = G_VALUE_TYPE (value);
 
-  if (pspec->value_type == GDK_TYPE_RGBA ||
-      pspec->value_type == GDK_TYPE_COLOR)
+  if (style_prop->pspec->value_type == GDK_TYPE_RGBA ||
+      style_prop->pspec->value_type == GDK_TYPE_COLOR)
     {
       /* Allow GtkSymbolicColor as well */
       g_return_if_fail (value_type == GDK_TYPE_RGBA ||
                         value_type == GDK_TYPE_COLOR ||
                         value_type == GTK_TYPE_SYMBOLIC_COLOR);
     }
-  else if (pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN)
+  else if (style_prop->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN)
     {
       /* Allow GtkGradient as a substitute */
       g_return_if_fail (value_type == CAIRO_GOBJECT_TYPE_PATTERN ||
                         value_type == GTK_TYPE_GRADIENT);
     }
   else
-    g_return_if_fail (pspec->value_type == value_type);
+    g_return_if_fail (style_prop->pspec->value_type == value_type);
 
   priv = props->priv;
-  prop = g_hash_table_lookup (priv->properties, pspec);
+  prop = g_hash_table_lookup (priv->properties, style_prop->pspec);
 
   if (!prop)
     {
       prop = property_data_new ();
-      g_hash_table_insert (priv->properties, pspec, prop);
+      g_hash_table_insert (priv->properties, style_prop->pspec, prop);
     }
 
   val = property_data_get_value (prop, state);
@@ -533,8 +533,8 @@ _gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
     }
 
   g_value_copy (value, val);
-  if (pspec->value_type == value_type)
-    g_param_value_validate (pspec, val);
+  if (style_prop->pspec->value_type == value_type)
+    g_param_value_validate (style_prop->pspec, val);
 }
 
 /**
@@ -568,10 +568,10 @@ gtk_style_properties_set_property (GtkStyleProperties *props,
       return;
     }
 
-  _gtk_style_properties_set_property_by_pspec (props,
-                                               node->pspec,
-                                               state,
-                                               value);
+  _gtk_style_properties_set_property_by_property (props,
+                                                  node,
+                                                  state,
+                                                  value);
 }
 
 /**
diff --git a/gtk/gtkstylepropertiesprivate.h b/gtk/gtkstylepropertiesprivate.h
index a75da44..bbb5d81 100644
--- a/gtk/gtkstylepropertiesprivate.h
+++ b/gtk/gtkstylepropertiesprivate.h
@@ -25,15 +25,15 @@
 
 G_BEGIN_DECLS
 
-const GValue * _gtk_style_properties_peek_property         (GtkStyleProperties      *props,
-                                                            const gchar             *prop_name,
-                                                            GtkStateFlags            state,
-                                                            const GtkStyleProperty **property);
+const GValue * _gtk_style_properties_peek_property            (GtkStyleProperties      *props,
+                                                               const gchar             *prop_name,
+                                                               GtkStateFlags            state,
+                                                               const GtkStyleProperty **property);
 
-void           _gtk_style_properties_set_property_by_pspec (GtkStyleProperties      *props,
-                                                            GParamSpec              *pspec,
-                                                            GtkStateFlags            state,
-                                                            const GValue            *value);
+void           _gtk_style_properties_set_property_by_property (GtkStyleProperties      *props,
+                                                               const GtkStyleProperty  *property,
+                                                               GtkStateFlags            state,
+                                                               const GValue            *value);
 
 G_END_DECLS
 



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