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 "gtkcssstylepropertyprivate.h"
25 #include "gtkcssstylefuncsprivate.h"
26 #include "gtkcsstypesprivate.h"
28 #include "gtkprivatetypebuiltins.h"
37 G_DEFINE_TYPE (GtkCssStyleProperty, _gtk_css_style_property, GTK_TYPE_STYLE_PROPERTY)
40 gtk_css_style_property_constructed (GObject *object)
42 GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object);
43 GtkCssStylePropertyClass *klass = GTK_CSS_STYLE_PROPERTY_GET_CLASS (property);
45 property->id = klass->style_properties->len;
46 g_ptr_array_add (klass->style_properties, property);
48 G_OBJECT_CLASS (_gtk_css_style_property_parent_class)->constructed (object);
52 gtk_css_style_property_set_property (GObject *object,
57 GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object);
58 const GValue *initial;
63 property->inherit = g_value_get_boolean (value);
66 initial = g_value_get_boxed (value);
68 g_value_init (&property->initial_value, G_VALUE_TYPE (initial));
69 g_value_copy (initial, &property->initial_value);
72 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
78 gtk_css_style_property_get_property (GObject *object,
83 GtkCssStyleProperty *property = GTK_CSS_STYLE_PROPERTY (object);
88 g_value_set_boolean (value, property->id);
91 g_value_set_boolean (value, property->inherit);
94 g_value_set_boxed (value, &property->initial_value);
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
103 _gtk_css_style_property_class_init (GtkCssStylePropertyClass *klass)
105 GObjectClass *object_class = G_OBJECT_CLASS (klass);
107 object_class->constructed = gtk_css_style_property_constructed;
108 object_class->set_property = gtk_css_style_property_set_property;
109 object_class->get_property = gtk_css_style_property_get_property;
111 g_object_class_install_property (object_class,
113 g_param_spec_uint ("id",
115 P_("The numeric id for quick access"),
118 g_object_class_install_property (object_class,
120 g_param_spec_boolean ("inherit",
122 P_("Set if the value is inherited by default"),
124 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
125 g_object_class_install_property (object_class,
127 g_param_spec_boxed ("initial-value",
129 P_("The initial specified value used for this property"),
131 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
133 klass->style_properties = g_ptr_array_new ();
138 _gtk_css_style_property_init (GtkCssStyleProperty *style_property)
143 * _gtk_css_style_property_get_n_properties:
145 * Gets the number of style properties. This number can increase when new
146 * theme engines are loaded. Shorthand properties are not included here.
148 * Returns: The number of style properties.
151 _gtk_css_style_property_get_n_properties (void)
153 GtkCssStylePropertyClass *klass;
155 klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
157 return klass->style_properties->len;
161 * _gtk_css_style_property_lookup_by_id:
162 * @id: the id of the property
164 * Gets the style property with the given id. All style properties (but not
165 * shorthand properties) are indexable by id so that it's easy to use arrays
166 * when doing style lookups.
168 * Returns: (transfer none): The style property with the given id
170 GtkCssStyleProperty *
171 _gtk_css_style_property_lookup_by_id (guint id)
173 GtkCssStylePropertyClass *klass;
175 klass = g_type_class_peek (GTK_TYPE_CSS_STYLE_PROPERTY);
177 return g_ptr_array_index (klass->style_properties, id);
181 * _gtk_css_style_property_is_inherit:
182 * @property: the property
184 * Queries if the given @property is inherited. See
185 * <ulink url="http://www.w3.org/TR/css3-cascade/#inheritance>
186 * the CSS documentation</ulink> for an explanation of this concept.
188 * Returns: %TRUE if the property is inherited by default.
191 _gtk_css_style_property_is_inherit (GtkCssStyleProperty *property)
193 g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
195 return property->inherit;
199 * _gtk_css_style_property_get_id:
200 * @property: the property
202 * Gets the id for the given property. IDs are used to allow using arrays
205 * Returns: The id of the property
208 _gtk_css_style_property_get_id (GtkCssStyleProperty *property)
210 g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), 0);
216 * _gtk_css_style_property_get_initial_value:
217 * @property: the property
219 * Queries the initial value of the given @property. See
220 * <ulink url="http://www.w3.org/TR/css3-cascade/#intial>
221 * the CSS documentation</ulink> for an explanation of this concept.
223 * Returns: a reference to the initial value. The value will never change.
226 _gtk_css_style_property_get_initial_value (GtkCssStyleProperty *property)
228 g_return_val_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property), NULL);
230 return &property->initial_value;
234 * _gtk_css_style_property_print_value:
235 * @property: the property
236 * @value: the value to print
237 * @string: the string to print to
239 * Prints @value to the given @string in CSS format. The @value must be a
240 * valid specified value as parsed using the parse functions or as assigned
241 * via _gtk_style_property_assign().
244 _gtk_css_style_property_print_value (GtkCssStyleProperty *property,
248 g_return_if_fail (GTK_IS_CSS_STYLE_PROPERTY (property));
249 g_return_if_fail (value != NULL);
250 g_return_if_fail (string != NULL);
252 if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
254 GEnumClass *enum_class;
255 GEnumValue *enum_value;
257 enum_class = g_type_class_ref (GTK_TYPE_CSS_SPECIAL_VALUE);
258 enum_value = g_enum_get_value (enum_class, g_value_get_enum (value));
260 g_string_append (string, enum_value->value_nick);
262 g_type_class_unref (enum_class);
264 else if (GTK_STYLE_PROPERTY (property)->print_func)
265 (* GTK_STYLE_PROPERTY (property)->print_func) (value, string);
267 _gtk_css_style_print_value (value, string);