2 * Copyright © 2011 Red Hat Inc.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Benjamin Otte <otte@gnome.org>
23 #include "gtkcssshorthandpropertyprivate.h"
25 #include "gtkcssstylefuncsprivate.h"
26 #include "gtkcsstypesprivate.h"
28 #include "gtkprivatetypebuiltins.h"
35 G_DEFINE_TYPE (GtkCssShorthandProperty, _gtk_css_shorthand_property, GTK_TYPE_STYLE_PROPERTY)
38 gtk_css_shorthand_property_set_property (GObject *object,
43 GtkCssShorthandProperty *property = GTK_CSS_SHORTHAND_PROPERTY (object);
44 const char **subproperties;
49 case PROP_SUBPROPERTIES:
50 subproperties = g_value_get_boxed (value);
51 g_assert (subproperties);
52 for (i = 0; subproperties[i] != NULL; i++)
54 GtkStyleProperty *subproperty = _gtk_style_property_lookup (subproperties[i]);
55 g_assert (GTK_IS_CSS_STYLE_PROPERTY (subproperty));
56 g_ptr_array_add (property->subproperties, subproperty);
60 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
66 _gtk_css_shorthand_property_assign (GtkStyleProperty *property,
67 GtkStyleProperties *props,
71 GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
73 shorthand->assign (shorthand, props, state, value);
77 _gtk_css_shorthand_property_query (GtkStyleProperty *property,
79 GtkStyleQueryFunc query_func,
82 GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
84 shorthand->query (shorthand, value, query_func, query_data);
88 gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
93 GtkCssShorthandProperty *shorthand = GTK_CSS_SHORTHAND_PROPERTY (property);
97 array = g_array_new (FALSE, TRUE, sizeof (GValue));
98 g_array_set_clear_func (array, (GDestroyNotify) g_value_unset);
99 g_array_set_size (array, shorthand->subproperties->len);
101 if (_gtk_css_parser_try (parser, "initial", TRUE))
103 /* the initial value can be explicitly specified with the
104 * ‘initial’ keyword which all properties accept.
106 for (i = 0; i < shorthand->subproperties->len; i++)
108 GValue *val = &g_array_index (array, GValue, i);
109 g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
110 g_value_set_enum (val, GTK_CSS_INITIAL);
113 else if (_gtk_css_parser_try (parser, "inherit", TRUE))
115 /* All properties accept the ‘inherit’ value which
116 * explicitly specifies that the value will be determined
117 * by inheritance. The ‘inherit’ value can be used to
118 * strengthen inherited values in the cascade, and it can
119 * also be used on properties that are not normally inherited.
121 for (i = 0; i < shorthand->subproperties->len; i++)
123 GValue *val = &g_array_index (array, GValue, i);
124 g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
125 g_value_set_enum (val, GTK_CSS_INHERIT);
128 else if (!shorthand->parse (shorthand, (GValue *) array->data, parser, base))
130 g_array_free (array, TRUE);
134 /* All values that aren't set by the parse func are set to their
135 * default values here.
136 * XXX: Is the default always initial or can it be inherit? */
137 for (i = 0; i < shorthand->subproperties->len; i++)
139 GValue *val = &g_array_index (array, GValue, i);
140 if (G_IS_VALUE (val))
142 g_value_init (val, GTK_TYPE_CSS_SPECIAL_VALUE);
143 g_value_set_enum (val, GTK_CSS_INITIAL);
146 g_value_init (value, G_TYPE_ARRAY);
147 g_value_take_boxed (value, array);
152 _gtk_css_shorthand_property_class_init (GtkCssShorthandPropertyClass *klass)
154 GObjectClass *object_class = G_OBJECT_CLASS (klass);
155 GtkStylePropertyClass *property_class = GTK_STYLE_PROPERTY_CLASS (klass);
157 object_class->set_property = gtk_css_shorthand_property_set_property;
159 g_object_class_install_property (object_class,
161 g_param_spec_boxed ("subproperties",
163 P_("The list of subproperties"),
165 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
167 property_class->assign = _gtk_css_shorthand_property_assign;
168 property_class->query = _gtk_css_shorthand_property_query;
169 property_class->parse_value = gtk_css_shorthand_property_parse_value;
173 _gtk_css_shorthand_property_init (GtkCssShorthandProperty *shorthand)
175 shorthand->subproperties = g_ptr_array_new_with_free_func (g_object_unref);
178 GtkCssStyleProperty *
179 _gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
182 g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), NULL);
183 g_return_val_if_fail (property < shorthand->subproperties->len, NULL);
185 return g_ptr_array_index (shorthand->subproperties, property);
189 _gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand)
191 g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), 0);
193 return shorthand->subproperties->len;