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"
28 #include <gdk-pixbuf/gdk-pixbuf.h>
29 #include <cairo-gobject.h>
31 #include "gtkcssprovider.h"
32 #include "gtkcssparserprivate.h"
33 #include "gtkcsstypesprivate.h"
35 /* the actual parsers we have */
36 #include "gtkanimationdescription.h"
37 #include "gtkbindings.h"
38 #include "gtkborderimageprivate.h"
39 #include "gtkgradient.h"
40 #include "gtkshadowprivate.h"
41 #include "gtkthemingengine.h"
42 #include "gtktypebuiltins.h"
44 static GHashTable *parse_funcs = NULL;
45 static GHashTable *print_funcs = NULL;
46 static GHashTable *properties = NULL;
49 register_conversion_function (GType type,
50 GtkStyleParseFunc parse,
51 GtkStylePrintFunc print)
54 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
56 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
60 string_append_double (GString *string,
63 char buf[G_ASCII_DTOSTR_BUF_SIZE];
65 g_ascii_dtostr (buf, sizeof (buf), d);
66 g_string_append (string, buf);
70 string_append_string (GString *str,
75 g_string_append_c (str, '"');
78 len = strcspn (string, "\"\n\r\f");
79 g_string_append (str, string);
86 g_string_append (str, "\\A ");
89 g_string_append (str, "\\D ");
92 g_string_append (str, "\\C ");
95 g_string_append (str, "\\\"");
98 g_assert_not_reached ();
103 g_string_append_c (str, '"');
106 /*** IMPLEMENTATIONS ***/
109 rgba_value_parse (GtkCssParser *parser,
113 GtkSymbolicColor *symbolic;
116 symbolic = _gtk_css_parser_read_symbolic_color (parser);
117 if (symbolic == NULL)
120 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
122 g_value_set_boxed (value, &rgba);
123 gtk_symbolic_color_unref (symbolic);
127 g_value_unset (value);
128 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
129 g_value_take_boxed (value, symbolic);
136 rgba_value_print (const GValue *value,
139 const GdkRGBA *rgba = g_value_get_boxed (value);
142 g_string_append (string, "none");
145 char *s = gdk_rgba_to_string (rgba);
146 g_string_append (string, s);
152 color_value_parse (GtkCssParser *parser,
156 GtkSymbolicColor *symbolic;
159 symbolic = _gtk_css_parser_read_symbolic_color (parser);
160 if (symbolic == NULL)
163 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
167 color.red = rgba.red * 65535. + 0.5;
168 color.green = rgba.green * 65535. + 0.5;
169 color.blue = rgba.blue * 65535. + 0.5;
171 g_value_set_boxed (value, &color);
175 g_value_unset (value);
176 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
177 g_value_take_boxed (value, symbolic);
184 color_value_print (const GValue *value,
187 const GdkColor *color = g_value_get_boxed (value);
190 g_string_append (string, "none");
193 char *s = gdk_color_to_string (color);
194 g_string_append (string, s);
200 symbolic_color_value_parse (GtkCssParser *parser,
204 GtkSymbolicColor *symbolic;
206 symbolic = _gtk_css_parser_read_symbolic_color (parser);
207 if (symbolic == NULL)
210 g_value_take_boxed (value, symbolic);
215 symbolic_color_value_print (const GValue *value,
218 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
220 if (symbolic == NULL)
221 g_string_append (string, "none");
224 char *s = gtk_symbolic_color_to_string (symbolic);
225 g_string_append (string, s);
231 font_description_value_parse (GtkCssParser *parser,
235 PangoFontDescription *font_desc;
238 str = _gtk_css_parser_read_value (parser);
242 font_desc = pango_font_description_from_string (str);
244 g_value_take_boxed (value, font_desc);
249 font_description_value_print (const GValue *value,
252 const PangoFontDescription *desc = g_value_get_boxed (value);
255 g_string_append (string, "none");
258 char *s = pango_font_description_to_string (desc);
259 g_string_append (string, s);
265 boolean_value_parse (GtkCssParser *parser,
269 if (_gtk_css_parser_try (parser, "true", TRUE) ||
270 _gtk_css_parser_try (parser, "1", TRUE))
272 g_value_set_boolean (value, TRUE);
275 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
276 _gtk_css_parser_try (parser, "0", TRUE))
278 g_value_set_boolean (value, FALSE);
283 _gtk_css_parser_error (parser, "Expected a boolean value");
289 boolean_value_print (const GValue *value,
292 if (g_value_get_boolean (value))
293 g_string_append (string, "true");
295 g_string_append (string, "false");
299 int_value_parse (GtkCssParser *parser,
305 if (!_gtk_css_parser_try_int (parser, &i))
307 _gtk_css_parser_error (parser, "Expected a valid integer value");
311 g_value_set_int (value, i);
316 int_value_print (const GValue *value,
319 g_string_append_printf (string, "%d", g_value_get_int (value));
323 uint_value_parse (GtkCssParser *parser,
329 if (!_gtk_css_parser_try_uint (parser, &u))
331 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
335 g_value_set_uint (value, u);
340 uint_value_print (const GValue *value,
343 g_string_append_printf (string, "%u", g_value_get_uint (value));
347 double_value_parse (GtkCssParser *parser,
353 if (!_gtk_css_parser_try_double (parser, &d))
355 _gtk_css_parser_error (parser, "Expected a number");
359 g_value_set_double (value, d);
364 double_value_print (const GValue *value,
367 string_append_double (string, g_value_get_double (value));
371 float_value_parse (GtkCssParser *parser,
377 if (!_gtk_css_parser_try_double (parser, &d))
379 _gtk_css_parser_error (parser, "Expected a number");
383 g_value_set_float (value, d);
388 float_value_print (const GValue *value,
391 string_append_double (string, g_value_get_float (value));
395 string_value_parse (GtkCssParser *parser,
399 char *str = _gtk_css_parser_read_string (parser);
404 g_value_take_string (value, str);
409 string_value_print (const GValue *value,
412 string_append_string (str, g_value_get_string (value));
416 theming_engine_value_parse (GtkCssParser *parser,
420 GtkThemingEngine *engine;
423 str = _gtk_css_parser_try_ident (parser, TRUE);
426 _gtk_css_parser_error (parser, "Expected a valid theme name");
430 engine = gtk_theming_engine_load (str);
433 _gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
438 g_value_set_object (value, engine);
444 theming_engine_value_print (const GValue *value,
447 GtkThemingEngine *engine;
450 engine = g_value_get_object (value);
452 g_string_append (string, "none");
455 /* XXX: gtk_theming_engine_get_name()? */
456 g_object_get (engine, "name", &name, NULL);
457 g_string_append (string, name);
463 animation_description_value_parse (GtkCssParser *parser,
467 GtkAnimationDescription *desc;
470 str = _gtk_css_parser_read_value (parser);
474 desc = _gtk_animation_description_from_string (str);
479 _gtk_css_parser_error (parser, "Invalid animation description");
483 g_value_take_boxed (value, desc);
488 animation_description_value_print (const GValue *value,
491 GtkAnimationDescription *desc = g_value_get_boxed (value);
494 g_string_append (string, "none");
496 _gtk_animation_description_print (desc, string);
500 border_value_parse (GtkCssParser *parser,
504 GtkBorder border = { 0, };
507 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
509 if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
512 /* XXX: shouldn't allow spaces here? */
513 _gtk_css_parser_try (parser, "px", TRUE);
518 _gtk_css_parser_error (parser, "Expected valid border");
522 border.top = numbers[0];
524 border.right = numbers[1];
526 border.right = border.top;
528 border.bottom = numbers[2];
530 border.bottom = border.top;
532 border.left = numbers[3];
534 border.left = border.right;
536 g_value_set_boxed (value, &border);
541 border_value_print (const GValue *value, GString *string)
543 const GtkBorder *border = g_value_get_boxed (value);
546 g_string_append (string, "none");
547 else if (border->left != border->right)
548 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
549 else if (border->top != border->bottom)
550 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
551 else if (border->top != border->left)
552 g_string_append_printf (string, "%d %d", border->top, border->right);
554 g_string_append_printf (string, "%d", border->top);
558 gradient_value_parse (GtkCssParser *parser,
562 GtkGradient *gradient;
563 cairo_pattern_type_t type;
567 if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
569 _gtk_css_parser_error (parser,
570 "Expected '-gtk-gradient'");
574 if (!_gtk_css_parser_try (parser, "(", TRUE))
576 _gtk_css_parser_error (parser,
577 "Expected '(' after '-gtk-gradient'");
581 /* Parse gradient type */
582 if (_gtk_css_parser_try (parser, "linear", TRUE))
583 type = CAIRO_PATTERN_TYPE_LINEAR;
584 else if (_gtk_css_parser_try (parser, "radial", TRUE))
585 type = CAIRO_PATTERN_TYPE_RADIAL;
588 _gtk_css_parser_error (parser,
589 "Gradient type must be 'radial' or 'linear'");
593 /* Parse start/stop position parameters */
594 for (i = 0; i < 2; i++)
596 if (! _gtk_css_parser_try (parser, ",", TRUE))
598 _gtk_css_parser_error (parser,
603 if (_gtk_css_parser_try (parser, "left", TRUE))
605 else if (_gtk_css_parser_try (parser, "right", TRUE))
607 else if (_gtk_css_parser_try (parser, "center", TRUE))
609 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
611 _gtk_css_parser_error (parser,
612 "Expected a valid X coordinate");
616 if (_gtk_css_parser_try (parser, "top", TRUE))
617 coords[i * 3 + 1] = 0;
618 else if (_gtk_css_parser_try (parser, "bottom", TRUE))
619 coords[i * 3 + 1] = 1;
620 else if (_gtk_css_parser_try (parser, "center", TRUE))
621 coords[i * 3 + 1] = 0.5;
622 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
624 _gtk_css_parser_error (parser,
625 "Expected a valid Y coordinate");
629 if (type == CAIRO_PATTERN_TYPE_RADIAL)
632 if (! _gtk_css_parser_try (parser, ",", TRUE))
634 _gtk_css_parser_error (parser,
639 if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
641 _gtk_css_parser_error (parser,
642 "Expected a numer for the radius");
648 if (type == CAIRO_PATTERN_TYPE_LINEAR)
649 gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
651 gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
652 coords[3], coords[4], coords[5]);
654 while (_gtk_css_parser_try (parser, ",", TRUE))
656 GtkSymbolicColor *color;
659 if (_gtk_css_parser_try (parser, "from", TRUE))
663 if (!_gtk_css_parser_try (parser, "(", TRUE))
665 gtk_gradient_unref (gradient);
666 _gtk_css_parser_error (parser,
672 else if (_gtk_css_parser_try (parser, "to", TRUE))
676 if (!_gtk_css_parser_try (parser, "(", TRUE))
678 gtk_gradient_unref (gradient);
679 _gtk_css_parser_error (parser,
685 else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
687 if (!_gtk_css_parser_try (parser, "(", TRUE))
689 gtk_gradient_unref (gradient);
690 _gtk_css_parser_error (parser,
695 if (!_gtk_css_parser_try_double (parser, &position))
697 gtk_gradient_unref (gradient);
698 _gtk_css_parser_error (parser,
699 "Expected a valid number");
703 if (!_gtk_css_parser_try (parser, ",", TRUE))
705 gtk_gradient_unref (gradient);
706 _gtk_css_parser_error (parser,
713 gtk_gradient_unref (gradient);
714 _gtk_css_parser_error (parser,
715 "Not a valid color-stop definition");
719 color = _gtk_css_parser_read_symbolic_color (parser);
722 gtk_gradient_unref (gradient);
726 gtk_gradient_add_color_stop (gradient, position, color);
727 gtk_symbolic_color_unref (color);
729 if (!_gtk_css_parser_try (parser, ")", TRUE))
731 gtk_gradient_unref (gradient);
732 _gtk_css_parser_error (parser,
738 if (!_gtk_css_parser_try (parser, ")", TRUE))
740 gtk_gradient_unref (gradient);
741 _gtk_css_parser_error (parser,
746 g_value_take_boxed (value, gradient);
751 gradient_value_print (const GValue *value,
754 GtkGradient *gradient = g_value_get_boxed (value);
756 if (gradient == NULL)
757 g_string_append (string, "none");
760 char *s = gtk_gradient_to_string (gradient);
761 g_string_append (string, s);
767 gtk_css_parse_url (GtkCssParser *parser,
773 if (_gtk_css_parser_try (parser, "url", FALSE))
775 if (!_gtk_css_parser_try (parser, "(", TRUE))
777 _gtk_css_parser_skip_whitespace (parser);
778 if (_gtk_css_parser_try (parser, "(", TRUE))
782 error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
783 GTK_CSS_PROVIDER_ERROR_DEPRECATED,
784 "Whitespace between 'url' and '(' is not allowed");
786 _gtk_css_parser_take_error (parser, error);
790 _gtk_css_parser_error (parser, "Expected '(' after 'url'");
795 path = _gtk_css_parser_read_string (parser);
799 if (!_gtk_css_parser_try (parser, ")", TRUE))
801 _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
808 path = _gtk_css_parser_try_name (parser, TRUE);
811 _gtk_css_parser_error (parser, "Not a valid url");
816 file = g_file_resolve_relative_path (base, path);
823 pattern_value_parse (GtkCssParser *parser,
827 if (_gtk_css_parser_begins_with (parser, '-'))
829 g_value_unset (value);
830 g_value_init (value, GTK_TYPE_GRADIENT);
831 return gradient_value_parse (parser, base, value);
835 GError *error = NULL;
839 cairo_surface_t *surface;
840 cairo_pattern_t *pattern;
842 cairo_matrix_t matrix;
844 file = gtk_css_parse_url (parser, base);
848 path = g_file_get_path (file);
849 g_object_unref (file);
851 pixbuf = gdk_pixbuf_new_from_file (path, &error);
855 _gtk_css_parser_take_error (parser, error);
859 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
860 gdk_pixbuf_get_width (pixbuf),
861 gdk_pixbuf_get_height (pixbuf));
862 cr = cairo_create (surface);
863 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
865 pattern = cairo_pattern_create_for_surface (surface);
867 cairo_matrix_init_scale (&matrix,
868 gdk_pixbuf_get_width (pixbuf),
869 gdk_pixbuf_get_height (pixbuf));
870 cairo_pattern_set_matrix (pattern, &matrix);
872 cairo_surface_destroy (surface);
874 g_object_unref (pixbuf);
876 g_value_take_boxed (value, pattern);
883 shadow_value_parse (GtkCssParser *parser,
888 gdouble hoffset, voffset, blur, spread;
889 GtkSymbolicColor *color;
892 shadow = _gtk_shadow_new ();
896 inset = _gtk_css_parser_try (parser, "inset", TRUE);
898 if (!_gtk_css_parser_try_double (parser, &hoffset) ||
899 !_gtk_css_parser_try_double (parser, &voffset))
901 _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
902 _gtk_shadow_unref (shadow);
906 if (!_gtk_css_parser_try_double (parser, &blur))
909 if (!_gtk_css_parser_try_double (parser, &spread))
912 /* XXX: the color is optional and UA-defined if it's missing,
913 * but it doesn't really make sense for us...
915 color = _gtk_css_parser_read_symbolic_color (parser);
919 _gtk_shadow_unref (shadow);
923 _gtk_shadow_append (shadow,
928 gtk_symbolic_color_unref (color);
931 while (_gtk_css_parser_try (parser, ",", TRUE));
933 g_value_take_boxed (value, shadow);
938 shadow_value_print (const GValue *value,
943 shadow = g_value_get_boxed (value);
946 g_string_append (string, "none");
948 _gtk_shadow_print (shadow, string);
952 border_image_repeat_value_parse (GtkCssParser *parser,
956 GtkCssBorderImageRepeat image_repeat;
957 GtkCssRepeatStyle styles[2];
960 for (i = 0; i < 2; i++)
962 if (_gtk_css_parser_try (parser, "stretch", TRUE))
963 styles[i] = GTK_CSS_REPEAT_STYLE_NONE;
964 else if (_gtk_css_parser_try (parser, "repeat", TRUE))
965 styles[i] = GTK_CSS_REPEAT_STYLE_REPEAT;
966 else if (_gtk_css_parser_try (parser, "round", TRUE))
967 styles[i] = GTK_CSS_REPEAT_STYLE_ROUND;
968 else if (_gtk_css_parser_try (parser, "space", TRUE))
969 styles[i] = GTK_CSS_REPEAT_STYLE_SPACE;
972 styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_NONE;
976 styles[i] = styles[0];
979 image_repeat.hrepeat = styles[0];
980 image_repeat.vrepeat = styles[1];
982 g_value_set_boxed (value, &image_repeat);
988 border_image_repeat_style_to_string (GtkCssRepeatStyle repeat)
992 case GTK_CSS_REPEAT_STYLE_NONE:
994 case GTK_CSS_REPEAT_STYLE_REPEAT:
996 case GTK_CSS_REPEAT_STYLE_ROUND:
998 case GTK_CSS_REPEAT_STYLE_SPACE:
1006 border_image_repeat_value_print (const GValue *value,
1009 GtkCssBorderImageRepeat *image_repeat;
1011 image_repeat = g_value_get_boxed (value);
1013 g_string_append_printf (string, "%s %s",
1014 border_image_repeat_style_to_string (image_repeat->hrepeat),
1015 border_image_repeat_style_to_string (image_repeat->vrepeat));
1019 border_image_value_parse (GtkCssParser *parser,
1023 GValue temp = { 0, };
1024 cairo_pattern_t *pattern = NULL;
1025 GtkGradient *gradient = NULL;
1026 GtkBorder border, *parsed_border;
1027 GtkCssBorderImageRepeat repeat, *parsed_repeat;
1028 gboolean retval = FALSE;
1029 GtkBorderImage *image = NULL;
1031 g_value_init (&temp, CAIRO_GOBJECT_TYPE_PATTERN);
1033 if (!pattern_value_parse (parser, base, &temp))
1036 if (G_VALUE_TYPE (&temp) == GTK_TYPE_GRADIENT)
1037 gradient = g_value_dup_boxed (&temp);
1039 pattern = g_value_dup_boxed (&temp);
1041 g_value_unset (&temp);
1042 g_value_init (&temp, GTK_TYPE_BORDER);
1044 if (!border_value_parse (parser, base, &temp))
1047 parsed_border = g_value_get_boxed (&temp);
1048 border = *parsed_border;
1050 g_value_unset (&temp);
1051 g_value_init (&temp, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
1053 if (!border_image_repeat_value_parse (parser, base, &temp))
1056 parsed_repeat = g_value_get_boxed (&temp);
1057 repeat = *parsed_repeat;
1059 g_value_unset (&temp);
1061 if (gradient != NULL)
1062 image = _gtk_border_image_new_for_gradient (gradient, &border, &repeat);
1063 else if (pattern != NULL)
1064 image = _gtk_border_image_new (pattern, &border, &repeat);
1069 g_value_take_boxed (value, image);
1073 if (pattern != NULL)
1074 cairo_pattern_destroy (pattern);
1076 if (gradient != NULL)
1077 gtk_gradient_unref (gradient);
1083 enum_value_parse (GtkCssParser *parser,
1087 GEnumClass *enum_class;
1088 GEnumValue *enum_value;
1091 str = _gtk_css_parser_try_ident (parser, TRUE);
1094 _gtk_css_parser_error (parser, "Expected an identifier");
1098 enum_class = g_type_class_ref (G_VALUE_TYPE (value));
1099 enum_value = g_enum_get_value_by_nick (enum_class, str);
1102 g_value_set_enum (value, enum_value->value);
1104 _gtk_css_parser_error (parser,
1105 "Unknown value '%s' for enum type '%s'",
1106 str, g_type_name (G_VALUE_TYPE (value)));
1108 g_type_class_unref (enum_class);
1111 return enum_value != NULL;
1115 enum_value_print (const GValue *value,
1118 GEnumClass *enum_class;
1119 GEnumValue *enum_value;
1121 enum_class = g_type_class_ref (G_VALUE_TYPE (value));
1122 enum_value = g_enum_get_value (enum_class, g_value_get_enum (value));
1124 g_string_append (string, enum_value->value_nick);
1126 g_type_class_unref (enum_class);
1130 flags_value_parse (GtkCssParser *parser,
1134 GFlagsClass *flags_class;
1135 GFlagsValue *flag_value;
1139 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1142 str = _gtk_css_parser_try_ident (parser, TRUE);
1145 _gtk_css_parser_error (parser, "Expected an identifier");
1146 g_type_class_unref (flags_class);
1150 flag_value = g_flags_get_value_by_nick (flags_class, str);
1153 _gtk_css_parser_error (parser,
1154 "Unknown flag value '%s' for type '%s'",
1155 str, g_type_name (G_VALUE_TYPE (value)));
1156 /* XXX Do we want to return FALSE here? We can get
1157 * forward-compatibility for new values this way
1160 g_type_class_unref (flags_class);
1166 while (_gtk_css_parser_try (parser, ",", FALSE));
1168 g_type_class_unref (flags_class);
1170 g_value_set_enum (value, flags);
1176 flags_value_print (const GValue *value,
1179 GFlagsClass *flags_class;
1182 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1183 flags = g_value_get_flags (value);
1185 for (i = 0; i < flags_class->n_values; i++)
1187 GFlagsValue *flags_value = &flags_class->values[i];
1189 if (flags & flags_value->value)
1191 if (string->len != 0)
1192 g_string_append (string, ", ");
1194 g_string_append (string, flags_value->value_nick);
1198 g_type_class_unref (flags_class);
1202 bindings_value_parse (GtkCssParser *parser,
1207 GtkBindingSet *binding_set;
1210 array = g_ptr_array_new ();
1213 name = _gtk_css_parser_try_ident (parser, TRUE);
1216 _gtk_css_parser_error (parser, "Not a valid binding name");
1217 g_ptr_array_free (array, TRUE);
1221 binding_set = gtk_binding_set_find (name);
1225 _gtk_css_parser_error (parser, "No binding set named '%s'", name);
1230 g_ptr_array_add (array, binding_set);
1233 while (_gtk_css_parser_try (parser, ",", TRUE));
1235 g_value_take_boxed (value, array);
1241 bindings_value_print (const GValue *value,
1247 array = g_value_get_boxed (value);
1249 for (i = 0; i < array->len; i++)
1251 GtkBindingSet *binding_set = g_ptr_array_index (array, i);
1254 g_string_append (string, ", ");
1255 g_string_append (string, binding_set->set_name);
1260 border_corner_radius_value_parse (GtkCssParser *parser,
1264 GtkCssBorderCornerRadius corner;
1266 if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
1268 _gtk_css_parser_error (parser, "Expected a number");
1271 else if (corner.horizontal < 0)
1274 if (!_gtk_css_parser_try_double (parser, &corner.vertical))
1275 corner.vertical = corner.horizontal;
1276 else if (corner.vertical < 0)
1279 g_value_set_boxed (value, &corner);
1283 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1288 border_corner_radius_value_print (const GValue *value,
1291 GtkCssBorderCornerRadius *corner;
1293 corner = g_value_get_boxed (value);
1297 g_string_append (string, "none");
1301 string_append_double (string, corner->horizontal);
1302 if (corner->horizontal != corner->vertical)
1304 g_string_append_c (string, ' ');
1305 string_append_double (string, corner->vertical);
1310 border_radius_value_parse (GtkCssParser *parser,
1314 GtkCssBorderRadius border;
1316 if (!_gtk_css_parser_try_double (parser, &border.top_left.horizontal))
1318 _gtk_css_parser_error (parser, "Expected a number");
1321 else if (border.top_left.horizontal < 0)
1324 if (_gtk_css_parser_try_double (parser, &border.top_right.horizontal))
1326 if (border.top_right.horizontal < 0)
1328 if (_gtk_css_parser_try_double (parser, &border.bottom_right.horizontal))
1330 if (border.bottom_right.horizontal < 0)
1332 if (!_gtk_css_parser_try_double (parser, &border.bottom_left.horizontal))
1333 border.bottom_left.horizontal = border.top_right.horizontal;
1334 else if (border.bottom_left.horizontal < 0)
1339 border.bottom_right.horizontal = border.top_left.horizontal;
1340 border.bottom_left.horizontal = border.top_right.horizontal;
1345 border.top_right.horizontal = border.top_left.horizontal;
1346 border.bottom_right.horizontal = border.top_left.horizontal;
1347 border.bottom_left.horizontal = border.top_left.horizontal;
1350 if (_gtk_css_parser_try (parser, "/", TRUE))
1352 if (!_gtk_css_parser_try_double (parser, &border.top_left.vertical))
1354 _gtk_css_parser_error (parser, "Expected a number");
1357 else if (border.top_left.vertical < 0)
1360 if (_gtk_css_parser_try_double (parser, &border.top_right.vertical))
1362 if (border.top_right.vertical < 0)
1364 if (_gtk_css_parser_try_double (parser, &border.bottom_right.vertical))
1366 if (border.bottom_right.vertical < 0)
1368 if (!_gtk_css_parser_try_double (parser, &border.bottom_left.vertical))
1369 border.bottom_left.vertical = border.top_right.vertical;
1370 else if (border.bottom_left.vertical < 0)
1375 border.bottom_right.vertical = border.top_left.vertical;
1376 border.bottom_left.vertical = border.top_right.vertical;
1381 border.top_right.vertical = border.top_left.vertical;
1382 border.bottom_right.vertical = border.top_left.vertical;
1383 border.bottom_left.vertical = border.top_left.vertical;
1388 border.top_left.vertical = border.top_left.horizontal;
1389 border.top_right.vertical = border.top_right.horizontal;
1390 border.bottom_right.vertical = border.bottom_right.horizontal;
1391 border.bottom_left.vertical = border.bottom_left.horizontal;
1394 /* border-radius is an int property for backwards-compat reasons */
1395 g_value_unset (value);
1396 g_value_init (value, GTK_TYPE_CSS_BORDER_RADIUS);
1397 g_value_set_boxed (value, &border);
1402 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1407 border_radius_value_print (const GValue *value,
1410 GtkCssBorderRadius *border;
1412 border = g_value_get_boxed (value);
1416 g_string_append (string, "none");
1420 string_append_double (string, border->top_left.horizontal);
1421 if (border->top_left.horizontal != border->top_right.horizontal ||
1422 border->top_left.horizontal != border->bottom_right.horizontal ||
1423 border->top_left.horizontal != border->bottom_left.horizontal)
1425 g_string_append_c (string, ' ');
1426 string_append_double (string, border->top_right.horizontal);
1427 if (border->top_left.horizontal != border->bottom_right.horizontal ||
1428 border->top_right.horizontal != border->bottom_left.horizontal)
1430 g_string_append_c (string, ' ');
1431 string_append_double (string, border->bottom_right.horizontal);
1432 if (border->top_right.horizontal != border->bottom_left.horizontal)
1434 g_string_append_c (string, ' ');
1435 string_append_double (string, border->bottom_left.horizontal);
1440 if (border->top_left.horizontal != border->top_left.vertical ||
1441 border->top_right.horizontal != border->top_right.vertical ||
1442 border->bottom_right.horizontal != border->bottom_right.vertical ||
1443 border->bottom_left.horizontal != border->bottom_left.vertical)
1445 g_string_append (string, " / ");
1446 string_append_double (string, border->top_left.vertical);
1447 if (border->top_left.vertical != border->top_right.vertical ||
1448 border->top_left.vertical != border->bottom_right.vertical ||
1449 border->top_left.vertical != border->bottom_left.vertical)
1451 g_string_append_c (string, ' ');
1452 string_append_double (string, border->top_right.vertical);
1453 if (border->top_left.vertical != border->bottom_right.vertical ||
1454 border->top_right.vertical != border->bottom_left.vertical)
1456 g_string_append_c (string, ' ');
1457 string_append_double (string, border->bottom_right.vertical);
1458 if (border->top_right.vertical != border->bottom_left.vertical)
1460 g_string_append_c (string, ' ');
1461 string_append_double (string, border->bottom_left.vertical);
1472 unpack_border (const GValue *value,
1479 GParameter *parameter = g_new0 (GParameter, 4);
1480 GtkBorder *border = g_value_get_boxed (value);
1482 parameter[0].name = top;
1483 g_value_init (¶meter[0].value, G_TYPE_INT);
1484 g_value_set_int (¶meter[0].value, border->top);
1485 parameter[1].name = left;
1486 g_value_init (¶meter[1].value, G_TYPE_INT);
1487 g_value_set_int (¶meter[1].value, border->left);
1488 parameter[2].name = bottom;
1489 g_value_init (¶meter[2].value, G_TYPE_INT);
1490 g_value_set_int (¶meter[2].value, border->bottom);
1491 parameter[3].name = right;
1492 g_value_init (¶meter[3].value, G_TYPE_INT);
1493 g_value_set_int (¶meter[3].value, border->right);
1500 pack_border (GValue *value,
1501 GtkStyleProperties *props,
1502 GtkStateFlags state,
1511 gtk_style_properties_get (props,
1524 g_value_set_boxed (value, &border);
1528 unpack_border_width (const GValue *value,
1531 return unpack_border (value, n_params,
1532 "border-top-width", "border-left-width",
1533 "border-bottom-width", "border-right-width");
1537 pack_border_width (GValue *value,
1538 GtkStyleProperties *props,
1539 GtkStateFlags state)
1541 pack_border (value, props, state,
1542 "border-top-width", "border-left-width",
1543 "border-bottom-width", "border-right-width");
1547 unpack_padding (const GValue *value,
1550 return unpack_border (value, n_params,
1551 "padding-top", "padding-left",
1552 "padding-bottom", "padding-right");
1556 pack_padding (GValue *value,
1557 GtkStyleProperties *props,
1558 GtkStateFlags state)
1560 pack_border (value, props, state,
1561 "padding-top", "padding-left",
1562 "padding-bottom", "padding-right");
1566 unpack_margin (const GValue *value,
1569 return unpack_border (value, n_params,
1570 "margin-top", "margin-left",
1571 "margin-bottom", "margin-right");
1575 pack_margin (GValue *value,
1576 GtkStyleProperties *props,
1577 GtkStateFlags state)
1579 pack_border (value, props, state,
1580 "margin-top", "margin-left",
1581 "margin-bottom", "margin-right");
1585 unpack_border_radius (const GValue *value,
1588 GParameter *parameter = g_new0 (GParameter, 4);
1589 GtkCssBorderRadius *border;
1591 if (G_VALUE_HOLDS_BOXED (value))
1592 border = g_value_get_boxed (value);
1596 parameter[0].name = "border-top-left-radius";
1597 g_value_init (¶meter[0].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1598 parameter[1].name = "border-top-right-radius";
1599 g_value_init (¶meter[1].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1600 parameter[2].name = "border-bottom-right-radius";
1601 g_value_init (¶meter[2].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1602 parameter[3].name = "border-bottom-left-radius";
1603 g_value_init (¶meter[3].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1606 g_value_set_boxed (¶meter[0].value, &border->top_left);
1607 g_value_set_boxed (¶meter[1].value, &border->top_right);
1608 g_value_set_boxed (¶meter[2].value, &border->bottom_right);
1609 g_value_set_boxed (¶meter[3].value, &border->bottom_left);
1617 pack_border_radius (GValue *value,
1618 GtkStyleProperties *props,
1619 GtkStateFlags state)
1621 GtkCssBorderCornerRadius *top_left;
1623 /* NB: We are an int property, so we have to resolve to an int here.
1624 * So we just resolve to an int. We pick one and stick to it.
1625 * Lesson learned: Don't query border-radius shorthand, query the
1626 * real properties instead. */
1627 gtk_style_properties_get (props,
1629 "border-top-left-radius", &top_left,
1633 g_value_set_int (value, top_left->horizontal);
1641 css_string_funcs_init (void)
1643 if (G_LIKELY (parse_funcs != NULL))
1646 parse_funcs = g_hash_table_new (NULL, NULL);
1647 print_funcs = g_hash_table_new (NULL, NULL);
1649 register_conversion_function (GDK_TYPE_RGBA,
1652 register_conversion_function (GDK_TYPE_COLOR,
1655 register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
1656 symbolic_color_value_parse,
1657 symbolic_color_value_print);
1658 register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
1659 font_description_value_parse,
1660 font_description_value_print);
1661 register_conversion_function (G_TYPE_BOOLEAN,
1662 boolean_value_parse,
1663 boolean_value_print);
1664 register_conversion_function (G_TYPE_INT,
1667 register_conversion_function (G_TYPE_UINT,
1670 register_conversion_function (G_TYPE_DOUBLE,
1672 double_value_print);
1673 register_conversion_function (G_TYPE_FLOAT,
1676 register_conversion_function (G_TYPE_STRING,
1678 string_value_print);
1679 register_conversion_function (GTK_TYPE_THEMING_ENGINE,
1680 theming_engine_value_parse,
1681 theming_engine_value_print);
1682 register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
1683 animation_description_value_parse,
1684 animation_description_value_print);
1685 register_conversion_function (GTK_TYPE_BORDER,
1687 border_value_print);
1688 register_conversion_function (GTK_TYPE_GRADIENT,
1689 gradient_value_parse,
1690 gradient_value_print);
1691 register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
1692 pattern_value_parse,
1694 register_conversion_function (GTK_TYPE_BORDER_IMAGE,
1695 border_image_value_parse,
1697 register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1698 border_image_repeat_value_parse,
1699 border_image_repeat_value_print);
1700 register_conversion_function (GTK_TYPE_SHADOW,
1702 shadow_value_print);
1703 register_conversion_function (G_TYPE_ENUM,
1706 register_conversion_function (G_TYPE_FLAGS,
1712 _gtk_style_property_parse_value (const GtkStyleProperty *property,
1714 GtkCssParser *parser,
1717 GtkStyleParseFunc func;
1719 g_return_val_if_fail (value != NULL, FALSE);
1720 g_return_val_if_fail (parser != NULL, FALSE);
1722 css_string_funcs_init ();
1726 if (_gtk_css_parser_try (parser, "none", TRUE))
1728 /* Insert the default value, so it has an opportunity
1729 * to override other style providers when merged
1731 g_param_value_set_default (property->pspec, value);
1734 else if (property->property_parse_func)
1736 GError *error = NULL;
1740 value_str = _gtk_css_parser_read_value (parser);
1741 if (value_str == NULL)
1744 success = (*property->property_parse_func) (value_str, value, &error);
1751 func = property->parse_func;
1757 func = g_hash_table_lookup (parse_funcs,
1758 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1760 func = g_hash_table_lookup (parse_funcs,
1761 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1765 _gtk_css_parser_error (parser,
1766 "Cannot convert to type '%s'",
1767 g_type_name (G_VALUE_TYPE (value)));
1771 return (*func) (parser, base, value);
1775 _gtk_style_property_print_value (const GtkStyleProperty *property,
1776 const GValue *value,
1779 GtkStylePrintFunc func;
1781 css_string_funcs_init ();
1784 func = property->print_func;
1789 func = g_hash_table_lookup (print_funcs,
1790 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1792 func = g_hash_table_lookup (print_funcs,
1793 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1797 char *s = g_strdup_value_contents (value);
1798 g_string_append (string, s);
1803 func (value, string);
1807 _gtk_style_property_default_value (const GtkStyleProperty *property,
1808 GtkStyleProperties *properties,
1811 if (property->default_value_func)
1812 property->default_value_func (properties, value);
1813 else if (property->pspec->value_type == GTK_TYPE_THEMING_ENGINE)
1814 g_value_set_object (value, gtk_theming_engine_load (NULL));
1815 else if (property->pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
1816 g_value_take_boxed (value, pango_font_description_from_string ("Sans 10"));
1817 else if (property->pspec->value_type == GDK_TYPE_RGBA)
1820 gdk_rgba_parse (&color, "pink");
1821 g_value_set_boxed (value, &color);
1823 else if (property->pspec->value_type == GTK_TYPE_BORDER)
1825 g_value_take_boxed (value, gtk_border_new ());
1828 g_param_value_set_default (property->pspec, value);
1832 _gtk_style_property_is_inherit (const GtkStyleProperty *property)
1834 g_return_val_if_fail (property != NULL, FALSE);
1836 return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
1840 resolve_color (GtkStyleProperties *props,
1845 /* Resolve symbolic color to GdkRGBA */
1846 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
1849 /* Store it back, this is where GdkRGBA caching happens */
1850 g_value_unset (value);
1851 g_value_init (value, GDK_TYPE_RGBA);
1852 g_value_set_boxed (value, &color);
1858 resolve_color_rgb (GtkStyleProperties *props,
1861 GdkColor color = { 0 };
1864 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
1867 color.red = rgba.red * 65535. + 0.5;
1868 color.green = rgba.green * 65535. + 0.5;
1869 color.blue = rgba.blue * 65535. + 0.5;
1871 g_value_unset (value);
1872 g_value_init (value, GDK_TYPE_COLOR);
1873 g_value_set_boxed (value, &color);
1879 resolve_gradient (GtkStyleProperties *props,
1882 cairo_pattern_t *gradient;
1884 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
1887 /* Store it back, this is where cairo_pattern_t caching happens */
1888 g_value_unset (value);
1889 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
1890 g_value_take_boxed (value, gradient);
1896 resolve_shadow (GtkStyleProperties *props,
1899 GtkShadow *resolved, *base;
1901 base = g_value_get_boxed (value);
1906 if (_gtk_shadow_get_resolved (base))
1909 resolved = _gtk_shadow_resolve (base, props);
1910 if (resolved == NULL)
1913 g_value_take_boxed (value, resolved);
1919 _gtk_style_property_resolve (const GtkStyleProperty *property,
1920 GtkStyleProperties *props,
1923 if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
1925 if (property->pspec->value_type == GDK_TYPE_RGBA)
1927 if (!resolve_color (props, val))
1928 _gtk_style_property_resolve (property, props, val);
1930 else if (property->pspec->value_type == GDK_TYPE_COLOR)
1932 if (!resolve_color_rgb (props, val))
1933 _gtk_style_property_resolve (property, props, val);
1936 _gtk_style_property_resolve (property, props, val);
1938 else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
1940 g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
1942 if (!resolve_gradient (props, val))
1943 _gtk_style_property_resolve (property, props, val);
1945 else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
1947 if (!resolve_shadow (props, val))
1948 _gtk_style_property_resolve (property, props, val);
1953 _gtk_style_property_is_shorthand (const GtkStyleProperty *property)
1955 g_return_val_if_fail (property != NULL, FALSE);
1957 return property->pack_func != NULL;
1961 _gtk_style_property_unpack (const GtkStyleProperty *property,
1962 const GValue *value,
1965 g_return_val_if_fail (property != NULL, NULL);
1966 g_return_val_if_fail (property->unpack_func != NULL, NULL);
1967 g_return_val_if_fail (value != NULL, NULL);
1968 g_return_val_if_fail (n_params != NULL, NULL);
1970 return property->unpack_func (value, n_params);
1974 _gtk_style_property_pack (const GtkStyleProperty *property,
1975 GtkStyleProperties *props,
1976 GtkStateFlags state,
1979 g_return_if_fail (property != NULL);
1980 g_return_if_fail (property->pack_func != NULL);
1981 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
1982 g_return_if_fail (G_IS_VALUE (value));
1984 property->pack_func (value, props, state);
1988 gtk_style_property_init (void)
1990 if (G_LIKELY (properties))
1993 /* stuff is never freed, so no need for free functions */
1994 properties = g_hash_table_new (g_str_hash, g_str_equal);
1996 /* note that gtk_style_properties_register_property() calls this function,
1997 * so make sure we're sanely inited to avoid infloops */
1999 _gtk_style_property_register (g_param_spec_boxed ("color",
2003 GTK_STYLE_PROPERTY_INHERIT,
2011 gtk_style_properties_register_property (NULL,
2012 g_param_spec_boxed ("background-color",
2017 _gtk_style_property_register (g_param_spec_boxed ("font",
2020 PANGO_TYPE_FONT_DESCRIPTION, 0),
2021 GTK_STYLE_PROPERTY_INHERIT,
2025 font_description_value_parse,
2026 font_description_value_print,
2029 _gtk_style_property_register (g_param_spec_boxed ("text-shadow",
2032 GTK_TYPE_SHADOW, 0),
2033 GTK_STYLE_PROPERTY_INHERIT,
2041 _gtk_style_property_register (g_param_spec_boxed ("icon-shadow",
2044 GTK_TYPE_SHADOW, 0),
2045 GTK_STYLE_PROPERTY_INHERIT,
2053 gtk_style_properties_register_property (NULL,
2054 g_param_spec_int ("margin-top",
2057 0, G_MAXINT, 0, 0));
2058 gtk_style_properties_register_property (NULL,
2059 g_param_spec_int ("margin-left",
2062 0, G_MAXINT, 0, 0));
2063 gtk_style_properties_register_property (NULL,
2064 g_param_spec_int ("margin-bottom",
2067 0, G_MAXINT, 0, 0));
2068 gtk_style_properties_register_property (NULL,
2069 g_param_spec_int ("margin-right",
2072 0, G_MAXINT, 0, 0));
2073 _gtk_style_property_register (g_param_spec_boxed ("margin",
2076 GTK_TYPE_BORDER, 0),
2084 gtk_style_properties_register_property (NULL,
2085 g_param_spec_int ("padding-top",
2088 0, G_MAXINT, 0, 0));
2089 gtk_style_properties_register_property (NULL,
2090 g_param_spec_int ("padding-left",
2093 0, G_MAXINT, 0, 0));
2094 gtk_style_properties_register_property (NULL,
2095 g_param_spec_int ("padding-bottom",
2097 "Padding at bottom",
2098 0, G_MAXINT, 0, 0));
2099 gtk_style_properties_register_property (NULL,
2100 g_param_spec_int ("padding-right",
2103 0, G_MAXINT, 0, 0));
2104 _gtk_style_property_register (g_param_spec_boxed ("padding",
2107 GTK_TYPE_BORDER, 0),
2115 gtk_style_properties_register_property (NULL,
2116 g_param_spec_int ("border-top-width",
2118 "Border width at top",
2119 0, G_MAXINT, 0, 0));
2120 gtk_style_properties_register_property (NULL,
2121 g_param_spec_int ("border-left-width",
2122 "border left width",
2123 "Border width at left",
2124 0, G_MAXINT, 0, 0));
2125 gtk_style_properties_register_property (NULL,
2126 g_param_spec_int ("border-bottom-width",
2127 "border bottom width",
2128 "Border width at bottom",
2129 0, G_MAXINT, 0, 0));
2130 gtk_style_properties_register_property (NULL,
2131 g_param_spec_int ("border-right-width",
2132 "border right width",
2133 "Border width at right",
2134 0, G_MAXINT, 0, 0));
2135 _gtk_style_property_register (g_param_spec_boxed ("border-width",
2137 "Border width, in pixels",
2138 GTK_TYPE_BORDER, 0),
2141 unpack_border_width,
2147 _gtk_style_property_register (g_param_spec_boxed ("border-top-left-radius",
2148 "Border top left radius",
2149 "Border radius of top left corner, in pixels",
2150 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2155 border_corner_radius_value_parse,
2156 border_corner_radius_value_print,
2158 _gtk_style_property_register (g_param_spec_boxed ("border-top-right-radius",
2159 "Border top right radius",
2160 "Border radius of top right corner, in pixels",
2161 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2166 border_corner_radius_value_parse,
2167 border_corner_radius_value_print,
2169 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-right-radius",
2170 "Border bottom right radius",
2171 "Border radius of bottom right corner, in pixels",
2172 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2177 border_corner_radius_value_parse,
2178 border_corner_radius_value_print,
2180 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-left-radius",
2181 "Border bottom left radius",
2182 "Border radius of bottom left corner, in pixels",
2183 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2188 border_corner_radius_value_parse,
2189 border_corner_radius_value_print,
2191 _gtk_style_property_register (g_param_spec_int ("border-radius",
2193 "Border radius, in pixels",
2197 unpack_border_radius,
2199 border_radius_value_parse,
2200 border_radius_value_print,
2203 gtk_style_properties_register_property (NULL,
2204 g_param_spec_enum ("border-style",
2207 GTK_TYPE_BORDER_STYLE,
2208 GTK_BORDER_STYLE_NONE, 0));
2209 gtk_style_properties_register_property (NULL,
2210 g_param_spec_boxed ("border-color",
2214 gtk_style_properties_register_property (NULL,
2215 g_param_spec_boxed ("background-image",
2218 CAIRO_GOBJECT_TYPE_PATTERN, 0));
2219 gtk_style_properties_register_property (NULL,
2220 g_param_spec_boxed ("border-image-source",
2221 "Border image source",
2222 "Border image source",
2223 CAIRO_GOBJECT_TYPE_PATTERN, 0));
2224 gtk_style_properties_register_property (NULL,
2225 g_param_spec_boxed ("border-image-repeat",
2226 "Border image repeat",
2227 "Border image repeat",
2228 GTK_TYPE_CSS_BORDER_IMAGE_REPEAT, 0));
2229 gtk_style_properties_register_property (NULL,
2230 g_param_spec_boxed ("border-image-slice",
2231 "Border image slice",
2232 "Border image slice",
2233 GTK_TYPE_BORDER, 0));
2234 _gtk_style_property_register (g_param_spec_boxed ("border-image",
2237 GTK_TYPE_BORDER_IMAGE, 0),
2240 _gtk_border_image_unpack,
2241 _gtk_border_image_pack,
2245 gtk_style_properties_register_property (NULL,
2246 g_param_spec_object ("engine",
2249 GTK_TYPE_THEMING_ENGINE, 0));
2250 gtk_style_properties_register_property (NULL,
2251 g_param_spec_boxed ("transition",
2252 "Transition animation description",
2253 "Transition animation description",
2254 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
2256 /* Private property holding the binding sets */
2257 _gtk_style_property_register (g_param_spec_boxed ("gtk-key-bindings",
2260 G_TYPE_PTR_ARRAY, 0),
2265 bindings_value_parse,
2266 bindings_value_print,
2270 const GtkStyleProperty *
2271 _gtk_style_property_lookup (const char *name)
2273 gtk_style_property_init ();
2275 return g_hash_table_lookup (properties, name);
2279 _gtk_style_property_register (GParamSpec *pspec,
2280 GtkStylePropertyFlags flags,
2281 GtkStylePropertyParser property_parse_func,
2282 GtkStyleUnpackFunc unpack_func,
2283 GtkStylePackFunc pack_func,
2284 GtkStyleParseFunc parse_func,
2285 GtkStylePrintFunc print_func,
2286 GtkStyleDefaultValueFunc default_value_func)
2288 const GtkStyleProperty *existing;
2289 GtkStyleProperty *node;
2291 g_return_if_fail ((pack_func == NULL) == (unpack_func == NULL));
2293 gtk_style_property_init ();
2295 existing = _gtk_style_property_lookup (pspec->name);
2296 if (existing != NULL)
2298 g_warning ("Property \"%s\" was already registered with type %s",
2299 pspec->name, g_type_name (existing->pspec->value_type));
2303 node = g_slice_new0 (GtkStyleProperty);
2304 node->flags = flags;
2305 node->pspec = pspec;
2306 node->property_parse_func = property_parse_func;
2307 node->pack_func = pack_func;
2308 node->unpack_func = unpack_func;
2309 node->parse_func = parse_func;
2310 node->print_func = print_func;
2311 node->default_value_func = default_value_func;
2313 g_hash_table_insert (properties, pspec->name, node);