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"
36 #include "gtkstylepropertiesprivate.h"
38 /* the actual parsers we have */
39 #include "gtkanimationdescription.h"
40 #include "gtkbindings.h"
41 #include "gtkborderimageprivate.h"
42 #include "gtkgradient.h"
43 #include "gtkshadowprivate.h"
44 #include "gtkthemingengine.h"
45 #include "gtktypebuiltins.h"
46 #include "gtkwin32themeprivate.h"
48 /* this is in case round() is not provided by the compiler,
49 * such as in the case of C89 compilers, like MSVC
51 #include "fallback-c89.c"
53 static GHashTable *parse_funcs = NULL;
54 static GHashTable *print_funcs = NULL;
55 static GHashTable *properties = NULL;
56 static GPtrArray *__style_property_array = NULL;
59 register_conversion_function (GType type,
60 GtkStyleParseFunc parse,
61 GtkStylePrintFunc print)
64 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
66 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
70 string_append_double (GString *string,
73 char buf[G_ASCII_DTOSTR_BUF_SIZE];
75 g_ascii_dtostr (buf, sizeof (buf), d);
76 g_string_append (string, buf);
80 string_append_string (GString *str,
85 g_string_append_c (str, '"');
88 len = strcspn (string, "\"\n\r\f");
89 g_string_append (str, string);
96 g_string_append (str, "\\A ");
99 g_string_append (str, "\\D ");
102 g_string_append (str, "\\C ");
105 g_string_append (str, "\\\"");
108 g_assert_not_reached ();
113 g_string_append_c (str, '"');
116 /*** IMPLEMENTATIONS ***/
119 enum_parse (GtkCssParser *parser,
125 if (_gtk_css_parser_try_enum (parser, type, res))
128 str = _gtk_css_parser_try_ident (parser, TRUE);
131 _gtk_css_parser_error (parser, "Expected an identifier");
135 _gtk_css_parser_error (parser,
136 "Unknown value '%s' for enum type '%s'",
137 str, g_type_name (type));
144 enum_print (int value,
148 GEnumClass *enum_class;
149 GEnumValue *enum_value;
151 enum_class = g_type_class_ref (type);
152 enum_value = g_enum_get_value (enum_class, value);
154 g_string_append (string, enum_value->value_nick);
156 g_type_class_unref (enum_class);
160 rgba_value_parse (GtkCssParser *parser,
164 GtkSymbolicColor *symbolic;
167 symbolic = _gtk_css_parser_read_symbolic_color (parser);
168 if (symbolic == NULL)
171 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
173 g_value_set_boxed (value, &rgba);
174 gtk_symbolic_color_unref (symbolic);
178 g_value_unset (value);
179 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
180 g_value_take_boxed (value, symbolic);
187 rgba_value_print (const GValue *value,
190 const GdkRGBA *rgba = g_value_get_boxed (value);
193 g_string_append (string, "none");
196 char *s = gdk_rgba_to_string (rgba);
197 g_string_append (string, s);
203 color_value_parse (GtkCssParser *parser,
207 GtkSymbolicColor *symbolic;
210 symbolic = _gtk_css_parser_read_symbolic_color (parser);
211 if (symbolic == NULL)
214 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
218 color.red = rgba.red * 65535. + 0.5;
219 color.green = rgba.green * 65535. + 0.5;
220 color.blue = rgba.blue * 65535. + 0.5;
222 g_value_set_boxed (value, &color);
226 g_value_unset (value);
227 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
228 g_value_take_boxed (value, symbolic);
235 color_value_print (const GValue *value,
238 const GdkColor *color = g_value_get_boxed (value);
241 g_string_append (string, "none");
244 char *s = gdk_color_to_string (color);
245 g_string_append (string, s);
251 symbolic_color_value_parse (GtkCssParser *parser,
255 GtkSymbolicColor *symbolic;
257 symbolic = _gtk_css_parser_read_symbolic_color (parser);
258 if (symbolic == NULL)
261 g_value_take_boxed (value, symbolic);
266 symbolic_color_value_print (const GValue *value,
269 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
271 if (symbolic == NULL)
272 g_string_append (string, "none");
275 char *s = gtk_symbolic_color_to_string (symbolic);
276 g_string_append (string, s);
282 font_family_parse (GtkCssParser *parser,
289 /* We don't special case generic families. Pango should do
292 names = g_ptr_array_new ();
295 name = _gtk_css_parser_try_ident (parser, TRUE);
298 GString *string = g_string_new (name);
300 while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
302 g_string_append_c (string, ' ');
303 g_string_append (string, name);
306 name = g_string_free (string, FALSE);
310 name = _gtk_css_parser_read_string (parser);
313 g_ptr_array_free (names, TRUE);
318 g_ptr_array_add (names, name);
319 } while (_gtk_css_parser_try (parser, ",", TRUE));
321 /* NULL-terminate array */
322 g_ptr_array_add (names, NULL);
323 g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
328 font_family_value_print (const GValue *value,
331 const char **names = g_value_get_boxed (value);
333 if (names == NULL || *names == NULL)
335 g_string_append (string, "none");
339 string_append_string (string, *names);
343 g_string_append (string, ", ");
344 string_append_string (string, *names);
350 font_description_value_parse (GtkCssParser *parser,
354 PangoFontDescription *font_desc;
358 str = _gtk_css_parser_read_value (parser);
362 font_desc = pango_font_description_from_string (str);
363 mask = pango_font_description_get_set_fields (font_desc);
364 /* These values are not really correct,
365 * but the fields must be set, so we set them to something */
366 if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
367 pango_font_description_set_family_static (font_desc, "Sans");
368 if ((mask & PANGO_FONT_MASK_SIZE) == 0)
369 pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
371 g_value_take_boxed (value, font_desc);
376 font_description_value_print (const GValue *value,
379 const PangoFontDescription *desc = g_value_get_boxed (value);
382 g_string_append (string, "none");
385 char *s = pango_font_description_to_string (desc);
386 g_string_append (string, s);
392 boolean_value_parse (GtkCssParser *parser,
396 if (_gtk_css_parser_try (parser, "true", TRUE) ||
397 _gtk_css_parser_try (parser, "1", TRUE))
399 g_value_set_boolean (value, TRUE);
402 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
403 _gtk_css_parser_try (parser, "0", TRUE))
405 g_value_set_boolean (value, FALSE);
410 _gtk_css_parser_error (parser, "Expected a boolean value");
416 boolean_value_print (const GValue *value,
419 if (g_value_get_boolean (value))
420 g_string_append (string, "true");
422 g_string_append (string, "false");
426 int_value_parse (GtkCssParser *parser,
432 if (_gtk_css_parser_begins_with (parser, '-'))
434 int res = _gtk_win32_theme_int_parse (parser, base, &i);
437 g_value_set_int (value, i);
440 /* < 0 => continue */
443 if (!_gtk_css_parser_try_int (parser, &i))
445 _gtk_css_parser_error (parser, "Expected a valid integer value");
449 g_value_set_int (value, i);
454 int_value_print (const GValue *value,
457 g_string_append_printf (string, "%d", g_value_get_int (value));
461 uint_value_parse (GtkCssParser *parser,
467 if (!_gtk_css_parser_try_uint (parser, &u))
469 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
473 g_value_set_uint (value, u);
478 uint_value_print (const GValue *value,
481 g_string_append_printf (string, "%u", g_value_get_uint (value));
485 double_value_parse (GtkCssParser *parser,
491 if (!_gtk_css_parser_try_double (parser, &d))
493 _gtk_css_parser_error (parser, "Expected a number");
497 g_value_set_double (value, d);
502 double_value_print (const GValue *value,
505 string_append_double (string, g_value_get_double (value));
509 float_value_parse (GtkCssParser *parser,
515 if (!_gtk_css_parser_try_double (parser, &d))
517 _gtk_css_parser_error (parser, "Expected a number");
521 g_value_set_float (value, d);
526 float_value_print (const GValue *value,
529 string_append_double (string, g_value_get_float (value));
533 string_value_parse (GtkCssParser *parser,
537 char *str = _gtk_css_parser_read_string (parser);
542 g_value_take_string (value, str);
547 string_value_print (const GValue *value,
550 string_append_string (str, g_value_get_string (value));
554 theming_engine_value_parse (GtkCssParser *parser,
558 GtkThemingEngine *engine;
561 if (_gtk_css_parser_try (parser, "none", TRUE))
563 g_value_set_object (value, gtk_theming_engine_load (NULL));
567 str = _gtk_css_parser_try_ident (parser, TRUE);
570 _gtk_css_parser_error (parser, "Expected a valid theme name");
574 engine = gtk_theming_engine_load (str);
578 _gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
583 g_value_set_object (value, engine);
589 theming_engine_value_print (const GValue *value,
592 GtkThemingEngine *engine;
595 engine = g_value_get_object (value);
597 g_string_append (string, "none");
600 /* XXX: gtk_theming_engine_get_name()? */
601 g_object_get (engine, "name", &name, NULL);
602 g_string_append (string, name ? name : "none");
608 animation_description_value_parse (GtkCssParser *parser,
612 GtkAnimationDescription *desc;
615 str = _gtk_css_parser_read_value (parser);
619 desc = _gtk_animation_description_from_string (str);
624 _gtk_css_parser_error (parser, "Invalid animation description");
628 g_value_take_boxed (value, desc);
633 animation_description_value_print (const GValue *value,
636 GtkAnimationDescription *desc = g_value_get_boxed (value);
639 g_string_append (string, "none");
641 _gtk_animation_description_print (desc, string);
645 border_value_parse (GtkCssParser *parser,
649 GtkBorder border = { 0, };
652 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
654 if (_gtk_css_parser_begins_with (parser, '-'))
656 /* These are strictly speaking signed, but we want to be able to use them
657 for unsigned types too, as the actual ranges of values make this safe */
658 int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
660 if (res == 0) /* Parse error, report */
663 if (res < 0) /* Nothing known to expand */
668 if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
671 /* XXX: shouldn't allow spaces here? */
672 _gtk_css_parser_try (parser, "px", TRUE);
678 _gtk_css_parser_error (parser, "Expected valid border");
682 border.top = numbers[0];
684 border.right = numbers[1];
686 border.right = border.top;
688 border.bottom = numbers[2];
690 border.bottom = border.top;
692 border.left = numbers[3];
694 border.left = border.right;
696 g_value_set_boxed (value, &border);
701 border_value_print (const GValue *value, GString *string)
703 const GtkBorder *border = g_value_get_boxed (value);
706 g_string_append (string, "none");
707 else if (border->left != border->right)
708 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
709 else if (border->top != border->bottom)
710 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
711 else if (border->top != border->left)
712 g_string_append_printf (string, "%d %d", border->top, border->right);
714 g_string_append_printf (string, "%d", border->top);
718 gradient_value_parse (GtkCssParser *parser,
722 GtkGradient *gradient;
723 cairo_pattern_type_t type;
727 if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
729 _gtk_css_parser_error (parser,
730 "Expected '-gtk-gradient'");
734 if (!_gtk_css_parser_try (parser, "(", TRUE))
736 _gtk_css_parser_error (parser,
737 "Expected '(' after '-gtk-gradient'");
741 /* Parse gradient type */
742 if (_gtk_css_parser_try (parser, "linear", TRUE))
743 type = CAIRO_PATTERN_TYPE_LINEAR;
744 else if (_gtk_css_parser_try (parser, "radial", TRUE))
745 type = CAIRO_PATTERN_TYPE_RADIAL;
748 _gtk_css_parser_error (parser,
749 "Gradient type must be 'radial' or 'linear'");
753 /* Parse start/stop position parameters */
754 for (i = 0; i < 2; i++)
756 if (! _gtk_css_parser_try (parser, ",", TRUE))
758 _gtk_css_parser_error (parser,
763 if (_gtk_css_parser_try (parser, "left", TRUE))
765 else if (_gtk_css_parser_try (parser, "right", TRUE))
767 else if (_gtk_css_parser_try (parser, "center", TRUE))
769 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
771 _gtk_css_parser_error (parser,
772 "Expected a valid X coordinate");
776 if (_gtk_css_parser_try (parser, "top", TRUE))
777 coords[i * 3 + 1] = 0;
778 else if (_gtk_css_parser_try (parser, "bottom", TRUE))
779 coords[i * 3 + 1] = 1;
780 else if (_gtk_css_parser_try (parser, "center", TRUE))
781 coords[i * 3 + 1] = 0.5;
782 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
784 _gtk_css_parser_error (parser,
785 "Expected a valid Y coordinate");
789 if (type == CAIRO_PATTERN_TYPE_RADIAL)
792 if (! _gtk_css_parser_try (parser, ",", TRUE))
794 _gtk_css_parser_error (parser,
799 if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
801 _gtk_css_parser_error (parser,
802 "Expected a numer for the radius");
808 if (type == CAIRO_PATTERN_TYPE_LINEAR)
809 gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
811 gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
812 coords[3], coords[4], coords[5]);
814 while (_gtk_css_parser_try (parser, ",", TRUE))
816 GtkSymbolicColor *color;
819 if (_gtk_css_parser_try (parser, "from", TRUE))
823 if (!_gtk_css_parser_try (parser, "(", TRUE))
825 gtk_gradient_unref (gradient);
826 _gtk_css_parser_error (parser,
832 else if (_gtk_css_parser_try (parser, "to", TRUE))
836 if (!_gtk_css_parser_try (parser, "(", TRUE))
838 gtk_gradient_unref (gradient);
839 _gtk_css_parser_error (parser,
845 else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
847 if (!_gtk_css_parser_try (parser, "(", TRUE))
849 gtk_gradient_unref (gradient);
850 _gtk_css_parser_error (parser,
855 if (!_gtk_css_parser_try_double (parser, &position))
857 gtk_gradient_unref (gradient);
858 _gtk_css_parser_error (parser,
859 "Expected a valid number");
863 if (!_gtk_css_parser_try (parser, ",", TRUE))
865 gtk_gradient_unref (gradient);
866 _gtk_css_parser_error (parser,
873 gtk_gradient_unref (gradient);
874 _gtk_css_parser_error (parser,
875 "Not a valid color-stop definition");
879 color = _gtk_css_parser_read_symbolic_color (parser);
882 gtk_gradient_unref (gradient);
886 gtk_gradient_add_color_stop (gradient, position, color);
887 gtk_symbolic_color_unref (color);
889 if (!_gtk_css_parser_try (parser, ")", TRUE))
891 gtk_gradient_unref (gradient);
892 _gtk_css_parser_error (parser,
898 if (!_gtk_css_parser_try (parser, ")", TRUE))
900 gtk_gradient_unref (gradient);
901 _gtk_css_parser_error (parser,
906 g_value_take_boxed (value, gradient);
911 gradient_value_print (const GValue *value,
914 GtkGradient *gradient = g_value_get_boxed (value);
916 if (gradient == NULL)
917 g_string_append (string, "none");
920 char *s = gtk_gradient_to_string (gradient);
921 g_string_append (string, s);
927 gtk_css_parse_url (GtkCssParser *parser,
933 if (_gtk_css_parser_try (parser, "url", FALSE))
935 if (!_gtk_css_parser_try (parser, "(", TRUE))
937 _gtk_css_parser_skip_whitespace (parser);
938 if (_gtk_css_parser_try (parser, "(", TRUE))
942 error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
943 GTK_CSS_PROVIDER_ERROR_DEPRECATED,
944 "Whitespace between 'url' and '(' is deprecated");
946 _gtk_css_parser_take_error (parser, error);
950 _gtk_css_parser_error (parser, "Expected '(' after 'url'");
955 path = _gtk_css_parser_read_string (parser);
959 if (!_gtk_css_parser_try (parser, ")", TRUE))
961 _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
968 path = _gtk_css_parser_try_name (parser, TRUE);
971 _gtk_css_parser_error (parser, "Not a valid url");
976 file = g_file_resolve_relative_path (base, path);
983 pattern_value_parse (GtkCssParser *parser,
987 if (_gtk_css_parser_try (parser, "none", TRUE))
989 /* nothing to do here */
991 else if (_gtk_css_parser_begins_with (parser, '-'))
994 res = _gtk_win32_theme_part_parse (parser, base, value);
997 /* < 0 => continue */
998 g_value_unset (value);
999 g_value_init (value, GTK_TYPE_GRADIENT);
1000 return gradient_value_parse (parser, base, value);
1004 GError *error = NULL;
1008 cairo_surface_t *surface;
1009 cairo_pattern_t *pattern;
1011 cairo_matrix_t matrix;
1013 file = gtk_css_parse_url (parser, base);
1017 path = g_file_get_path (file);
1018 g_object_unref (file);
1020 pixbuf = gdk_pixbuf_new_from_file (path, &error);
1024 _gtk_css_parser_take_error (parser, error);
1028 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1029 gdk_pixbuf_get_width (pixbuf),
1030 gdk_pixbuf_get_height (pixbuf));
1031 cr = cairo_create (surface);
1032 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
1034 pattern = cairo_pattern_create_for_surface (surface);
1036 cairo_matrix_init_scale (&matrix,
1037 gdk_pixbuf_get_width (pixbuf),
1038 gdk_pixbuf_get_height (pixbuf));
1039 cairo_pattern_set_matrix (pattern, &matrix);
1041 cairo_surface_destroy (surface);
1043 g_object_unref (pixbuf);
1045 g_value_take_boxed (value, pattern);
1051 static cairo_status_t
1052 surface_write (void *closure,
1053 const unsigned char *data,
1054 unsigned int length)
1056 g_byte_array_append (closure, data, length);
1058 return CAIRO_STATUS_SUCCESS;
1062 surface_print (cairo_surface_t *surface,
1065 #if CAIRO_HAS_PNG_FUNCTIONS
1069 array = g_byte_array_new ();
1070 cairo_surface_write_to_png_stream (surface, surface_write, array);
1071 base64 = g_base64_encode (array->data, array->len);
1072 g_byte_array_free (array, TRUE);
1074 g_string_append (string, "url(\"data:image/png;base64,");
1075 g_string_append (string, base64);
1076 g_string_append (string, "\")");
1080 g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
1085 pattern_value_print (const GValue *value,
1088 cairo_pattern_t *pattern;
1089 cairo_surface_t *surface;
1091 pattern = g_value_get_boxed (value);
1093 if (pattern == NULL)
1095 g_string_append (string, "none");
1099 switch (cairo_pattern_get_type (pattern))
1101 case CAIRO_PATTERN_TYPE_SURFACE:
1102 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
1104 g_assert_not_reached ();
1106 surface_print (surface, string);
1108 case CAIRO_PATTERN_TYPE_SOLID:
1109 case CAIRO_PATTERN_TYPE_LINEAR:
1110 case CAIRO_PATTERN_TYPE_RADIAL:
1112 g_assert_not_reached ();
1118 shadow_value_parse (GtkCssParser *parser,
1122 gboolean have_inset, have_color, have_lengths;
1123 gdouble hoffset, voffset, blur, spread;
1124 GtkSymbolicColor *color;
1128 shadow = _gtk_shadow_new ();
1130 if (_gtk_css_parser_try (parser, "none", TRUE))
1135 have_inset = have_lengths = have_color = FALSE;
1137 for (i = 0; i < 3; i++)
1140 _gtk_css_parser_try (parser, "inset", TRUE))
1146 if (!have_lengths &&
1147 _gtk_css_parser_try_double (parser, &hoffset))
1149 have_lengths = TRUE;
1151 if (!_gtk_css_parser_try_double (parser, &voffset))
1153 _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
1154 _gtk_shadow_unref (shadow);
1158 if (!_gtk_css_parser_try_double (parser, &blur))
1161 if (!_gtk_css_parser_try_double (parser, &spread))
1171 /* XXX: the color is optional and UA-defined if it's missing,
1172 * but it doesn't really make sense for us...
1174 color = _gtk_css_parser_read_symbolic_color (parser);
1178 _gtk_shadow_unref (shadow);
1184 if (!have_color || !have_lengths)
1186 _gtk_css_parser_error (parser, "Must specify at least color and offsets");
1187 _gtk_shadow_unref (shadow);
1191 _gtk_shadow_append (shadow,
1196 gtk_symbolic_color_unref (color);
1199 while (_gtk_css_parser_try (parser, ",", TRUE));
1201 g_value_take_boxed (value, shadow);
1206 shadow_value_print (const GValue *value,
1211 shadow = g_value_get_boxed (value);
1214 g_string_append (string, "none");
1216 _gtk_shadow_print (shadow, string);
1220 background_repeat_value_parse (GtkCssParser *parser,
1224 GtkCssBackgroundRepeat repeat;
1227 if (!enum_parse (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, &style))
1230 repeat.repeat = style;
1232 g_value_set_boxed (value, &repeat);
1238 background_repeat_value_print (const GValue *value,
1241 GtkCssBackgroundRepeat *repeat;
1243 repeat = g_value_get_boxed (value);
1245 enum_print (repeat->repeat, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, string);
1249 border_image_repeat_value_parse (GtkCssParser *parser,
1253 GtkCssBorderImageRepeat image_repeat;
1254 GtkCssBorderRepeatStyle styles[2];
1257 for (i = 0; i < 2; i++)
1259 if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
1263 styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
1267 styles[i] = styles[0];
1270 image_repeat.hrepeat = styles[0];
1271 image_repeat.vrepeat = styles[1];
1273 g_value_set_boxed (value, &image_repeat);
1279 border_image_repeat_value_print (const GValue *value,
1282 GtkCssBorderImageRepeat *image_repeat;
1284 image_repeat = g_value_get_boxed (value);
1286 enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1287 if (image_repeat->hrepeat != image_repeat->vrepeat)
1289 g_string_append (string, " ");
1290 enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1295 border_image_value_parse (GtkCssParser *parser,
1299 GValue temp = G_VALUE_INIT;
1300 cairo_pattern_t *pattern = NULL;
1301 gconstpointer *boxed = NULL;
1303 GtkBorder slice, *width = NULL, *parsed_slice;
1304 GtkCssBorderImageRepeat repeat, *parsed_repeat;
1305 gboolean retval = FALSE;
1306 GtkBorderImage *image = NULL;
1308 if (_gtk_css_parser_try (parser, "none", TRUE))
1311 g_value_init (&temp, CAIRO_GOBJECT_TYPE_PATTERN);
1313 if (!pattern_value_parse (parser, base, &temp))
1316 boxed_type = G_VALUE_TYPE (&temp);
1317 if (boxed_type != CAIRO_GOBJECT_TYPE_PATTERN)
1318 boxed = g_value_dup_boxed (&temp);
1320 pattern = g_value_dup_boxed (&temp);
1322 g_value_unset (&temp);
1323 g_value_init (&temp, GTK_TYPE_BORDER);
1325 if (!border_value_parse (parser, base, &temp))
1328 parsed_slice = g_value_get_boxed (&temp);
1329 slice = *parsed_slice;
1331 if (_gtk_css_parser_try (parser, "/", TRUE))
1333 g_value_unset (&temp);
1334 g_value_init (&temp, GTK_TYPE_BORDER);
1336 if (!border_value_parse (parser, base, &temp))
1339 width = g_value_dup_boxed (&temp);
1342 g_value_unset (&temp);
1343 g_value_init (&temp, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
1345 if (!border_image_repeat_value_parse (parser, base, &temp))
1348 parsed_repeat = g_value_get_boxed (&temp);
1349 repeat = *parsed_repeat;
1351 g_value_unset (&temp);
1354 image = _gtk_border_image_new_for_boxed (boxed_type, boxed, &slice, width, &repeat);
1355 else if (pattern != NULL)
1356 image = _gtk_border_image_new (pattern, &slice, width, &repeat);
1361 g_value_take_boxed (value, image);
1365 if (pattern != NULL)
1366 cairo_pattern_destroy (pattern);
1369 g_boxed_free (boxed_type, boxed);
1372 gtk_border_free (width);
1378 enum_value_parse (GtkCssParser *parser,
1384 if (enum_parse (parser, G_VALUE_TYPE (value), &v))
1386 g_value_set_enum (value, v);
1394 enum_value_print (const GValue *value,
1397 enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
1401 flags_value_parse (GtkCssParser *parser,
1405 GFlagsClass *flags_class;
1406 GFlagsValue *flag_value;
1410 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1413 str = _gtk_css_parser_try_ident (parser, TRUE);
1416 _gtk_css_parser_error (parser, "Expected an identifier");
1417 g_type_class_unref (flags_class);
1421 flag_value = g_flags_get_value_by_nick (flags_class, str);
1424 _gtk_css_parser_error (parser,
1425 "Unknown flag value '%s' for type '%s'",
1426 str, g_type_name (G_VALUE_TYPE (value)));
1427 /* XXX Do we want to return FALSE here? We can get
1428 * forward-compatibility for new values this way
1431 g_type_class_unref (flags_class);
1437 while (_gtk_css_parser_try (parser, ",", FALSE));
1439 g_type_class_unref (flags_class);
1441 g_value_set_enum (value, flags);
1447 flags_value_print (const GValue *value,
1450 GFlagsClass *flags_class;
1453 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1454 flags = g_value_get_flags (value);
1456 for (i = 0; i < flags_class->n_values; i++)
1458 GFlagsValue *flags_value = &flags_class->values[i];
1460 if (flags & flags_value->value)
1462 if (string->len != 0)
1463 g_string_append (string, ", ");
1465 g_string_append (string, flags_value->value_nick);
1469 g_type_class_unref (flags_class);
1473 bindings_value_parse (GtkCssParser *parser,
1478 GtkBindingSet *binding_set;
1481 array = g_ptr_array_new ();
1484 name = _gtk_css_parser_try_ident (parser, TRUE);
1487 _gtk_css_parser_error (parser, "Not a valid binding name");
1488 g_ptr_array_free (array, TRUE);
1492 binding_set = gtk_binding_set_find (name);
1496 _gtk_css_parser_error (parser, "No binding set named '%s'", name);
1501 g_ptr_array_add (array, binding_set);
1504 while (_gtk_css_parser_try (parser, ",", TRUE));
1506 g_value_take_boxed (value, array);
1512 bindings_value_print (const GValue *value,
1518 array = g_value_get_boxed (value);
1520 for (i = 0; i < array->len; i++)
1522 GtkBindingSet *binding_set = g_ptr_array_index (array, i);
1525 g_string_append (string, ", ");
1526 g_string_append (string, binding_set->set_name);
1531 border_corner_radius_value_parse (GtkCssParser *parser,
1535 GtkCssBorderCornerRadius corner;
1537 if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
1539 _gtk_css_parser_error (parser, "Expected a number");
1542 else if (corner.horizontal < 0)
1545 if (!_gtk_css_parser_try_double (parser, &corner.vertical))
1546 corner.vertical = corner.horizontal;
1547 else if (corner.vertical < 0)
1550 g_value_set_boxed (value, &corner);
1554 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1559 border_corner_radius_value_print (const GValue *value,
1562 GtkCssBorderCornerRadius *corner;
1564 corner = g_value_get_boxed (value);
1568 g_string_append (string, "none");
1572 string_append_double (string, corner->horizontal);
1573 if (corner->horizontal != corner->vertical)
1575 g_string_append_c (string, ' ');
1576 string_append_double (string, corner->vertical);
1581 border_radius_value_parse (GtkCssParser *parser,
1585 GtkCssBorderRadius border;
1587 if (!_gtk_css_parser_try_double (parser, &border.top_left.horizontal))
1589 _gtk_css_parser_error (parser, "Expected a number");
1592 else if (border.top_left.horizontal < 0)
1595 if (_gtk_css_parser_try_double (parser, &border.top_right.horizontal))
1597 if (border.top_right.horizontal < 0)
1599 if (_gtk_css_parser_try_double (parser, &border.bottom_right.horizontal))
1601 if (border.bottom_right.horizontal < 0)
1603 if (!_gtk_css_parser_try_double (parser, &border.bottom_left.horizontal))
1604 border.bottom_left.horizontal = border.top_right.horizontal;
1605 else if (border.bottom_left.horizontal < 0)
1610 border.bottom_right.horizontal = border.top_left.horizontal;
1611 border.bottom_left.horizontal = border.top_right.horizontal;
1616 border.top_right.horizontal = border.top_left.horizontal;
1617 border.bottom_right.horizontal = border.top_left.horizontal;
1618 border.bottom_left.horizontal = border.top_left.horizontal;
1621 if (_gtk_css_parser_try (parser, "/", TRUE))
1623 if (!_gtk_css_parser_try_double (parser, &border.top_left.vertical))
1625 _gtk_css_parser_error (parser, "Expected a number");
1628 else if (border.top_left.vertical < 0)
1631 if (_gtk_css_parser_try_double (parser, &border.top_right.vertical))
1633 if (border.top_right.vertical < 0)
1635 if (_gtk_css_parser_try_double (parser, &border.bottom_right.vertical))
1637 if (border.bottom_right.vertical < 0)
1639 if (!_gtk_css_parser_try_double (parser, &border.bottom_left.vertical))
1640 border.bottom_left.vertical = border.top_right.vertical;
1641 else if (border.bottom_left.vertical < 0)
1646 border.bottom_right.vertical = border.top_left.vertical;
1647 border.bottom_left.vertical = border.top_right.vertical;
1652 border.top_right.vertical = border.top_left.vertical;
1653 border.bottom_right.vertical = border.top_left.vertical;
1654 border.bottom_left.vertical = border.top_left.vertical;
1659 border.top_left.vertical = border.top_left.horizontal;
1660 border.top_right.vertical = border.top_right.horizontal;
1661 border.bottom_right.vertical = border.bottom_right.horizontal;
1662 border.bottom_left.vertical = border.bottom_left.horizontal;
1665 /* border-radius is an int property for backwards-compat reasons */
1666 g_value_unset (value);
1667 g_value_init (value, GTK_TYPE_CSS_BORDER_RADIUS);
1668 g_value_set_boxed (value, &border);
1673 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1678 border_radius_value_print (const GValue *value,
1681 GtkCssBorderRadius *border;
1683 border = g_value_get_boxed (value);
1687 g_string_append (string, "none");
1691 string_append_double (string, border->top_left.horizontal);
1692 if (border->top_left.horizontal != border->top_right.horizontal ||
1693 border->top_left.horizontal != border->bottom_right.horizontal ||
1694 border->top_left.horizontal != border->bottom_left.horizontal)
1696 g_string_append_c (string, ' ');
1697 string_append_double (string, border->top_right.horizontal);
1698 if (border->top_left.horizontal != border->bottom_right.horizontal ||
1699 border->top_right.horizontal != border->bottom_left.horizontal)
1701 g_string_append_c (string, ' ');
1702 string_append_double (string, border->bottom_right.horizontal);
1703 if (border->top_right.horizontal != border->bottom_left.horizontal)
1705 g_string_append_c (string, ' ');
1706 string_append_double (string, border->bottom_left.horizontal);
1711 if (border->top_left.horizontal != border->top_left.vertical ||
1712 border->top_right.horizontal != border->top_right.vertical ||
1713 border->bottom_right.horizontal != border->bottom_right.vertical ||
1714 border->bottom_left.horizontal != border->bottom_left.vertical)
1716 g_string_append (string, " / ");
1717 string_append_double (string, border->top_left.vertical);
1718 if (border->top_left.vertical != border->top_right.vertical ||
1719 border->top_left.vertical != border->bottom_right.vertical ||
1720 border->top_left.vertical != border->bottom_left.vertical)
1722 g_string_append_c (string, ' ');
1723 string_append_double (string, border->top_right.vertical);
1724 if (border->top_left.vertical != border->bottom_right.vertical ||
1725 border->top_right.vertical != border->bottom_left.vertical)
1727 g_string_append_c (string, ' ');
1728 string_append_double (string, border->bottom_right.vertical);
1729 if (border->top_right.vertical != border->bottom_left.vertical)
1731 g_string_append_c (string, ' ');
1732 string_append_double (string, border->bottom_left.vertical);
1741 transparent_color_value_parse (GtkCssParser *parser,
1745 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1747 GdkRGBA transparent = { 0, 0, 0, 0 };
1749 g_value_set_boxed (value, &transparent);
1754 return rgba_value_parse (parser, base, value);
1758 border_color_shorthand_value_parse (GtkCssParser *parser,
1762 GtkSymbolicColor *symbolic;
1765 array = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_symbolic_color_unref);
1769 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1771 GdkRGBA transparent = { 0, 0, 0, 0 };
1773 symbolic = gtk_symbolic_color_new_literal (&transparent);
1777 symbolic = _gtk_css_parser_read_symbolic_color (parser);
1779 if (symbolic == NULL)
1783 g_ptr_array_add (array, symbolic);
1785 while (array->len < 4 &&
1786 !_gtk_css_parser_is_eof (parser) &&
1787 !_gtk_css_parser_begins_with (parser, ';') &&
1788 !_gtk_css_parser_begins_with (parser, '}'));
1793 g_assert_not_reached ();
1796 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 0)));
1799 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 0)));
1802 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 1)));
1808 g_value_unset (value);
1809 g_value_init (value, G_TYPE_PTR_ARRAY);
1810 g_value_take_boxed (value, array);
1818 unpack_border (const GValue *value,
1825 GParameter *parameter = g_new0 (GParameter, 4);
1826 GtkBorder *border = g_value_get_boxed (value);
1828 parameter[0].name = top;
1829 g_value_init (¶meter[0].value, G_TYPE_INT);
1830 g_value_set_int (¶meter[0].value, border->top);
1831 parameter[1].name = left;
1832 g_value_init (¶meter[1].value, G_TYPE_INT);
1833 g_value_set_int (¶meter[1].value, border->left);
1834 parameter[2].name = bottom;
1835 g_value_init (¶meter[2].value, G_TYPE_INT);
1836 g_value_set_int (¶meter[2].value, border->bottom);
1837 parameter[3].name = right;
1838 g_value_init (¶meter[3].value, G_TYPE_INT);
1839 g_value_set_int (¶meter[3].value, border->right);
1846 pack_border (GValue *value,
1847 GtkStyleProperties *props,
1848 GtkStateFlags state,
1857 gtk_style_properties_get (props,
1870 g_value_set_boxed (value, &border);
1874 unpack_border_width (const GValue *value,
1877 return unpack_border (value, n_params,
1878 "border-top-width", "border-left-width",
1879 "border-bottom-width", "border-right-width");
1883 pack_border_width (GValue *value,
1884 GtkStyleProperties *props,
1885 GtkStateFlags state,
1886 GtkStylePropertyContext *context)
1888 pack_border (value, props, state,
1889 "border-top-width", "border-left-width",
1890 "border-bottom-width", "border-right-width");
1894 unpack_padding (const GValue *value,
1897 return unpack_border (value, n_params,
1898 "padding-top", "padding-left",
1899 "padding-bottom", "padding-right");
1903 pack_padding (GValue *value,
1904 GtkStyleProperties *props,
1905 GtkStateFlags state,
1906 GtkStylePropertyContext *context)
1908 pack_border (value, props, state,
1909 "padding-top", "padding-left",
1910 "padding-bottom", "padding-right");
1914 unpack_margin (const GValue *value,
1917 return unpack_border (value, n_params,
1918 "margin-top", "margin-left",
1919 "margin-bottom", "margin-right");
1923 pack_margin (GValue *value,
1924 GtkStyleProperties *props,
1925 GtkStateFlags state,
1926 GtkStylePropertyContext *context)
1928 pack_border (value, props, state,
1929 "margin-top", "margin-left",
1930 "margin-bottom", "margin-right");
1934 unpack_border_radius (const GValue *value,
1937 GParameter *parameter = g_new0 (GParameter, 4);
1938 GtkCssBorderRadius *border;
1940 if (G_VALUE_HOLDS_BOXED (value))
1941 border = g_value_get_boxed (value);
1945 parameter[0].name = "border-top-left-radius";
1946 g_value_init (¶meter[0].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1947 parameter[1].name = "border-top-right-radius";
1948 g_value_init (¶meter[1].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1949 parameter[2].name = "border-bottom-right-radius";
1950 g_value_init (¶meter[2].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1951 parameter[3].name = "border-bottom-left-radius";
1952 g_value_init (¶meter[3].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1955 g_value_set_boxed (¶meter[0].value, &border->top_left);
1956 g_value_set_boxed (¶meter[1].value, &border->top_right);
1957 g_value_set_boxed (¶meter[2].value, &border->bottom_right);
1958 g_value_set_boxed (¶meter[3].value, &border->bottom_left);
1966 pack_border_radius (GValue *value,
1967 GtkStyleProperties *props,
1968 GtkStateFlags state,
1969 GtkStylePropertyContext *context)
1971 GtkCssBorderCornerRadius *top_left;
1973 /* NB: We are an int property, so we have to resolve to an int here.
1974 * So we just resolve to an int. We pick one and stick to it.
1975 * Lesson learned: Don't query border-radius shorthand, query the
1976 * real properties instead. */
1977 gtk_style_properties_get (props,
1979 "border-top-left-radius", &top_left,
1983 g_value_set_int (value, top_left->horizontal);
1989 unpack_font_description (const GValue *value,
1992 GParameter *parameter = g_new0 (GParameter, 5);
1993 PangoFontDescription *description;
1997 /* For backwards compat, we only unpack values that are indeed set.
1998 * For strict CSS conformance we need to unpack all of them.
1999 * Note that we do set all of them in the parse function, so it
2000 * will not have effects when parsing CSS files. It will though
2001 * for custom style providers.
2004 description = g_value_get_boxed (value);
2008 mask = pango_font_description_get_set_fields (description);
2012 if (mask & PANGO_FONT_MASK_FAMILY)
2014 GPtrArray *strv = g_ptr_array_new ();
2016 g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
2017 g_ptr_array_add (strv, NULL);
2018 parameter[n].name = "font-family";
2019 g_value_init (¶meter[n].value, G_TYPE_STRV);
2020 g_value_take_boxed (¶meter[n].value,
2021 g_ptr_array_free (strv, FALSE));
2025 if (mask & PANGO_FONT_MASK_STYLE)
2027 parameter[n].name = "font-style";
2028 g_value_init (¶meter[n].value, PANGO_TYPE_STYLE);
2029 g_value_set_enum (¶meter[n].value,
2030 pango_font_description_get_style (description));
2034 if (mask & PANGO_FONT_MASK_VARIANT)
2036 parameter[n].name = "font-variant";
2037 g_value_init (¶meter[n].value, PANGO_TYPE_VARIANT);
2038 g_value_set_enum (¶meter[n].value,
2039 pango_font_description_get_variant (description));
2043 if (mask & PANGO_FONT_MASK_WEIGHT)
2045 parameter[n].name = "font-weight";
2046 g_value_init (¶meter[n].value, PANGO_TYPE_WEIGHT);
2047 g_value_set_enum (¶meter[n].value,
2048 pango_font_description_get_weight (description));
2052 if (mask & PANGO_FONT_MASK_SIZE)
2054 parameter[n].name = "font-size";
2055 g_value_init (¶meter[n].value, G_TYPE_DOUBLE);
2056 g_value_set_double (¶meter[n].value,
2057 (double) pango_font_description_get_size (description) / PANGO_SCALE);
2067 pack_font_description (GValue *value,
2068 GtkStyleProperties *props,
2069 GtkStateFlags state,
2070 GtkStylePropertyContext *context)
2072 PangoFontDescription *description;
2075 PangoVariant variant;
2079 gtk_style_properties_get (props,
2081 "font-family", &families,
2082 "font-style", &style,
2083 "font-variant", &variant,
2084 "font-weight", &weight,
2088 description = pango_font_description_new ();
2089 /* xxx: Can we set all the families here somehow? */
2091 pango_font_description_set_family (description, families[0]);
2092 pango_font_description_set_size (description, round (size * PANGO_SCALE));
2093 pango_font_description_set_style (description, style);
2094 pango_font_description_set_variant (description, variant);
2095 pango_font_description_set_weight (description, weight);
2097 g_strfreev (families);
2099 g_value_take_boxed (value, description);
2103 unpack_border_color (const GValue *value,
2106 GParameter *parameter = g_new0 (GParameter, 4);
2109 type = G_VALUE_TYPE (value);
2110 if (type == G_TYPE_PTR_ARRAY)
2111 type = GTK_TYPE_SYMBOLIC_COLOR;
2113 parameter[0].name = "border-top-color";
2114 g_value_init (¶meter[0].value, type);
2115 parameter[1].name = "border-right-color";
2116 g_value_init (¶meter[1].value, type);
2117 parameter[2].name = "border-bottom-color";
2118 g_value_init (¶meter[2].value, type);
2119 parameter[3].name = "border-left-color";
2120 g_value_init (¶meter[3].value, type);
2122 if (G_VALUE_TYPE (value) == G_TYPE_PTR_ARRAY)
2124 GPtrArray *array = g_value_get_boxed (value);
2127 for (i = 0; i < 4; i++)
2128 g_value_set_boxed (¶meter[i].value, g_ptr_array_index (array, i));
2132 /* can be RGBA or symbolic color */
2133 gpointer p = g_value_get_boxed (value);
2135 g_value_set_boxed (¶meter[0].value, p);
2136 g_value_set_boxed (¶meter[1].value, p);
2137 g_value_set_boxed (¶meter[2].value, p);
2138 g_value_set_boxed (¶meter[3].value, p);
2146 pack_border_color (GValue *value,
2147 GtkStyleProperties *props,
2148 GtkStateFlags state,
2149 GtkStylePropertyContext *context)
2151 /* NB: We are a color property, so we have to resolve to a color here.
2152 * So we just resolve to a color. We pick one and stick to it.
2153 * Lesson learned: Don't query border-color shorthand, query the
2154 * real properties instead. */
2155 g_value_unset (value);
2156 gtk_style_properties_get_property (props, "border-top-color", state, value);
2159 /*** UNSET FUNCS ***/
2162 unset_font_description (GtkStyleProperties *props,
2163 GtkStateFlags state)
2165 gtk_style_properties_unset_property (props, "font-family", state);
2166 gtk_style_properties_unset_property (props, "font-style", state);
2167 gtk_style_properties_unset_property (props, "font-variant", state);
2168 gtk_style_properties_unset_property (props, "font-weight", state);
2169 gtk_style_properties_unset_property (props, "font-size", state);
2173 unset_margin (GtkStyleProperties *props,
2174 GtkStateFlags state)
2176 gtk_style_properties_unset_property (props, "margin-top", state);
2177 gtk_style_properties_unset_property (props, "margin-right", state);
2178 gtk_style_properties_unset_property (props, "margin-bottom", state);
2179 gtk_style_properties_unset_property (props, "margin-left", state);
2183 unset_padding (GtkStyleProperties *props,
2184 GtkStateFlags state)
2186 gtk_style_properties_unset_property (props, "padding-top", state);
2187 gtk_style_properties_unset_property (props, "padding-right", state);
2188 gtk_style_properties_unset_property (props, "padding-bottom", state);
2189 gtk_style_properties_unset_property (props, "padding-left", state);
2193 unset_border_width (GtkStyleProperties *props,
2194 GtkStateFlags state)
2196 gtk_style_properties_unset_property (props, "border-top-width", state);
2197 gtk_style_properties_unset_property (props, "border-right-width", state);
2198 gtk_style_properties_unset_property (props, "border-bottom-width", state);
2199 gtk_style_properties_unset_property (props, "border-left-width", state);
2203 unset_border_radius (GtkStyleProperties *props,
2204 GtkStateFlags state)
2206 gtk_style_properties_unset_property (props, "border-top-right-radius", state);
2207 gtk_style_properties_unset_property (props, "border-bottom-right-radius", state);
2208 gtk_style_properties_unset_property (props, "border-bottom-left-radius", state);
2209 gtk_style_properties_unset_property (props, "border-top-left-radius", state);
2213 unset_border_color (GtkStyleProperties *props,
2214 GtkStateFlags state)
2216 gtk_style_properties_unset_property (props, "border-top-color", state);
2217 gtk_style_properties_unset_property (props, "border-right-color", state);
2218 gtk_style_properties_unset_property (props, "border-bottom-color", state);
2219 gtk_style_properties_unset_property (props, "border-left-color", state);
2223 unset_border_image (GtkStyleProperties *props,
2224 GtkStateFlags state)
2226 gtk_style_properties_unset_property (props, "border-image-source", state);
2227 gtk_style_properties_unset_property (props, "border-image-slice", state);
2228 gtk_style_properties_unset_property (props, "border-image-repeat", state);
2229 gtk_style_properties_unset_property (props, "border-image-width", state);
2235 _gtk_style_property_get_count (void)
2237 return __style_property_array ? __style_property_array->len : 0;
2240 const GtkStyleProperty *
2241 _gtk_style_property_get (guint id)
2243 g_assert (__style_property_array);
2245 return g_ptr_array_index (__style_property_array, id);
2249 _gtk_style_property_generate_id (GtkStyleProperty *node)
2251 if (__style_property_array == NULL)
2252 __style_property_array = g_ptr_array_new ();
2254 node->id = __style_property_array->len;
2255 g_ptr_array_add (__style_property_array, node);
2259 css_string_funcs_init (void)
2261 if (G_LIKELY (parse_funcs != NULL))
2264 parse_funcs = g_hash_table_new (NULL, NULL);
2265 print_funcs = g_hash_table_new (NULL, NULL);
2267 register_conversion_function (GDK_TYPE_RGBA,
2270 register_conversion_function (GDK_TYPE_COLOR,
2273 register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
2274 symbolic_color_value_parse,
2275 symbolic_color_value_print);
2276 register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
2277 font_description_value_parse,
2278 font_description_value_print);
2279 register_conversion_function (G_TYPE_BOOLEAN,
2280 boolean_value_parse,
2281 boolean_value_print);
2282 register_conversion_function (G_TYPE_INT,
2285 register_conversion_function (G_TYPE_UINT,
2288 register_conversion_function (G_TYPE_DOUBLE,
2290 double_value_print);
2291 register_conversion_function (G_TYPE_FLOAT,
2294 register_conversion_function (G_TYPE_STRING,
2296 string_value_print);
2297 register_conversion_function (GTK_TYPE_THEMING_ENGINE,
2298 theming_engine_value_parse,
2299 theming_engine_value_print);
2300 register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
2301 animation_description_value_parse,
2302 animation_description_value_print);
2303 register_conversion_function (GTK_TYPE_BORDER,
2305 border_value_print);
2306 register_conversion_function (GTK_TYPE_GRADIENT,
2307 gradient_value_parse,
2308 gradient_value_print);
2309 register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
2310 pattern_value_parse,
2311 pattern_value_print);
2312 register_conversion_function (GTK_TYPE_BORDER_IMAGE,
2313 border_image_value_parse,
2315 register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
2316 border_image_repeat_value_parse,
2317 border_image_repeat_value_print);
2318 register_conversion_function (GTK_TYPE_SHADOW,
2320 shadow_value_print);
2321 register_conversion_function (G_TYPE_ENUM,
2324 register_conversion_function (G_TYPE_FLAGS,
2327 register_conversion_function (GTK_TYPE_CSS_BACKGROUND_REPEAT,
2328 background_repeat_value_parse,
2329 background_repeat_value_print);
2333 _gtk_style_property_parse_value (const GtkStyleProperty *property,
2335 GtkCssParser *parser,
2338 GtkStyleParseFunc func;
2340 g_return_val_if_fail (value != NULL, FALSE);
2341 g_return_val_if_fail (parser != NULL, FALSE);
2343 css_string_funcs_init ();
2347 if (_gtk_css_parser_try (parser, "initial", TRUE))
2349 /* the initial value can be explicitly specified with the
2350 * ‘initial’ keyword which all properties accept.
2352 g_value_unset (value);
2353 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
2354 g_value_set_enum (value, GTK_CSS_INITIAL);
2357 else if (_gtk_css_parser_try (parser, "inherit", TRUE))
2359 /* All properties accept the ‘inherit’ value which
2360 * explicitly specifies that the value will be determined
2361 * by inheritance. The ‘inherit’ value can be used to
2362 * strengthen inherited values in the cascade, and it can
2363 * also be used on properties that are not normally inherited.
2365 g_value_unset (value);
2366 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
2367 g_value_set_enum (value, GTK_CSS_INHERIT);
2370 else if (property->property_parse_func)
2372 GError *error = NULL;
2376 value_str = _gtk_css_parser_read_value (parser);
2377 if (value_str == NULL)
2380 success = (*property->property_parse_func) (value_str, value, &error);
2387 func = property->parse_func;
2393 func = g_hash_table_lookup (parse_funcs,
2394 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
2396 func = g_hash_table_lookup (parse_funcs,
2397 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
2401 _gtk_css_parser_error (parser,
2402 "Cannot convert to type '%s'",
2403 g_type_name (G_VALUE_TYPE (value)));
2407 return (*func) (parser, base, value);
2411 _gtk_style_property_print_value (const GtkStyleProperty *property,
2412 const GValue *value,
2415 GtkStylePrintFunc func;
2417 css_string_funcs_init ();
2419 if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
2420 func = enum_value_print;
2422 func = property->print_func;
2427 func = g_hash_table_lookup (print_funcs,
2428 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
2430 func = g_hash_table_lookup (print_funcs,
2431 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
2435 char *s = g_strdup_value_contents (value);
2436 g_string_append (string, s);
2441 func (value, string);
2445 _gtk_style_property_default_value (const GtkStyleProperty *property,
2446 GtkStyleProperties *properties,
2447 GtkStateFlags state,
2450 g_value_copy (&property->initial_value, value);
2454 _gtk_style_property_is_inherit (const GtkStyleProperty *property)
2456 g_return_val_if_fail (property != NULL, FALSE);
2458 return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
2462 _gtk_style_property_get_id (const GtkStyleProperty *property)
2464 g_return_val_if_fail (property != NULL, FALSE);
2466 return property->id;
2470 resolve_color (GtkStyleProperties *props,
2475 /* Resolve symbolic color to GdkRGBA */
2476 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
2479 /* Store it back, this is where GdkRGBA caching happens */
2480 g_value_unset (value);
2481 g_value_init (value, GDK_TYPE_RGBA);
2482 g_value_set_boxed (value, &color);
2488 resolve_color_rgb (GtkStyleProperties *props,
2491 GdkColor color = { 0 };
2494 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
2497 color.red = rgba.red * 65535. + 0.5;
2498 color.green = rgba.green * 65535. + 0.5;
2499 color.blue = rgba.blue * 65535. + 0.5;
2501 g_value_unset (value);
2502 g_value_init (value, GDK_TYPE_COLOR);
2503 g_value_set_boxed (value, &color);
2509 resolve_win32_theme_part (GtkStyleProperties *props,
2512 GtkStylePropertyContext *context)
2514 GtkWin32ThemePart *part;
2515 cairo_pattern_t *pattern;
2517 part = g_value_get_boxed (value);
2521 pattern = _gtk_win32_theme_part_render (part, context->width, context->height);
2523 g_value_take_boxed (value_out, pattern);
2530 resolve_gradient (GtkStyleProperties *props,
2533 cairo_pattern_t *gradient;
2535 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
2538 /* Store it back, this is where cairo_pattern_t caching happens */
2539 g_value_unset (value);
2540 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
2541 g_value_take_boxed (value, gradient);
2547 resolve_shadow (GtkStyleProperties *props,
2550 GtkShadow *resolved, *base;
2552 base = g_value_get_boxed (value);
2557 if (_gtk_shadow_get_resolved (base))
2560 resolved = _gtk_shadow_resolve (base, props);
2561 if (resolved == NULL)
2564 g_value_take_boxed (value, resolved);
2570 _gtk_style_property_resolve (const GtkStyleProperty *property,
2571 GtkStyleProperties *props,
2572 GtkStateFlags state,
2573 GtkStylePropertyContext *context,
2577 if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_SPECIAL_VALUE)
2579 GtkCssSpecialValue special = g_value_get_enum (val);
2581 g_value_unset (val);
2584 case GTK_CSS_CURRENT_COLOR:
2585 g_assert (property->pspec->value_type == GDK_TYPE_RGBA);
2586 gtk_style_properties_get_property (props, "color", state, val);
2588 case GTK_CSS_INHERIT:
2589 case GTK_CSS_INITIAL:
2591 g_assert_not_reached ();
2594 else if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
2596 if (property->pspec->value_type == GDK_TYPE_RGBA)
2598 if (resolve_color (props, val))
2601 else if (property->pspec->value_type == GDK_TYPE_COLOR)
2603 if (resolve_color_rgb (props, val))
2607 g_value_unset (val);
2608 g_value_init (val, property->pspec->value_type);
2609 _gtk_style_property_default_value (property, props, state, val);
2611 else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
2613 if (g_value_get_boxed (val) == NULL)
2614 _gtk_style_property_default_value (property, props, state, val);
2616 else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
2618 g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
2620 if (!resolve_gradient (props, val))
2622 g_value_unset (val);
2623 g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
2624 _gtk_style_property_default_value (property, props, state, val);
2627 else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
2629 if (!resolve_shadow (props, val))
2630 _gtk_style_property_default_value (property, props, state, val);
2632 else if (G_VALUE_TYPE (val) == GTK_TYPE_WIN32_THEME_PART)
2634 if (resolve_win32_theme_part (props, val, val_out, context))
2635 return; /* Don't copy val, this sets val_out */
2636 _gtk_style_property_default_value (property, props, state, val);
2640 g_value_copy (val, val_out);
2644 _gtk_style_property_get_initial_value (const GtkStyleProperty *property)
2646 g_return_val_if_fail (property != NULL, NULL);
2648 return &property->initial_value;
2652 _gtk_style_property_is_shorthand (const GtkStyleProperty *property)
2654 g_return_val_if_fail (property != NULL, FALSE);
2656 return property->pack_func != NULL;
2660 _gtk_style_property_unpack (const GtkStyleProperty *property,
2661 const GValue *value,
2664 g_return_val_if_fail (property != NULL, NULL);
2665 g_return_val_if_fail (property->unpack_func != NULL, NULL);
2666 g_return_val_if_fail (value != NULL, NULL);
2667 g_return_val_if_fail (n_params != NULL, NULL);
2669 return property->unpack_func (value, n_params);
2673 _gtk_style_property_pack (const GtkStyleProperty *property,
2674 GtkStyleProperties *props,
2675 GtkStateFlags state,
2676 GtkStylePropertyContext *context,
2679 g_return_if_fail (property != NULL);
2680 g_return_if_fail (property->pack_func != NULL);
2681 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2682 g_return_if_fail (G_IS_VALUE (value));
2684 property->pack_func (value, props, state, context);
2688 _gtk_style_property_query (const GtkStyleProperty *property,
2689 GtkStyleProperties *props,
2690 GtkStateFlags state,
2691 GtkStylePropertyContext *context,
2696 g_return_if_fail (property != NULL);
2697 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2698 g_return_if_fail (context != NULL);
2699 g_return_if_fail (value != NULL);
2701 val = _gtk_style_properties_peek_property (props, property, state);
2702 g_value_init (value, property->pspec->value_type);
2705 _gtk_style_property_resolve (property, props, state, context, (GValue *) val, value);
2706 else if (_gtk_style_property_is_shorthand (property))
2707 _gtk_style_property_pack (property, props, state, context, value);
2709 _gtk_style_property_default_value (property, props, state, value);
2712 #define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
2713 (rgba)->red = (r); \
2714 (rgba)->green = (g); \
2715 (rgba)->blue = (b); \
2716 (rgba)->alpha = (a); \
2719 gtk_style_property_init (void)
2721 GValue value = { 0, };
2722 char *default_font_family[] = { "Sans", NULL };
2725 if (G_LIKELY (properties))
2728 /* stuff is never freed, so no need for free functions */
2729 properties = g_hash_table_new (g_str_hash, g_str_equal);
2731 /* note that gtk_style_properties_register_property() calls this function,
2732 * so make sure we're sanely inited to avoid infloops */
2734 g_value_init (&value, GDK_TYPE_RGBA);
2735 rgba_init (&rgba, 1, 1, 1, 1);
2736 g_value_set_boxed (&value, &rgba);
2737 _gtk_style_property_register (g_param_spec_boxed ("color",
2741 GTK_STYLE_PROPERTY_INHERIT,
2749 rgba_init (&rgba, 0, 0, 0, 0);
2750 g_value_set_boxed (&value, &rgba);
2751 _gtk_style_property_register (g_param_spec_boxed ("background-color",
2759 transparent_color_value_parse,
2763 g_value_unset (&value);
2765 g_value_init (&value, G_TYPE_STRV);
2766 g_value_set_boxed (&value, default_font_family);
2767 _gtk_style_property_register (g_param_spec_boxed ("font-family",
2771 GTK_STYLE_PROPERTY_INHERIT,
2776 font_family_value_print,
2779 g_value_unset (&value);
2780 _gtk_style_property_register (g_param_spec_enum ("font-style",
2784 PANGO_STYLE_NORMAL, 0),
2785 GTK_STYLE_PROPERTY_INHERIT,
2793 _gtk_style_property_register (g_param_spec_enum ("font-variant",
2797 PANGO_VARIANT_NORMAL, 0),
2798 GTK_STYLE_PROPERTY_INHERIT,
2806 /* xxx: need to parse this properly, ie parse the numbers */
2807 _gtk_style_property_register (g_param_spec_enum ("font-weight",
2811 PANGO_WEIGHT_NORMAL, 0),
2812 GTK_STYLE_PROPERTY_INHERIT,
2820 g_value_init (&value, G_TYPE_DOUBLE);
2821 g_value_set_double (&value, 10);
2822 _gtk_style_property_register (g_param_spec_double ("font-size",
2825 0, G_MAXDOUBLE, 0, 0),
2826 GTK_STYLE_PROPERTY_INHERIT,
2834 g_value_unset (&value);
2835 _gtk_style_property_register (g_param_spec_boxed ("font",
2838 PANGO_TYPE_FONT_DESCRIPTION, 0),
2839 GTK_STYLE_PROPERTY_INHERIT,
2841 unpack_font_description,
2842 pack_font_description,
2843 font_description_value_parse,
2844 font_description_value_print,
2846 unset_font_description);
2848 _gtk_style_property_register (g_param_spec_boxed ("text-shadow",
2851 GTK_TYPE_SHADOW, 0),
2852 GTK_STYLE_PROPERTY_INHERIT,
2861 _gtk_style_property_register (g_param_spec_boxed ("icon-shadow",
2864 GTK_TYPE_SHADOW, 0),
2865 GTK_STYLE_PROPERTY_INHERIT,
2874 gtk_style_properties_register_property (NULL,
2875 g_param_spec_boxed ("box-shadow",
2878 GTK_TYPE_SHADOW, 0));
2879 gtk_style_properties_register_property (NULL,
2880 g_param_spec_int ("margin-top",
2883 0, G_MAXINT, 0, 0));
2884 gtk_style_properties_register_property (NULL,
2885 g_param_spec_int ("margin-left",
2888 0, G_MAXINT, 0, 0));
2889 gtk_style_properties_register_property (NULL,
2890 g_param_spec_int ("margin-bottom",
2893 0, G_MAXINT, 0, 0));
2894 gtk_style_properties_register_property (NULL,
2895 g_param_spec_int ("margin-right",
2898 0, G_MAXINT, 0, 0));
2899 _gtk_style_property_register (g_param_spec_boxed ("margin",
2902 GTK_TYPE_BORDER, 0),
2911 gtk_style_properties_register_property (NULL,
2912 g_param_spec_int ("padding-top",
2915 0, G_MAXINT, 0, 0));
2916 gtk_style_properties_register_property (NULL,
2917 g_param_spec_int ("padding-left",
2920 0, G_MAXINT, 0, 0));
2921 gtk_style_properties_register_property (NULL,
2922 g_param_spec_int ("padding-bottom",
2924 "Padding at bottom",
2925 0, G_MAXINT, 0, 0));
2926 gtk_style_properties_register_property (NULL,
2927 g_param_spec_int ("padding-right",
2930 0, G_MAXINT, 0, 0));
2931 _gtk_style_property_register (g_param_spec_boxed ("padding",
2934 GTK_TYPE_BORDER, 0),
2943 gtk_style_properties_register_property (NULL,
2944 g_param_spec_int ("border-top-width",
2946 "Border width at top",
2947 0, G_MAXINT, 0, 0));
2948 gtk_style_properties_register_property (NULL,
2949 g_param_spec_int ("border-left-width",
2950 "border left width",
2951 "Border width at left",
2952 0, G_MAXINT, 0, 0));
2953 gtk_style_properties_register_property (NULL,
2954 g_param_spec_int ("border-bottom-width",
2955 "border bottom width",
2956 "Border width at bottom",
2957 0, G_MAXINT, 0, 0));
2958 gtk_style_properties_register_property (NULL,
2959 g_param_spec_int ("border-right-width",
2960 "border right width",
2961 "Border width at right",
2962 0, G_MAXINT, 0, 0));
2963 _gtk_style_property_register (g_param_spec_boxed ("border-width",
2965 "Border width, in pixels",
2966 GTK_TYPE_BORDER, 0),
2969 unpack_border_width,
2974 unset_border_width);
2976 _gtk_style_property_register (g_param_spec_boxed ("border-top-left-radius",
2977 "Border top left radius",
2978 "Border radius of top left corner, in pixels",
2979 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2984 border_corner_radius_value_parse,
2985 border_corner_radius_value_print,
2988 _gtk_style_property_register (g_param_spec_boxed ("border-top-right-radius",
2989 "Border top right radius",
2990 "Border radius of top right corner, in pixels",
2991 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2996 border_corner_radius_value_parse,
2997 border_corner_radius_value_print,
3000 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-right-radius",
3001 "Border bottom right radius",
3002 "Border radius of bottom right corner, in pixels",
3003 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
3008 border_corner_radius_value_parse,
3009 border_corner_radius_value_print,
3012 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-left-radius",
3013 "Border bottom left radius",
3014 "Border radius of bottom left corner, in pixels",
3015 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
3020 border_corner_radius_value_parse,
3021 border_corner_radius_value_print,
3024 _gtk_style_property_register (g_param_spec_int ("border-radius",
3026 "Border radius, in pixels",
3030 unpack_border_radius,
3032 border_radius_value_parse,
3033 border_radius_value_print,
3035 unset_border_radius);
3037 gtk_style_properties_register_property (NULL,
3038 g_param_spec_enum ("border-style",
3041 GTK_TYPE_BORDER_STYLE,
3042 GTK_BORDER_STYLE_NONE, 0));
3043 gtk_style_properties_register_property (NULL,
3044 g_param_spec_enum ("background-clip",
3048 GTK_CSS_AREA_BORDER_BOX, 0));
3049 gtk_style_properties_register_property (NULL,
3050 g_param_spec_enum ("background-origin",
3051 "Background origin",
3052 "Background origin",
3054 GTK_CSS_AREA_PADDING_BOX, 0));
3055 g_value_init (&value, GTK_TYPE_CSS_SPECIAL_VALUE);
3056 g_value_set_enum (&value, GTK_CSS_CURRENT_COLOR);
3057 _gtk_style_property_register (g_param_spec_boxed ("border-top-color",
3065 transparent_color_value_parse,
3069 _gtk_style_property_register (g_param_spec_boxed ("border-right-color",
3070 "Border right color",
3071 "Border right color",
3077 transparent_color_value_parse,
3081 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-color",
3082 "Border bottom color",
3083 "Border bottom color",
3089 transparent_color_value_parse,
3093 _gtk_style_property_register (g_param_spec_boxed ("border-left-color",
3094 "Border left color",
3095 "Border left color",
3101 transparent_color_value_parse,
3105 g_value_unset (&value);
3106 _gtk_style_property_register (g_param_spec_boxed ("border-color",
3112 unpack_border_color,
3114 border_color_shorthand_value_parse,
3117 unset_border_color);
3119 gtk_style_properties_register_property (NULL,
3120 g_param_spec_boxed ("background-image",
3123 CAIRO_GOBJECT_TYPE_PATTERN, 0));
3124 gtk_style_properties_register_property (NULL,
3125 g_param_spec_boxed ("background-repeat",
3126 "Background repeat",
3127 "Background repeat",
3128 GTK_TYPE_CSS_BACKGROUND_REPEAT, 0));
3130 gtk_style_properties_register_property (NULL,
3131 g_param_spec_boxed ("border-image-source",
3132 "Border image source",
3133 "Border image source",
3134 CAIRO_GOBJECT_TYPE_PATTERN, 0));
3135 gtk_style_properties_register_property (NULL,
3136 g_param_spec_boxed ("border-image-repeat",
3137 "Border image repeat",
3138 "Border image repeat",
3139 GTK_TYPE_CSS_BORDER_IMAGE_REPEAT, 0));
3140 gtk_style_properties_register_property (NULL,
3141 g_param_spec_boxed ("border-image-slice",
3142 "Border image slice",
3143 "Border image slice",
3144 GTK_TYPE_BORDER, 0));
3145 g_value_init (&value, GTK_TYPE_BORDER);
3146 _gtk_style_property_register (g_param_spec_boxed ("border-image-width",
3147 "Border image width",
3148 "Border image width",
3149 GTK_TYPE_BORDER, 0),
3158 g_value_unset (&value);
3159 _gtk_style_property_register (g_param_spec_boxed ("border-image",
3162 GTK_TYPE_BORDER_IMAGE, 0),
3165 _gtk_border_image_unpack,
3166 _gtk_border_image_pack,
3170 unset_border_image);
3171 gtk_style_properties_register_property (NULL,
3172 g_param_spec_object ("engine",
3175 GTK_TYPE_THEMING_ENGINE, 0));
3176 gtk_style_properties_register_property (NULL,
3177 g_param_spec_boxed ("transition",
3178 "Transition animation description",
3179 "Transition animation description",
3180 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
3182 /* Private property holding the binding sets */
3183 _gtk_style_property_register (g_param_spec_boxed ("gtk-key-bindings",
3186 G_TYPE_PTR_ARRAY, 0),
3191 bindings_value_parse,
3192 bindings_value_print,
3197 const GtkStyleProperty *
3198 _gtk_style_property_lookup (const char *name)
3200 gtk_style_property_init ();
3202 return g_hash_table_lookup (properties, name);
3206 _gtk_style_property_register (GParamSpec *pspec,
3207 GtkStylePropertyFlags flags,
3208 GtkStylePropertyParser property_parse_func,
3209 GtkStyleUnpackFunc unpack_func,
3210 GtkStylePackFunc pack_func,
3211 GtkStyleParseFunc parse_func,
3212 GtkStylePrintFunc print_func,
3213 const GValue * initial_value,
3214 GtkStyleUnsetFunc unset_func)
3216 const GtkStyleProperty *existing;
3217 GtkStyleProperty *node;
3219 g_return_if_fail ((pack_func == NULL) == (unpack_func == NULL));
3221 gtk_style_property_init ();
3223 existing = _gtk_style_property_lookup (pspec->name);
3224 if (existing != NULL)
3226 g_warning ("Property \"%s\" was already registered with type %s",
3227 pspec->name, g_type_name (existing->pspec->value_type));
3231 node = g_slice_new0 (GtkStyleProperty);
3232 node->flags = flags;
3233 node->pspec = pspec;
3234 node->property_parse_func = property_parse_func;
3235 node->pack_func = pack_func;
3236 node->unpack_func = unpack_func;
3237 node->parse_func = parse_func;
3238 node->print_func = print_func;
3239 node->unset_func = unset_func;
3241 if (!_gtk_style_property_is_shorthand (node))
3243 _gtk_style_property_generate_id (node);
3245 /* initialize the initial value */
3248 g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value));
3249 g_value_copy (initial_value, &node->initial_value);
3253 g_value_init (&node->initial_value, pspec->value_type);
3254 if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
3255 g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
3256 else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
3257 g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10"));
3258 else if (pspec->value_type == GDK_TYPE_RGBA)
3261 gdk_rgba_parse (&color, "pink");
3262 g_value_set_boxed (&node->initial_value, &color);
3264 else if (pspec->value_type == GTK_TYPE_BORDER)
3266 g_value_take_boxed (&node->initial_value, gtk_border_new ());
3269 g_param_value_set_default (pspec, &node->initial_value);
3273 /* pspec owns name */
3274 g_hash_table_insert (properties, (gchar *)pspec->name, node);