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 "gtkcsscustompropertyprivate.h"
27 #include "gtkthemingengine.h"
29 G_DEFINE_TYPE (GtkCssCustomProperty, _gtk_css_custom_property, GTK_TYPE_CSS_STYLE_PROPERTY)
32 _gtk_css_custom_property_class_init (GtkCssCustomPropertyClass *klass)
38 _gtk_css_custom_property_init (GtkCssCustomProperty *custom_property)
43 gtk_css_custom_property_create_initial_value (GParamSpec *pspec,
46 g_value_init (value, pspec->value_type);
48 if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
49 g_value_set_object (value, gtk_theming_engine_load (NULL));
50 else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
51 g_value_take_boxed (value, pango_font_description_from_string ("Sans 10"));
52 else if (pspec->value_type == GDK_TYPE_RGBA)
55 gdk_rgba_parse (&color, "pink");
56 g_value_set_boxed (value, &color);
58 else if (pspec->value_type == GTK_TYPE_BORDER)
60 g_value_take_boxed (value, gtk_border_new ());
63 g_param_value_set_default (pspec, value);
66 /* Property registration functions */
69 * gtk_theming_engine_register_property: (skip)
70 * @name_space: namespace for the property name
71 * @parse_func: parsing function to use, or %NULL
72 * @pspec: the #GParamSpec for the new property
74 * Registers a property so it can be used in the CSS file format,
75 * on the CSS file the property will look like
76 * "-${@name_space}-${property_name}". being
77 * ${property_name} the given to @pspec. @name_space will usually
78 * be the theme engine name.
80 * For any type a @parse_func may be provided, being this function
81 * used for turning any property value (between ':' and ';') in
82 * CSS to the #GValue needed. For basic types there is already
83 * builtin parsing support, so %NULL may be provided for these
87 * Engines must ensure property registration happens exactly once,
88 * usually GTK+ deals with theming engines as singletons, so this
89 * should be guaranteed to happen once, but bear this in mind
90 * when creating #GtkThemeEngine<!-- -->s yourself.
94 * In order to make use of the custom registered properties in
95 * the CSS file, make sure the engine is loaded first by specifying
96 * the engine property, either in a previous rule or within the same
100 * engine: someengine;
101 * -SomeEngine-custom-property: 2;
109 gtk_theming_engine_register_property (const gchar *name_space,
110 GtkStylePropertyParser parse_func,
113 GtkStyleProperty *node;
114 GValue initial = { 0, };
117 g_return_if_fail (name_space != NULL);
118 g_return_if_fail (strchr (name_space, ' ') == NULL);
119 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
121 name = g_strdup_printf ("-%s-%s", name_space, pspec->name);
122 gtk_css_custom_property_create_initial_value (pspec, &initial);
124 node = g_object_new (GTK_TYPE_CSS_CUSTOM_PROPERTY,
125 "initial-value", &initial,
127 "value-type", pspec->value_type,
130 node->property_parse_func = parse_func;
132 g_value_unset (&initial);
137 * gtk_style_properties_register_property: (skip)
138 * @parse_func: parsing function to use, or %NULL
139 * @pspec: the #GParamSpec for the new property
141 * Registers a property so it can be used in the CSS file format.
142 * This function is the low-level equivalent of
143 * gtk_theming_engine_register_property(), if you are implementing
144 * a theming engine, you want to use that function instead.
149 gtk_style_properties_register_property (GtkStylePropertyParser parse_func,
152 GtkStyleProperty *node;
153 GValue initial = { 0, };
155 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
157 gtk_css_custom_property_create_initial_value (pspec, &initial);
159 node = g_object_new (GTK_TYPE_CSS_CUSTOM_PROPERTY,
160 "initial-value", &initial,
162 "value-type", pspec->value_type,
165 node->property_parse_func = parse_func;
167 g_value_unset (&initial);
171 * gtk_style_properties_lookup_property: (skip)
172 * @property_name: property name to look up
173 * @parse_func: (out): return location for the parse function
174 * @pspec: (out) (transfer none): return location for the #GParamSpec
176 * Returns %TRUE if a property has been registered, if @pspec or
177 * @parse_func are not %NULL, the #GParamSpec and parsing function
178 * will be respectively returned.
180 * Returns: %TRUE if the property is registered, %FALSE otherwise
185 gtk_style_properties_lookup_property (const gchar *property_name,
186 GtkStylePropertyParser *parse_func,
189 GtkStyleProperty *node;
190 gboolean found = FALSE;
192 g_return_val_if_fail (property_name != NULL, FALSE);
194 node = _gtk_style_property_lookup (property_name);
196 if (GTK_IS_CSS_CUSTOM_PROPERTY (node))
199 *pspec = node->pspec;
202 *parse_func = node->property_parse_func;