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"
40 * SECTION:gtkstyleproperties
41 * @Short_description: Store for style property information
42 * @Title: GtkStyleProperties
44 * GtkStyleProperties provides the storage for style information
45 * that is used by #GtkStyleContext and other #GtkStyleProvider
48 * Before style properties can be stored in GtkStyleProperties, they
49 * must be registered with gtk_style_properties_register_property().
51 * Unless you are writing a #GtkStyleProvider implementation, you
52 * are unlikely to use this API directly, as gtk_style_context_get()
53 * and its variants are the preferred way to access styling information
54 * from widget implementations and theming engine implementations
55 * should use the APIs provided by #GtkThemingEngine instead.
58 typedef struct GtkStylePropertiesPrivate GtkStylePropertiesPrivate;
59 typedef struct PropertyData PropertyData;
60 typedef struct PropertyNode PropertyNode;
61 typedef struct ValueData ValueData;
65 GQuark property_quark;
67 GtkStylePropertyParser parse_func;
81 struct GtkStylePropertiesPrivate
83 GHashTable *color_map;
84 GHashTable *properties;
87 static GArray *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);
102 object_class->finalize = gtk_style_properties_finalize;
104 /* Initialize default property set */
105 gtk_style_properties_register_property (NULL,
106 g_param_spec_boxed ("color",
110 gtk_style_properties_register_property (NULL,
111 g_param_spec_boxed ("background-color",
116 gtk_style_properties_register_property (NULL,
117 g_param_spec_boxed ("font",
120 PANGO_TYPE_FONT_DESCRIPTION, 0));
122 gtk_style_properties_register_property (NULL,
123 g_param_spec_boxed ("margin",
126 GTK_TYPE_BORDER, 0));
127 gtk_style_properties_register_property (NULL,
128 g_param_spec_boxed ("padding",
131 GTK_TYPE_BORDER, 0));
132 gtk_style_properties_register_property (NULL,
133 g_param_spec_boxed ("border-width",
135 "Border width, in pixels",
136 GTK_TYPE_BORDER, 0));
137 gtk_style_properties_register_property (NULL,
138 g_param_spec_int ("border-radius",
140 "Border radius, in pixels",
142 gtk_style_properties_register_property (NULL,
143 g_param_spec_enum ("border-style",
146 GTK_TYPE_BORDER_STYLE,
147 GTK_BORDER_STYLE_NONE, 0));
148 gtk_style_properties_register_property (NULL,
149 g_param_spec_boxed ("border-color",
153 gtk_style_properties_register_property (NULL,
154 g_param_spec_boxed ("background-image",
157 CAIRO_GOBJECT_TYPE_PATTERN, 0));
158 gtk_style_properties_register_property (NULL,
159 g_param_spec_boxed ("border-image",
162 GTK_TYPE_9SLICE, 0));
163 gtk_style_properties_register_property (NULL,
164 g_param_spec_object ("engine",
167 GTK_TYPE_THEMING_ENGINE, 0));
168 gtk_style_properties_register_property (NULL,
169 g_param_spec_boxed ("transition",
170 "Transition animation description",
171 "Transition animation description",
172 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
174 g_type_class_add_private (object_class, sizeof (GtkStylePropertiesPrivate));
177 static PropertyData *
178 property_data_new (void)
182 data = g_slice_new0 (PropertyData);
183 data->values = g_array_new (FALSE, FALSE, sizeof (ValueData));
189 property_data_free (PropertyData *data)
193 for (i = 0; i < data->values->len; i++)
195 ValueData *value_data;
197 value_data = &g_array_index (data->values, ValueData, i);
199 if (G_IS_VALUE (&value_data->value))
200 g_value_unset (&value_data->value);
203 g_array_free (data->values, TRUE);
204 g_slice_free (PropertyData, data);
208 property_data_find_position (PropertyData *data,
213 gboolean found = FALSE;
219 if (data->values->len == 0)
222 /* Find position for the given state, or the position where
223 * it would be if not found, the array is ordered by the
227 max = data->values->len - 1;
231 ValueData *value_data;
233 mid = (min + max) / 2;
234 value_data = &g_array_index (data->values, ValueData, mid);
236 if (value_data->state == state)
241 else if (value_data->state < state)
242 position = min = mid + 1;
249 while (!found && min <= max);
258 property_data_get_value (PropertyData *data,
264 if (!property_data_find_position (data, state, &pos))
266 ValueData new = { 0 };
269 g_array_insert_val (data->values, pos, new);
272 val_data = &g_array_index (data->values, ValueData, pos);
274 return &val_data->value;
278 property_data_match_state (PropertyData *data,
284 if (property_data_find_position (data, state, &pos))
289 val_data = &g_array_index (data->values, ValueData, pos);
290 return &val_data->value;
293 if (pos >= data->values->len)
294 pos = data->values->len - 1;
296 /* No exact match, go downwards the list to find
297 * the closest match to the given state flags, as
298 * a side effect, there is an implicit precedence
299 * of higher flags over the smaller ones.
301 for (i = pos; i >= 0; i--)
305 val_data = &g_array_index (data->values, ValueData, i);
307 /* Check whether any of the requested
308 * flags are set, and no other flags are.
310 * Also, no flags acts as a wildcard, such
311 * value should be always in the first position
312 * in the array (if present) anyways.
314 if (val_data->state == 0 ||
315 ((val_data->state & state) != 0 &&
316 (val_data->state & ~state) == 0))
317 return &val_data->value;
324 gtk_style_properties_init (GtkStyleProperties *props)
326 GtkStylePropertiesPrivate *priv;
328 priv = props->priv = G_TYPE_INSTANCE_GET_PRIVATE (props,
329 GTK_TYPE_STYLE_PROPERTIES,
330 GtkStylePropertiesPrivate);
332 priv->properties = g_hash_table_new_full (NULL, NULL, NULL,
333 (GDestroyNotify) property_data_free);
337 gtk_style_properties_finalize (GObject *object)
339 GtkStylePropertiesPrivate *priv;
340 GtkStyleProperties *props;
342 props = GTK_STYLE_PROPERTIES (object);
344 g_hash_table_destroy (priv->properties);
347 g_hash_table_destroy (priv->color_map);
349 G_OBJECT_CLASS (gtk_style_properties_parent_class)->finalize (object);
353 gtk_style_properties_get_style (GtkStyleProvider *provider,
356 /* Return style set itself */
357 return g_object_ref (provider);
361 gtk_style_properties_provider_init (GtkStyleProviderIface *iface)
363 iface->get_style = gtk_style_properties_get_style;
367 compare_property (gconstpointer p1,
370 PropertyNode *key = (PropertyNode *) p1;
371 PropertyNode *node = (PropertyNode *) p2;
373 if (key->property_quark > node->property_quark)
375 else if (key->property_quark < node->property_quark)
381 static PropertyNode *
382 property_node_lookup (GQuark quark)
384 PropertyNode key = { 0 };
392 key.property_quark = quark;
394 return bsearch (&key, properties->data, properties->len,
395 sizeof (PropertyNode), compare_property);
398 /* Property registration functions */
401 * gtk_style_properties_register_property:
402 * @parse_func: parsing function to use, or %NULL
403 * @pspec: the #GParamSpec for the new property
405 * Registers a property so it can be used in the CSS file format.
406 * This function is the low-level equivalent of
407 * gtk_theming_engine_register_property(), if you are implementing
408 * a theming engine, you want to use that function instead.
413 gtk_style_properties_register_property (GtkStylePropertyParser parse_func,
416 PropertyNode *node, new = { 0 };
420 g_return_if_fail (G_IS_PARAM_SPEC (pspec));
422 if (G_UNLIKELY (!properties))
423 properties = g_array_new (FALSE, TRUE, sizeof (PropertyNode));
425 quark = g_quark_from_string (pspec->name);
427 if ((node = property_node_lookup (quark)) != NULL)
429 g_warning ("Property \"%s\" was already registered with type %s",
430 pspec->name, g_type_name (node->pspec->value_type));
434 new.property_quark = quark;
438 new.parse_func = parse_func;
440 for (i = 0; i < properties->len; i++)
442 node = &g_array_index (properties, PropertyNode, i);
444 if (node->property_quark > quark)
448 g_array_insert_val (properties, i, new);
452 * gtk_style_properties_lookup_property:
453 * @property_name: property name to look up
454 * @parse_func: (out): return location for the parse function
455 * @pspec: (out): return location for the #GParamSpec
457 * Returns %TRUE if a property has been registered, if @pspec or
458 * @parse_func are not %NULL, the #GParamSpec and parsing function
459 * will be respectively returned.
461 * Returns: %TRUE if the property is registered, %FALSE otherwise
466 gtk_style_properties_lookup_property (const gchar *property_name,
467 GtkStylePropertyParser *parse_func,
471 GtkStylePropertiesClass *klass;
472 gboolean found = FALSE;
476 g_return_val_if_fail (property_name != NULL, FALSE);
478 klass = g_type_class_ref (GTK_TYPE_STYLE_PROPERTIES);
479 quark = g_quark_try_string (property_name);
483 g_type_class_unref (klass);
487 for (i = 0; i < properties->len; i++)
489 node = &g_array_index (properties, PropertyNode, i);
491 if (node->property_quark == quark)
494 *pspec = node->pspec;
497 *parse_func = node->parse_func;
502 else if (node->property_quark > quark)
506 g_type_class_unref (klass);
511 /* GtkStyleProperties methods */
514 * gtk_style_properties_new:
516 * Returns a newly created #GtkStyleProperties
518 * Returns: a new #GtkStyleProperties
521 gtk_style_properties_new (void)
523 return g_object_new (GTK_TYPE_STYLE_PROPERTIES, NULL);
527 * gtk_style_properties_map_color:
528 * @props: a #GtkStyleProperties
530 * @color: #GtkSymbolicColor to map @name to
532 * Maps @color so it can be referenced by @name. See
533 * gtk_style_properties_lookup_color()
538 gtk_style_properties_map_color (GtkStyleProperties *props,
540 GtkSymbolicColor *color)
542 GtkStylePropertiesPrivate *priv;
544 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
545 g_return_if_fail (name != NULL);
546 g_return_if_fail (color != NULL);
550 if (G_UNLIKELY (!priv->color_map))
551 priv->color_map = g_hash_table_new_full (g_str_hash,
553 (GDestroyNotify) g_free,
554 (GDestroyNotify) gtk_symbolic_color_unref);
556 g_hash_table_replace (priv->color_map,
558 gtk_symbolic_color_ref (color));
562 * gtk_style_properties_lookup_color:
563 * @props: a #GtkStyleProperties
564 * @name: color name to lookup
566 * Returns the symbolic color that is mapped
569 * Returns: The mapped color
574 gtk_style_properties_lookup_color (GtkStyleProperties *props,
577 GtkStylePropertiesPrivate *priv;
579 g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL);
580 g_return_val_if_fail (name != NULL, NULL);
584 if (!priv->color_map)
587 return g_hash_table_lookup (priv->color_map, name);
591 * gtk_style_properties_set_property:
592 * @props: a #GtkStyleProperties
593 * @property: styling property to set
594 * @state: state to set the value for
595 * @value: new value for the property
597 * Sets a styling property in @props.
602 gtk_style_properties_set_property (GtkStyleProperties *props,
603 const gchar *property,
607 GtkStylePropertiesPrivate *priv;
613 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
614 g_return_if_fail (property != NULL);
615 g_return_if_fail (value != NULL);
617 value_type = G_VALUE_TYPE (value);
618 node = property_node_lookup (g_quark_try_string (property));
622 g_warning ("Style property \"%s\" is not registered", property);
626 if (node->pspec->value_type == GDK_TYPE_RGBA ||
627 node->pspec->value_type == GDK_TYPE_COLOR)
629 /* Allow GtkSymbolicColor as well */
630 g_return_if_fail (value_type == GDK_TYPE_RGBA ||
631 value_type == GDK_TYPE_COLOR ||
632 value_type == GTK_TYPE_SYMBOLIC_COLOR);
634 else if (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN)
636 /* Allow GtkGradient as a substitute */
637 g_return_if_fail (value_type == CAIRO_GOBJECT_TYPE_PATTERN ||
638 value_type == GTK_TYPE_GRADIENT);
641 g_return_if_fail (node->pspec->value_type == value_type);
644 prop = g_hash_table_lookup (priv->properties,
645 GINT_TO_POINTER (node->property_quark));
649 prop = property_data_new ();
650 g_hash_table_insert (priv->properties,
651 GINT_TO_POINTER (node->property_quark),
655 val = property_data_get_value (prop, state);
657 if (G_VALUE_TYPE (val) == value_type)
661 if (G_IS_VALUE (val))
664 g_value_init (val, value_type);
667 g_value_copy (value, val);
671 * gtk_style_properties_set_valist:
672 * @props: a #GtkStyleProperties
673 * @state: state to set the values for
674 * @args: va_list of property name/value pairs, followed by %NULL
676 * Sets several style properties on @props.
681 gtk_style_properties_set_valist (GtkStyleProperties *props,
685 GtkStylePropertiesPrivate *priv;
686 const gchar *property_name;
688 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
691 property_name = va_arg (args, const gchar *);
693 while (property_name)
700 node = property_node_lookup (g_quark_try_string (property_name));
704 g_warning ("Style property \"%s\" is not registered", property_name);
708 prop = g_hash_table_lookup (priv->properties,
709 GINT_TO_POINTER (node->property_quark));
713 prop = property_data_new ();
714 g_hash_table_insert (priv->properties,
715 GINT_TO_POINTER (node->property_quark),
719 val = property_data_get_value (prop, state);
721 if (G_IS_VALUE (val))
724 g_value_init (val, node->pspec->value_type);
725 G_VALUE_COLLECT (val, args, 0, &error);
729 g_warning ("Could not set style property \"%s\": %s", property_name, error);
735 property_name = va_arg (args, const gchar *);
740 * gtk_style_properties_set:
741 * @props: a #GtkStyleProperties
742 * @state: state to set the values for
743 * @...: property name/value pairs, followed by %NULL
745 * Sets several style properties on @props.
750 gtk_style_properties_set (GtkStyleProperties *props,
756 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
758 va_start (args, state);
759 gtk_style_properties_set_valist (props, state, args);
764 resolve_color (GtkStyleProperties *props,
769 /* Resolve symbolic color to GdkRGBA */
770 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
773 /* Store it back, this is where GdkRGBA caching happens */
774 g_value_unset (value);
775 g_value_init (value, GDK_TYPE_RGBA);
776 g_value_set_boxed (value, &color);
782 resolve_color_rgb (GtkStyleProperties *props,
785 GdkColor color = { 0 };
788 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
791 color.red = rgba.red * 65535. + 0.5;
792 color.green = rgba.green * 65535. + 0.5;
793 color.blue = rgba.blue * 65535. + 0.5;
795 g_value_unset (value);
796 g_value_init (value, GDK_TYPE_COLOR);
797 g_value_set_boxed (value, &color);
803 resolve_gradient (GtkStyleProperties *props,
806 cairo_pattern_t *gradient;
808 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
811 /* Store it back, this is where cairo_pattern_t caching happens */
812 g_value_unset (value);
813 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
814 g_value_take_boxed (value, gradient);
820 style_properties_resolve_type (GtkStyleProperties *props,
824 if (val && G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
826 if (node->pspec->value_type == GDK_TYPE_RGBA)
828 if (!resolve_color (props, val))
831 else if (node->pspec->value_type == GDK_TYPE_COLOR)
833 if (!resolve_color_rgb (props, val))
839 else if (val && G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
841 g_return_val_if_fail (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE);
843 if (!resolve_gradient (props, val))
851 lookup_default_value (PropertyNode *node,
854 if (node->pspec->value_type == GTK_TYPE_THEMING_ENGINE)
855 g_value_set_object (value, gtk_theming_engine_load (NULL));
856 else if (node->pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
857 g_value_take_boxed (value, pango_font_description_from_string ("Sans 10"));
859 g_param_value_set_default (node->pspec, value);
863 _gtk_style_properties_peek_property (GtkStyleProperties *props,
864 const gchar *prop_name,
867 GtkStylePropertiesPrivate *priv;
872 g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL);
873 g_return_val_if_fail (prop_name != NULL, NULL);
875 node = property_node_lookup (g_quark_try_string (prop_name));
879 g_warning ("Style property \"%s\" is not registered", prop_name);
884 prop = g_hash_table_lookup (priv->properties,
885 GINT_TO_POINTER (node->property_quark));
890 val = property_data_match_state (prop, state);
893 !style_properties_resolve_type (props, node, val))
900 * gtk_style_properties_get_property:
901 * @props: a #GtkStyleProperties
902 * @property: style property name
903 * @state: state to retrieve the property value for
904 * @value: (out) (transfer full): return location for the style property value.
906 * Gets a style property from @props for the given state. When done with @value,
907 * g_value_unset() needs to be called to free any allocated memory.
909 * Returns: %TRUE if the property exists in @props, %FALSE otherwise
914 gtk_style_properties_get_property (GtkStyleProperties *props,
915 const gchar *property,
919 GtkStylePropertiesPrivate *priv;
924 g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
925 g_return_val_if_fail (property != NULL, FALSE);
926 g_return_val_if_fail (value != NULL, FALSE);
928 node = property_node_lookup (g_quark_try_string (property));
932 g_warning ("Style property \"%s\" is not registered", property);
937 prop = g_hash_table_lookup (priv->properties,
938 GINT_TO_POINTER (node->property_quark));
943 g_value_init (value, node->pspec->value_type);
944 val = property_data_match_state (prop, state);
947 !style_properties_resolve_type (props, node, val))
952 g_param_value_validate (node->pspec, val);
953 g_value_copy (val, value);
956 lookup_default_value (node, value);
962 * gtk_style_properties_get_valist:
963 * @props: a #GtkStyleProperties
964 * @state: state to retrieve the property values for
965 * @args: va_list of property name/return location pairs, followed by %NULL
967 * Retrieves several style property values from @props for a given state.
972 gtk_style_properties_get_valist (GtkStyleProperties *props,
976 GtkStylePropertiesPrivate *priv;
977 const gchar *property_name;
979 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
982 property_name = va_arg (args, const gchar *);
984 while (property_name)
991 node = property_node_lookup (g_quark_try_string (property_name));
995 g_warning ("Style property \"%s\" is not registered", property_name);
999 prop = g_hash_table_lookup (priv->properties,
1000 GINT_TO_POINTER (node->property_quark));
1003 val = property_data_match_state (prop, state);
1006 !style_properties_resolve_type (props, node, val))
1011 g_param_value_validate (node->pspec, val);
1012 G_VALUE_LCOPY (val, args, 0, &error);
1016 GValue default_value = { 0 };
1018 g_value_init (&default_value, node->pspec->value_type);
1019 lookup_default_value (node, &default_value);
1020 G_VALUE_LCOPY (&default_value, args, 0, &error);
1021 g_value_unset (&default_value);
1026 g_warning ("Could not get style property \"%s\": %s", property_name, error);
1031 property_name = va_arg (args, const gchar *);
1036 * gtk_style_properties_get:
1037 * @props: a #GtkStyleProperties
1038 * @state: state to retrieve the property values for
1039 * @...: property name /return value pairs, followed by %NULL
1041 * Retrieves several style property values from @props for a
1047 gtk_style_properties_get (GtkStyleProperties *props,
1048 GtkStateFlags state,
1053 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1055 va_start (args, state);
1056 gtk_style_properties_get_valist (props, state, args);
1061 * gtk_style_properties_unset_property:
1062 * @props: a #GtkStyleProperties
1063 * @property: property to unset
1064 * @state: state to unset
1066 * Unsets a style property in @props.
1071 gtk_style_properties_unset_property (GtkStyleProperties *props,
1072 const gchar *property,
1073 GtkStateFlags state)
1075 GtkStylePropertiesPrivate *priv;
1080 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1081 g_return_if_fail (property != NULL);
1083 node = property_node_lookup (g_quark_try_string (property));
1087 g_warning ("Style property \"%s\" is not registered", property);
1092 prop = g_hash_table_lookup (priv->properties,
1093 GINT_TO_POINTER (node->property_quark));
1098 if (property_data_find_position (prop, state, &pos))
1102 data = &g_array_index (prop->values, ValueData, pos);
1104 if (G_IS_VALUE (&data->value))
1105 g_value_unset (&data->value);
1107 g_array_remove_index (prop->values, pos);
1112 * gtk_style_properties_clear:
1113 * @props: a #GtkStyleProperties
1115 * Clears all style information from @props.
1118 gtk_style_properties_clear (GtkStyleProperties *props)
1120 GtkStylePropertiesPrivate *priv;
1122 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1125 g_hash_table_remove_all (priv->properties);
1129 * gtk_style_properties_merge:
1130 * @props: a #GtkStyleProperties
1131 * @props_to_merge: a second #GtkStyleProperties
1132 * @replace: whether to replace values or not
1134 * Merges into @props all the style information contained
1135 * in @props_to_merge. If @replace is %TRUE, the values
1136 * will be overwritten, if it is %FALSE, the older values
1142 gtk_style_properties_merge (GtkStyleProperties *props,
1143 const GtkStyleProperties *props_to_merge,
1146 GtkStylePropertiesPrivate *priv, *priv_to_merge;
1147 GHashTableIter iter;
1148 gpointer key, value;
1150 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1151 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props_to_merge));
1154 priv_to_merge = props_to_merge->priv;
1156 /* Merge symbolic color map */
1157 if (priv_to_merge->color_map)
1159 g_hash_table_iter_init (&iter, priv_to_merge->color_map);
1161 while (g_hash_table_iter_next (&iter, &key, &value))
1164 GtkSymbolicColor *color;
1170 g_hash_table_lookup (priv->color_map, name))
1173 gtk_style_properties_map_color (props, name, color);
1177 /* Merge symbolic style properties */
1178 g_hash_table_iter_init (&iter, priv_to_merge->properties);
1180 while (g_hash_table_iter_next (&iter, &key, &value))
1182 PropertyData *prop_to_merge = value;
1186 prop = g_hash_table_lookup (priv->properties, key);
1190 prop = property_data_new ();
1191 g_hash_table_insert (priv->properties, key, prop);
1194 for (i = 0; i < prop_to_merge->values->len; i++)
1199 data = &g_array_index (prop_to_merge->values, ValueData, i);
1200 value = property_data_get_value (prop, data->state);
1202 if (G_VALUE_TYPE (&data->value) == PANGO_TYPE_FONT_DESCRIPTION &&
1205 PangoFontDescription *font_desc;
1206 PangoFontDescription *font_desc_to_merge;
1208 /* Handle merging of font descriptions */
1209 font_desc = g_value_get_boxed (value);
1210 font_desc_to_merge = g_value_get_boxed (&data->value);
1212 pango_font_description_merge (font_desc, font_desc_to_merge, replace);
1214 else if (replace || !G_IS_VALUE (value))
1216 if (!G_IS_VALUE (value))
1217 g_value_init (value, G_VALUE_TYPE (&data->value));
1218 else if (G_VALUE_TYPE (value) != G_VALUE_TYPE (&data->value))
1220 g_value_unset (value);
1221 g_value_init (value, G_VALUE_TYPE (&data->value));
1224 g_value_copy (&data->value, value);