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"
32 G_DEFINE_TYPE (GtkCssShorthandProperty, _gtk_css_shorthand_property, GTK_TYPE_STYLE_PROPERTY)
35 gtk_css_shorthand_property_set_property (GObject *object,
40 GtkCssShorthandProperty *property = GTK_CSS_SHORTHAND_PROPERTY (object);
41 const char **subproperties;
46 case PROP_SUBPROPERTIES:
47 subproperties = g_value_get_boxed (value);
48 g_assert (subproperties);
49 for (i = 0; subproperties[i] != NULL; i++)
51 GtkStyleProperty *subproperty = _gtk_style_property_lookup (subproperties[i]);
52 g_assert (GTK_IS_CSS_STYLE_PROPERTY (subproperty));
53 g_ptr_array_add (property->subproperties, subproperty);
57 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
63 _gtk_css_shorthand_property_assign (GtkStyleProperty *property,
64 GtkStyleProperties *props,
68 GParameter *parameters;
69 guint i, n_parameters;
71 parameters = _gtk_style_property_unpack (property, value, &n_parameters);
73 for (i = 0; i < n_parameters; i++)
75 _gtk_style_property_assign (_gtk_style_property_lookup (parameters[i].name),
78 ¶meters[i].value);
79 g_value_unset (¶meters[i].value);
85 _gtk_css_shorthand_property_query (GtkStyleProperty *property,
86 GtkStyleProperties *props,
88 GtkStylePropertyContext *context,
91 property->pack_func (value, props, state, context);
95 _gtk_css_shorthand_property_class_init (GtkCssShorthandPropertyClass *klass)
97 GObjectClass *object_class = G_OBJECT_CLASS (klass);
98 GtkStylePropertyClass *property_class = GTK_STYLE_PROPERTY_CLASS (klass);
100 object_class->set_property = gtk_css_shorthand_property_set_property;
102 g_object_class_install_property (object_class,
104 g_param_spec_boxed ("subproperties",
106 P_("The list of subproperties"),
108 G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
110 property_class->assign = _gtk_css_shorthand_property_assign;
111 property_class->query = _gtk_css_shorthand_property_query;
115 _gtk_css_shorthand_property_init (GtkCssShorthandProperty *shorthand)
117 shorthand->subproperties = g_ptr_array_new_with_free_func (g_object_unref);
120 GtkCssStyleProperty *
121 _gtk_css_shorthand_property_get_subproperty (GtkCssShorthandProperty *shorthand,
124 g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), NULL);
125 g_return_val_if_fail (property < shorthand->subproperties->len, NULL);
127 return g_ptr_array_index (shorthand->subproperties, property);
131 _gtk_css_shorthand_property_get_n_subproperties (GtkCssShorthandProperty *shorthand)
133 g_return_val_if_fail (GTK_IS_CSS_SHORTHAND_PROPERTY (shorthand), 0);
135 return shorthand->subproperties->len;