]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkcssshorthandproperty.c
Change FSF Address
[~andy/gtk] / gtk / gtkcssshorthandproperty.c
index 6b85a98bc983bd83ce6580e747dc83c98a54971d..157c946ef4ae939918b0ad7461718dadb4f50347 100644 (file)
@@ -12,8 +12,7 @@
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  *
  * Authors: Benjamin Otte <otte@gnome.org>
  */
 
 #include "gtkcssshorthandpropertyprivate.h"
 
+#include "gtkcssstylefuncsprivate.h"
+#include "gtkcsstypesprivate.h"
 #include "gtkintl.h"
+#include "gtkprivatetypebuiltins.h"
 
 enum {
   PROP_0,
@@ -65,30 +67,91 @@ _gtk_css_shorthand_property_assign (GtkStyleProperty   *property,
                                     GtkStateFlags       state,
                                     const GValue       *value)
 {
-  GParameter *parameters;
-  guint i, n_parameters;
+  GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
 
-  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);
+  shorthand->assign (shorthand, props, state, value);
 }
 
 static void
 _gtk_css_shorthand_property_query (GtkStyleProperty   *property,
-                                   GtkStyleProperties *props,
-                                   GtkStateFlags       state,
-                                  GtkStylePropertyContext *context,
-                                   GValue             *value)
+                                   GValue             *value,
+                                   GtkStyleQueryFunc   query_func,
+                                   gpointer            query_data)
+{
+  GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
+
+  shorthand->query (shorthand, value, query_func, query_data);
+}
+
+static void
+gtk_css_shorthand_property_unset_value (gpointer value)
+{
+  if (G_IS_VALUE (value))
+    g_value_unset (value);
+}
+
+static gboolean
+gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
+                                        GValue           *value,
+                                        GtkCssParser     *parser,
+                                        GFile            *base)
 {
-  property->pack_func (value, props, state, context);
+  GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
+  GArray *array;
+  guint i;
+
+  array = g_array_new (FALSE, TRUE, sizeof (GValue));
+  g_array_set_clear_func (array, gtk_css_shorthand_property_unset_value);
+  g_array_set_size (array, shorthand->subproperties->len);
+
+  if (_gtk_css_parser_try (parser, "initial", TRUE))
+    {
+      /* the initial value can be explicitly specified with the
+       * ‘initial’ keyword which all properties accept.
+       */
+      for (i = 0; i < shorthand->subproperties->len; i++)
+        {
+          GValue *val = &g_array_index (array, GValue, i);
+          g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
+          g_value_set_enum (val, GTK_CSS_INITIAL);
+        }
+    }
+  else if (_gtk_css_parser_try (parser, "inherit", TRUE))
+    {
+      /* All properties accept the ‘inherit’ value which
+       * explicitly specifies that the value will be determined
+       * by inheritance. The ‘inherit’ value can be used to
+       * strengthen inherited values in the cascade, and it can
+       * also be used on properties that are not normally inherited.
+       */
+      for (i = 0; i < shorthand->subproperties->len; i++)
+        {
+          GValue *val = &g_array_index (array, GValue, i);
+          g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
+          g_value_set_enum (val, GTK_CSS_INHERIT);
+        }
+    }
+  else if (!shorthand->parse (shorthand, (GValue *) array->data, parser, base))
+    {
+      g_array_free (array, TRUE);
+      return FALSE;
+    }
+
+  /* All values that aren't set by the parse func are set to their
+   * default values here.
+   * XXX: Is the default always initial or can it be inherit? */
+  for (i = 0; i < shorthand->subproperties->len; i++)
+    {
+      GValue *val = &g_array_index (array, GValue, i);
+      if (G_IS_VALUE (val))
+        continue;
+      g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
+      g_value_set_enum (val, GTK_CSS_INITIAL);
+    }
+
+  g_value_init (value, G_TYPE_ARRAY);
+  g_value_take_boxed (value, array);
+  return TRUE;
 }
 
 static void
@@ -109,6 +172,7 @@ _gtk_css_shorthand_property_class_init (GtkCssShorthandPropertyClass *klass)
 
   property_class->assign = _gtk_css_shorthand_property_assign;
   property_class->query = _gtk_css_shorthand_property_query;
+  property_class->parse_value = gtk_css_shorthand_property_parse_value;
 }
 
 static void