1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
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 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
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include "gtkstyleproperties.h"
25 #include <gobject/gvaluecollector.h>
26 #include <cairo-gobject.h>
28 #include "gtktypebuiltins.h"
29 #include "gtkstyleprovider.h"
30 #include "gtksymboliccolor.h"
31 #include "gtkprivate.h"
32 #include "gtkthemingengine.h"
33 #include "gtkanimationdescription.h"
34 #include "gtkborder.h"
35 #include "gtkgradient.h"
36 #include "gtk9slice.h"
37 #include "gtkshadowprivate.h"
41 * SECTION:gtkstyleproperties
42 * @Short_description: Store for style property information
43 * @Title: GtkStyleProperties
45 * GtkStyleProperties provides the storage for style information
46 * that is used by #GtkStyleContext and other #GtkStyleProvider
49 * Before style properties can be stored in GtkStyleProperties, they
50 * must be registered with gtk_style_properties_register_property().
52 * Unless you are writing a #GtkStyleProvider implementation, you
53 * are unlikely to use this API directly, as gtk_style_context_get()
54 * and its variants are the preferred way to access styling information
55 * from widget implementations and theming engine implementations
56 * should use the APIs provided by #GtkThemingEngine instead.
59 typedef struct GtkStylePropertiesPrivate GtkStylePropertiesPrivate;
60 typedef struct PropertyData PropertyData;
61 typedef struct _GtkStyleProperty GtkStyleProperty;
62 typedef struct ValueData ValueData;
64 struct _GtkStyleProperty
67 GtkStylePropertyParser parse_func;
81 struct GtkStylePropertiesPrivate
83 GHashTable *color_map;
84 GHashTable *properties;
87 static GHashTable *properties = NULL;
89 static void gtk_style_properties_provider_init (GtkStyleProviderIface *iface);
90 static void gtk_style_properties_finalize (GObject *object);
93 G_DEFINE_TYPE_EXTENDED (GtkStyleProperties, gtk_style_properties, G_TYPE_OBJECT, 0,
94 G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
95 gtk_style_properties_provider_init));
98 gtk_style_properties_class_init (GtkStylePropertiesClass *klass)
100 GObjectClass *object_class = G_OBJECT_CLASS (klass);
103 object_class->finalize = gtk_style_properties_finalize;
105 /* Initialize default property set */
106 pspec = g_param_spec_boxed ("color",
110 gtk_style_param_set_inherit (pspec, TRUE);
111 gtk_style_properties_register_property (NULL, pspec);
113 pspec = g_param_spec_boxed ("font",
116 PANGO_TYPE_FONT_DESCRIPTION, 0);
117 gtk_style_param_set_inherit (pspec, TRUE);
118 gtk_style_properties_register_property (NULL, pspec);
120 pspec = g_param_spec_boxed ("text-shadow",
124 gtk_style_param_set_inherit (pspec, TRUE);
125 gtk_style_properties_register_property (NULL, pspec);
127 gtk_style_properties_register_property (NULL,
128 g_param_spec_boxed ("margin",
131 GTK_TYPE_BORDER, 0));
132 gtk_style_properties_register_property (NULL,
133 g_param_spec_boxed ("padding",
136 GTK_TYPE_BORDER, 0));
137 gtk_style_properties_register_property (NULL,
138 g_param_spec_boxed ("border-width",
140 "Border width, in pixels",
141 GTK_TYPE_BORDER, 0));
142 gtk_style_properties_register_property (NULL,
143 g_param_spec_int ("border-radius",
145 "Border radius, in pixels",
147 gtk_style_properties_register_property (NULL,
148 g_param_spec_enum ("border-style",
151 GTK_TYPE_BORDER_STYLE,
152 GTK_BORDER_STYLE_NONE, 0));
153 gtk_style_properties_register_property (NULL,
154 g_param_spec_boxed ("border-color",
158 gtk_style_properties_register_property (NULL,
159 g_param_spec_boxed ("background-color",
163 gtk_style_properties_register_property (NULL,
164 g_param_spec_boxed ("background-image",
167 CAIRO_GOBJECT_TYPE_PATTERN, 0));
168 gtk_style_properties_register_property (NULL,
169 g_param_spec_boxed ("border-image",
172 GTK_TYPE_9SLICE, 0));
173 gtk_style_properties_register_property (NULL,
174 g_param_spec_object ("engine",
177 GTK_TYPE_THEMING_ENGINE, 0));
178 gtk_style_properties_register_property (NULL,
179 g_param_spec_boxed ("transition",
180 "Transition animation description",
181 "Transition animation description",
182 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
184 /* Private property holding the binding sets */
185 gtk_style_properties_register_property (NULL,
186 g_param_spec_boxed ("gtk-key-bindings",
189 G_TYPE_PTR_ARRAY, 0));
191 g_type_class_add_private (object_class, sizeof (GtkStylePropertiesPrivate));
194 static PropertyData *
195 property_data_new (void)
199 data = g_slice_new0 (PropertyData);
200 data->values = g_array_new (FALSE, FALSE, sizeof (ValueData));
206 property_data_remove_values (PropertyData *data)
210 for (i = 0; i < data->values->len; i++)
212 ValueData *value_data;
214 value_data = &g_array_index (data->values, ValueData, i);
216 if (G_IS_VALUE (&value_data->value))
217 g_value_unset (&value_data->value);
220 if (data->values->len > 0)
221 g_array_remove_range (data->values, 0, data->values->len);
225 property_data_free (PropertyData *data)
227 property_data_remove_values (data);
228 g_array_free (data->values, TRUE);
229 g_slice_free (PropertyData, data);
233 property_data_find_position (PropertyData *data,
238 gboolean found = FALSE;
244 if (data->values->len == 0)
247 /* Find position for the given state, or the position where
248 * it would be if not found, the array is ordered by the
252 max = data->values->len - 1;
256 ValueData *value_data;
258 mid = (min + max) / 2;
259 value_data = &g_array_index (data->values, ValueData, mid);
261 if (value_data->state == state)
266 else if (value_data->state < state)
267 position = min = mid + 1;
274 while (!found && min <= max);
283 property_data_get_value (PropertyData *data,
289 if (!property_data_find_position (data, state, &pos))
291 ValueData new = { 0 };
294 g_array_insert_val (data->values, pos, new);
297 val_data = &g_array_index (data->values, ValueData, pos);
299 return &val_data->value;
303 property_data_match_state (PropertyData *data,
309 if (property_data_find_position (data, state, &pos))
314 val_data = &g_array_index (data->values, ValueData, pos);
315 return &val_data->value;
318 if (pos >= data->values->len)
319 pos = data->values->len - 1;
321 /* No exact match, go downwards the list to find
322 * the closest match to the given state flags, as
323 * a side effect, there is an implicit precedence
324 * of higher flags over the smaller ones.
326 for (i = pos; i >= 0; i--)
330 val_data = &g_array_index (data->values, ValueData, i);
332 /* Check whether any of the requested
333 * flags are set, and no other flags are.
335 * Also, no flags acts as a wildcard, such
336 * value should be always in the first position
337 * in the array (if present) anyways.
339 if (val_data->state == 0 ||
340 ((val_data->state & state) != 0 &&
341 (val_data->state & ~state) == 0))
342 return &val_data->value;
349 gtk_style_properties_init (GtkStyleProperties *props)
351 GtkStylePropertiesPrivate *priv;
353 priv = props->priv = G_TYPE_INSTANCE_GET_PRIVATE (props,
354 GTK_TYPE_STYLE_PROPERTIES,
355 GtkStylePropertiesPrivate);
357 priv->properties = g_hash_table_new_full (NULL, NULL, NULL,
358 (GDestroyNotify) property_data_free);
362 gtk_style_properties_finalize (GObject *object)
364 GtkStylePropertiesPrivate *priv;
365 GtkStyleProperties *props;
367 props = GTK_STYLE_PROPERTIES (object);
369 g_hash_table_destroy (priv->properties);
372 g_hash_table_destroy (priv->color_map);
374 G_OBJECT_CLASS (gtk_style_properties_parent_class)->finalize (object);
378 gtk_style_properties_get_style (GtkStyleProvider *provider,
381 /* Return style set itself */
382 return g_object_ref (provider);
386 gtk_style_properties_provider_init (GtkStyleProviderIface *iface)
388 iface->get_style = gtk_style_properties_get_style;
391 static GtkStyleProperty *
392 gtk_style_property_lookup (const char *name)
397 return g_hash_table_lookup (properties, name);
400 /* Property registration functions */
403 * gtk_style_properties_register_property: (skip)
404 * @parse_func: parsing function to use, or %NULL
405 * @pspec: the #GParamSpec for the new property
407 * Registers a property so it can be used in the CSS file format.
408 * This function is the low-level equivalent of
409 * gtk_theming_engine_register_property(), if you are implementing
410 * a theming engine, you want to use that function instead.
415 gtk_style_properties_register_property (GtkStylePropertyParser parse_func,
418 GtkStyleProperty *node;
420 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
422 /* stuff is never freed, so no need for free functions */
423 if (G_UNLIKELY (!properties))
424 properties = g_hash_table_new (g_str_hash, g_str_equal);
426 if ((node = gtk_style_property_lookup (pspec->name)) != NULL)
428 g_warning ("Property \"%s\" was already registered with type %s",
429 pspec->name, g_type_name (node->pspec->value_type));
433 node = g_slice_new0 (GtkStyleProperty);
435 node->parse_func = parse_func;
437 g_hash_table_insert (properties, pspec->name, node);
441 * gtk_style_properties_lookup_property: (skip)
442 * @property_name: property name to look up
443 * @parse_func: (out): return location for the parse function
444 * @pspec: (out) (transfer none): return location for the #GParamSpec
446 * Returns %TRUE if a property has been registered, if @pspec or
447 * @parse_func are not %NULL, the #GParamSpec and parsing function
448 * will be respectively returned.
450 * Returns: %TRUE if the property is registered, %FALSE otherwise
455 gtk_style_properties_lookup_property (const gchar *property_name,
456 GtkStylePropertyParser *parse_func,
459 GtkStyleProperty *node;
460 GtkStylePropertiesClass *klass;
461 gboolean found = FALSE;
463 g_return_val_if_fail (property_name != NULL, FALSE);
465 klass = g_type_class_ref (GTK_TYPE_STYLE_PROPERTIES);
467 node = gtk_style_property_lookup (property_name);
472 *pspec = node->pspec;
475 *parse_func = node->parse_func;
480 g_type_class_unref (klass);
485 /* GParamSpec functionality */
488 GTK_STYLE_PROPERTY_INHERIT = 1 << G_PARAM_USER_SHIFT
492 * gtk_style_param_set_inherit:
493 * @pspec: A style param
494 * @inherit: whether the @pspec value should be inherited
496 * Sets whether a param spec installed with function such as
497 * gtk_style_properties_register_property() or
498 * gtk_widget_class_install_style_property() should inherit their
499 * value from the parent widget if it is not set instead of using
500 * the default value of @pspec. See the
501 * <ulink url="http://www.w3.org/TR/CSS21/cascade.html#inheritance">
502 * CSS specification's description of inheritance</ulink> for a
503 * longer description of this concept.
505 * By default, param specs do not inherit their value.
508 gtk_style_param_set_inherit (GParamSpec *pspec,
512 pspec->flags |= GTK_STYLE_PROPERTY_INHERIT;
514 pspec->flags &= ~GTK_STYLE_PROPERTY_INHERIT;
518 * gtk_style_param_get_inherit:
519 * @pspec: a style param
521 * Checks if the value of this param should be inherited from the parent
522 * #GtkWidget instead of using the default value when it has not been
523 * specified. See gtk_style_param_set_inherit() for more details.
525 * Returns: %TRUE if the param should inherit its value
528 gtk_style_param_get_inherit (GParamSpec *pspec)
530 return (pspec->flags & GTK_STYLE_PROPERTY_INHERIT) ? TRUE : FALSE;
533 /* GtkStyleProperties methods */
536 * gtk_style_properties_new:
538 * Returns a newly created #GtkStyleProperties
540 * Returns: a new #GtkStyleProperties
543 gtk_style_properties_new (void)
545 return g_object_new (GTK_TYPE_STYLE_PROPERTIES, NULL);
549 * gtk_style_properties_map_color:
550 * @props: a #GtkStyleProperties
552 * @color: #GtkSymbolicColor to map @name to
554 * Maps @color so it can be referenced by @name. See
555 * gtk_style_properties_lookup_color()
560 gtk_style_properties_map_color (GtkStyleProperties *props,
562 GtkSymbolicColor *color)
564 GtkStylePropertiesPrivate *priv;
566 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
567 g_return_if_fail (name != NULL);
568 g_return_if_fail (color != NULL);
572 if (G_UNLIKELY (!priv->color_map))
573 priv->color_map = g_hash_table_new_full (g_str_hash,
575 (GDestroyNotify) g_free,
576 (GDestroyNotify) gtk_symbolic_color_unref);
578 g_hash_table_replace (priv->color_map,
580 gtk_symbolic_color_ref (color));
584 * gtk_style_properties_lookup_color:
585 * @props: a #GtkStyleProperties
586 * @name: color name to lookup
588 * Returns the symbolic color that is mapped
591 * Returns: (transfer none): The mapped color
596 gtk_style_properties_lookup_color (GtkStyleProperties *props,
599 GtkStylePropertiesPrivate *priv;
601 g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL);
602 g_return_val_if_fail (name != NULL, NULL);
606 if (!priv->color_map)
609 return g_hash_table_lookup (priv->color_map, name);
613 _gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
618 GtkStylePropertiesPrivate *priv;
623 value_type = G_VALUE_TYPE (value);
625 if (pspec->value_type == GDK_TYPE_RGBA ||
626 pspec->value_type == GDK_TYPE_COLOR)
628 /* Allow GtkSymbolicColor as well */
629 g_return_if_fail (value_type == GDK_TYPE_RGBA ||
630 value_type == GDK_TYPE_COLOR ||
631 value_type == GTK_TYPE_SYMBOLIC_COLOR);
633 else if (pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN)
635 /* Allow GtkGradient as a substitute */
636 g_return_if_fail (value_type == CAIRO_GOBJECT_TYPE_PATTERN ||
637 value_type == GTK_TYPE_GRADIENT);
640 g_return_if_fail (pspec->value_type == value_type);
643 prop = g_hash_table_lookup (priv->properties, pspec);
647 prop = property_data_new ();
648 g_hash_table_insert (priv->properties, pspec, prop);
651 val = property_data_get_value (prop, state);
653 if (G_VALUE_TYPE (val) == value_type)
657 if (G_IS_VALUE (val))
660 g_value_init (val, value_type);
663 g_value_copy (value, val);
667 * gtk_style_properties_set_property:
668 * @props: a #GtkStyleProperties
669 * @property: styling property to set
670 * @state: state to set the value for
671 * @value: new value for the property
673 * Sets a styling property in @props.
678 gtk_style_properties_set_property (GtkStyleProperties *props,
679 const gchar *property,
683 GtkStyleProperty *node;
685 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
686 g_return_if_fail (property != NULL);
687 g_return_if_fail (value != NULL);
689 node = gtk_style_property_lookup (property);
693 g_warning ("Style property \"%s\" is not registered", property);
697 _gtk_style_properties_set_property_by_pspec (props,
704 * gtk_style_properties_set_valist:
705 * @props: a #GtkStyleProperties
706 * @state: state to set the values for
707 * @args: va_list of property name/value pairs, followed by %NULL
709 * Sets several style properties on @props.
714 gtk_style_properties_set_valist (GtkStyleProperties *props,
718 GtkStylePropertiesPrivate *priv;
719 const gchar *property_name;
721 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
724 property_name = va_arg (args, const gchar *);
726 while (property_name)
728 GtkStyleProperty *node;
733 node = gtk_style_property_lookup (property_name);
737 g_warning ("Style property \"%s\" is not registered", property_name);
741 prop = g_hash_table_lookup (priv->properties, node->pspec);
745 prop = property_data_new ();
746 g_hash_table_insert (priv->properties, node->pspec, prop);
749 val = property_data_get_value (prop, state);
751 if (G_IS_VALUE (val))
754 G_VALUE_COLLECT_INIT (val, node->pspec->value_type,
758 g_warning ("Could not set style property \"%s\": %s", property_name, error);
764 property_name = va_arg (args, const gchar *);
769 * gtk_style_properties_set:
770 * @props: a #GtkStyleProperties
771 * @state: state to set the values for
772 * @...: property name/value pairs, followed by %NULL
774 * Sets several style properties on @props.
779 gtk_style_properties_set (GtkStyleProperties *props,
785 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
787 va_start (args, state);
788 gtk_style_properties_set_valist (props, state, args);
793 resolve_color (GtkStyleProperties *props,
798 /* Resolve symbolic color to GdkRGBA */
799 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
802 /* Store it back, this is where GdkRGBA caching happens */
803 g_value_unset (value);
804 g_value_init (value, GDK_TYPE_RGBA);
805 g_value_set_boxed (value, &color);
811 resolve_color_rgb (GtkStyleProperties *props,
814 GdkColor color = { 0 };
817 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
820 color.red = rgba.red * 65535. + 0.5;
821 color.green = rgba.green * 65535. + 0.5;
822 color.blue = rgba.blue * 65535. + 0.5;
824 g_value_unset (value);
825 g_value_init (value, GDK_TYPE_COLOR);
826 g_value_set_boxed (value, &color);
832 resolve_gradient (GtkStyleProperties *props,
835 cairo_pattern_t *gradient;
837 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
840 /* Store it back, this is where cairo_pattern_t caching happens */
841 g_value_unset (value);
842 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
843 g_value_take_boxed (value, gradient);
849 resolve_shadow (GtkStyleProperties *props,
852 GtkShadow *resolved, *base;
854 base = g_value_get_boxed (value);
859 if (_gtk_shadow_get_resolved (base))
862 resolved = _gtk_shadow_resolve (base, props);
863 if (resolved == NULL)
866 g_value_take_boxed (value, resolved);
872 style_properties_resolve_type (GtkStyleProperties *props,
873 GtkStyleProperty *node,
876 if (val && G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
878 if (node->pspec->value_type == GDK_TYPE_RGBA)
880 if (!resolve_color (props, val))
883 else if (node->pspec->value_type == GDK_TYPE_COLOR)
885 if (!resolve_color_rgb (props, val))
891 else if (val && G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
893 g_return_val_if_fail (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE);
895 if (!resolve_gradient (props, val))
898 else if (val && G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
900 if (!resolve_shadow (props, val))
908 lookup_default_value (GtkStyleProperty *node,
911 if (node->pspec->value_type == GTK_TYPE_THEMING_ENGINE)
912 g_value_set_object (value, gtk_theming_engine_load (NULL));
913 else if (node->pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
914 g_value_take_boxed (value, pango_font_description_from_string ("Sans 10"));
915 else if (node->pspec->value_type == GDK_TYPE_RGBA)
918 gdk_rgba_parse (&color, "pink");
919 g_value_set_boxed (value, &color);
921 else if (node->pspec->value_type == GTK_TYPE_BORDER)
923 g_value_take_boxed (value, gtk_border_new ());
926 g_param_value_set_default (node->pspec, value);
930 _gtk_style_properties_peek_property (GtkStyleProperties *props,
931 const gchar *prop_name,
934 GtkStylePropertiesPrivate *priv;
935 GtkStyleProperty *node;
939 g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL);
940 g_return_val_if_fail (prop_name != NULL, NULL);
942 node = gtk_style_property_lookup (prop_name);
946 g_warning ("Style property \"%s\" is not registered", prop_name);
951 prop = g_hash_table_lookup (priv->properties, node->pspec);
956 val = property_data_match_state (prop, state);
959 !style_properties_resolve_type (props, node, val))
966 * gtk_style_properties_get_property:
967 * @props: a #GtkStyleProperties
968 * @property: style property name
969 * @state: state to retrieve the property value for
970 * @value: (out) (transfer full): return location for the style property value.
972 * Gets a style property from @props for the given state. When done with @value,
973 * g_value_unset() needs to be called to free any allocated memory.
975 * Returns: %TRUE if the property exists in @props, %FALSE otherwise
980 gtk_style_properties_get_property (GtkStyleProperties *props,
981 const gchar *property,
985 GtkStylePropertiesPrivate *priv;
986 GtkStyleProperty *node;
990 g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
991 g_return_val_if_fail (property != NULL, FALSE);
992 g_return_val_if_fail (value != NULL, FALSE);
994 node = gtk_style_property_lookup (property);
998 g_warning ("Style property \"%s\" is not registered", property);
1003 prop = g_hash_table_lookup (priv->properties, node->pspec);
1008 g_value_init (value, node->pspec->value_type);
1009 val = property_data_match_state (prop, state);
1012 !style_properties_resolve_type (props, node, val))
1017 g_param_value_validate (node->pspec, val);
1018 g_value_copy (val, value);
1021 lookup_default_value (node, value);
1027 * gtk_style_properties_get_valist:
1028 * @props: a #GtkStyleProperties
1029 * @state: state to retrieve the property values for
1030 * @args: va_list of property name/return location pairs, followed by %NULL
1032 * Retrieves several style property values from @props for a given state.
1037 gtk_style_properties_get_valist (GtkStyleProperties *props,
1038 GtkStateFlags state,
1041 GtkStylePropertiesPrivate *priv;
1042 const gchar *property_name;
1044 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1047 property_name = va_arg (args, const gchar *);
1049 while (property_name)
1051 GtkStyleProperty *node;
1053 gchar *error = NULL;
1056 node = gtk_style_property_lookup (property_name);
1060 g_warning ("Style property \"%s\" is not registered", property_name);
1064 prop = g_hash_table_lookup (priv->properties, node->pspec);
1067 val = property_data_match_state (prop, state);
1070 !style_properties_resolve_type (props, node, val))
1075 g_param_value_validate (node->pspec, val);
1076 G_VALUE_LCOPY (val, args, 0, &error);
1080 GValue default_value = { 0 };
1082 g_value_init (&default_value, node->pspec->value_type);
1083 lookup_default_value (node, &default_value);
1084 G_VALUE_LCOPY (&default_value, args, 0, &error);
1085 g_value_unset (&default_value);
1090 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1095 property_name = va_arg (args, const gchar *);
1100 * gtk_style_properties_get:
1101 * @props: a #GtkStyleProperties
1102 * @state: state to retrieve the property values for
1103 * @...: property name /return value pairs, followed by %NULL
1105 * Retrieves several style property values from @props for a
1111 gtk_style_properties_get (GtkStyleProperties *props,
1112 GtkStateFlags state,
1117 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1119 va_start (args, state);
1120 gtk_style_properties_get_valist (props, state, args);
1125 * gtk_style_properties_unset_property:
1126 * @props: a #GtkStyleProperties
1127 * @property: property to unset
1128 * @state: state to unset
1130 * Unsets a style property in @props.
1135 gtk_style_properties_unset_property (GtkStyleProperties *props,
1136 const gchar *property,
1137 GtkStateFlags state)
1139 GtkStylePropertiesPrivate *priv;
1140 GtkStyleProperty *node;
1144 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1145 g_return_if_fail (property != NULL);
1147 node = gtk_style_property_lookup (property);
1151 g_warning ("Style property \"%s\" is not registered", property);
1156 prop = g_hash_table_lookup (priv->properties, node->pspec);
1161 if (property_data_find_position (prop, state, &pos))
1165 data = &g_array_index (prop->values, ValueData, pos);
1167 if (G_IS_VALUE (&data->value))
1168 g_value_unset (&data->value);
1170 g_array_remove_index (prop->values, pos);
1175 * gtk_style_properties_clear:
1176 * @props: a #GtkStyleProperties
1178 * Clears all style information from @props.
1181 gtk_style_properties_clear (GtkStyleProperties *props)
1183 GtkStylePropertiesPrivate *priv;
1185 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1188 g_hash_table_remove_all (priv->properties);
1192 * gtk_style_properties_merge:
1193 * @props: a #GtkStyleProperties
1194 * @props_to_merge: a second #GtkStyleProperties
1195 * @replace: whether to replace values or not
1197 * Merges into @props all the style information contained
1198 * in @props_to_merge. If @replace is %TRUE, the values
1199 * will be overwritten, if it is %FALSE, the older values
1205 gtk_style_properties_merge (GtkStyleProperties *props,
1206 const GtkStyleProperties *props_to_merge,
1209 GtkStylePropertiesPrivate *priv, *priv_to_merge;
1210 GHashTableIter iter;
1211 gpointer key, value;
1213 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1214 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props_to_merge));
1217 priv_to_merge = props_to_merge->priv;
1219 /* Merge symbolic color map */
1220 if (priv_to_merge->color_map)
1222 g_hash_table_iter_init (&iter, priv_to_merge->color_map);
1224 while (g_hash_table_iter_next (&iter, &key, &value))
1227 GtkSymbolicColor *color;
1233 g_hash_table_lookup (priv->color_map, name))
1236 gtk_style_properties_map_color (props, name, color);
1240 /* Merge symbolic style properties */
1241 g_hash_table_iter_init (&iter, priv_to_merge->properties);
1243 while (g_hash_table_iter_next (&iter, &key, &value))
1245 PropertyData *prop_to_merge = value;
1249 prop = g_hash_table_lookup (priv->properties, key);
1253 prop = property_data_new ();
1254 g_hash_table_insert (priv->properties, key, prop);
1257 for (i = 0; i < prop_to_merge->values->len; i++)
1262 data = &g_array_index (prop_to_merge->values, ValueData, i);
1264 if (replace && data->state == GTK_STATE_FLAG_NORMAL &&
1265 G_VALUE_TYPE (&data->value) != PANGO_TYPE_FONT_DESCRIPTION)
1267 /* Let normal state override all states
1268 * previously set in the original set
1270 property_data_remove_values (prop);
1273 value = property_data_get_value (prop, data->state);
1275 if (G_VALUE_TYPE (&data->value) == PANGO_TYPE_FONT_DESCRIPTION &&
1278 PangoFontDescription *font_desc;
1279 PangoFontDescription *font_desc_to_merge;
1281 /* Handle merging of font descriptions */
1282 font_desc = g_value_get_boxed (value);
1283 font_desc_to_merge = g_value_get_boxed (&data->value);
1285 pango_font_description_merge (font_desc, font_desc_to_merge, replace);
1287 else if (G_VALUE_TYPE (&data->value) == G_TYPE_PTR_ARRAY &&
1290 GPtrArray *array, *array_to_merge;
1293 /* Append the array, mainly thought
1294 * for the gtk-key-bindings property
1296 array = g_value_get_boxed (value);
1297 array_to_merge = g_value_get_boxed (&data->value);
1299 for (i = 0; i < array_to_merge->len; i++)
1300 g_ptr_array_add (array, g_ptr_array_index (array_to_merge, i));
1302 else if (replace || !G_IS_VALUE (value))
1304 if (!G_IS_VALUE (value))
1305 g_value_init (value, G_VALUE_TYPE (&data->value));
1306 else if (G_VALUE_TYPE (value) != G_VALUE_TYPE (&data->value))
1308 g_value_unset (value);
1309 g_value_init (value, G_VALUE_TYPE (&data->value));
1312 g_value_copy (&data->value, value);