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 "gtkstylepropertyprivate.h"
29 #include <gdk-pixbuf/gdk-pixbuf.h>
30 #include <cairo-gobject.h>
32 #include "gtkcssprovider.h"
33 #include "gtkcssparserprivate.h"
34 #include "gtkcsstypesprivate.h"
35 #include "gtkprivatetypebuiltins.h"
37 /* the actual parsers we have */
38 #include "gtkanimationdescription.h"
39 #include "gtkbindings.h"
40 #include "gtkborderimageprivate.h"
41 #include "gtkgradient.h"
42 #include "gtkshadowprivate.h"
43 #include "gtkthemingengine.h"
44 #include "gtktypebuiltins.h"
45 #include "gtkwin32themeprivate.h"
47 /* this is in case round() is not provided by the compiler,
48 * such as in the case of C89 compilers, like MSVC
50 #include "fallback-c89.c"
52 static GHashTable *parse_funcs = NULL;
53 static GHashTable *print_funcs = NULL;
54 static GHashTable *properties = NULL;
55 static GPtrArray *__style_property_array = NULL;
58 register_conversion_function (GType type,
59 GtkStyleParseFunc parse,
60 GtkStylePrintFunc print)
63 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
65 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
69 string_append_double (GString *string,
72 char buf[G_ASCII_DTOSTR_BUF_SIZE];
74 g_ascii_dtostr (buf, sizeof (buf), d);
75 g_string_append (string, buf);
79 string_append_string (GString *str,
84 g_string_append_c (str, '"');
87 len = strcspn (string, "\"\n\r\f");
88 g_string_append (str, string);
95 g_string_append (str, "\\A ");
98 g_string_append (str, "\\D ");
101 g_string_append (str, "\\C ");
104 g_string_append (str, "\\\"");
107 g_assert_not_reached ();
112 g_string_append_c (str, '"');
115 /*** IMPLEMENTATIONS ***/
118 enum_parse (GtkCssParser *parser,
124 if (_gtk_css_parser_try_enum (parser, type, res))
127 str = _gtk_css_parser_try_ident (parser, TRUE);
130 _gtk_css_parser_error (parser, "Expected an identifier");
134 _gtk_css_parser_error (parser,
135 "Unknown value '%s' for enum type '%s'",
136 str, g_type_name (type));
143 enum_print (int value,
147 GEnumClass *enum_class;
148 GEnumValue *enum_value;
150 enum_class = g_type_class_ref (type);
151 enum_value = g_enum_get_value (enum_class, value);
153 g_string_append (string, enum_value->value_nick);
155 g_type_class_unref (enum_class);
159 rgba_value_parse (GtkCssParser *parser,
163 GtkSymbolicColor *symbolic;
166 symbolic = _gtk_css_parser_read_symbolic_color (parser);
167 if (symbolic == NULL)
170 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
172 g_value_set_boxed (value, &rgba);
173 gtk_symbolic_color_unref (symbolic);
177 g_value_unset (value);
178 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
179 g_value_take_boxed (value, symbolic);
186 rgba_value_print (const GValue *value,
189 const GdkRGBA *rgba = g_value_get_boxed (value);
192 g_string_append (string, "none");
195 char *s = gdk_rgba_to_string (rgba);
196 g_string_append (string, s);
202 color_value_parse (GtkCssParser *parser,
206 GtkSymbolicColor *symbolic;
209 symbolic = _gtk_css_parser_read_symbolic_color (parser);
210 if (symbolic == NULL)
213 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
217 color.red = rgba.red * 65535. + 0.5;
218 color.green = rgba.green * 65535. + 0.5;
219 color.blue = rgba.blue * 65535. + 0.5;
221 g_value_set_boxed (value, &color);
225 g_value_unset (value);
226 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
227 g_value_take_boxed (value, symbolic);
234 color_value_print (const GValue *value,
237 const GdkColor *color = g_value_get_boxed (value);
240 g_string_append (string, "none");
243 char *s = gdk_color_to_string (color);
244 g_string_append (string, s);
250 symbolic_color_value_parse (GtkCssParser *parser,
254 GtkSymbolicColor *symbolic;
256 symbolic = _gtk_css_parser_read_symbolic_color (parser);
257 if (symbolic == NULL)
260 g_value_take_boxed (value, symbolic);
265 symbolic_color_value_print (const GValue *value,
268 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
270 if (symbolic == NULL)
271 g_string_append (string, "none");
274 char *s = gtk_symbolic_color_to_string (symbolic);
275 g_string_append (string, s);
281 font_family_parse (GtkCssParser *parser,
288 /* We don't special case generic families. Pango should do
291 names = g_ptr_array_new ();
294 name = _gtk_css_parser_try_ident (parser, TRUE);
297 GString *string = g_string_new (name);
299 while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
301 g_string_append_c (string, ' ');
302 g_string_append (string, name);
305 name = g_string_free (string, FALSE);
309 name = _gtk_css_parser_read_string (parser);
312 g_ptr_array_free (names, TRUE);
317 g_ptr_array_add (names, name);
318 } while (_gtk_css_parser_try (parser, ",", TRUE));
320 /* NULL-terminate array */
321 g_ptr_array_add (names, NULL);
322 g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
327 font_family_value_print (const GValue *value,
330 const char **names = g_value_get_boxed (value);
332 if (names == NULL || *names == NULL)
334 g_string_append (string, "none");
338 string_append_string (string, *names);
342 g_string_append (string, ", ");
343 string_append_string (string, *names);
349 font_description_value_parse (GtkCssParser *parser,
353 PangoFontDescription *font_desc;
357 str = _gtk_css_parser_read_value (parser);
361 font_desc = pango_font_description_from_string (str);
362 mask = pango_font_description_get_set_fields (font_desc);
363 /* These values are not really correct,
364 * but the fields must be set, so we set them to something */
365 if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
366 pango_font_description_set_family_static (font_desc, "Sans");
367 if ((mask & PANGO_FONT_MASK_SIZE) == 0)
368 pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
370 g_value_take_boxed (value, font_desc);
375 font_description_value_print (const GValue *value,
378 const PangoFontDescription *desc = g_value_get_boxed (value);
381 g_string_append (string, "none");
384 char *s = pango_font_description_to_string (desc);
385 g_string_append (string, s);
391 boolean_value_parse (GtkCssParser *parser,
395 if (_gtk_css_parser_try (parser, "true", TRUE) ||
396 _gtk_css_parser_try (parser, "1", TRUE))
398 g_value_set_boolean (value, TRUE);
401 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
402 _gtk_css_parser_try (parser, "0", TRUE))
404 g_value_set_boolean (value, FALSE);
409 _gtk_css_parser_error (parser, "Expected a boolean value");
415 boolean_value_print (const GValue *value,
418 if (g_value_get_boolean (value))
419 g_string_append (string, "true");
421 g_string_append (string, "false");
425 int_value_parse (GtkCssParser *parser,
431 if (_gtk_css_parser_begins_with (parser, '-'))
433 int res = _gtk_win32_theme_int_parse (parser, base, &i);
436 g_value_set_int (value, i);
439 /* < 0 => continue */
442 if (!_gtk_css_parser_try_int (parser, &i))
444 _gtk_css_parser_error (parser, "Expected a valid integer value");
448 g_value_set_int (value, i);
453 int_value_print (const GValue *value,
456 g_string_append_printf (string, "%d", g_value_get_int (value));
460 uint_value_parse (GtkCssParser *parser,
466 if (!_gtk_css_parser_try_uint (parser, &u))
468 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
472 g_value_set_uint (value, u);
477 uint_value_print (const GValue *value,
480 g_string_append_printf (string, "%u", g_value_get_uint (value));
484 double_value_parse (GtkCssParser *parser,
490 if (!_gtk_css_parser_try_double (parser, &d))
492 _gtk_css_parser_error (parser, "Expected a number");
496 g_value_set_double (value, d);
501 double_value_print (const GValue *value,
504 string_append_double (string, g_value_get_double (value));
508 float_value_parse (GtkCssParser *parser,
514 if (!_gtk_css_parser_try_double (parser, &d))
516 _gtk_css_parser_error (parser, "Expected a number");
520 g_value_set_float (value, d);
525 float_value_print (const GValue *value,
528 string_append_double (string, g_value_get_float (value));
532 string_value_parse (GtkCssParser *parser,
536 char *str = _gtk_css_parser_read_string (parser);
541 g_value_take_string (value, str);
546 string_value_print (const GValue *value,
549 string_append_string (str, g_value_get_string (value));
553 theming_engine_value_parse (GtkCssParser *parser,
557 GtkThemingEngine *engine;
560 if (_gtk_css_parser_try (parser, "none", TRUE))
562 g_value_set_object (value, gtk_theming_engine_load (NULL));
566 str = _gtk_css_parser_try_ident (parser, TRUE);
569 _gtk_css_parser_error (parser, "Expected a valid theme name");
573 engine = gtk_theming_engine_load (str);
577 _gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
582 g_value_set_object (value, engine);
588 theming_engine_value_print (const GValue *value,
591 GtkThemingEngine *engine;
594 engine = g_value_get_object (value);
596 g_string_append (string, "none");
599 /* XXX: gtk_theming_engine_get_name()? */
600 g_object_get (engine, "name", &name, NULL);
601 g_string_append (string, name ? name : "none");
607 animation_description_value_parse (GtkCssParser *parser,
611 GtkAnimationDescription *desc;
614 str = _gtk_css_parser_read_value (parser);
618 desc = _gtk_animation_description_from_string (str);
623 _gtk_css_parser_error (parser, "Invalid animation description");
627 g_value_take_boxed (value, desc);
632 animation_description_value_print (const GValue *value,
635 GtkAnimationDescription *desc = g_value_get_boxed (value);
638 g_string_append (string, "none");
640 _gtk_animation_description_print (desc, string);
644 border_value_parse (GtkCssParser *parser,
648 GtkBorder border = { 0, };
651 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
653 if (_gtk_css_parser_begins_with (parser, '-'))
655 /* These are strictly speaking signed, but we want to be able to use them
656 for unsigned types too, as the actual ranges of values make this safe */
657 int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
659 if (res == 0) /* Parse error, report */
662 if (res < 0) /* Nothing known to expand */
667 if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
670 /* XXX: shouldn't allow spaces here? */
671 _gtk_css_parser_try (parser, "px", TRUE);
677 _gtk_css_parser_error (parser, "Expected valid border");
681 border.top = numbers[0];
683 border.right = numbers[1];
685 border.right = border.top;
687 border.bottom = numbers[2];
689 border.bottom = border.top;
691 border.left = numbers[3];
693 border.left = border.right;
695 g_value_set_boxed (value, &border);
700 border_value_print (const GValue *value, GString *string)
702 const GtkBorder *border = g_value_get_boxed (value);
705 g_string_append (string, "none");
706 else if (border->left != border->right)
707 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
708 else if (border->top != border->bottom)
709 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
710 else if (border->top != border->left)
711 g_string_append_printf (string, "%d %d", border->top, border->right);
713 g_string_append_printf (string, "%d", border->top);
717 gradient_value_parse (GtkCssParser *parser,
721 GtkGradient *gradient;
722 cairo_pattern_type_t type;
726 if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
728 _gtk_css_parser_error (parser,
729 "Expected '-gtk-gradient'");
733 if (!_gtk_css_parser_try (parser, "(", TRUE))
735 _gtk_css_parser_error (parser,
736 "Expected '(' after '-gtk-gradient'");
740 /* Parse gradient type */
741 if (_gtk_css_parser_try (parser, "linear", TRUE))
742 type = CAIRO_PATTERN_TYPE_LINEAR;
743 else if (_gtk_css_parser_try (parser, "radial", TRUE))
744 type = CAIRO_PATTERN_TYPE_RADIAL;
747 _gtk_css_parser_error (parser,
748 "Gradient type must be 'radial' or 'linear'");
752 /* Parse start/stop position parameters */
753 for (i = 0; i < 2; i++)
755 if (! _gtk_css_parser_try (parser, ",", TRUE))
757 _gtk_css_parser_error (parser,
762 if (_gtk_css_parser_try (parser, "left", TRUE))
764 else if (_gtk_css_parser_try (parser, "right", TRUE))
766 else if (_gtk_css_parser_try (parser, "center", TRUE))
768 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
770 _gtk_css_parser_error (parser,
771 "Expected a valid X coordinate");
775 if (_gtk_css_parser_try (parser, "top", TRUE))
776 coords[i * 3 + 1] = 0;
777 else if (_gtk_css_parser_try (parser, "bottom", TRUE))
778 coords[i * 3 + 1] = 1;
779 else if (_gtk_css_parser_try (parser, "center", TRUE))
780 coords[i * 3 + 1] = 0.5;
781 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
783 _gtk_css_parser_error (parser,
784 "Expected a valid Y coordinate");
788 if (type == CAIRO_PATTERN_TYPE_RADIAL)
791 if (! _gtk_css_parser_try (parser, ",", TRUE))
793 _gtk_css_parser_error (parser,
798 if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
800 _gtk_css_parser_error (parser,
801 "Expected a numer for the radius");
807 if (type == CAIRO_PATTERN_TYPE_LINEAR)
808 gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
810 gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
811 coords[3], coords[4], coords[5]);
813 while (_gtk_css_parser_try (parser, ",", TRUE))
815 GtkSymbolicColor *color;
818 if (_gtk_css_parser_try (parser, "from", TRUE))
822 if (!_gtk_css_parser_try (parser, "(", TRUE))
824 gtk_gradient_unref (gradient);
825 _gtk_css_parser_error (parser,
831 else if (_gtk_css_parser_try (parser, "to", TRUE))
835 if (!_gtk_css_parser_try (parser, "(", TRUE))
837 gtk_gradient_unref (gradient);
838 _gtk_css_parser_error (parser,
844 else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
846 if (!_gtk_css_parser_try (parser, "(", TRUE))
848 gtk_gradient_unref (gradient);
849 _gtk_css_parser_error (parser,
854 if (!_gtk_css_parser_try_double (parser, &position))
856 gtk_gradient_unref (gradient);
857 _gtk_css_parser_error (parser,
858 "Expected a valid number");
862 if (!_gtk_css_parser_try (parser, ",", TRUE))
864 gtk_gradient_unref (gradient);
865 _gtk_css_parser_error (parser,
872 gtk_gradient_unref (gradient);
873 _gtk_css_parser_error (parser,
874 "Not a valid color-stop definition");
878 color = _gtk_css_parser_read_symbolic_color (parser);
881 gtk_gradient_unref (gradient);
885 gtk_gradient_add_color_stop (gradient, position, color);
886 gtk_symbolic_color_unref (color);
888 if (!_gtk_css_parser_try (parser, ")", TRUE))
890 gtk_gradient_unref (gradient);
891 _gtk_css_parser_error (parser,
897 if (!_gtk_css_parser_try (parser, ")", TRUE))
899 gtk_gradient_unref (gradient);
900 _gtk_css_parser_error (parser,
905 g_value_take_boxed (value, gradient);
910 gradient_value_print (const GValue *value,
913 GtkGradient *gradient = g_value_get_boxed (value);
915 if (gradient == NULL)
916 g_string_append (string, "none");
919 char *s = gtk_gradient_to_string (gradient);
920 g_string_append (string, s);
926 gtk_css_parse_url (GtkCssParser *parser,
932 if (_gtk_css_parser_try (parser, "url", FALSE))
934 if (!_gtk_css_parser_try (parser, "(", TRUE))
936 _gtk_css_parser_skip_whitespace (parser);
937 if (_gtk_css_parser_try (parser, "(", TRUE))
941 error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
942 GTK_CSS_PROVIDER_ERROR_DEPRECATED,
943 "Whitespace between 'url' and '(' is deprecated");
945 _gtk_css_parser_take_error (parser, error);
949 _gtk_css_parser_error (parser, "Expected '(' after 'url'");
954 path = _gtk_css_parser_read_string (parser);
958 if (!_gtk_css_parser_try (parser, ")", TRUE))
960 _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
967 path = _gtk_css_parser_try_name (parser, TRUE);
970 _gtk_css_parser_error (parser, "Not a valid url");
975 file = g_file_resolve_relative_path (base, path);
982 pattern_value_parse (GtkCssParser *parser,
986 if (_gtk_css_parser_try (parser, "none", TRUE))
988 /* nothing to do here */
990 else if (_gtk_css_parser_begins_with (parser, '-'))
993 res = _gtk_win32_theme_part_parse (parser, base, value);
996 /* < 0 => continue */
997 g_value_unset (value);
998 g_value_init (value, GTK_TYPE_GRADIENT);
999 return gradient_value_parse (parser, base, value);
1003 GError *error = NULL;
1007 cairo_surface_t *surface;
1008 cairo_pattern_t *pattern;
1010 cairo_matrix_t matrix;
1012 file = gtk_css_parse_url (parser, base);
1016 path = g_file_get_path (file);
1017 g_object_unref (file);
1019 pixbuf = gdk_pixbuf_new_from_file (path, &error);
1023 _gtk_css_parser_take_error (parser, error);
1027 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1028 gdk_pixbuf_get_width (pixbuf),
1029 gdk_pixbuf_get_height (pixbuf));
1030 cr = cairo_create (surface);
1031 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
1033 pattern = cairo_pattern_create_for_surface (surface);
1035 cairo_matrix_init_scale (&matrix,
1036 gdk_pixbuf_get_width (pixbuf),
1037 gdk_pixbuf_get_height (pixbuf));
1038 cairo_pattern_set_matrix (pattern, &matrix);
1040 cairo_surface_destroy (surface);
1042 g_object_unref (pixbuf);
1044 g_value_take_boxed (value, pattern);
1050 static cairo_status_t
1051 surface_write (void *closure,
1052 const unsigned char *data,
1053 unsigned int length)
1055 g_byte_array_append (closure, data, length);
1057 return CAIRO_STATUS_SUCCESS;
1061 surface_print (cairo_surface_t *surface,
1064 #if CAIRO_HAS_PNG_FUNCTIONS
1068 array = g_byte_array_new ();
1069 cairo_surface_write_to_png_stream (surface, surface_write, array);
1070 base64 = g_base64_encode (array->data, array->len);
1071 g_byte_array_free (array, TRUE);
1073 g_string_append (string, "url(\"data:image/png;base64,");
1074 g_string_append (string, base64);
1075 g_string_append (string, "\")");
1079 g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
1084 pattern_value_print (const GValue *value,
1087 cairo_pattern_t *pattern;
1088 cairo_surface_t *surface;
1090 pattern = g_value_get_boxed (value);
1092 if (pattern == NULL)
1094 g_string_append (string, "none");
1098 switch (cairo_pattern_get_type (pattern))
1100 case CAIRO_PATTERN_TYPE_SURFACE:
1101 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
1103 g_assert_not_reached ();
1105 surface_print (surface, string);
1107 case CAIRO_PATTERN_TYPE_SOLID:
1108 case CAIRO_PATTERN_TYPE_LINEAR:
1109 case CAIRO_PATTERN_TYPE_RADIAL:
1111 g_assert_not_reached ();
1117 shadow_value_parse (GtkCssParser *parser,
1121 gboolean have_inset, have_color, have_lengths;
1122 gdouble hoffset, voffset, blur, spread;
1123 GtkSymbolicColor *color;
1127 shadow = _gtk_shadow_new ();
1129 if (_gtk_css_parser_try (parser, "none", TRUE))
1134 have_inset = have_lengths = have_color = FALSE;
1136 for (i = 0; i < 3; i++)
1139 _gtk_css_parser_try (parser, "inset", TRUE))
1145 if (!have_lengths &&
1146 _gtk_css_parser_try_double (parser, &hoffset))
1148 have_lengths = TRUE;
1150 if (!_gtk_css_parser_try_double (parser, &voffset))
1152 _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
1153 _gtk_shadow_unref (shadow);
1157 if (!_gtk_css_parser_try_double (parser, &blur))
1160 if (!_gtk_css_parser_try_double (parser, &spread))
1170 /* XXX: the color is optional and UA-defined if it's missing,
1171 * but it doesn't really make sense for us...
1173 color = _gtk_css_parser_read_symbolic_color (parser);
1177 _gtk_shadow_unref (shadow);
1183 if (!have_color || !have_lengths)
1185 _gtk_css_parser_error (parser, "Must specify at least color and offsets");
1186 _gtk_shadow_unref (shadow);
1190 _gtk_shadow_append (shadow,
1195 gtk_symbolic_color_unref (color);
1198 while (_gtk_css_parser_try (parser, ",", TRUE));
1200 g_value_take_boxed (value, shadow);
1205 shadow_value_print (const GValue *value,
1210 shadow = g_value_get_boxed (value);
1213 g_string_append (string, "none");
1215 _gtk_shadow_print (shadow, string);
1219 background_repeat_value_parse (GtkCssParser *parser,
1223 GtkCssBackgroundRepeat repeat;
1226 if (!enum_parse (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, &style))
1229 repeat.repeat = style;
1231 g_value_set_boxed (value, &repeat);
1237 background_repeat_value_print (const GValue *value,
1240 GtkCssBackgroundRepeat *repeat;
1242 repeat = g_value_get_boxed (value);
1244 enum_print (repeat->repeat, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, string);
1248 border_image_repeat_value_parse (GtkCssParser *parser,
1252 GtkCssBorderImageRepeat image_repeat;
1253 GtkCssBorderRepeatStyle styles[2];
1256 for (i = 0; i < 2; i++)
1258 if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
1262 styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
1266 styles[i] = styles[0];
1269 image_repeat.hrepeat = styles[0];
1270 image_repeat.vrepeat = styles[1];
1272 g_value_set_boxed (value, &image_repeat);
1278 border_image_repeat_value_print (const GValue *value,
1281 GtkCssBorderImageRepeat *image_repeat;
1283 image_repeat = g_value_get_boxed (value);
1285 enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1286 if (image_repeat->hrepeat != image_repeat->vrepeat)
1288 g_string_append (string, " ");
1289 enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1294 border_image_value_parse (GtkCssParser *parser,
1298 GValue temp = G_VALUE_INIT;
1299 cairo_pattern_t *pattern = NULL;
1300 gconstpointer *boxed = NULL;
1302 GtkBorder slice, *width = NULL, *parsed_slice;
1303 GtkCssBorderImageRepeat repeat, *parsed_repeat;
1304 gboolean retval = FALSE;
1305 GtkBorderImage *image = NULL;
1307 if (_gtk_css_parser_try (parser, "none", TRUE))
1310 g_value_init (&temp, CAIRO_GOBJECT_TYPE_PATTERN);
1312 if (!pattern_value_parse (parser, base, &temp))
1315 boxed_type = G_VALUE_TYPE (&temp);
1316 if (boxed_type != CAIRO_GOBJECT_TYPE_PATTERN)
1317 boxed = g_value_dup_boxed (&temp);
1319 pattern = g_value_dup_boxed (&temp);
1321 g_value_unset (&temp);
1322 g_value_init (&temp, GTK_TYPE_BORDER);
1324 if (!border_value_parse (parser, base, &temp))
1327 parsed_slice = g_value_get_boxed (&temp);
1328 slice = *parsed_slice;
1330 if (_gtk_css_parser_try (parser, "/", TRUE))
1332 g_value_unset (&temp);
1333 g_value_init (&temp, GTK_TYPE_BORDER);
1335 if (!border_value_parse (parser, base, &temp))
1338 width = g_value_dup_boxed (&temp);
1341 g_value_unset (&temp);
1342 g_value_init (&temp, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
1344 if (!border_image_repeat_value_parse (parser, base, &temp))
1347 parsed_repeat = g_value_get_boxed (&temp);
1348 repeat = *parsed_repeat;
1350 g_value_unset (&temp);
1353 image = _gtk_border_image_new_for_boxed (boxed_type, boxed, &slice, width, &repeat);
1354 else if (pattern != NULL)
1355 image = _gtk_border_image_new (pattern, &slice, width, &repeat);
1360 g_value_take_boxed (value, image);
1364 if (pattern != NULL)
1365 cairo_pattern_destroy (pattern);
1368 g_boxed_free (boxed_type, boxed);
1371 gtk_border_free (width);
1377 enum_value_parse (GtkCssParser *parser,
1383 if (enum_parse (parser, G_VALUE_TYPE (value), &v))
1385 g_value_set_enum (value, v);
1393 enum_value_print (const GValue *value,
1396 enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
1400 flags_value_parse (GtkCssParser *parser,
1404 GFlagsClass *flags_class;
1405 GFlagsValue *flag_value;
1409 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1412 str = _gtk_css_parser_try_ident (parser, TRUE);
1415 _gtk_css_parser_error (parser, "Expected an identifier");
1416 g_type_class_unref (flags_class);
1420 flag_value = g_flags_get_value_by_nick (flags_class, str);
1423 _gtk_css_parser_error (parser,
1424 "Unknown flag value '%s' for type '%s'",
1425 str, g_type_name (G_VALUE_TYPE (value)));
1426 /* XXX Do we want to return FALSE here? We can get
1427 * forward-compatibility for new values this way
1430 g_type_class_unref (flags_class);
1436 while (_gtk_css_parser_try (parser, ",", FALSE));
1438 g_type_class_unref (flags_class);
1440 g_value_set_enum (value, flags);
1446 flags_value_print (const GValue *value,
1449 GFlagsClass *flags_class;
1452 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1453 flags = g_value_get_flags (value);
1455 for (i = 0; i < flags_class->n_values; i++)
1457 GFlagsValue *flags_value = &flags_class->values[i];
1459 if (flags & flags_value->value)
1461 if (string->len != 0)
1462 g_string_append (string, ", ");
1464 g_string_append (string, flags_value->value_nick);
1468 g_type_class_unref (flags_class);
1472 bindings_value_parse (GtkCssParser *parser,
1477 GtkBindingSet *binding_set;
1480 array = g_ptr_array_new ();
1483 name = _gtk_css_parser_try_ident (parser, TRUE);
1486 _gtk_css_parser_error (parser, "Not a valid binding name");
1487 g_ptr_array_free (array, TRUE);
1491 binding_set = gtk_binding_set_find (name);
1495 _gtk_css_parser_error (parser, "No binding set named '%s'", name);
1500 g_ptr_array_add (array, binding_set);
1503 while (_gtk_css_parser_try (parser, ",", TRUE));
1505 g_value_take_boxed (value, array);
1511 bindings_value_print (const GValue *value,
1517 array = g_value_get_boxed (value);
1519 for (i = 0; i < array->len; i++)
1521 GtkBindingSet *binding_set = g_ptr_array_index (array, i);
1524 g_string_append (string, ", ");
1525 g_string_append (string, binding_set->set_name);
1530 border_corner_radius_value_parse (GtkCssParser *parser,
1534 GtkCssBorderCornerRadius corner;
1536 if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
1538 _gtk_css_parser_error (parser, "Expected a number");
1541 else if (corner.horizontal < 0)
1544 if (!_gtk_css_parser_try_double (parser, &corner.vertical))
1545 corner.vertical = corner.horizontal;
1546 else if (corner.vertical < 0)
1549 g_value_set_boxed (value, &corner);
1553 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1558 border_corner_radius_value_print (const GValue *value,
1561 GtkCssBorderCornerRadius *corner;
1563 corner = g_value_get_boxed (value);
1567 g_string_append (string, "none");
1571 string_append_double (string, corner->horizontal);
1572 if (corner->horizontal != corner->vertical)
1574 g_string_append_c (string, ' ');
1575 string_append_double (string, corner->vertical);
1580 border_radius_value_parse (GtkCssParser *parser,
1584 GtkCssBorderRadius border;
1586 if (!_gtk_css_parser_try_double (parser, &border.top_left.horizontal))
1588 _gtk_css_parser_error (parser, "Expected a number");
1591 else if (border.top_left.horizontal < 0)
1594 if (_gtk_css_parser_try_double (parser, &border.top_right.horizontal))
1596 if (border.top_right.horizontal < 0)
1598 if (_gtk_css_parser_try_double (parser, &border.bottom_right.horizontal))
1600 if (border.bottom_right.horizontal < 0)
1602 if (!_gtk_css_parser_try_double (parser, &border.bottom_left.horizontal))
1603 border.bottom_left.horizontal = border.top_right.horizontal;
1604 else if (border.bottom_left.horizontal < 0)
1609 border.bottom_right.horizontal = border.top_left.horizontal;
1610 border.bottom_left.horizontal = border.top_right.horizontal;
1615 border.top_right.horizontal = border.top_left.horizontal;
1616 border.bottom_right.horizontal = border.top_left.horizontal;
1617 border.bottom_left.horizontal = border.top_left.horizontal;
1620 if (_gtk_css_parser_try (parser, "/", TRUE))
1622 if (!_gtk_css_parser_try_double (parser, &border.top_left.vertical))
1624 _gtk_css_parser_error (parser, "Expected a number");
1627 else if (border.top_left.vertical < 0)
1630 if (_gtk_css_parser_try_double (parser, &border.top_right.vertical))
1632 if (border.top_right.vertical < 0)
1634 if (_gtk_css_parser_try_double (parser, &border.bottom_right.vertical))
1636 if (border.bottom_right.vertical < 0)
1638 if (!_gtk_css_parser_try_double (parser, &border.bottom_left.vertical))
1639 border.bottom_left.vertical = border.top_right.vertical;
1640 else if (border.bottom_left.vertical < 0)
1645 border.bottom_right.vertical = border.top_left.vertical;
1646 border.bottom_left.vertical = border.top_right.vertical;
1651 border.top_right.vertical = border.top_left.vertical;
1652 border.bottom_right.vertical = border.top_left.vertical;
1653 border.bottom_left.vertical = border.top_left.vertical;
1658 border.top_left.vertical = border.top_left.horizontal;
1659 border.top_right.vertical = border.top_right.horizontal;
1660 border.bottom_right.vertical = border.bottom_right.horizontal;
1661 border.bottom_left.vertical = border.bottom_left.horizontal;
1664 /* border-radius is an int property for backwards-compat reasons */
1665 g_value_unset (value);
1666 g_value_init (value, GTK_TYPE_CSS_BORDER_RADIUS);
1667 g_value_set_boxed (value, &border);
1672 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1677 border_radius_value_print (const GValue *value,
1680 GtkCssBorderRadius *border;
1682 border = g_value_get_boxed (value);
1686 g_string_append (string, "none");
1690 string_append_double (string, border->top_left.horizontal);
1691 if (border->top_left.horizontal != border->top_right.horizontal ||
1692 border->top_left.horizontal != border->bottom_right.horizontal ||
1693 border->top_left.horizontal != border->bottom_left.horizontal)
1695 g_string_append_c (string, ' ');
1696 string_append_double (string, border->top_right.horizontal);
1697 if (border->top_left.horizontal != border->bottom_right.horizontal ||
1698 border->top_right.horizontal != border->bottom_left.horizontal)
1700 g_string_append_c (string, ' ');
1701 string_append_double (string, border->bottom_right.horizontal);
1702 if (border->top_right.horizontal != border->bottom_left.horizontal)
1704 g_string_append_c (string, ' ');
1705 string_append_double (string, border->bottom_left.horizontal);
1710 if (border->top_left.horizontal != border->top_left.vertical ||
1711 border->top_right.horizontal != border->top_right.vertical ||
1712 border->bottom_right.horizontal != border->bottom_right.vertical ||
1713 border->bottom_left.horizontal != border->bottom_left.vertical)
1715 g_string_append (string, " / ");
1716 string_append_double (string, border->top_left.vertical);
1717 if (border->top_left.vertical != border->top_right.vertical ||
1718 border->top_left.vertical != border->bottom_right.vertical ||
1719 border->top_left.vertical != border->bottom_left.vertical)
1721 g_string_append_c (string, ' ');
1722 string_append_double (string, border->top_right.vertical);
1723 if (border->top_left.vertical != border->bottom_right.vertical ||
1724 border->top_right.vertical != border->bottom_left.vertical)
1726 g_string_append_c (string, ' ');
1727 string_append_double (string, border->bottom_right.vertical);
1728 if (border->top_right.vertical != border->bottom_left.vertical)
1730 g_string_append_c (string, ' ');
1731 string_append_double (string, border->bottom_left.vertical);
1740 transparent_color_value_parse (GtkCssParser *parser,
1744 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1746 GdkRGBA transparent = { 0, 0, 0, 0 };
1748 g_value_set_boxed (value, &transparent);
1753 return rgba_value_parse (parser, base, value);
1757 border_color_shorthand_value_parse (GtkCssParser *parser,
1761 GtkSymbolicColor *symbolic;
1764 array = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_symbolic_color_unref);
1768 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1770 GdkRGBA transparent = { 0, 0, 0, 0 };
1772 symbolic = gtk_symbolic_color_new_literal (&transparent);
1776 symbolic = _gtk_css_parser_read_symbolic_color (parser);
1778 if (symbolic == NULL)
1782 g_ptr_array_add (array, symbolic);
1784 while (array->len < 4 &&
1785 !_gtk_css_parser_is_eof (parser) &&
1786 !_gtk_css_parser_begins_with (parser, ';') &&
1787 !_gtk_css_parser_begins_with (parser, '}'));
1792 g_assert_not_reached ();
1795 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 0)));
1798 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 0)));
1801 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 1)));
1807 g_value_unset (value);
1808 g_value_init (value, G_TYPE_PTR_ARRAY);
1809 g_value_take_boxed (value, array);
1817 unpack_border (const GValue *value,
1824 GParameter *parameter = g_new0 (GParameter, 4);
1825 GtkBorder *border = g_value_get_boxed (value);
1827 parameter[0].name = top;
1828 g_value_init (¶meter[0].value, G_TYPE_INT);
1829 g_value_set_int (¶meter[0].value, border->top);
1830 parameter[1].name = left;
1831 g_value_init (¶meter[1].value, G_TYPE_INT);
1832 g_value_set_int (¶meter[1].value, border->left);
1833 parameter[2].name = bottom;
1834 g_value_init (¶meter[2].value, G_TYPE_INT);
1835 g_value_set_int (¶meter[2].value, border->bottom);
1836 parameter[3].name = right;
1837 g_value_init (¶meter[3].value, G_TYPE_INT);
1838 g_value_set_int (¶meter[3].value, border->right);
1845 pack_border (GValue *value,
1846 GtkStyleProperties *props,
1847 GtkStateFlags state,
1856 gtk_style_properties_get (props,
1869 g_value_set_boxed (value, &border);
1873 unpack_border_width (const GValue *value,
1876 return unpack_border (value, n_params,
1877 "border-top-width", "border-left-width",
1878 "border-bottom-width", "border-right-width");
1882 pack_border_width (GValue *value,
1883 GtkStyleProperties *props,
1884 GtkStateFlags state,
1885 GtkStylePropertyContext *context)
1887 pack_border (value, props, state,
1888 "border-top-width", "border-left-width",
1889 "border-bottom-width", "border-right-width");
1893 unpack_padding (const GValue *value,
1896 return unpack_border (value, n_params,
1897 "padding-top", "padding-left",
1898 "padding-bottom", "padding-right");
1902 pack_padding (GValue *value,
1903 GtkStyleProperties *props,
1904 GtkStateFlags state,
1905 GtkStylePropertyContext *context)
1907 pack_border (value, props, state,
1908 "padding-top", "padding-left",
1909 "padding-bottom", "padding-right");
1913 unpack_margin (const GValue *value,
1916 return unpack_border (value, n_params,
1917 "margin-top", "margin-left",
1918 "margin-bottom", "margin-right");
1922 pack_margin (GValue *value,
1923 GtkStyleProperties *props,
1924 GtkStateFlags state,
1925 GtkStylePropertyContext *context)
1927 pack_border (value, props, state,
1928 "margin-top", "margin-left",
1929 "margin-bottom", "margin-right");
1933 unpack_border_radius (const GValue *value,
1936 GParameter *parameter = g_new0 (GParameter, 4);
1937 GtkCssBorderRadius *border;
1939 if (G_VALUE_HOLDS_BOXED (value))
1940 border = g_value_get_boxed (value);
1944 parameter[0].name = "border-top-left-radius";
1945 g_value_init (¶meter[0].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1946 parameter[1].name = "border-top-right-radius";
1947 g_value_init (¶meter[1].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1948 parameter[2].name = "border-bottom-right-radius";
1949 g_value_init (¶meter[2].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1950 parameter[3].name = "border-bottom-left-radius";
1951 g_value_init (¶meter[3].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1954 g_value_set_boxed (¶meter[0].value, &border->top_left);
1955 g_value_set_boxed (¶meter[1].value, &border->top_right);
1956 g_value_set_boxed (¶meter[2].value, &border->bottom_right);
1957 g_value_set_boxed (¶meter[3].value, &border->bottom_left);
1965 pack_border_radius (GValue *value,
1966 GtkStyleProperties *props,
1967 GtkStateFlags state,
1968 GtkStylePropertyContext *context)
1970 GtkCssBorderCornerRadius *top_left;
1972 /* NB: We are an int property, so we have to resolve to an int here.
1973 * So we just resolve to an int. We pick one and stick to it.
1974 * Lesson learned: Don't query border-radius shorthand, query the
1975 * real properties instead. */
1976 gtk_style_properties_get (props,
1978 "border-top-left-radius", &top_left,
1982 g_value_set_int (value, top_left->horizontal);
1988 unpack_font_description (const GValue *value,
1991 GParameter *parameter = g_new0 (GParameter, 5);
1992 PangoFontDescription *description;
1996 /* For backwards compat, we only unpack values that are indeed set.
1997 * For strict CSS conformance we need to unpack all of them.
1998 * Note that we do set all of them in the parse function, so it
1999 * will not have effects when parsing CSS files. It will though
2000 * for custom style providers.
2003 description = g_value_get_boxed (value);
2007 mask = pango_font_description_get_set_fields (description);
2011 if (mask & PANGO_FONT_MASK_FAMILY)
2013 GPtrArray *strv = g_ptr_array_new ();
2015 g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
2016 g_ptr_array_add (strv, NULL);
2017 parameter[n].name = "font-family";
2018 g_value_init (¶meter[n].value, G_TYPE_STRV);
2019 g_value_take_boxed (¶meter[n].value,
2020 g_ptr_array_free (strv, FALSE));
2024 if (mask & PANGO_FONT_MASK_STYLE)
2026 parameter[n].name = "font-style";
2027 g_value_init (¶meter[n].value, PANGO_TYPE_STYLE);
2028 g_value_set_enum (¶meter[n].value,
2029 pango_font_description_get_style (description));
2033 if (mask & PANGO_FONT_MASK_VARIANT)
2035 parameter[n].name = "font-variant";
2036 g_value_init (¶meter[n].value, PANGO_TYPE_VARIANT);
2037 g_value_set_enum (¶meter[n].value,
2038 pango_font_description_get_variant (description));
2042 if (mask & PANGO_FONT_MASK_WEIGHT)
2044 parameter[n].name = "font-weight";
2045 g_value_init (¶meter[n].value, PANGO_TYPE_WEIGHT);
2046 g_value_set_enum (¶meter[n].value,
2047 pango_font_description_get_weight (description));
2051 if (mask & PANGO_FONT_MASK_SIZE)
2053 parameter[n].name = "font-size";
2054 g_value_init (¶meter[n].value, G_TYPE_DOUBLE);
2055 g_value_set_double (¶meter[n].value,
2056 (double) pango_font_description_get_size (description) / PANGO_SCALE);
2066 pack_font_description (GValue *value,
2067 GtkStyleProperties *props,
2068 GtkStateFlags state,
2069 GtkStylePropertyContext *context)
2071 PangoFontDescription *description;
2074 PangoVariant variant;
2078 gtk_style_properties_get (props,
2080 "font-family", &families,
2081 "font-style", &style,
2082 "font-variant", &variant,
2083 "font-weight", &weight,
2087 description = pango_font_description_new ();
2088 /* xxx: Can we set all the families here somehow? */
2090 pango_font_description_set_family (description, families[0]);
2091 pango_font_description_set_size (description, round (size * PANGO_SCALE));
2092 pango_font_description_set_style (description, style);
2093 pango_font_description_set_variant (description, variant);
2094 pango_font_description_set_weight (description, weight);
2096 g_strfreev (families);
2098 g_value_take_boxed (value, description);
2102 unpack_border_color (const GValue *value,
2105 GParameter *parameter = g_new0 (GParameter, 4);
2108 type = G_VALUE_TYPE (value);
2109 if (type == G_TYPE_PTR_ARRAY)
2110 type = GTK_TYPE_SYMBOLIC_COLOR;
2112 parameter[0].name = "border-top-color";
2113 g_value_init (¶meter[0].value, type);
2114 parameter[1].name = "border-right-color";
2115 g_value_init (¶meter[1].value, type);
2116 parameter[2].name = "border-bottom-color";
2117 g_value_init (¶meter[2].value, type);
2118 parameter[3].name = "border-left-color";
2119 g_value_init (¶meter[3].value, type);
2121 if (G_VALUE_TYPE (value) == G_TYPE_PTR_ARRAY)
2123 GPtrArray *array = g_value_get_boxed (value);
2126 for (i = 0; i < 4; i++)
2127 g_value_set_boxed (¶meter[i].value, g_ptr_array_index (array, i));
2131 /* can be RGBA or symbolic color */
2132 gpointer p = g_value_get_boxed (value);
2134 g_value_set_boxed (¶meter[0].value, p);
2135 g_value_set_boxed (¶meter[1].value, p);
2136 g_value_set_boxed (¶meter[2].value, p);
2137 g_value_set_boxed (¶meter[3].value, p);
2145 pack_border_color (GValue *value,
2146 GtkStyleProperties *props,
2147 GtkStateFlags state,
2148 GtkStylePropertyContext *context)
2150 /* NB: We are a color property, so we have to resolve to a color here.
2151 * So we just resolve to a color. We pick one and stick to it.
2152 * Lesson learned: Don't query border-color shorthand, query the
2153 * real properties instead. */
2154 g_value_unset (value);
2155 gtk_style_properties_get_property (props, "border-top-color", state, value);
2158 /*** UNSET FUNCS ***/
2161 unset_font_description (GtkStyleProperties *props,
2162 GtkStateFlags state)
2164 gtk_style_properties_unset_property (props, "font-family", state);
2165 gtk_style_properties_unset_property (props, "font-style", state);
2166 gtk_style_properties_unset_property (props, "font-variant", state);
2167 gtk_style_properties_unset_property (props, "font-weight", state);
2168 gtk_style_properties_unset_property (props, "font-size", state);
2172 unset_margin (GtkStyleProperties *props,
2173 GtkStateFlags state)
2175 gtk_style_properties_unset_property (props, "margin-top", state);
2176 gtk_style_properties_unset_property (props, "margin-right", state);
2177 gtk_style_properties_unset_property (props, "margin-bottom", state);
2178 gtk_style_properties_unset_property (props, "margin-left", state);
2182 unset_padding (GtkStyleProperties *props,
2183 GtkStateFlags state)
2185 gtk_style_properties_unset_property (props, "padding-top", state);
2186 gtk_style_properties_unset_property (props, "padding-right", state);
2187 gtk_style_properties_unset_property (props, "padding-bottom", state);
2188 gtk_style_properties_unset_property (props, "padding-left", state);
2192 unset_border_width (GtkStyleProperties *props,
2193 GtkStateFlags state)
2195 gtk_style_properties_unset_property (props, "border-top-width", state);
2196 gtk_style_properties_unset_property (props, "border-right-width", state);
2197 gtk_style_properties_unset_property (props, "border-bottom-width", state);
2198 gtk_style_properties_unset_property (props, "border-left-width", state);
2202 unset_border_radius (GtkStyleProperties *props,
2203 GtkStateFlags state)
2205 gtk_style_properties_unset_property (props, "border-top-right-radius", state);
2206 gtk_style_properties_unset_property (props, "border-bottom-right-radius", state);
2207 gtk_style_properties_unset_property (props, "border-bottom-left-radius", state);
2208 gtk_style_properties_unset_property (props, "border-top-left-radius", state);
2212 unset_border_color (GtkStyleProperties *props,
2213 GtkStateFlags state)
2215 gtk_style_properties_unset_property (props, "border-top-color", state);
2216 gtk_style_properties_unset_property (props, "border-right-color", state);
2217 gtk_style_properties_unset_property (props, "border-bottom-color", state);
2218 gtk_style_properties_unset_property (props, "border-left-color", state);
2222 unset_border_image (GtkStyleProperties *props,
2223 GtkStateFlags state)
2225 gtk_style_properties_unset_property (props, "border-image-source", state);
2226 gtk_style_properties_unset_property (props, "border-image-slice", state);
2227 gtk_style_properties_unset_property (props, "border-image-repeat", state);
2228 gtk_style_properties_unset_property (props, "border-image-width", state);
2234 _gtk_style_property_get_count (void)
2236 return __style_property_array ? __style_property_array->len : 0;
2239 const GtkStyleProperty *
2240 _gtk_style_property_get (guint id)
2242 g_assert (__style_property_array);
2244 return g_ptr_array_index (__style_property_array, id);
2248 _gtk_style_property_generate_id (GtkStyleProperty *node)
2250 if (__style_property_array == NULL)
2251 __style_property_array = g_ptr_array_new ();
2253 node->id = __style_property_array->len;
2254 g_ptr_array_add (__style_property_array, node);
2258 css_string_funcs_init (void)
2260 if (G_LIKELY (parse_funcs != NULL))
2263 parse_funcs = g_hash_table_new (NULL, NULL);
2264 print_funcs = g_hash_table_new (NULL, NULL);
2266 register_conversion_function (GDK_TYPE_RGBA,
2269 register_conversion_function (GDK_TYPE_COLOR,
2272 register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
2273 symbolic_color_value_parse,
2274 symbolic_color_value_print);
2275 register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
2276 font_description_value_parse,
2277 font_description_value_print);
2278 register_conversion_function (G_TYPE_BOOLEAN,
2279 boolean_value_parse,
2280 boolean_value_print);
2281 register_conversion_function (G_TYPE_INT,
2284 register_conversion_function (G_TYPE_UINT,
2287 register_conversion_function (G_TYPE_DOUBLE,
2289 double_value_print);
2290 register_conversion_function (G_TYPE_FLOAT,
2293 register_conversion_function (G_TYPE_STRING,
2295 string_value_print);
2296 register_conversion_function (GTK_TYPE_THEMING_ENGINE,
2297 theming_engine_value_parse,
2298 theming_engine_value_print);
2299 register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
2300 animation_description_value_parse,
2301 animation_description_value_print);
2302 register_conversion_function (GTK_TYPE_BORDER,
2304 border_value_print);
2305 register_conversion_function (GTK_TYPE_GRADIENT,
2306 gradient_value_parse,
2307 gradient_value_print);
2308 register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
2309 pattern_value_parse,
2310 pattern_value_print);
2311 register_conversion_function (GTK_TYPE_BORDER_IMAGE,
2312 border_image_value_parse,
2314 register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
2315 border_image_repeat_value_parse,
2316 border_image_repeat_value_print);
2317 register_conversion_function (GTK_TYPE_SHADOW,
2319 shadow_value_print);
2320 register_conversion_function (G_TYPE_ENUM,
2323 register_conversion_function (G_TYPE_FLAGS,
2326 register_conversion_function (GTK_TYPE_CSS_BACKGROUND_REPEAT,
2327 background_repeat_value_parse,
2328 background_repeat_value_print);
2332 _gtk_style_property_parse_value (const GtkStyleProperty *property,
2334 GtkCssParser *parser,
2337 GtkStyleParseFunc func;
2339 g_return_val_if_fail (value != NULL, FALSE);
2340 g_return_val_if_fail (parser != NULL, FALSE);
2342 css_string_funcs_init ();
2346 if (_gtk_css_parser_try (parser, "initial", TRUE))
2348 /* the initial value can be explicitly specified with the
2349 * ‘initial’ keyword which all properties accept.
2351 g_value_unset (value);
2352 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
2353 g_value_set_enum (value, GTK_CSS_INITIAL);
2356 else if (_gtk_css_parser_try (parser, "inherit", TRUE))
2358 /* All properties accept the ‘inherit’ value which
2359 * explicitly specifies that the value will be determined
2360 * by inheritance. The ‘inherit’ value can be used to
2361 * strengthen inherited values in the cascade, and it can
2362 * also be used on properties that are not normally inherited.
2364 g_value_unset (value);
2365 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
2366 g_value_set_enum (value, GTK_CSS_INHERIT);
2369 else if (property->property_parse_func)
2371 GError *error = NULL;
2375 value_str = _gtk_css_parser_read_value (parser);
2376 if (value_str == NULL)
2379 success = (*property->property_parse_func) (value_str, value, &error);
2386 func = property->parse_func;
2392 func = g_hash_table_lookup (parse_funcs,
2393 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
2395 func = g_hash_table_lookup (parse_funcs,
2396 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
2400 _gtk_css_parser_error (parser,
2401 "Cannot convert to type '%s'",
2402 g_type_name (G_VALUE_TYPE (value)));
2406 return (*func) (parser, base, value);
2410 _gtk_style_property_print_value (const GtkStyleProperty *property,
2411 const GValue *value,
2414 GtkStylePrintFunc func;
2416 css_string_funcs_init ();
2418 if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
2419 func = enum_value_print;
2421 func = property->print_func;
2426 func = g_hash_table_lookup (print_funcs,
2427 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
2429 func = g_hash_table_lookup (print_funcs,
2430 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
2434 char *s = g_strdup_value_contents (value);
2435 g_string_append (string, s);
2440 func (value, string);
2444 _gtk_style_property_default_value (const GtkStyleProperty *property,
2445 GtkStyleProperties *properties,
2446 GtkStateFlags state,
2449 g_value_copy (&property->initial_value, value);
2453 _gtk_style_property_is_inherit (const GtkStyleProperty *property)
2455 g_return_val_if_fail (property != NULL, FALSE);
2457 return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
2461 _gtk_style_property_get_id (const GtkStyleProperty *property)
2463 g_return_val_if_fail (property != NULL, FALSE);
2465 return property->id;
2469 resolve_color (GtkStyleProperties *props,
2474 /* Resolve symbolic color to GdkRGBA */
2475 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
2478 /* Store it back, this is where GdkRGBA caching happens */
2479 g_value_unset (value);
2480 g_value_init (value, GDK_TYPE_RGBA);
2481 g_value_set_boxed (value, &color);
2487 resolve_color_rgb (GtkStyleProperties *props,
2490 GdkColor color = { 0 };
2493 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
2496 color.red = rgba.red * 65535. + 0.5;
2497 color.green = rgba.green * 65535. + 0.5;
2498 color.blue = rgba.blue * 65535. + 0.5;
2500 g_value_unset (value);
2501 g_value_init (value, GDK_TYPE_COLOR);
2502 g_value_set_boxed (value, &color);
2508 resolve_win32_theme_part (GtkStyleProperties *props,
2511 GtkStylePropertyContext *context)
2513 GtkWin32ThemePart *part;
2514 cairo_pattern_t *pattern;
2516 part = g_value_get_boxed (value);
2520 pattern = _gtk_win32_theme_part_render (part, context->width, context->height);
2522 g_value_take_boxed (value_out, pattern);
2529 resolve_gradient (GtkStyleProperties *props,
2532 cairo_pattern_t *gradient;
2534 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
2537 /* Store it back, this is where cairo_pattern_t caching happens */
2538 g_value_unset (value);
2539 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
2540 g_value_take_boxed (value, gradient);
2546 resolve_shadow (GtkStyleProperties *props,
2549 GtkShadow *resolved, *base;
2551 base = g_value_get_boxed (value);
2556 if (_gtk_shadow_get_resolved (base))
2559 resolved = _gtk_shadow_resolve (base, props);
2560 if (resolved == NULL)
2563 g_value_take_boxed (value, resolved);
2569 _gtk_style_property_resolve (const GtkStyleProperty *property,
2570 GtkStyleProperties *props,
2571 GtkStateFlags state,
2572 GtkStylePropertyContext *context,
2576 if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_SPECIAL_VALUE)
2578 GtkCssSpecialValue special = g_value_get_enum (val);
2580 g_value_unset (val);
2583 case GTK_CSS_CURRENT_COLOR:
2584 g_assert (property->pspec->value_type == GDK_TYPE_RGBA);
2585 gtk_style_properties_get_property (props, "color", state, val);
2587 case GTK_CSS_INHERIT:
2588 case GTK_CSS_INITIAL:
2590 g_assert_not_reached ();
2593 else if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
2595 if (property->pspec->value_type == GDK_TYPE_RGBA)
2597 if (resolve_color (props, val))
2600 else if (property->pspec->value_type == GDK_TYPE_COLOR)
2602 if (resolve_color_rgb (props, val))
2606 g_value_unset (val);
2607 g_value_init (val, property->pspec->value_type);
2608 _gtk_style_property_default_value (property, props, state, val);
2610 else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
2612 if (g_value_get_boxed (val) == NULL)
2613 _gtk_style_property_default_value (property, props, state, val);
2615 else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
2617 g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
2619 if (!resolve_gradient (props, val))
2621 g_value_unset (val);
2622 g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
2623 _gtk_style_property_default_value (property, props, state, val);
2626 else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
2628 if (!resolve_shadow (props, val))
2629 _gtk_style_property_default_value (property, props, state, val);
2631 else if (G_VALUE_TYPE (val) == GTK_TYPE_WIN32_THEME_PART)
2633 if (resolve_win32_theme_part (props, val, val_out, context))
2634 return; /* Don't copy val, this sets val_out */
2635 _gtk_style_property_default_value (property, props, state, val);
2639 g_value_copy (val, val_out);
2643 _gtk_style_property_get_initial_value (const GtkStyleProperty *property)
2645 g_return_val_if_fail (property != NULL, NULL);
2647 return &property->initial_value;
2651 _gtk_style_property_is_shorthand (const GtkStyleProperty *property)
2653 g_return_val_if_fail (property != NULL, FALSE);
2655 return property->pack_func != NULL;
2659 _gtk_style_property_unpack (const GtkStyleProperty *property,
2660 const GValue *value,
2663 g_return_val_if_fail (property != NULL, NULL);
2664 g_return_val_if_fail (property->unpack_func != NULL, NULL);
2665 g_return_val_if_fail (value != NULL, NULL);
2666 g_return_val_if_fail (n_params != NULL, NULL);
2668 return property->unpack_func (value, n_params);
2672 _gtk_style_property_pack (const GtkStyleProperty *property,
2673 GtkStyleProperties *props,
2674 GtkStateFlags state,
2675 GtkStylePropertyContext *context,
2678 g_return_if_fail (property != NULL);
2679 g_return_if_fail (property->pack_func != NULL);
2680 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2681 g_return_if_fail (G_IS_VALUE (value));
2683 property->pack_func (value, props, state, context);
2686 #define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
2687 (rgba)->red = (r); \
2688 (rgba)->green = (g); \
2689 (rgba)->blue = (b); \
2690 (rgba)->alpha = (a); \
2693 gtk_style_property_init (void)
2695 GValue value = { 0, };
2696 char *default_font_family[] = { "Sans", NULL };
2699 if (G_LIKELY (properties))
2702 /* stuff is never freed, so no need for free functions */
2703 properties = g_hash_table_new (g_str_hash, g_str_equal);
2705 /* note that gtk_style_properties_register_property() calls this function,
2706 * so make sure we're sanely inited to avoid infloops */
2708 g_value_init (&value, GDK_TYPE_RGBA);
2709 rgba_init (&rgba, 1, 1, 1, 1);
2710 g_value_set_boxed (&value, &rgba);
2711 _gtk_style_property_register (g_param_spec_boxed ("color",
2715 GTK_STYLE_PROPERTY_INHERIT,
2723 rgba_init (&rgba, 0, 0, 0, 0);
2724 g_value_set_boxed (&value, &rgba);
2725 _gtk_style_property_register (g_param_spec_boxed ("background-color",
2733 transparent_color_value_parse,
2737 g_value_unset (&value);
2739 g_value_init (&value, G_TYPE_STRV);
2740 g_value_set_boxed (&value, default_font_family);
2741 _gtk_style_property_register (g_param_spec_boxed ("font-family",
2745 GTK_STYLE_PROPERTY_INHERIT,
2750 font_family_value_print,
2753 g_value_unset (&value);
2754 _gtk_style_property_register (g_param_spec_enum ("font-style",
2758 PANGO_STYLE_NORMAL, 0),
2759 GTK_STYLE_PROPERTY_INHERIT,
2767 _gtk_style_property_register (g_param_spec_enum ("font-variant",
2771 PANGO_VARIANT_NORMAL, 0),
2772 GTK_STYLE_PROPERTY_INHERIT,
2780 /* xxx: need to parse this properly, ie parse the numbers */
2781 _gtk_style_property_register (g_param_spec_enum ("font-weight",
2785 PANGO_WEIGHT_NORMAL, 0),
2786 GTK_STYLE_PROPERTY_INHERIT,
2794 g_value_init (&value, G_TYPE_DOUBLE);
2795 g_value_set_double (&value, 10);
2796 _gtk_style_property_register (g_param_spec_double ("font-size",
2799 0, G_MAXDOUBLE, 0, 0),
2800 GTK_STYLE_PROPERTY_INHERIT,
2808 g_value_unset (&value);
2809 _gtk_style_property_register (g_param_spec_boxed ("font",
2812 PANGO_TYPE_FONT_DESCRIPTION, 0),
2813 GTK_STYLE_PROPERTY_INHERIT,
2815 unpack_font_description,
2816 pack_font_description,
2817 font_description_value_parse,
2818 font_description_value_print,
2820 unset_font_description);
2822 _gtk_style_property_register (g_param_spec_boxed ("text-shadow",
2825 GTK_TYPE_SHADOW, 0),
2826 GTK_STYLE_PROPERTY_INHERIT,
2835 _gtk_style_property_register (g_param_spec_boxed ("icon-shadow",
2838 GTK_TYPE_SHADOW, 0),
2839 GTK_STYLE_PROPERTY_INHERIT,
2848 gtk_style_properties_register_property (NULL,
2849 g_param_spec_boxed ("box-shadow",
2852 GTK_TYPE_SHADOW, 0));
2853 gtk_style_properties_register_property (NULL,
2854 g_param_spec_int ("margin-top",
2857 0, G_MAXINT, 0, 0));
2858 gtk_style_properties_register_property (NULL,
2859 g_param_spec_int ("margin-left",
2862 0, G_MAXINT, 0, 0));
2863 gtk_style_properties_register_property (NULL,
2864 g_param_spec_int ("margin-bottom",
2867 0, G_MAXINT, 0, 0));
2868 gtk_style_properties_register_property (NULL,
2869 g_param_spec_int ("margin-right",
2872 0, G_MAXINT, 0, 0));
2873 _gtk_style_property_register (g_param_spec_boxed ("margin",
2876 GTK_TYPE_BORDER, 0),
2885 gtk_style_properties_register_property (NULL,
2886 g_param_spec_int ("padding-top",
2889 0, G_MAXINT, 0, 0));
2890 gtk_style_properties_register_property (NULL,
2891 g_param_spec_int ("padding-left",
2894 0, G_MAXINT, 0, 0));
2895 gtk_style_properties_register_property (NULL,
2896 g_param_spec_int ("padding-bottom",
2898 "Padding at bottom",
2899 0, G_MAXINT, 0, 0));
2900 gtk_style_properties_register_property (NULL,
2901 g_param_spec_int ("padding-right",
2904 0, G_MAXINT, 0, 0));
2905 _gtk_style_property_register (g_param_spec_boxed ("padding",
2908 GTK_TYPE_BORDER, 0),
2917 gtk_style_properties_register_property (NULL,
2918 g_param_spec_int ("border-top-width",
2920 "Border width at top",
2921 0, G_MAXINT, 0, 0));
2922 gtk_style_properties_register_property (NULL,
2923 g_param_spec_int ("border-left-width",
2924 "border left width",
2925 "Border width at left",
2926 0, G_MAXINT, 0, 0));
2927 gtk_style_properties_register_property (NULL,
2928 g_param_spec_int ("border-bottom-width",
2929 "border bottom width",
2930 "Border width at bottom",
2931 0, G_MAXINT, 0, 0));
2932 gtk_style_properties_register_property (NULL,
2933 g_param_spec_int ("border-right-width",
2934 "border right width",
2935 "Border width at right",
2936 0, G_MAXINT, 0, 0));
2937 _gtk_style_property_register (g_param_spec_boxed ("border-width",
2939 "Border width, in pixels",
2940 GTK_TYPE_BORDER, 0),
2943 unpack_border_width,
2948 unset_border_width);
2950 _gtk_style_property_register (g_param_spec_boxed ("border-top-left-radius",
2951 "Border top left radius",
2952 "Border radius of top left corner, in pixels",
2953 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2958 border_corner_radius_value_parse,
2959 border_corner_radius_value_print,
2962 _gtk_style_property_register (g_param_spec_boxed ("border-top-right-radius",
2963 "Border top right radius",
2964 "Border radius of top right corner, in pixels",
2965 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2970 border_corner_radius_value_parse,
2971 border_corner_radius_value_print,
2974 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-right-radius",
2975 "Border bottom right radius",
2976 "Border radius of bottom right corner, in pixels",
2977 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2982 border_corner_radius_value_parse,
2983 border_corner_radius_value_print,
2986 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-left-radius",
2987 "Border bottom left radius",
2988 "Border radius of bottom left corner, in pixels",
2989 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2994 border_corner_radius_value_parse,
2995 border_corner_radius_value_print,
2998 _gtk_style_property_register (g_param_spec_int ("border-radius",
3000 "Border radius, in pixels",
3004 unpack_border_radius,
3006 border_radius_value_parse,
3007 border_radius_value_print,
3009 unset_border_radius);
3011 gtk_style_properties_register_property (NULL,
3012 g_param_spec_enum ("border-style",
3015 GTK_TYPE_BORDER_STYLE,
3016 GTK_BORDER_STYLE_NONE, 0));
3017 gtk_style_properties_register_property (NULL,
3018 g_param_spec_enum ("background-clip",
3022 GTK_CSS_AREA_BORDER_BOX, 0));
3023 gtk_style_properties_register_property (NULL,
3024 g_param_spec_enum ("background-origin",
3025 "Background origin",
3026 "Background origin",
3028 GTK_CSS_AREA_PADDING_BOX, 0));
3029 g_value_init (&value, GTK_TYPE_CSS_SPECIAL_VALUE);
3030 g_value_set_enum (&value, GTK_CSS_CURRENT_COLOR);
3031 _gtk_style_property_register (g_param_spec_boxed ("border-top-color",
3039 transparent_color_value_parse,
3043 _gtk_style_property_register (g_param_spec_boxed ("border-right-color",
3044 "Border right color",
3045 "Border right color",
3051 transparent_color_value_parse,
3055 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-color",
3056 "Border bottom color",
3057 "Border bottom color",
3063 transparent_color_value_parse,
3067 _gtk_style_property_register (g_param_spec_boxed ("border-left-color",
3068 "Border left color",
3069 "Border left color",
3075 transparent_color_value_parse,
3079 g_value_unset (&value);
3080 _gtk_style_property_register (g_param_spec_boxed ("border-color",
3086 unpack_border_color,
3088 border_color_shorthand_value_parse,
3091 unset_border_color);
3093 gtk_style_properties_register_property (NULL,
3094 g_param_spec_boxed ("background-image",
3097 CAIRO_GOBJECT_TYPE_PATTERN, 0));
3098 gtk_style_properties_register_property (NULL,
3099 g_param_spec_boxed ("background-repeat",
3100 "Background repeat",
3101 "Background repeat",
3102 GTK_TYPE_CSS_BACKGROUND_REPEAT, 0));
3104 gtk_style_properties_register_property (NULL,
3105 g_param_spec_boxed ("border-image-source",
3106 "Border image source",
3107 "Border image source",
3108 CAIRO_GOBJECT_TYPE_PATTERN, 0));
3109 gtk_style_properties_register_property (NULL,
3110 g_param_spec_boxed ("border-image-repeat",
3111 "Border image repeat",
3112 "Border image repeat",
3113 GTK_TYPE_CSS_BORDER_IMAGE_REPEAT, 0));
3114 gtk_style_properties_register_property (NULL,
3115 g_param_spec_boxed ("border-image-slice",
3116 "Border image slice",
3117 "Border image slice",
3118 GTK_TYPE_BORDER, 0));
3119 g_value_init (&value, GTK_TYPE_BORDER);
3120 _gtk_style_property_register (g_param_spec_boxed ("border-image-width",
3121 "Border image width",
3122 "Border image width",
3123 GTK_TYPE_BORDER, 0),
3132 g_value_unset (&value);
3133 _gtk_style_property_register (g_param_spec_boxed ("border-image",
3136 GTK_TYPE_BORDER_IMAGE, 0),
3139 _gtk_border_image_unpack,
3140 _gtk_border_image_pack,
3144 unset_border_image);
3145 gtk_style_properties_register_property (NULL,
3146 g_param_spec_object ("engine",
3149 GTK_TYPE_THEMING_ENGINE, 0));
3150 gtk_style_properties_register_property (NULL,
3151 g_param_spec_boxed ("transition",
3152 "Transition animation description",
3153 "Transition animation description",
3154 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
3156 /* Private property holding the binding sets */
3157 _gtk_style_property_register (g_param_spec_boxed ("gtk-key-bindings",
3160 G_TYPE_PTR_ARRAY, 0),
3165 bindings_value_parse,
3166 bindings_value_print,
3171 const GtkStyleProperty *
3172 _gtk_style_property_lookup (const char *name)
3174 gtk_style_property_init ();
3176 return g_hash_table_lookup (properties, name);
3180 _gtk_style_property_register (GParamSpec *pspec,
3181 GtkStylePropertyFlags flags,
3182 GtkStylePropertyParser property_parse_func,
3183 GtkStyleUnpackFunc unpack_func,
3184 GtkStylePackFunc pack_func,
3185 GtkStyleParseFunc parse_func,
3186 GtkStylePrintFunc print_func,
3187 const GValue * initial_value,
3188 GtkStyleUnsetFunc unset_func)
3190 const GtkStyleProperty *existing;
3191 GtkStyleProperty *node;
3193 g_return_if_fail ((pack_func == NULL) == (unpack_func == NULL));
3195 gtk_style_property_init ();
3197 existing = _gtk_style_property_lookup (pspec->name);
3198 if (existing != NULL)
3200 g_warning ("Property \"%s\" was already registered with type %s",
3201 pspec->name, g_type_name (existing->pspec->value_type));
3205 node = g_slice_new0 (GtkStyleProperty);
3206 node->flags = flags;
3207 node->pspec = pspec;
3208 node->property_parse_func = property_parse_func;
3209 node->pack_func = pack_func;
3210 node->unpack_func = unpack_func;
3211 node->parse_func = parse_func;
3212 node->print_func = print_func;
3213 node->unset_func = unset_func;
3215 if (!_gtk_style_property_is_shorthand (node))
3217 _gtk_style_property_generate_id (node);
3219 /* initialize the initial value */
3222 g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value));
3223 g_value_copy (initial_value, &node->initial_value);
3227 g_value_init (&node->initial_value, pspec->value_type);
3228 if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
3229 g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
3230 else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
3231 g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10"));
3232 else if (pspec->value_type == GDK_TYPE_RGBA)
3235 gdk_rgba_parse (&color, "pink");
3236 g_value_set_boxed (&node->initial_value, &color);
3238 else if (pspec->value_type == GTK_TYPE_BORDER)
3240 g_value_take_boxed (&node->initial_value, gtk_border_new ());
3243 g_param_value_set_default (pspec, &node->initial_value);
3247 /* pspec owns name */
3248 g_hash_table_insert (properties, (gchar *)pspec->name, node);