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 "gtkcssshorthandpropertyprivate.h"
35 #include "gtkcssstylepropertyprivate.h"
36 #include "gtkcsstypesprivate.h"
37 #include "gtkprivatetypebuiltins.h"
38 #include "gtkstylepropertiesprivate.h"
40 /* the actual parsers we have */
41 #include "gtkanimationdescription.h"
42 #include "gtkbindings.h"
43 #include "gtkborderimageprivate.h"
44 #include "gtkgradient.h"
45 #include "gtkshadowprivate.h"
46 #include "gtkthemingengine.h"
47 #include "gtktypebuiltins.h"
48 #include "gtkwin32themeprivate.h"
50 /* this is in case round() is not provided by the compiler,
51 * such as in the case of C89 compilers, like MSVC
53 #include "fallback-c89.c"
55 static GHashTable *parse_funcs = NULL;
56 static GHashTable *print_funcs = NULL;
57 static GHashTable *properties = NULL;
58 static GPtrArray *__style_property_array = NULL;
60 G_DEFINE_ABSTRACT_TYPE (GtkStyleProperty, _gtk_style_property, G_TYPE_OBJECT)
63 gtk_style_property_finalize (GObject *object)
65 GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
67 g_warning ("finalizing %s `%s', how could this happen?", G_OBJECT_TYPE_NAME (object), property->pspec->name);
69 G_OBJECT_CLASS (_gtk_style_property_parent_class)->finalize (object);
73 _gtk_style_property_class_init (GtkStylePropertyClass *klass)
75 GObjectClass *object_class = G_OBJECT_CLASS (klass);
77 object_class->finalize = gtk_style_property_finalize;
81 _gtk_style_property_init (GtkStyleProperty *property)
86 register_conversion_function (GType type,
87 GtkStyleParseFunc parse,
88 GtkStylePrintFunc print)
91 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
93 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
97 string_append_double (GString *string,
100 char buf[G_ASCII_DTOSTR_BUF_SIZE];
102 g_ascii_dtostr (buf, sizeof (buf), d);
103 g_string_append (string, buf);
107 string_append_string (GString *str,
112 g_string_append_c (str, '"');
115 len = strcspn (string, "\"\n\r\f");
116 g_string_append (str, string);
123 g_string_append (str, "\\A ");
126 g_string_append (str, "\\D ");
129 g_string_append (str, "\\C ");
132 g_string_append (str, "\\\"");
135 g_assert_not_reached ();
140 g_string_append_c (str, '"');
143 /*** IMPLEMENTATIONS ***/
146 enum_parse (GtkCssParser *parser,
152 if (_gtk_css_parser_try_enum (parser, type, res))
155 str = _gtk_css_parser_try_ident (parser, TRUE);
158 _gtk_css_parser_error (parser, "Expected an identifier");
162 _gtk_css_parser_error (parser,
163 "Unknown value '%s' for enum type '%s'",
164 str, g_type_name (type));
171 enum_print (int value,
175 GEnumClass *enum_class;
176 GEnumValue *enum_value;
178 enum_class = g_type_class_ref (type);
179 enum_value = g_enum_get_value (enum_class, value);
181 g_string_append (string, enum_value->value_nick);
183 g_type_class_unref (enum_class);
187 rgba_value_parse (GtkCssParser *parser,
191 GtkSymbolicColor *symbolic;
194 symbolic = _gtk_css_parser_read_symbolic_color (parser);
195 if (symbolic == NULL)
198 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
200 g_value_set_boxed (value, &rgba);
201 gtk_symbolic_color_unref (symbolic);
205 g_value_unset (value);
206 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
207 g_value_take_boxed (value, symbolic);
214 rgba_value_print (const GValue *value,
217 const GdkRGBA *rgba = g_value_get_boxed (value);
220 g_string_append (string, "none");
223 char *s = gdk_rgba_to_string (rgba);
224 g_string_append (string, s);
230 color_value_parse (GtkCssParser *parser,
234 GtkSymbolicColor *symbolic;
237 symbolic = _gtk_css_parser_read_symbolic_color (parser);
238 if (symbolic == NULL)
241 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
245 color.red = rgba.red * 65535. + 0.5;
246 color.green = rgba.green * 65535. + 0.5;
247 color.blue = rgba.blue * 65535. + 0.5;
249 g_value_set_boxed (value, &color);
253 g_value_unset (value);
254 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
255 g_value_take_boxed (value, symbolic);
262 color_value_print (const GValue *value,
265 const GdkColor *color = g_value_get_boxed (value);
268 g_string_append (string, "none");
271 char *s = gdk_color_to_string (color);
272 g_string_append (string, s);
278 symbolic_color_value_parse (GtkCssParser *parser,
282 GtkSymbolicColor *symbolic;
284 symbolic = _gtk_css_parser_read_symbolic_color (parser);
285 if (symbolic == NULL)
288 g_value_take_boxed (value, symbolic);
293 symbolic_color_value_print (const GValue *value,
296 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
298 if (symbolic == NULL)
299 g_string_append (string, "none");
302 char *s = gtk_symbolic_color_to_string (symbolic);
303 g_string_append (string, s);
309 font_family_parse (GtkCssParser *parser,
316 /* We don't special case generic families. Pango should do
319 names = g_ptr_array_new ();
322 name = _gtk_css_parser_try_ident (parser, TRUE);
325 GString *string = g_string_new (name);
327 while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
329 g_string_append_c (string, ' ');
330 g_string_append (string, name);
333 name = g_string_free (string, FALSE);
337 name = _gtk_css_parser_read_string (parser);
340 g_ptr_array_free (names, TRUE);
345 g_ptr_array_add (names, name);
346 } while (_gtk_css_parser_try (parser, ",", TRUE));
348 /* NULL-terminate array */
349 g_ptr_array_add (names, NULL);
350 g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
355 font_family_value_print (const GValue *value,
358 const char **names = g_value_get_boxed (value);
360 if (names == NULL || *names == NULL)
362 g_string_append (string, "none");
366 string_append_string (string, *names);
370 g_string_append (string, ", ");
371 string_append_string (string, *names);
377 font_description_value_parse (GtkCssParser *parser,
381 PangoFontDescription *font_desc;
385 str = _gtk_css_parser_read_value (parser);
389 font_desc = pango_font_description_from_string (str);
390 mask = pango_font_description_get_set_fields (font_desc);
391 /* These values are not really correct,
392 * but the fields must be set, so we set them to something */
393 if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
394 pango_font_description_set_family_static (font_desc, "Sans");
395 if ((mask & PANGO_FONT_MASK_SIZE) == 0)
396 pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
398 g_value_take_boxed (value, font_desc);
403 font_description_value_print (const GValue *value,
406 const PangoFontDescription *desc = g_value_get_boxed (value);
409 g_string_append (string, "none");
412 char *s = pango_font_description_to_string (desc);
413 g_string_append (string, s);
419 boolean_value_parse (GtkCssParser *parser,
423 if (_gtk_css_parser_try (parser, "true", TRUE) ||
424 _gtk_css_parser_try (parser, "1", TRUE))
426 g_value_set_boolean (value, TRUE);
429 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
430 _gtk_css_parser_try (parser, "0", TRUE))
432 g_value_set_boolean (value, FALSE);
437 _gtk_css_parser_error (parser, "Expected a boolean value");
443 boolean_value_print (const GValue *value,
446 if (g_value_get_boolean (value))
447 g_string_append (string, "true");
449 g_string_append (string, "false");
453 int_value_parse (GtkCssParser *parser,
459 if (_gtk_css_parser_begins_with (parser, '-'))
461 int res = _gtk_win32_theme_int_parse (parser, base, &i);
464 g_value_set_int (value, i);
467 /* < 0 => continue */
470 if (!_gtk_css_parser_try_int (parser, &i))
472 _gtk_css_parser_error (parser, "Expected a valid integer value");
476 g_value_set_int (value, i);
481 int_value_print (const GValue *value,
484 g_string_append_printf (string, "%d", g_value_get_int (value));
488 uint_value_parse (GtkCssParser *parser,
494 if (!_gtk_css_parser_try_uint (parser, &u))
496 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
500 g_value_set_uint (value, u);
505 uint_value_print (const GValue *value,
508 g_string_append_printf (string, "%u", g_value_get_uint (value));
512 double_value_parse (GtkCssParser *parser,
518 if (!_gtk_css_parser_try_double (parser, &d))
520 _gtk_css_parser_error (parser, "Expected a number");
524 g_value_set_double (value, d);
529 double_value_print (const GValue *value,
532 string_append_double (string, g_value_get_double (value));
536 float_value_parse (GtkCssParser *parser,
542 if (!_gtk_css_parser_try_double (parser, &d))
544 _gtk_css_parser_error (parser, "Expected a number");
548 g_value_set_float (value, d);
553 float_value_print (const GValue *value,
556 string_append_double (string, g_value_get_float (value));
560 string_value_parse (GtkCssParser *parser,
564 char *str = _gtk_css_parser_read_string (parser);
569 g_value_take_string (value, str);
574 string_value_print (const GValue *value,
577 string_append_string (str, g_value_get_string (value));
581 theming_engine_value_parse (GtkCssParser *parser,
585 GtkThemingEngine *engine;
588 if (_gtk_css_parser_try (parser, "none", TRUE))
590 g_value_set_object (value, gtk_theming_engine_load (NULL));
594 str = _gtk_css_parser_try_ident (parser, TRUE);
597 _gtk_css_parser_error (parser, "Expected a valid theme name");
601 engine = gtk_theming_engine_load (str);
605 _gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
610 g_value_set_object (value, engine);
616 theming_engine_value_print (const GValue *value,
619 GtkThemingEngine *engine;
622 engine = g_value_get_object (value);
624 g_string_append (string, "none");
627 /* XXX: gtk_theming_engine_get_name()? */
628 g_object_get (engine, "name", &name, NULL);
629 g_string_append (string, name ? name : "none");
635 animation_description_value_parse (GtkCssParser *parser,
639 GtkAnimationDescription *desc;
642 str = _gtk_css_parser_read_value (parser);
646 desc = _gtk_animation_description_from_string (str);
651 _gtk_css_parser_error (parser, "Invalid animation description");
655 g_value_take_boxed (value, desc);
660 animation_description_value_print (const GValue *value,
663 GtkAnimationDescription *desc = g_value_get_boxed (value);
666 g_string_append (string, "none");
668 _gtk_animation_description_print (desc, string);
672 border_value_parse (GtkCssParser *parser,
676 GtkBorder border = { 0, };
679 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
681 if (_gtk_css_parser_begins_with (parser, '-'))
683 /* These are strictly speaking signed, but we want to be able to use them
684 for unsigned types too, as the actual ranges of values make this safe */
685 int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
687 if (res == 0) /* Parse error, report */
690 if (res < 0) /* Nothing known to expand */
695 if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
698 /* XXX: shouldn't allow spaces here? */
699 _gtk_css_parser_try (parser, "px", TRUE);
705 _gtk_css_parser_error (parser, "Expected valid border");
709 border.top = numbers[0];
711 border.right = numbers[1];
713 border.right = border.top;
715 border.bottom = numbers[2];
717 border.bottom = border.top;
719 border.left = numbers[3];
721 border.left = border.right;
723 g_value_set_boxed (value, &border);
728 border_value_print (const GValue *value, GString *string)
730 const GtkBorder *border = g_value_get_boxed (value);
733 g_string_append (string, "none");
734 else if (border->left != border->right)
735 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
736 else if (border->top != border->bottom)
737 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
738 else if (border->top != border->left)
739 g_string_append_printf (string, "%d %d", border->top, border->right);
741 g_string_append_printf (string, "%d", border->top);
745 gradient_value_parse (GtkCssParser *parser,
749 GtkGradient *gradient;
750 cairo_pattern_type_t type;
754 if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
756 _gtk_css_parser_error (parser,
757 "Expected '-gtk-gradient'");
761 if (!_gtk_css_parser_try (parser, "(", TRUE))
763 _gtk_css_parser_error (parser,
764 "Expected '(' after '-gtk-gradient'");
768 /* Parse gradient type */
769 if (_gtk_css_parser_try (parser, "linear", TRUE))
770 type = CAIRO_PATTERN_TYPE_LINEAR;
771 else if (_gtk_css_parser_try (parser, "radial", TRUE))
772 type = CAIRO_PATTERN_TYPE_RADIAL;
775 _gtk_css_parser_error (parser,
776 "Gradient type must be 'radial' or 'linear'");
780 /* Parse start/stop position parameters */
781 for (i = 0; i < 2; i++)
783 if (! _gtk_css_parser_try (parser, ",", TRUE))
785 _gtk_css_parser_error (parser,
790 if (_gtk_css_parser_try (parser, "left", TRUE))
792 else if (_gtk_css_parser_try (parser, "right", TRUE))
794 else if (_gtk_css_parser_try (parser, "center", TRUE))
796 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
798 _gtk_css_parser_error (parser,
799 "Expected a valid X coordinate");
803 if (_gtk_css_parser_try (parser, "top", TRUE))
804 coords[i * 3 + 1] = 0;
805 else if (_gtk_css_parser_try (parser, "bottom", TRUE))
806 coords[i * 3 + 1] = 1;
807 else if (_gtk_css_parser_try (parser, "center", TRUE))
808 coords[i * 3 + 1] = 0.5;
809 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
811 _gtk_css_parser_error (parser,
812 "Expected a valid Y coordinate");
816 if (type == CAIRO_PATTERN_TYPE_RADIAL)
819 if (! _gtk_css_parser_try (parser, ",", TRUE))
821 _gtk_css_parser_error (parser,
826 if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
828 _gtk_css_parser_error (parser,
829 "Expected a numer for the radius");
835 if (type == CAIRO_PATTERN_TYPE_LINEAR)
836 gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
838 gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
839 coords[3], coords[4], coords[5]);
841 while (_gtk_css_parser_try (parser, ",", TRUE))
843 GtkSymbolicColor *color;
846 if (_gtk_css_parser_try (parser, "from", TRUE))
850 if (!_gtk_css_parser_try (parser, "(", TRUE))
852 gtk_gradient_unref (gradient);
853 _gtk_css_parser_error (parser,
859 else if (_gtk_css_parser_try (parser, "to", TRUE))
863 if (!_gtk_css_parser_try (parser, "(", TRUE))
865 gtk_gradient_unref (gradient);
866 _gtk_css_parser_error (parser,
872 else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
874 if (!_gtk_css_parser_try (parser, "(", TRUE))
876 gtk_gradient_unref (gradient);
877 _gtk_css_parser_error (parser,
882 if (!_gtk_css_parser_try_double (parser, &position))
884 gtk_gradient_unref (gradient);
885 _gtk_css_parser_error (parser,
886 "Expected a valid number");
890 if (!_gtk_css_parser_try (parser, ",", TRUE))
892 gtk_gradient_unref (gradient);
893 _gtk_css_parser_error (parser,
900 gtk_gradient_unref (gradient);
901 _gtk_css_parser_error (parser,
902 "Not a valid color-stop definition");
906 color = _gtk_css_parser_read_symbolic_color (parser);
909 gtk_gradient_unref (gradient);
913 gtk_gradient_add_color_stop (gradient, position, color);
914 gtk_symbolic_color_unref (color);
916 if (!_gtk_css_parser_try (parser, ")", TRUE))
918 gtk_gradient_unref (gradient);
919 _gtk_css_parser_error (parser,
925 if (!_gtk_css_parser_try (parser, ")", TRUE))
927 gtk_gradient_unref (gradient);
928 _gtk_css_parser_error (parser,
933 g_value_take_boxed (value, gradient);
938 gradient_value_print (const GValue *value,
941 GtkGradient *gradient = g_value_get_boxed (value);
943 if (gradient == NULL)
944 g_string_append (string, "none");
947 char *s = gtk_gradient_to_string (gradient);
948 g_string_append (string, s);
954 gtk_css_parse_url (GtkCssParser *parser,
960 if (_gtk_css_parser_try (parser, "url", FALSE))
962 if (!_gtk_css_parser_try (parser, "(", TRUE))
964 _gtk_css_parser_skip_whitespace (parser);
965 if (_gtk_css_parser_try (parser, "(", TRUE))
969 error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
970 GTK_CSS_PROVIDER_ERROR_DEPRECATED,
971 "Whitespace between 'url' and '(' is deprecated");
973 _gtk_css_parser_take_error (parser, error);
977 _gtk_css_parser_error (parser, "Expected '(' after 'url'");
982 path = _gtk_css_parser_read_string (parser);
986 if (!_gtk_css_parser_try (parser, ")", TRUE))
988 _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
995 path = _gtk_css_parser_try_name (parser, TRUE);
998 _gtk_css_parser_error (parser, "Not a valid url");
1003 file = g_file_resolve_relative_path (base, path);
1010 pattern_value_parse (GtkCssParser *parser,
1014 if (_gtk_css_parser_try (parser, "none", TRUE))
1016 /* nothing to do here */
1018 else if (_gtk_css_parser_begins_with (parser, '-'))
1021 res = _gtk_win32_theme_part_parse (parser, base, value);
1024 /* < 0 => continue */
1025 g_value_unset (value);
1026 g_value_init (value, GTK_TYPE_GRADIENT);
1027 return gradient_value_parse (parser, base, value);
1031 GError *error = NULL;
1035 cairo_surface_t *surface;
1036 cairo_pattern_t *pattern;
1038 cairo_matrix_t matrix;
1040 file = gtk_css_parse_url (parser, base);
1044 path = g_file_get_path (file);
1045 g_object_unref (file);
1047 pixbuf = gdk_pixbuf_new_from_file (path, &error);
1051 _gtk_css_parser_take_error (parser, error);
1055 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1056 gdk_pixbuf_get_width (pixbuf),
1057 gdk_pixbuf_get_height (pixbuf));
1058 cr = cairo_create (surface);
1059 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
1061 pattern = cairo_pattern_create_for_surface (surface);
1063 cairo_matrix_init_scale (&matrix,
1064 gdk_pixbuf_get_width (pixbuf),
1065 gdk_pixbuf_get_height (pixbuf));
1066 cairo_pattern_set_matrix (pattern, &matrix);
1068 cairo_surface_destroy (surface);
1070 g_object_unref (pixbuf);
1072 g_value_take_boxed (value, pattern);
1078 static cairo_status_t
1079 surface_write (void *closure,
1080 const unsigned char *data,
1081 unsigned int length)
1083 g_byte_array_append (closure, data, length);
1085 return CAIRO_STATUS_SUCCESS;
1089 surface_print (cairo_surface_t *surface,
1092 #if CAIRO_HAS_PNG_FUNCTIONS
1096 array = g_byte_array_new ();
1097 cairo_surface_write_to_png_stream (surface, surface_write, array);
1098 base64 = g_base64_encode (array->data, array->len);
1099 g_byte_array_free (array, TRUE);
1101 g_string_append (string, "url(\"data:image/png;base64,");
1102 g_string_append (string, base64);
1103 g_string_append (string, "\")");
1107 g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
1112 pattern_value_print (const GValue *value,
1115 cairo_pattern_t *pattern;
1116 cairo_surface_t *surface;
1118 pattern = g_value_get_boxed (value);
1120 if (pattern == NULL)
1122 g_string_append (string, "none");
1126 switch (cairo_pattern_get_type (pattern))
1128 case CAIRO_PATTERN_TYPE_SURFACE:
1129 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
1131 g_assert_not_reached ();
1133 surface_print (surface, string);
1135 case CAIRO_PATTERN_TYPE_SOLID:
1136 case CAIRO_PATTERN_TYPE_LINEAR:
1137 case CAIRO_PATTERN_TYPE_RADIAL:
1139 g_assert_not_reached ();
1145 shadow_value_parse (GtkCssParser *parser,
1149 gboolean have_inset, have_color, have_lengths;
1150 gdouble hoffset, voffset, blur, spread;
1151 GtkSymbolicColor *color;
1155 shadow = _gtk_shadow_new ();
1157 if (_gtk_css_parser_try (parser, "none", TRUE))
1162 have_inset = have_lengths = have_color = FALSE;
1164 for (i = 0; i < 3; i++)
1167 _gtk_css_parser_try (parser, "inset", TRUE))
1173 if (!have_lengths &&
1174 _gtk_css_parser_try_double (parser, &hoffset))
1176 have_lengths = TRUE;
1178 if (!_gtk_css_parser_try_double (parser, &voffset))
1180 _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
1181 _gtk_shadow_unref (shadow);
1185 if (!_gtk_css_parser_try_double (parser, &blur))
1188 if (!_gtk_css_parser_try_double (parser, &spread))
1198 /* XXX: the color is optional and UA-defined if it's missing,
1199 * but it doesn't really make sense for us...
1201 color = _gtk_css_parser_read_symbolic_color (parser);
1205 _gtk_shadow_unref (shadow);
1211 if (!have_color || !have_lengths)
1213 _gtk_css_parser_error (parser, "Must specify at least color and offsets");
1214 _gtk_shadow_unref (shadow);
1218 _gtk_shadow_append (shadow,
1223 gtk_symbolic_color_unref (color);
1226 while (_gtk_css_parser_try (parser, ",", TRUE));
1228 g_value_take_boxed (value, shadow);
1233 shadow_value_print (const GValue *value,
1238 shadow = g_value_get_boxed (value);
1241 g_string_append (string, "none");
1243 _gtk_shadow_print (shadow, string);
1247 background_repeat_value_parse (GtkCssParser *parser,
1251 GtkCssBackgroundRepeat repeat;
1254 if (!enum_parse (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, &style))
1257 repeat.repeat = style;
1259 g_value_set_boxed (value, &repeat);
1265 background_repeat_value_print (const GValue *value,
1268 GtkCssBackgroundRepeat *repeat;
1270 repeat = g_value_get_boxed (value);
1272 enum_print (repeat->repeat, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, string);
1276 border_image_repeat_value_parse (GtkCssParser *parser,
1280 GtkCssBorderImageRepeat image_repeat;
1281 GtkCssBorderRepeatStyle styles[2];
1284 for (i = 0; i < 2; i++)
1286 if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
1290 styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
1294 styles[i] = styles[0];
1297 image_repeat.hrepeat = styles[0];
1298 image_repeat.vrepeat = styles[1];
1300 g_value_set_boxed (value, &image_repeat);
1306 border_image_repeat_value_print (const GValue *value,
1309 GtkCssBorderImageRepeat *image_repeat;
1311 image_repeat = g_value_get_boxed (value);
1313 enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1314 if (image_repeat->hrepeat != image_repeat->vrepeat)
1316 g_string_append (string, " ");
1317 enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1322 border_image_value_parse (GtkCssParser *parser,
1326 GValue temp = G_VALUE_INIT;
1327 cairo_pattern_t *pattern = NULL;
1328 gconstpointer *boxed = NULL;
1330 GtkBorder slice, *width = NULL, *parsed_slice;
1331 GtkCssBorderImageRepeat repeat, *parsed_repeat;
1332 gboolean retval = FALSE;
1333 GtkBorderImage *image = NULL;
1335 if (_gtk_css_parser_try (parser, "none", TRUE))
1338 g_value_init (&temp, CAIRO_GOBJECT_TYPE_PATTERN);
1340 if (!pattern_value_parse (parser, base, &temp))
1343 boxed_type = G_VALUE_TYPE (&temp);
1344 if (boxed_type != CAIRO_GOBJECT_TYPE_PATTERN)
1345 boxed = g_value_dup_boxed (&temp);
1347 pattern = g_value_dup_boxed (&temp);
1349 g_value_unset (&temp);
1350 g_value_init (&temp, GTK_TYPE_BORDER);
1352 if (!border_value_parse (parser, base, &temp))
1355 parsed_slice = g_value_get_boxed (&temp);
1356 slice = *parsed_slice;
1358 if (_gtk_css_parser_try (parser, "/", TRUE))
1360 g_value_unset (&temp);
1361 g_value_init (&temp, GTK_TYPE_BORDER);
1363 if (!border_value_parse (parser, base, &temp))
1366 width = g_value_dup_boxed (&temp);
1369 g_value_unset (&temp);
1370 g_value_init (&temp, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
1372 if (!border_image_repeat_value_parse (parser, base, &temp))
1375 parsed_repeat = g_value_get_boxed (&temp);
1376 repeat = *parsed_repeat;
1378 g_value_unset (&temp);
1381 image = _gtk_border_image_new_for_boxed (boxed_type, boxed, &slice, width, &repeat);
1382 else if (pattern != NULL)
1383 image = _gtk_border_image_new (pattern, &slice, width, &repeat);
1388 g_value_take_boxed (value, image);
1392 if (pattern != NULL)
1393 cairo_pattern_destroy (pattern);
1396 g_boxed_free (boxed_type, boxed);
1399 gtk_border_free (width);
1405 enum_value_parse (GtkCssParser *parser,
1411 if (enum_parse (parser, G_VALUE_TYPE (value), &v))
1413 g_value_set_enum (value, v);
1421 enum_value_print (const GValue *value,
1424 enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
1428 flags_value_parse (GtkCssParser *parser,
1432 GFlagsClass *flags_class;
1433 GFlagsValue *flag_value;
1437 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1440 str = _gtk_css_parser_try_ident (parser, TRUE);
1443 _gtk_css_parser_error (parser, "Expected an identifier");
1444 g_type_class_unref (flags_class);
1448 flag_value = g_flags_get_value_by_nick (flags_class, str);
1451 _gtk_css_parser_error (parser,
1452 "Unknown flag value '%s' for type '%s'",
1453 str, g_type_name (G_VALUE_TYPE (value)));
1454 /* XXX Do we want to return FALSE here? We can get
1455 * forward-compatibility for new values this way
1458 g_type_class_unref (flags_class);
1464 while (_gtk_css_parser_try (parser, ",", FALSE));
1466 g_type_class_unref (flags_class);
1468 g_value_set_enum (value, flags);
1474 flags_value_print (const GValue *value,
1477 GFlagsClass *flags_class;
1480 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1481 flags = g_value_get_flags (value);
1483 for (i = 0; i < flags_class->n_values; i++)
1485 GFlagsValue *flags_value = &flags_class->values[i];
1487 if (flags & flags_value->value)
1489 if (string->len != 0)
1490 g_string_append (string, ", ");
1492 g_string_append (string, flags_value->value_nick);
1496 g_type_class_unref (flags_class);
1500 bindings_value_parse (GtkCssParser *parser,
1505 GtkBindingSet *binding_set;
1508 array = g_ptr_array_new ();
1511 name = _gtk_css_parser_try_ident (parser, TRUE);
1514 _gtk_css_parser_error (parser, "Not a valid binding name");
1515 g_ptr_array_free (array, TRUE);
1519 binding_set = gtk_binding_set_find (name);
1523 _gtk_css_parser_error (parser, "No binding set named '%s'", name);
1528 g_ptr_array_add (array, binding_set);
1531 while (_gtk_css_parser_try (parser, ",", TRUE));
1533 g_value_take_boxed (value, array);
1539 bindings_value_print (const GValue *value,
1545 array = g_value_get_boxed (value);
1547 for (i = 0; i < array->len; i++)
1549 GtkBindingSet *binding_set = g_ptr_array_index (array, i);
1552 g_string_append (string, ", ");
1553 g_string_append (string, binding_set->set_name);
1558 border_corner_radius_value_parse (GtkCssParser *parser,
1562 GtkCssBorderCornerRadius corner;
1564 if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
1566 _gtk_css_parser_error (parser, "Expected a number");
1569 else if (corner.horizontal < 0)
1572 if (!_gtk_css_parser_try_double (parser, &corner.vertical))
1573 corner.vertical = corner.horizontal;
1574 else if (corner.vertical < 0)
1577 g_value_set_boxed (value, &corner);
1581 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1586 border_corner_radius_value_print (const GValue *value,
1589 GtkCssBorderCornerRadius *corner;
1591 corner = g_value_get_boxed (value);
1595 g_string_append (string, "none");
1599 string_append_double (string, corner->horizontal);
1600 if (corner->horizontal != corner->vertical)
1602 g_string_append_c (string, ' ');
1603 string_append_double (string, corner->vertical);
1608 border_radius_value_parse (GtkCssParser *parser,
1612 GtkCssBorderRadius border;
1614 if (!_gtk_css_parser_try_double (parser, &border.top_left.horizontal))
1616 _gtk_css_parser_error (parser, "Expected a number");
1619 else if (border.top_left.horizontal < 0)
1622 if (_gtk_css_parser_try_double (parser, &border.top_right.horizontal))
1624 if (border.top_right.horizontal < 0)
1626 if (_gtk_css_parser_try_double (parser, &border.bottom_right.horizontal))
1628 if (border.bottom_right.horizontal < 0)
1630 if (!_gtk_css_parser_try_double (parser, &border.bottom_left.horizontal))
1631 border.bottom_left.horizontal = border.top_right.horizontal;
1632 else if (border.bottom_left.horizontal < 0)
1637 border.bottom_right.horizontal = border.top_left.horizontal;
1638 border.bottom_left.horizontal = border.top_right.horizontal;
1643 border.top_right.horizontal = border.top_left.horizontal;
1644 border.bottom_right.horizontal = border.top_left.horizontal;
1645 border.bottom_left.horizontal = border.top_left.horizontal;
1648 if (_gtk_css_parser_try (parser, "/", TRUE))
1650 if (!_gtk_css_parser_try_double (parser, &border.top_left.vertical))
1652 _gtk_css_parser_error (parser, "Expected a number");
1655 else if (border.top_left.vertical < 0)
1658 if (_gtk_css_parser_try_double (parser, &border.top_right.vertical))
1660 if (border.top_right.vertical < 0)
1662 if (_gtk_css_parser_try_double (parser, &border.bottom_right.vertical))
1664 if (border.bottom_right.vertical < 0)
1666 if (!_gtk_css_parser_try_double (parser, &border.bottom_left.vertical))
1667 border.bottom_left.vertical = border.top_right.vertical;
1668 else if (border.bottom_left.vertical < 0)
1673 border.bottom_right.vertical = border.top_left.vertical;
1674 border.bottom_left.vertical = border.top_right.vertical;
1679 border.top_right.vertical = border.top_left.vertical;
1680 border.bottom_right.vertical = border.top_left.vertical;
1681 border.bottom_left.vertical = border.top_left.vertical;
1686 border.top_left.vertical = border.top_left.horizontal;
1687 border.top_right.vertical = border.top_right.horizontal;
1688 border.bottom_right.vertical = border.bottom_right.horizontal;
1689 border.bottom_left.vertical = border.bottom_left.horizontal;
1692 /* border-radius is an int property for backwards-compat reasons */
1693 g_value_unset (value);
1694 g_value_init (value, GTK_TYPE_CSS_BORDER_RADIUS);
1695 g_value_set_boxed (value, &border);
1700 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1705 border_radius_value_print (const GValue *value,
1708 GtkCssBorderRadius *border;
1710 border = g_value_get_boxed (value);
1714 g_string_append (string, "none");
1718 string_append_double (string, border->top_left.horizontal);
1719 if (border->top_left.horizontal != border->top_right.horizontal ||
1720 border->top_left.horizontal != border->bottom_right.horizontal ||
1721 border->top_left.horizontal != border->bottom_left.horizontal)
1723 g_string_append_c (string, ' ');
1724 string_append_double (string, border->top_right.horizontal);
1725 if (border->top_left.horizontal != border->bottom_right.horizontal ||
1726 border->top_right.horizontal != border->bottom_left.horizontal)
1728 g_string_append_c (string, ' ');
1729 string_append_double (string, border->bottom_right.horizontal);
1730 if (border->top_right.horizontal != border->bottom_left.horizontal)
1732 g_string_append_c (string, ' ');
1733 string_append_double (string, border->bottom_left.horizontal);
1738 if (border->top_left.horizontal != border->top_left.vertical ||
1739 border->top_right.horizontal != border->top_right.vertical ||
1740 border->bottom_right.horizontal != border->bottom_right.vertical ||
1741 border->bottom_left.horizontal != border->bottom_left.vertical)
1743 g_string_append (string, " / ");
1744 string_append_double (string, border->top_left.vertical);
1745 if (border->top_left.vertical != border->top_right.vertical ||
1746 border->top_left.vertical != border->bottom_right.vertical ||
1747 border->top_left.vertical != border->bottom_left.vertical)
1749 g_string_append_c (string, ' ');
1750 string_append_double (string, border->top_right.vertical);
1751 if (border->top_left.vertical != border->bottom_right.vertical ||
1752 border->top_right.vertical != border->bottom_left.vertical)
1754 g_string_append_c (string, ' ');
1755 string_append_double (string, border->bottom_right.vertical);
1756 if (border->top_right.vertical != border->bottom_left.vertical)
1758 g_string_append_c (string, ' ');
1759 string_append_double (string, border->bottom_left.vertical);
1768 transparent_color_value_parse (GtkCssParser *parser,
1772 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1774 GdkRGBA transparent = { 0, 0, 0, 0 };
1776 g_value_set_boxed (value, &transparent);
1781 return rgba_value_parse (parser, base, value);
1785 border_color_shorthand_value_parse (GtkCssParser *parser,
1789 GtkSymbolicColor *symbolic;
1792 array = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_symbolic_color_unref);
1796 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1798 GdkRGBA transparent = { 0, 0, 0, 0 };
1800 symbolic = gtk_symbolic_color_new_literal (&transparent);
1804 symbolic = _gtk_css_parser_read_symbolic_color (parser);
1806 if (symbolic == NULL)
1810 g_ptr_array_add (array, symbolic);
1812 while (array->len < 4 &&
1813 !_gtk_css_parser_is_eof (parser) &&
1814 !_gtk_css_parser_begins_with (parser, ';') &&
1815 !_gtk_css_parser_begins_with (parser, '}'));
1820 g_assert_not_reached ();
1823 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 0)));
1826 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 0)));
1829 g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 1)));
1835 g_value_unset (value);
1836 g_value_init (value, G_TYPE_PTR_ARRAY);
1837 g_value_take_boxed (value, array);
1845 unpack_border (const GValue *value,
1852 GParameter *parameter = g_new0 (GParameter, 4);
1853 GtkBorder *border = g_value_get_boxed (value);
1855 parameter[0].name = top;
1856 g_value_init (¶meter[0].value, G_TYPE_INT);
1857 g_value_set_int (¶meter[0].value, border->top);
1858 parameter[1].name = left;
1859 g_value_init (¶meter[1].value, G_TYPE_INT);
1860 g_value_set_int (¶meter[1].value, border->left);
1861 parameter[2].name = bottom;
1862 g_value_init (¶meter[2].value, G_TYPE_INT);
1863 g_value_set_int (¶meter[2].value, border->bottom);
1864 parameter[3].name = right;
1865 g_value_init (¶meter[3].value, G_TYPE_INT);
1866 g_value_set_int (¶meter[3].value, border->right);
1873 pack_border (GValue *value,
1874 GtkStyleProperties *props,
1875 GtkStateFlags state,
1884 gtk_style_properties_get (props,
1897 g_value_set_boxed (value, &border);
1901 unpack_border_width (const GValue *value,
1904 return unpack_border (value, n_params,
1905 "border-top-width", "border-left-width",
1906 "border-bottom-width", "border-right-width");
1910 pack_border_width (GValue *value,
1911 GtkStyleProperties *props,
1912 GtkStateFlags state,
1913 GtkStylePropertyContext *context)
1915 pack_border (value, props, state,
1916 "border-top-width", "border-left-width",
1917 "border-bottom-width", "border-right-width");
1921 unpack_padding (const GValue *value,
1924 return unpack_border (value, n_params,
1925 "padding-top", "padding-left",
1926 "padding-bottom", "padding-right");
1930 pack_padding (GValue *value,
1931 GtkStyleProperties *props,
1932 GtkStateFlags state,
1933 GtkStylePropertyContext *context)
1935 pack_border (value, props, state,
1936 "padding-top", "padding-left",
1937 "padding-bottom", "padding-right");
1941 unpack_margin (const GValue *value,
1944 return unpack_border (value, n_params,
1945 "margin-top", "margin-left",
1946 "margin-bottom", "margin-right");
1950 pack_margin (GValue *value,
1951 GtkStyleProperties *props,
1952 GtkStateFlags state,
1953 GtkStylePropertyContext *context)
1955 pack_border (value, props, state,
1956 "margin-top", "margin-left",
1957 "margin-bottom", "margin-right");
1961 unpack_border_radius (const GValue *value,
1964 GParameter *parameter = g_new0 (GParameter, 4);
1965 GtkCssBorderRadius *border;
1967 if (G_VALUE_HOLDS_BOXED (value))
1968 border = g_value_get_boxed (value);
1972 parameter[0].name = "border-top-left-radius";
1973 g_value_init (¶meter[0].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1974 parameter[1].name = "border-top-right-radius";
1975 g_value_init (¶meter[1].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1976 parameter[2].name = "border-bottom-right-radius";
1977 g_value_init (¶meter[2].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1978 parameter[3].name = "border-bottom-left-radius";
1979 g_value_init (¶meter[3].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1982 g_value_set_boxed (¶meter[0].value, &border->top_left);
1983 g_value_set_boxed (¶meter[1].value, &border->top_right);
1984 g_value_set_boxed (¶meter[2].value, &border->bottom_right);
1985 g_value_set_boxed (¶meter[3].value, &border->bottom_left);
1993 pack_border_radius (GValue *value,
1994 GtkStyleProperties *props,
1995 GtkStateFlags state,
1996 GtkStylePropertyContext *context)
1998 GtkCssBorderCornerRadius *top_left;
2000 /* NB: We are an int property, so we have to resolve to an int here.
2001 * So we just resolve to an int. We pick one and stick to it.
2002 * Lesson learned: Don't query border-radius shorthand, query the
2003 * real properties instead. */
2004 gtk_style_properties_get (props,
2006 "border-top-left-radius", &top_left,
2010 g_value_set_int (value, top_left->horizontal);
2016 unpack_font_description (const GValue *value,
2019 GParameter *parameter = g_new0 (GParameter, 5);
2020 PangoFontDescription *description;
2024 /* For backwards compat, we only unpack values that are indeed set.
2025 * For strict CSS conformance we need to unpack all of them.
2026 * Note that we do set all of them in the parse function, so it
2027 * will not have effects when parsing CSS files. It will though
2028 * for custom style providers.
2031 description = g_value_get_boxed (value);
2035 mask = pango_font_description_get_set_fields (description);
2039 if (mask & PANGO_FONT_MASK_FAMILY)
2041 GPtrArray *strv = g_ptr_array_new ();
2043 g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
2044 g_ptr_array_add (strv, NULL);
2045 parameter[n].name = "font-family";
2046 g_value_init (¶meter[n].value, G_TYPE_STRV);
2047 g_value_take_boxed (¶meter[n].value,
2048 g_ptr_array_free (strv, FALSE));
2052 if (mask & PANGO_FONT_MASK_STYLE)
2054 parameter[n].name = "font-style";
2055 g_value_init (¶meter[n].value, PANGO_TYPE_STYLE);
2056 g_value_set_enum (¶meter[n].value,
2057 pango_font_description_get_style (description));
2061 if (mask & PANGO_FONT_MASK_VARIANT)
2063 parameter[n].name = "font-variant";
2064 g_value_init (¶meter[n].value, PANGO_TYPE_VARIANT);
2065 g_value_set_enum (¶meter[n].value,
2066 pango_font_description_get_variant (description));
2070 if (mask & PANGO_FONT_MASK_WEIGHT)
2072 parameter[n].name = "font-weight";
2073 g_value_init (¶meter[n].value, PANGO_TYPE_WEIGHT);
2074 g_value_set_enum (¶meter[n].value,
2075 pango_font_description_get_weight (description));
2079 if (mask & PANGO_FONT_MASK_SIZE)
2081 parameter[n].name = "font-size";
2082 g_value_init (¶meter[n].value, G_TYPE_DOUBLE);
2083 g_value_set_double (¶meter[n].value,
2084 (double) pango_font_description_get_size (description) / PANGO_SCALE);
2094 pack_font_description (GValue *value,
2095 GtkStyleProperties *props,
2096 GtkStateFlags state,
2097 GtkStylePropertyContext *context)
2099 PangoFontDescription *description;
2102 PangoVariant variant;
2106 gtk_style_properties_get (props,
2108 "font-family", &families,
2109 "font-style", &style,
2110 "font-variant", &variant,
2111 "font-weight", &weight,
2115 description = pango_font_description_new ();
2116 /* xxx: Can we set all the families here somehow? */
2118 pango_font_description_set_family (description, families[0]);
2119 pango_font_description_set_size (description, round (size * PANGO_SCALE));
2120 pango_font_description_set_style (description, style);
2121 pango_font_description_set_variant (description, variant);
2122 pango_font_description_set_weight (description, weight);
2124 g_strfreev (families);
2126 g_value_take_boxed (value, description);
2130 unpack_border_color (const GValue *value,
2133 GParameter *parameter = g_new0 (GParameter, 4);
2136 type = G_VALUE_TYPE (value);
2137 if (type == G_TYPE_PTR_ARRAY)
2138 type = GTK_TYPE_SYMBOLIC_COLOR;
2140 parameter[0].name = "border-top-color";
2141 g_value_init (¶meter[0].value, type);
2142 parameter[1].name = "border-right-color";
2143 g_value_init (¶meter[1].value, type);
2144 parameter[2].name = "border-bottom-color";
2145 g_value_init (¶meter[2].value, type);
2146 parameter[3].name = "border-left-color";
2147 g_value_init (¶meter[3].value, type);
2149 if (G_VALUE_TYPE (value) == G_TYPE_PTR_ARRAY)
2151 GPtrArray *array = g_value_get_boxed (value);
2154 for (i = 0; i < 4; i++)
2155 g_value_set_boxed (¶meter[i].value, g_ptr_array_index (array, i));
2159 /* can be RGBA or symbolic color */
2160 gpointer p = g_value_get_boxed (value);
2162 g_value_set_boxed (¶meter[0].value, p);
2163 g_value_set_boxed (¶meter[1].value, p);
2164 g_value_set_boxed (¶meter[2].value, p);
2165 g_value_set_boxed (¶meter[3].value, p);
2173 pack_border_color (GValue *value,
2174 GtkStyleProperties *props,
2175 GtkStateFlags state,
2176 GtkStylePropertyContext *context)
2178 /* NB: We are a color property, so we have to resolve to a color here.
2179 * So we just resolve to a color. We pick one and stick to it.
2180 * Lesson learned: Don't query border-color shorthand, query the
2181 * real properties instead. */
2182 g_value_unset (value);
2183 gtk_style_properties_get_property (props, "border-top-color", state, value);
2186 /*** UNSET FUNCS ***/
2189 unset_font_description (GtkStyleProperties *props,
2190 GtkStateFlags state)
2192 gtk_style_properties_unset_property (props, "font-family", state);
2193 gtk_style_properties_unset_property (props, "font-style", state);
2194 gtk_style_properties_unset_property (props, "font-variant", state);
2195 gtk_style_properties_unset_property (props, "font-weight", state);
2196 gtk_style_properties_unset_property (props, "font-size", state);
2200 unset_margin (GtkStyleProperties *props,
2201 GtkStateFlags state)
2203 gtk_style_properties_unset_property (props, "margin-top", state);
2204 gtk_style_properties_unset_property (props, "margin-right", state);
2205 gtk_style_properties_unset_property (props, "margin-bottom", state);
2206 gtk_style_properties_unset_property (props, "margin-left", state);
2210 unset_padding (GtkStyleProperties *props,
2211 GtkStateFlags state)
2213 gtk_style_properties_unset_property (props, "padding-top", state);
2214 gtk_style_properties_unset_property (props, "padding-right", state);
2215 gtk_style_properties_unset_property (props, "padding-bottom", state);
2216 gtk_style_properties_unset_property (props, "padding-left", state);
2220 unset_border_width (GtkStyleProperties *props,
2221 GtkStateFlags state)
2223 gtk_style_properties_unset_property (props, "border-top-width", state);
2224 gtk_style_properties_unset_property (props, "border-right-width", state);
2225 gtk_style_properties_unset_property (props, "border-bottom-width", state);
2226 gtk_style_properties_unset_property (props, "border-left-width", state);
2230 unset_border_radius (GtkStyleProperties *props,
2231 GtkStateFlags state)
2233 gtk_style_properties_unset_property (props, "border-top-right-radius", state);
2234 gtk_style_properties_unset_property (props, "border-bottom-right-radius", state);
2235 gtk_style_properties_unset_property (props, "border-bottom-left-radius", state);
2236 gtk_style_properties_unset_property (props, "border-top-left-radius", state);
2240 unset_border_color (GtkStyleProperties *props,
2241 GtkStateFlags state)
2243 gtk_style_properties_unset_property (props, "border-top-color", state);
2244 gtk_style_properties_unset_property (props, "border-right-color", state);
2245 gtk_style_properties_unset_property (props, "border-bottom-color", state);
2246 gtk_style_properties_unset_property (props, "border-left-color", state);
2250 unset_border_image (GtkStyleProperties *props,
2251 GtkStateFlags state)
2253 gtk_style_properties_unset_property (props, "border-image-source", state);
2254 gtk_style_properties_unset_property (props, "border-image-slice", state);
2255 gtk_style_properties_unset_property (props, "border-image-repeat", state);
2256 gtk_style_properties_unset_property (props, "border-image-width", state);
2262 _gtk_style_property_get_count (void)
2264 return __style_property_array ? __style_property_array->len : 0;
2267 const GtkStyleProperty *
2268 _gtk_style_property_get (guint id)
2270 g_assert (__style_property_array);
2272 return g_ptr_array_index (__style_property_array, id);
2276 _gtk_style_property_generate_id (GtkStyleProperty *node)
2278 if (__style_property_array == NULL)
2279 __style_property_array = g_ptr_array_new ();
2281 node->id = __style_property_array->len;
2282 g_ptr_array_add (__style_property_array, node);
2286 css_string_funcs_init (void)
2288 if (G_LIKELY (parse_funcs != NULL))
2291 parse_funcs = g_hash_table_new (NULL, NULL);
2292 print_funcs = g_hash_table_new (NULL, NULL);
2294 register_conversion_function (GDK_TYPE_RGBA,
2297 register_conversion_function (GDK_TYPE_COLOR,
2300 register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
2301 symbolic_color_value_parse,
2302 symbolic_color_value_print);
2303 register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
2304 font_description_value_parse,
2305 font_description_value_print);
2306 register_conversion_function (G_TYPE_BOOLEAN,
2307 boolean_value_parse,
2308 boolean_value_print);
2309 register_conversion_function (G_TYPE_INT,
2312 register_conversion_function (G_TYPE_UINT,
2315 register_conversion_function (G_TYPE_DOUBLE,
2317 double_value_print);
2318 register_conversion_function (G_TYPE_FLOAT,
2321 register_conversion_function (G_TYPE_STRING,
2323 string_value_print);
2324 register_conversion_function (GTK_TYPE_THEMING_ENGINE,
2325 theming_engine_value_parse,
2326 theming_engine_value_print);
2327 register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
2328 animation_description_value_parse,
2329 animation_description_value_print);
2330 register_conversion_function (GTK_TYPE_BORDER,
2332 border_value_print);
2333 register_conversion_function (GTK_TYPE_GRADIENT,
2334 gradient_value_parse,
2335 gradient_value_print);
2336 register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
2337 pattern_value_parse,
2338 pattern_value_print);
2339 register_conversion_function (GTK_TYPE_BORDER_IMAGE,
2340 border_image_value_parse,
2342 register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
2343 border_image_repeat_value_parse,
2344 border_image_repeat_value_print);
2345 register_conversion_function (GTK_TYPE_SHADOW,
2347 shadow_value_print);
2348 register_conversion_function (G_TYPE_ENUM,
2351 register_conversion_function (G_TYPE_FLAGS,
2354 register_conversion_function (GTK_TYPE_CSS_BACKGROUND_REPEAT,
2355 background_repeat_value_parse,
2356 background_repeat_value_print);
2360 _gtk_style_property_parse_value (const GtkStyleProperty *property,
2362 GtkCssParser *parser,
2365 GtkStyleParseFunc func;
2367 g_return_val_if_fail (value != NULL, FALSE);
2368 g_return_val_if_fail (parser != NULL, FALSE);
2370 css_string_funcs_init ();
2374 if (_gtk_css_parser_try (parser, "initial", TRUE))
2376 /* the initial value can be explicitly specified with the
2377 * ‘initial’ keyword which all properties accept.
2379 g_value_unset (value);
2380 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
2381 g_value_set_enum (value, GTK_CSS_INITIAL);
2384 else if (_gtk_css_parser_try (parser, "inherit", TRUE))
2386 /* All properties accept the ‘inherit’ value which
2387 * explicitly specifies that the value will be determined
2388 * by inheritance. The ‘inherit’ value can be used to
2389 * strengthen inherited values in the cascade, and it can
2390 * also be used on properties that are not normally inherited.
2392 g_value_unset (value);
2393 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
2394 g_value_set_enum (value, GTK_CSS_INHERIT);
2397 else if (property->property_parse_func)
2399 GError *error = NULL;
2403 value_str = _gtk_css_parser_read_value (parser);
2404 if (value_str == NULL)
2407 success = (*property->property_parse_func) (value_str, value, &error);
2414 func = property->parse_func;
2420 func = g_hash_table_lookup (parse_funcs,
2421 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
2423 func = g_hash_table_lookup (parse_funcs,
2424 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
2428 _gtk_css_parser_error (parser,
2429 "Cannot convert to type '%s'",
2430 g_type_name (G_VALUE_TYPE (value)));
2434 return (*func) (parser, base, value);
2438 _gtk_style_property_print_value (const GtkStyleProperty *property,
2439 const GValue *value,
2442 GtkStylePrintFunc func;
2444 css_string_funcs_init ();
2446 if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
2447 func = enum_value_print;
2449 func = property->print_func;
2454 func = g_hash_table_lookup (print_funcs,
2455 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
2457 func = g_hash_table_lookup (print_funcs,
2458 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
2462 char *s = g_strdup_value_contents (value);
2463 g_string_append (string, s);
2468 func (value, string);
2472 _gtk_style_property_default_value (const GtkStyleProperty *property,
2473 GtkStyleProperties *properties,
2474 GtkStateFlags state,
2477 g_value_copy (&property->initial_value, value);
2481 _gtk_style_property_is_inherit (const GtkStyleProperty *property)
2483 g_return_val_if_fail (property != NULL, FALSE);
2485 return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
2489 _gtk_style_property_get_id (const GtkStyleProperty *property)
2491 g_return_val_if_fail (property != NULL, FALSE);
2493 return property->id;
2497 resolve_color (GtkStyleProperties *props,
2502 /* Resolve symbolic color to GdkRGBA */
2503 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
2506 /* Store it back, this is where GdkRGBA caching happens */
2507 g_value_unset (value);
2508 g_value_init (value, GDK_TYPE_RGBA);
2509 g_value_set_boxed (value, &color);
2515 resolve_color_rgb (GtkStyleProperties *props,
2518 GdkColor color = { 0 };
2521 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
2524 color.red = rgba.red * 65535. + 0.5;
2525 color.green = rgba.green * 65535. + 0.5;
2526 color.blue = rgba.blue * 65535. + 0.5;
2528 g_value_unset (value);
2529 g_value_init (value, GDK_TYPE_COLOR);
2530 g_value_set_boxed (value, &color);
2536 resolve_win32_theme_part (GtkStyleProperties *props,
2539 GtkStylePropertyContext *context)
2541 GtkWin32ThemePart *part;
2542 cairo_pattern_t *pattern;
2544 part = g_value_get_boxed (value);
2548 pattern = _gtk_win32_theme_part_render (part, context->width, context->height);
2550 g_value_take_boxed (value_out, pattern);
2557 resolve_gradient (GtkStyleProperties *props,
2560 cairo_pattern_t *gradient;
2562 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
2565 /* Store it back, this is where cairo_pattern_t caching happens */
2566 g_value_unset (value);
2567 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
2568 g_value_take_boxed (value, gradient);
2574 resolve_shadow (GtkStyleProperties *props,
2577 GtkShadow *resolved, *base;
2579 base = g_value_get_boxed (value);
2584 if (_gtk_shadow_get_resolved (base))
2587 resolved = _gtk_shadow_resolve (base, props);
2588 if (resolved == NULL)
2591 g_value_take_boxed (value, resolved);
2597 _gtk_style_property_resolve (const GtkStyleProperty *property,
2598 GtkStyleProperties *props,
2599 GtkStateFlags state,
2600 GtkStylePropertyContext *context,
2604 if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_SPECIAL_VALUE)
2606 GtkCssSpecialValue special = g_value_get_enum (val);
2608 g_value_unset (val);
2611 case GTK_CSS_CURRENT_COLOR:
2612 g_assert (property->pspec->value_type == GDK_TYPE_RGBA);
2613 gtk_style_properties_get_property (props, "color", state, val);
2615 case GTK_CSS_INHERIT:
2616 case GTK_CSS_INITIAL:
2618 g_assert_not_reached ();
2621 else if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
2623 if (property->pspec->value_type == GDK_TYPE_RGBA)
2625 if (resolve_color (props, val))
2628 else if (property->pspec->value_type == GDK_TYPE_COLOR)
2630 if (resolve_color_rgb (props, val))
2634 g_value_unset (val);
2635 g_value_init (val, property->pspec->value_type);
2636 _gtk_style_property_default_value (property, props, state, val);
2638 else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
2640 if (g_value_get_boxed (val) == NULL)
2641 _gtk_style_property_default_value (property, props, state, val);
2643 else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
2645 g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
2647 if (!resolve_gradient (props, val))
2649 g_value_unset (val);
2650 g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
2651 _gtk_style_property_default_value (property, props, state, val);
2654 else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
2656 if (!resolve_shadow (props, val))
2657 _gtk_style_property_default_value (property, props, state, val);
2659 else if (G_VALUE_TYPE (val) == GTK_TYPE_WIN32_THEME_PART)
2661 if (resolve_win32_theme_part (props, val, val_out, context))
2662 return; /* Don't copy val, this sets val_out */
2663 _gtk_style_property_default_value (property, props, state, val);
2667 g_value_copy (val, val_out);
2671 _gtk_style_property_get_initial_value (const GtkStyleProperty *property)
2673 g_return_val_if_fail (property != NULL, NULL);
2675 return &property->initial_value;
2679 _gtk_style_property_unpack (const GtkStyleProperty *property,
2680 const GValue *value,
2683 g_return_val_if_fail (property != NULL, NULL);
2684 g_return_val_if_fail (property->unpack_func != NULL, NULL);
2685 g_return_val_if_fail (value != NULL, NULL);
2686 g_return_val_if_fail (n_params != NULL, NULL);
2688 return property->unpack_func (value, n_params);
2692 _gtk_style_property_pack (const GtkStyleProperty *property,
2693 GtkStyleProperties *props,
2694 GtkStateFlags state,
2695 GtkStylePropertyContext *context,
2698 g_return_if_fail (property != NULL);
2699 g_return_if_fail (property->pack_func != NULL);
2700 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2701 g_return_if_fail (G_IS_VALUE (value));
2703 property->pack_func (value, props, state, context);
2707 _gtk_style_property_query (const GtkStyleProperty *property,
2708 GtkStyleProperties *props,
2709 GtkStateFlags state,
2710 GtkStylePropertyContext *context,
2715 g_return_if_fail (property != NULL);
2716 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2717 g_return_if_fail (context != NULL);
2718 g_return_if_fail (value != NULL);
2720 val = _gtk_style_properties_peek_property (props, property, state);
2721 g_value_init (value, property->pspec->value_type);
2724 _gtk_style_property_resolve (property, props, state, context, (GValue *) val, value);
2725 else if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
2726 _gtk_style_property_pack (property, props, state, context, value);
2728 _gtk_style_property_default_value (property, props, state, value);
2731 #define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
2732 (rgba)->red = (r); \
2733 (rgba)->green = (g); \
2734 (rgba)->blue = (b); \
2735 (rgba)->alpha = (a); \
2738 gtk_style_property_init (void)
2740 GValue value = { 0, };
2741 char *default_font_family[] = { "Sans", NULL };
2744 if (G_LIKELY (properties))
2747 /* stuff is never freed, so no need for free functions */
2748 properties = g_hash_table_new (g_str_hash, g_str_equal);
2750 /* note that gtk_style_properties_register_property() calls this function,
2751 * so make sure we're sanely inited to avoid infloops */
2753 g_value_init (&value, GDK_TYPE_RGBA);
2754 rgba_init (&rgba, 1, 1, 1, 1);
2755 g_value_set_boxed (&value, &rgba);
2756 _gtk_style_property_register (g_param_spec_boxed ("color",
2760 GTK_STYLE_PROPERTY_INHERIT,
2768 rgba_init (&rgba, 0, 0, 0, 0);
2769 g_value_set_boxed (&value, &rgba);
2770 _gtk_style_property_register (g_param_spec_boxed ("background-color",
2778 transparent_color_value_parse,
2782 g_value_unset (&value);
2784 g_value_init (&value, G_TYPE_STRV);
2785 g_value_set_boxed (&value, default_font_family);
2786 _gtk_style_property_register (g_param_spec_boxed ("font-family",
2790 GTK_STYLE_PROPERTY_INHERIT,
2795 font_family_value_print,
2798 g_value_unset (&value);
2799 _gtk_style_property_register (g_param_spec_enum ("font-style",
2803 PANGO_STYLE_NORMAL, 0),
2804 GTK_STYLE_PROPERTY_INHERIT,
2812 _gtk_style_property_register (g_param_spec_enum ("font-variant",
2816 PANGO_VARIANT_NORMAL, 0),
2817 GTK_STYLE_PROPERTY_INHERIT,
2825 /* xxx: need to parse this properly, ie parse the numbers */
2826 _gtk_style_property_register (g_param_spec_enum ("font-weight",
2830 PANGO_WEIGHT_NORMAL, 0),
2831 GTK_STYLE_PROPERTY_INHERIT,
2839 g_value_init (&value, G_TYPE_DOUBLE);
2840 g_value_set_double (&value, 10);
2841 _gtk_style_property_register (g_param_spec_double ("font-size",
2844 0, G_MAXDOUBLE, 0, 0),
2845 GTK_STYLE_PROPERTY_INHERIT,
2853 g_value_unset (&value);
2854 _gtk_style_property_register (g_param_spec_boxed ("font",
2857 PANGO_TYPE_FONT_DESCRIPTION, 0),
2858 GTK_STYLE_PROPERTY_INHERIT,
2860 unpack_font_description,
2861 pack_font_description,
2862 font_description_value_parse,
2863 font_description_value_print,
2865 unset_font_description);
2867 _gtk_style_property_register (g_param_spec_boxed ("text-shadow",
2870 GTK_TYPE_SHADOW, 0),
2871 GTK_STYLE_PROPERTY_INHERIT,
2880 _gtk_style_property_register (g_param_spec_boxed ("icon-shadow",
2883 GTK_TYPE_SHADOW, 0),
2884 GTK_STYLE_PROPERTY_INHERIT,
2893 gtk_style_properties_register_property (NULL,
2894 g_param_spec_boxed ("box-shadow",
2897 GTK_TYPE_SHADOW, 0));
2898 gtk_style_properties_register_property (NULL,
2899 g_param_spec_int ("margin-top",
2902 0, G_MAXINT, 0, 0));
2903 gtk_style_properties_register_property (NULL,
2904 g_param_spec_int ("margin-left",
2907 0, G_MAXINT, 0, 0));
2908 gtk_style_properties_register_property (NULL,
2909 g_param_spec_int ("margin-bottom",
2912 0, G_MAXINT, 0, 0));
2913 gtk_style_properties_register_property (NULL,
2914 g_param_spec_int ("margin-right",
2917 0, G_MAXINT, 0, 0));
2918 _gtk_style_property_register (g_param_spec_boxed ("margin",
2921 GTK_TYPE_BORDER, 0),
2930 gtk_style_properties_register_property (NULL,
2931 g_param_spec_int ("padding-top",
2934 0, G_MAXINT, 0, 0));
2935 gtk_style_properties_register_property (NULL,
2936 g_param_spec_int ("padding-left",
2939 0, G_MAXINT, 0, 0));
2940 gtk_style_properties_register_property (NULL,
2941 g_param_spec_int ("padding-bottom",
2943 "Padding at bottom",
2944 0, G_MAXINT, 0, 0));
2945 gtk_style_properties_register_property (NULL,
2946 g_param_spec_int ("padding-right",
2949 0, G_MAXINT, 0, 0));
2950 _gtk_style_property_register (g_param_spec_boxed ("padding",
2953 GTK_TYPE_BORDER, 0),
2962 gtk_style_properties_register_property (NULL,
2963 g_param_spec_int ("border-top-width",
2965 "Border width at top",
2966 0, G_MAXINT, 0, 0));
2967 gtk_style_properties_register_property (NULL,
2968 g_param_spec_int ("border-left-width",
2969 "border left width",
2970 "Border width at left",
2971 0, G_MAXINT, 0, 0));
2972 gtk_style_properties_register_property (NULL,
2973 g_param_spec_int ("border-bottom-width",
2974 "border bottom width",
2975 "Border width at bottom",
2976 0, G_MAXINT, 0, 0));
2977 gtk_style_properties_register_property (NULL,
2978 g_param_spec_int ("border-right-width",
2979 "border right width",
2980 "Border width at right",
2981 0, G_MAXINT, 0, 0));
2982 _gtk_style_property_register (g_param_spec_boxed ("border-width",
2984 "Border width, in pixels",
2985 GTK_TYPE_BORDER, 0),
2988 unpack_border_width,
2993 unset_border_width);
2995 _gtk_style_property_register (g_param_spec_boxed ("border-top-left-radius",
2996 "Border top left radius",
2997 "Border radius of top left corner, in pixels",
2998 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
3003 border_corner_radius_value_parse,
3004 border_corner_radius_value_print,
3007 _gtk_style_property_register (g_param_spec_boxed ("border-top-right-radius",
3008 "Border top right radius",
3009 "Border radius of top right corner, in pixels",
3010 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
3015 border_corner_radius_value_parse,
3016 border_corner_radius_value_print,
3019 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-right-radius",
3020 "Border bottom right radius",
3021 "Border radius of bottom right corner, in pixels",
3022 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
3027 border_corner_radius_value_parse,
3028 border_corner_radius_value_print,
3031 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-left-radius",
3032 "Border bottom left radius",
3033 "Border radius of bottom left corner, in pixels",
3034 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
3039 border_corner_radius_value_parse,
3040 border_corner_radius_value_print,
3043 _gtk_style_property_register (g_param_spec_int ("border-radius",
3045 "Border radius, in pixels",
3049 unpack_border_radius,
3051 border_radius_value_parse,
3052 border_radius_value_print,
3054 unset_border_radius);
3056 gtk_style_properties_register_property (NULL,
3057 g_param_spec_enum ("border-style",
3060 GTK_TYPE_BORDER_STYLE,
3061 GTK_BORDER_STYLE_NONE, 0));
3062 gtk_style_properties_register_property (NULL,
3063 g_param_spec_enum ("background-clip",
3067 GTK_CSS_AREA_BORDER_BOX, 0));
3068 gtk_style_properties_register_property (NULL,
3069 g_param_spec_enum ("background-origin",
3070 "Background origin",
3071 "Background origin",
3073 GTK_CSS_AREA_PADDING_BOX, 0));
3074 g_value_init (&value, GTK_TYPE_CSS_SPECIAL_VALUE);
3075 g_value_set_enum (&value, GTK_CSS_CURRENT_COLOR);
3076 _gtk_style_property_register (g_param_spec_boxed ("border-top-color",
3084 transparent_color_value_parse,
3088 _gtk_style_property_register (g_param_spec_boxed ("border-right-color",
3089 "Border right color",
3090 "Border right color",
3096 transparent_color_value_parse,
3100 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-color",
3101 "Border bottom color",
3102 "Border bottom color",
3108 transparent_color_value_parse,
3112 _gtk_style_property_register (g_param_spec_boxed ("border-left-color",
3113 "Border left color",
3114 "Border left color",
3120 transparent_color_value_parse,
3124 g_value_unset (&value);
3125 _gtk_style_property_register (g_param_spec_boxed ("border-color",
3131 unpack_border_color,
3133 border_color_shorthand_value_parse,
3136 unset_border_color);
3138 gtk_style_properties_register_property (NULL,
3139 g_param_spec_boxed ("background-image",
3142 CAIRO_GOBJECT_TYPE_PATTERN, 0));
3143 gtk_style_properties_register_property (NULL,
3144 g_param_spec_boxed ("background-repeat",
3145 "Background repeat",
3146 "Background repeat",
3147 GTK_TYPE_CSS_BACKGROUND_REPEAT, 0));
3149 gtk_style_properties_register_property (NULL,
3150 g_param_spec_boxed ("border-image-source",
3151 "Border image source",
3152 "Border image source",
3153 CAIRO_GOBJECT_TYPE_PATTERN, 0));
3154 gtk_style_properties_register_property (NULL,
3155 g_param_spec_boxed ("border-image-repeat",
3156 "Border image repeat",
3157 "Border image repeat",
3158 GTK_TYPE_CSS_BORDER_IMAGE_REPEAT, 0));
3159 gtk_style_properties_register_property (NULL,
3160 g_param_spec_boxed ("border-image-slice",
3161 "Border image slice",
3162 "Border image slice",
3163 GTK_TYPE_BORDER, 0));
3164 g_value_init (&value, GTK_TYPE_BORDER);
3165 _gtk_style_property_register (g_param_spec_boxed ("border-image-width",
3166 "Border image width",
3167 "Border image width",
3168 GTK_TYPE_BORDER, 0),
3177 g_value_unset (&value);
3178 _gtk_style_property_register (g_param_spec_boxed ("border-image",
3181 GTK_TYPE_BORDER_IMAGE, 0),
3184 _gtk_border_image_unpack,
3185 _gtk_border_image_pack,
3189 unset_border_image);
3190 gtk_style_properties_register_property (NULL,
3191 g_param_spec_object ("engine",
3194 GTK_TYPE_THEMING_ENGINE, 0));
3195 gtk_style_properties_register_property (NULL,
3196 g_param_spec_boxed ("transition",
3197 "Transition animation description",
3198 "Transition animation description",
3199 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
3201 /* Private property holding the binding sets */
3202 _gtk_style_property_register (g_param_spec_boxed ("gtk-key-bindings",
3205 G_TYPE_PTR_ARRAY, 0),
3210 bindings_value_parse,
3211 bindings_value_print,
3216 const GtkStyleProperty *
3217 _gtk_style_property_lookup (const char *name)
3219 gtk_style_property_init ();
3221 return g_hash_table_lookup (properties, name);
3225 _gtk_style_property_register (GParamSpec *pspec,
3226 GtkStylePropertyFlags flags,
3227 GtkStylePropertyParser property_parse_func,
3228 GtkStyleUnpackFunc unpack_func,
3229 GtkStylePackFunc pack_func,
3230 GtkStyleParseFunc parse_func,
3231 GtkStylePrintFunc print_func,
3232 const GValue * initial_value,
3233 GtkStyleUnsetFunc unset_func)
3235 const GtkStyleProperty *existing;
3236 GtkStyleProperty *node;
3238 g_return_if_fail ((pack_func == NULL) == (unpack_func == NULL));
3240 gtk_style_property_init ();
3242 existing = _gtk_style_property_lookup (pspec->name);
3243 if (existing != NULL)
3245 g_warning ("Property \"%s\" was already registered with type %s",
3246 pspec->name, g_type_name (existing->pspec->value_type));
3250 if (pack_func == NULL)
3251 node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY, NULL);
3253 node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY, NULL);
3254 node->flags = flags;
3255 node->pspec = pspec;
3256 node->property_parse_func = property_parse_func;
3257 node->pack_func = pack_func;
3258 node->unpack_func = unpack_func;
3259 node->parse_func = parse_func;
3260 node->print_func = print_func;
3261 node->unset_func = unset_func;
3263 if (!GTK_IS_CSS_SHORTHAND_PROPERTY (node))
3265 _gtk_style_property_generate_id (node);
3267 /* initialize the initial value */
3270 g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value));
3271 g_value_copy (initial_value, &node->initial_value);
3275 g_value_init (&node->initial_value, pspec->value_type);
3276 if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
3277 g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
3278 else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
3279 g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10"));
3280 else if (pspec->value_type == GDK_TYPE_RGBA)
3283 gdk_rgba_parse (&color, "pink");
3284 g_value_set_boxed (&node->initial_value, &color);
3286 else if (pspec->value_type == GTK_TYPE_BORDER)
3288 g_value_take_boxed (&node->initial_value, gtk_border_new ());
3291 g_param_value_set_default (pspec, &node->initial_value);
3295 /* pspec owns name */
3296 g_hash_table_insert (properties, (gchar *)pspec->name, node);