]> Pileus Git - ~andy/gtk/commitdiff
shorthand: Add a "pack_first_element" pack function
authorBenjamin Otte <otte@redhat.com>
Tue, 10 Jan 2012 22:49:21 +0000 (23:49 +0100)
committerBenjamin Otte <otte@redhat.com>
Wed, 11 Jan 2012 14:48:53 +0000 (15:48 +0100)
And use it where appropriate.
See the docs in the function for what it does.

gtk/gtkcssshorthandpropertyimpl.c

index d2a62ea3482c4bcaf0d438e5bb516ef74b9e6613..c3e6332a2991b6cf5f81bc546b888e91655e6302 100644 (file)
@@ -797,17 +797,30 @@ unpack_border_color (GtkCssShorthandProperty *shorthand,
 }
 
 static void
-pack_border_color (GtkCssShorthandProperty *shorthand,
-                   GValue                  *value,
-                   GtkStyleProperties      *props,
-                   GtkStateFlags            state)
+pack_first_element (GtkCssShorthandProperty *shorthand,
+                    GValue                  *value,
+                    GtkStyleProperties      *props,
+                    GtkStateFlags            state)
 {
-  /* NB: We are a color property, so we have to resolve to a color here.
-   * So we just resolve to a color. We pick one and stick to it.
-   * Lesson learned: Don't query border-color shorthand, query the 
+  GtkCssStyleProperty *prop;
+  const GValue *v;
+  guint i;
+
+  /* NB: This is a fallback for properties that originally were
+   * not used as shorthand. We just pick the first subproperty
+   * as a representative.
+   * Lesson learned: Don't query the shorthand, query the 
    * real properties instead. */
-  g_value_unset (value);
-  gtk_style_properties_get_property (props, "border-top-color", state, value);
+  for (i = 0; i < _gtk_css_shorthand_property_get_n_subproperties (shorthand); i++)
+    {
+      prop = _gtk_css_shorthand_property_get_subproperty (shorthand, 0);
+      v = _gtk_style_properties_peek_property (props, prop, state);
+      if (v)
+        {
+          g_value_copy (v, value);
+          return;
+        }
+    }
 }
 
 static GParameter *
@@ -837,19 +850,6 @@ unpack_border_style (GtkCssShorthandProperty *shorthand,
   return parameter;
 }
 
-static void
-pack_border_style (GtkCssShorthandProperty *shorthand,
-                   GValue                  *value,
-                   GtkStyleProperties      *props,
-                   GtkStateFlags            state)
-{
-  /* NB: We can just resolve to a style. We pick one and stick to it.
-   * Lesson learned: Don't query border-style shorthand, query the
-   * real properties instead. */
-  g_value_unset (value);
-  gtk_style_properties_get_property (props, "border-top-style", state, value);
-}
-
 static void
 _gtk_css_shorthand_property_register (const char                        *name,
                                       GType                              value_type,
@@ -931,13 +931,13 @@ _gtk_css_shorthand_property_init_properties (void)
                                           border_color_subproperties,
                                           parse_border_color,
                                           unpack_border_color,
-                                          pack_border_color);
+                                          pack_first_element);
   _gtk_css_shorthand_property_register   ("border-style",
                                           GTK_TYPE_BORDER_STYLE,
                                           border_style_subproperties,
                                           parse_border_style,
                                           unpack_border_style,
-                                          pack_border_style);
+                                          pack_first_element);
   _gtk_css_shorthand_property_register   ("border-image",
                                           G_TYPE_NONE,
                                           border_image_subproperties,