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"
38 #include "gtkprivatetypebuiltins.h"
39 #include "gtkstylepropertiesprivate.h"
41 /* the actual parsers we have */
42 #include "gtkanimationdescription.h"
43 #include "gtkbindings.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"
61 static GHashTable *parse_funcs = NULL;
62 static GHashTable *print_funcs = NULL;
63 static GPtrArray *__style_property_array = NULL;
65 G_DEFINE_ABSTRACT_TYPE (GtkStyleProperty, _gtk_style_property, G_TYPE_OBJECT)
68 gtk_style_property_finalize (GObject *object)
70 GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
72 g_warning ("finalizing %s `%s', how could this happen?", G_OBJECT_TYPE_NAME (object), property->name);
74 G_OBJECT_CLASS (_gtk_style_property_parent_class)->finalize (object);
78 gtk_style_property_set_property (GObject *object,
83 GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
84 GtkStylePropertyClass *klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
89 property->name = g_value_dup_string (value);
90 g_assert (property->name);
91 g_assert (g_hash_table_lookup (klass->properties, property->name) == NULL);
92 g_hash_table_insert (klass->properties, property->name, property);
95 property->value_type = g_value_get_gtype (value);
98 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
104 gtk_style_property_get_property (GObject *object,
109 GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
114 g_value_set_string (value, property->name);
116 case PROP_VALUE_TYPE:
117 g_value_set_gtype (value, property->value_type);
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
126 _gtk_style_property_class_init (GtkStylePropertyClass *klass)
128 GObjectClass *object_class = G_OBJECT_CLASS (klass);
130 object_class->finalize = gtk_style_property_finalize;
131 object_class->set_property = gtk_style_property_set_property;
132 object_class->get_property = gtk_style_property_get_property;
134 g_object_class_install_property (object_class,
136 g_param_spec_string ("name",
138 P_("The name of the property"),
140 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
141 g_object_class_install_property (object_class,
143 g_param_spec_gtype ("value-type",
145 P_("The value type returned by GtkStyleContext"),
147 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
149 klass->properties = g_hash_table_new (g_str_hash, g_str_equal);
153 _gtk_style_property_init (GtkStyleProperty *property)
155 property->value_type = G_TYPE_NONE;
159 register_conversion_function (GType type,
160 GtkStyleParseFunc parse,
161 GtkStylePrintFunc print)
164 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
166 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
170 string_append_double (GString *string,
173 char buf[G_ASCII_DTOSTR_BUF_SIZE];
175 g_ascii_dtostr (buf, sizeof (buf), d);
176 g_string_append (string, buf);
180 string_append_string (GString *str,
185 g_string_append_c (str, '"');
188 len = strcspn (string, "\"\n\r\f");
189 g_string_append (str, string);
196 g_string_append (str, "\\A ");
199 g_string_append (str, "\\D ");
202 g_string_append (str, "\\C ");
205 g_string_append (str, "\\\"");
208 g_assert_not_reached ();
213 g_string_append_c (str, '"');
216 /*** IMPLEMENTATIONS ***/
219 enum_parse (GtkCssParser *parser,
225 if (_gtk_css_parser_try_enum (parser, type, res))
228 str = _gtk_css_parser_try_ident (parser, TRUE);
231 _gtk_css_parser_error (parser, "Expected an identifier");
235 _gtk_css_parser_error (parser,
236 "Unknown value '%s' for enum type '%s'",
237 str, g_type_name (type));
244 enum_print (int value,
248 GEnumClass *enum_class;
249 GEnumValue *enum_value;
251 enum_class = g_type_class_ref (type);
252 enum_value = g_enum_get_value (enum_class, value);
254 g_string_append (string, enum_value->value_nick);
256 g_type_class_unref (enum_class);
260 rgba_value_parse (GtkCssParser *parser,
264 GtkSymbolicColor *symbolic;
267 symbolic = _gtk_css_parser_read_symbolic_color (parser);
268 if (symbolic == NULL)
271 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
273 g_value_set_boxed (value, &rgba);
274 gtk_symbolic_color_unref (symbolic);
278 g_value_unset (value);
279 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
280 g_value_take_boxed (value, symbolic);
287 rgba_value_print (const GValue *value,
290 const GdkRGBA *rgba = g_value_get_boxed (value);
293 g_string_append (string, "none");
296 char *s = gdk_rgba_to_string (rgba);
297 g_string_append (string, s);
303 color_value_parse (GtkCssParser *parser,
307 GtkSymbolicColor *symbolic;
310 symbolic = _gtk_css_parser_read_symbolic_color (parser);
311 if (symbolic == NULL)
314 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
318 color.red = rgba.red * 65535. + 0.5;
319 color.green = rgba.green * 65535. + 0.5;
320 color.blue = rgba.blue * 65535. + 0.5;
322 g_value_set_boxed (value, &color);
326 g_value_unset (value);
327 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
328 g_value_take_boxed (value, symbolic);
335 color_value_print (const GValue *value,
338 const GdkColor *color = g_value_get_boxed (value);
341 g_string_append (string, "none");
344 char *s = gdk_color_to_string (color);
345 g_string_append (string, s);
351 symbolic_color_value_parse (GtkCssParser *parser,
355 GtkSymbolicColor *symbolic;
357 symbolic = _gtk_css_parser_read_symbolic_color (parser);
358 if (symbolic == NULL)
361 g_value_take_boxed (value, symbolic);
366 symbolic_color_value_print (const GValue *value,
369 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
371 if (symbolic == NULL)
372 g_string_append (string, "none");
375 char *s = gtk_symbolic_color_to_string (symbolic);
376 g_string_append (string, s);
382 font_family_parse (GtkCssParser *parser,
389 /* We don't special case generic families. Pango should do
392 names = g_ptr_array_new ();
395 name = _gtk_css_parser_try_ident (parser, TRUE);
398 GString *string = g_string_new (name);
400 while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
402 g_string_append_c (string, ' ');
403 g_string_append (string, name);
406 name = g_string_free (string, FALSE);
410 name = _gtk_css_parser_read_string (parser);
413 g_ptr_array_free (names, TRUE);
418 g_ptr_array_add (names, name);
419 } while (_gtk_css_parser_try (parser, ",", TRUE));
421 /* NULL-terminate array */
422 g_ptr_array_add (names, NULL);
423 g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
428 font_family_value_print (const GValue *value,
431 const char **names = g_value_get_boxed (value);
433 if (names == NULL || *names == NULL)
435 g_string_append (string, "none");
439 string_append_string (string, *names);
443 g_string_append (string, ", ");
444 string_append_string (string, *names);
450 font_description_value_parse (GtkCssParser *parser,
454 PangoFontDescription *font_desc;
458 str = _gtk_css_parser_read_value (parser);
462 font_desc = pango_font_description_from_string (str);
463 mask = pango_font_description_get_set_fields (font_desc);
464 /* These values are not really correct,
465 * but the fields must be set, so we set them to something */
466 if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
467 pango_font_description_set_family_static (font_desc, "Sans");
468 if ((mask & PANGO_FONT_MASK_SIZE) == 0)
469 pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
471 g_value_take_boxed (value, font_desc);
476 font_description_value_print (const GValue *value,
479 const PangoFontDescription *desc = g_value_get_boxed (value);
482 g_string_append (string, "none");
485 char *s = pango_font_description_to_string (desc);
486 g_string_append (string, s);
492 boolean_value_parse (GtkCssParser *parser,
496 if (_gtk_css_parser_try (parser, "true", TRUE) ||
497 _gtk_css_parser_try (parser, "1", TRUE))
499 g_value_set_boolean (value, TRUE);
502 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
503 _gtk_css_parser_try (parser, "0", TRUE))
505 g_value_set_boolean (value, FALSE);
510 _gtk_css_parser_error (parser, "Expected a boolean value");
516 boolean_value_print (const GValue *value,
519 if (g_value_get_boolean (value))
520 g_string_append (string, "true");
522 g_string_append (string, "false");
526 int_value_parse (GtkCssParser *parser,
532 if (_gtk_css_parser_begins_with (parser, '-'))
534 int res = _gtk_win32_theme_int_parse (parser, base, &i);
537 g_value_set_int (value, i);
540 /* < 0 => continue */
543 if (!_gtk_css_parser_try_int (parser, &i))
545 _gtk_css_parser_error (parser, "Expected a valid integer value");
549 g_value_set_int (value, i);
554 int_value_print (const GValue *value,
557 g_string_append_printf (string, "%d", g_value_get_int (value));
561 uint_value_parse (GtkCssParser *parser,
567 if (!_gtk_css_parser_try_uint (parser, &u))
569 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
573 g_value_set_uint (value, u);
578 uint_value_print (const GValue *value,
581 g_string_append_printf (string, "%u", g_value_get_uint (value));
585 double_value_parse (GtkCssParser *parser,
591 if (!_gtk_css_parser_try_double (parser, &d))
593 _gtk_css_parser_error (parser, "Expected a number");
597 g_value_set_double (value, d);
602 double_value_print (const GValue *value,
605 string_append_double (string, g_value_get_double (value));
609 float_value_parse (GtkCssParser *parser,
615 if (!_gtk_css_parser_try_double (parser, &d))
617 _gtk_css_parser_error (parser, "Expected a number");
621 g_value_set_float (value, d);
626 float_value_print (const GValue *value,
629 string_append_double (string, g_value_get_float (value));
633 string_value_parse (GtkCssParser *parser,
637 char *str = _gtk_css_parser_read_string (parser);
642 g_value_take_string (value, str);
647 string_value_print (const GValue *value,
650 string_append_string (str, g_value_get_string (value));
654 theming_engine_value_parse (GtkCssParser *parser,
658 GtkThemingEngine *engine;
661 if (_gtk_css_parser_try (parser, "none", TRUE))
663 g_value_set_object (value, gtk_theming_engine_load (NULL));
667 str = _gtk_css_parser_try_ident (parser, TRUE);
670 _gtk_css_parser_error (parser, "Expected a valid theme name");
674 engine = gtk_theming_engine_load (str);
678 _gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
683 g_value_set_object (value, engine);
689 theming_engine_value_print (const GValue *value,
692 GtkThemingEngine *engine;
695 engine = g_value_get_object (value);
697 g_string_append (string, "none");
700 /* XXX: gtk_theming_engine_get_name()? */
701 g_object_get (engine, "name", &name, NULL);
702 g_string_append (string, name ? name : "none");
708 animation_description_value_parse (GtkCssParser *parser,
712 GtkAnimationDescription *desc;
715 str = _gtk_css_parser_read_value (parser);
719 desc = _gtk_animation_description_from_string (str);
724 _gtk_css_parser_error (parser, "Invalid animation description");
728 g_value_take_boxed (value, desc);
733 animation_description_value_print (const GValue *value,
736 GtkAnimationDescription *desc = g_value_get_boxed (value);
739 g_string_append (string, "none");
741 _gtk_animation_description_print (desc, string);
745 border_value_parse (GtkCssParser *parser,
749 GtkBorder border = { 0, };
752 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
754 if (_gtk_css_parser_begins_with (parser, '-'))
756 /* These are strictly speaking signed, but we want to be able to use them
757 for unsigned types too, as the actual ranges of values make this safe */
758 int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
760 if (res == 0) /* Parse error, report */
763 if (res < 0) /* Nothing known to expand */
768 if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
771 /* XXX: shouldn't allow spaces here? */
772 _gtk_css_parser_try (parser, "px", TRUE);
778 _gtk_css_parser_error (parser, "Expected valid border");
782 border.top = numbers[0];
784 border.right = numbers[1];
786 border.right = border.top;
788 border.bottom = numbers[2];
790 border.bottom = border.top;
792 border.left = numbers[3];
794 border.left = border.right;
796 g_value_set_boxed (value, &border);
801 border_value_print (const GValue *value, GString *string)
803 const GtkBorder *border = g_value_get_boxed (value);
806 g_string_append (string, "none");
807 else if (border->left != border->right)
808 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
809 else if (border->top != border->bottom)
810 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
811 else if (border->top != border->left)
812 g_string_append_printf (string, "%d %d", border->top, border->right);
814 g_string_append_printf (string, "%d", border->top);
818 gradient_value_parse (GtkCssParser *parser,
822 GtkGradient *gradient;
823 cairo_pattern_type_t type;
827 if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
829 _gtk_css_parser_error (parser,
830 "Expected '-gtk-gradient'");
834 if (!_gtk_css_parser_try (parser, "(", TRUE))
836 _gtk_css_parser_error (parser,
837 "Expected '(' after '-gtk-gradient'");
841 /* Parse gradient type */
842 if (_gtk_css_parser_try (parser, "linear", TRUE))
843 type = CAIRO_PATTERN_TYPE_LINEAR;
844 else if (_gtk_css_parser_try (parser, "radial", TRUE))
845 type = CAIRO_PATTERN_TYPE_RADIAL;
848 _gtk_css_parser_error (parser,
849 "Gradient type must be 'radial' or 'linear'");
853 /* Parse start/stop position parameters */
854 for (i = 0; i < 2; i++)
856 if (! _gtk_css_parser_try (parser, ",", TRUE))
858 _gtk_css_parser_error (parser,
863 if (_gtk_css_parser_try (parser, "left", TRUE))
865 else if (_gtk_css_parser_try (parser, "right", TRUE))
867 else if (_gtk_css_parser_try (parser, "center", TRUE))
869 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
871 _gtk_css_parser_error (parser,
872 "Expected a valid X coordinate");
876 if (_gtk_css_parser_try (parser, "top", TRUE))
877 coords[i * 3 + 1] = 0;
878 else if (_gtk_css_parser_try (parser, "bottom", TRUE))
879 coords[i * 3 + 1] = 1;
880 else if (_gtk_css_parser_try (parser, "center", TRUE))
881 coords[i * 3 + 1] = 0.5;
882 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
884 _gtk_css_parser_error (parser,
885 "Expected a valid Y coordinate");
889 if (type == CAIRO_PATTERN_TYPE_RADIAL)
892 if (! _gtk_css_parser_try (parser, ",", TRUE))
894 _gtk_css_parser_error (parser,
899 if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
901 _gtk_css_parser_error (parser,
902 "Expected a numer for the radius");
908 if (type == CAIRO_PATTERN_TYPE_LINEAR)
909 gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
911 gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
912 coords[3], coords[4], coords[5]);
914 while (_gtk_css_parser_try (parser, ",", TRUE))
916 GtkSymbolicColor *color;
919 if (_gtk_css_parser_try (parser, "from", TRUE))
923 if (!_gtk_css_parser_try (parser, "(", TRUE))
925 gtk_gradient_unref (gradient);
926 _gtk_css_parser_error (parser,
932 else if (_gtk_css_parser_try (parser, "to", TRUE))
936 if (!_gtk_css_parser_try (parser, "(", TRUE))
938 gtk_gradient_unref (gradient);
939 _gtk_css_parser_error (parser,
945 else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
947 if (!_gtk_css_parser_try (parser, "(", TRUE))
949 gtk_gradient_unref (gradient);
950 _gtk_css_parser_error (parser,
955 if (!_gtk_css_parser_try_double (parser, &position))
957 gtk_gradient_unref (gradient);
958 _gtk_css_parser_error (parser,
959 "Expected a valid number");
963 if (!_gtk_css_parser_try (parser, ",", TRUE))
965 gtk_gradient_unref (gradient);
966 _gtk_css_parser_error (parser,
973 gtk_gradient_unref (gradient);
974 _gtk_css_parser_error (parser,
975 "Not a valid color-stop definition");
979 color = _gtk_css_parser_read_symbolic_color (parser);
982 gtk_gradient_unref (gradient);
986 gtk_gradient_add_color_stop (gradient, position, color);
987 gtk_symbolic_color_unref (color);
989 if (!_gtk_css_parser_try (parser, ")", TRUE))
991 gtk_gradient_unref (gradient);
992 _gtk_css_parser_error (parser,
998 if (!_gtk_css_parser_try (parser, ")", TRUE))
1000 gtk_gradient_unref (gradient);
1001 _gtk_css_parser_error (parser,
1006 g_value_take_boxed (value, gradient);
1011 gradient_value_print (const GValue *value,
1014 GtkGradient *gradient = g_value_get_boxed (value);
1016 if (gradient == NULL)
1017 g_string_append (string, "none");
1020 char *s = gtk_gradient_to_string (gradient);
1021 g_string_append (string, s);
1027 gtk_css_parse_url (GtkCssParser *parser,
1033 if (_gtk_css_parser_try (parser, "url", FALSE))
1035 if (!_gtk_css_parser_try (parser, "(", TRUE))
1037 _gtk_css_parser_skip_whitespace (parser);
1038 if (_gtk_css_parser_try (parser, "(", TRUE))
1042 error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
1043 GTK_CSS_PROVIDER_ERROR_DEPRECATED,
1044 "Whitespace between 'url' and '(' is deprecated");
1046 _gtk_css_parser_take_error (parser, error);
1050 _gtk_css_parser_error (parser, "Expected '(' after 'url'");
1055 path = _gtk_css_parser_read_string (parser);
1059 if (!_gtk_css_parser_try (parser, ")", TRUE))
1061 _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
1068 path = _gtk_css_parser_try_name (parser, TRUE);
1071 _gtk_css_parser_error (parser, "Not a valid url");
1076 file = g_file_resolve_relative_path (base, path);
1083 pattern_value_parse (GtkCssParser *parser,
1087 if (_gtk_css_parser_try (parser, "none", TRUE))
1089 /* nothing to do here */
1091 else if (_gtk_css_parser_begins_with (parser, '-'))
1094 res = _gtk_win32_theme_part_parse (parser, base, value);
1097 /* < 0 => continue */
1098 g_value_unset (value);
1099 g_value_init (value, GTK_TYPE_GRADIENT);
1100 return gradient_value_parse (parser, base, value);
1104 GError *error = NULL;
1108 cairo_surface_t *surface;
1109 cairo_pattern_t *pattern;
1111 cairo_matrix_t matrix;
1113 file = gtk_css_parse_url (parser, base);
1117 path = g_file_get_path (file);
1118 g_object_unref (file);
1120 pixbuf = gdk_pixbuf_new_from_file (path, &error);
1124 _gtk_css_parser_take_error (parser, error);
1128 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1129 gdk_pixbuf_get_width (pixbuf),
1130 gdk_pixbuf_get_height (pixbuf));
1131 cr = cairo_create (surface);
1132 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
1134 pattern = cairo_pattern_create_for_surface (surface);
1136 cairo_matrix_init_scale (&matrix,
1137 gdk_pixbuf_get_width (pixbuf),
1138 gdk_pixbuf_get_height (pixbuf));
1139 cairo_pattern_set_matrix (pattern, &matrix);
1141 cairo_surface_destroy (surface);
1143 g_object_unref (pixbuf);
1145 g_value_take_boxed (value, pattern);
1151 static cairo_status_t
1152 surface_write (void *closure,
1153 const unsigned char *data,
1154 unsigned int length)
1156 g_byte_array_append (closure, data, length);
1158 return CAIRO_STATUS_SUCCESS;
1162 surface_print (cairo_surface_t *surface,
1165 #if CAIRO_HAS_PNG_FUNCTIONS
1169 array = g_byte_array_new ();
1170 cairo_surface_write_to_png_stream (surface, surface_write, array);
1171 base64 = g_base64_encode (array->data, array->len);
1172 g_byte_array_free (array, TRUE);
1174 g_string_append (string, "url(\"data:image/png;base64,");
1175 g_string_append (string, base64);
1176 g_string_append (string, "\")");
1180 g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
1185 pattern_value_print (const GValue *value,
1188 cairo_pattern_t *pattern;
1189 cairo_surface_t *surface;
1191 pattern = g_value_get_boxed (value);
1193 if (pattern == NULL)
1195 g_string_append (string, "none");
1199 switch (cairo_pattern_get_type (pattern))
1201 case CAIRO_PATTERN_TYPE_SURFACE:
1202 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
1204 g_assert_not_reached ();
1206 surface_print (surface, string);
1208 case CAIRO_PATTERN_TYPE_SOLID:
1209 case CAIRO_PATTERN_TYPE_LINEAR:
1210 case CAIRO_PATTERN_TYPE_RADIAL:
1212 g_assert_not_reached ();
1218 shadow_value_parse (GtkCssParser *parser,
1222 gboolean have_inset, have_color, have_lengths;
1223 gdouble hoffset, voffset, blur, spread;
1224 GtkSymbolicColor *color;
1228 shadow = _gtk_shadow_new ();
1230 if (_gtk_css_parser_try (parser, "none", TRUE))
1235 have_inset = have_lengths = have_color = FALSE;
1237 for (i = 0; i < 3; i++)
1240 _gtk_css_parser_try (parser, "inset", TRUE))
1246 if (!have_lengths &&
1247 _gtk_css_parser_try_double (parser, &hoffset))
1249 have_lengths = TRUE;
1251 if (!_gtk_css_parser_try_double (parser, &voffset))
1253 _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
1254 _gtk_shadow_unref (shadow);
1258 if (!_gtk_css_parser_try_double (parser, &blur))
1261 if (!_gtk_css_parser_try_double (parser, &spread))
1271 /* XXX: the color is optional and UA-defined if it's missing,
1272 * but it doesn't really make sense for us...
1274 color = _gtk_css_parser_read_symbolic_color (parser);
1278 _gtk_shadow_unref (shadow);
1284 if (!have_color || !have_lengths)
1286 _gtk_css_parser_error (parser, "Must specify at least color and offsets");
1287 _gtk_shadow_unref (shadow);
1291 _gtk_shadow_append (shadow,
1296 gtk_symbolic_color_unref (color);
1299 while (_gtk_css_parser_try (parser, ",", TRUE));
1301 g_value_take_boxed (value, shadow);
1306 shadow_value_print (const GValue *value,
1311 shadow = g_value_get_boxed (value);
1314 g_string_append (string, "none");
1316 _gtk_shadow_print (shadow, string);
1320 background_repeat_value_parse (GtkCssParser *parser,
1324 GtkCssBackgroundRepeat repeat;
1327 if (!enum_parse (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, &style))
1330 repeat.repeat = style;
1332 g_value_set_boxed (value, &repeat);
1338 background_repeat_value_print (const GValue *value,
1341 GtkCssBackgroundRepeat *repeat;
1343 repeat = g_value_get_boxed (value);
1345 enum_print (repeat->repeat, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, string);
1349 border_image_repeat_value_parse (GtkCssParser *parser,
1353 GtkCssBorderImageRepeat image_repeat;
1354 GtkCssBorderRepeatStyle styles[2];
1357 for (i = 0; i < 2; i++)
1359 if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
1363 styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
1367 styles[i] = styles[0];
1370 image_repeat.hrepeat = styles[0];
1371 image_repeat.vrepeat = styles[1];
1373 g_value_set_boxed (value, &image_repeat);
1379 border_image_repeat_value_print (const GValue *value,
1382 GtkCssBorderImageRepeat *image_repeat;
1384 image_repeat = g_value_get_boxed (value);
1386 enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1387 if (image_repeat->hrepeat != image_repeat->vrepeat)
1389 g_string_append (string, " ");
1390 enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1395 enum_value_parse (GtkCssParser *parser,
1401 if (enum_parse (parser, G_VALUE_TYPE (value), &v))
1403 g_value_set_enum (value, v);
1411 enum_value_print (const GValue *value,
1414 enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
1418 flags_value_parse (GtkCssParser *parser,
1422 GFlagsClass *flags_class;
1423 GFlagsValue *flag_value;
1427 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1430 str = _gtk_css_parser_try_ident (parser, TRUE);
1433 _gtk_css_parser_error (parser, "Expected an identifier");
1434 g_type_class_unref (flags_class);
1438 flag_value = g_flags_get_value_by_nick (flags_class, str);
1441 _gtk_css_parser_error (parser,
1442 "Unknown flag value '%s' for type '%s'",
1443 str, g_type_name (G_VALUE_TYPE (value)));
1444 /* XXX Do we want to return FALSE here? We can get
1445 * forward-compatibility for new values this way
1448 g_type_class_unref (flags_class);
1454 while (_gtk_css_parser_try (parser, ",", FALSE));
1456 g_type_class_unref (flags_class);
1458 g_value_set_enum (value, flags);
1464 flags_value_print (const GValue *value,
1467 GFlagsClass *flags_class;
1470 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1471 flags = g_value_get_flags (value);
1473 for (i = 0; i < flags_class->n_values; i++)
1475 GFlagsValue *flags_value = &flags_class->values[i];
1477 if (flags & flags_value->value)
1479 if (string->len != 0)
1480 g_string_append (string, ", ");
1482 g_string_append (string, flags_value->value_nick);
1486 g_type_class_unref (flags_class);
1490 bindings_value_parse (GtkCssParser *parser,
1495 GtkBindingSet *binding_set;
1498 array = g_ptr_array_new ();
1501 name = _gtk_css_parser_try_ident (parser, TRUE);
1504 _gtk_css_parser_error (parser, "Not a valid binding name");
1505 g_ptr_array_free (array, TRUE);
1509 binding_set = gtk_binding_set_find (name);
1513 _gtk_css_parser_error (parser, "No binding set named '%s'", name);
1518 g_ptr_array_add (array, binding_set);
1521 while (_gtk_css_parser_try (parser, ",", TRUE));
1523 g_value_take_boxed (value, array);
1529 bindings_value_print (const GValue *value,
1535 array = g_value_get_boxed (value);
1537 for (i = 0; i < array->len; i++)
1539 GtkBindingSet *binding_set = g_ptr_array_index (array, i);
1542 g_string_append (string, ", ");
1543 g_string_append (string, binding_set->set_name);
1548 border_corner_radius_value_parse (GtkCssParser *parser,
1552 GtkCssBorderCornerRadius corner;
1554 if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
1556 _gtk_css_parser_error (parser, "Expected a number");
1559 else if (corner.horizontal < 0)
1562 if (!_gtk_css_parser_try_double (parser, &corner.vertical))
1563 corner.vertical = corner.horizontal;
1564 else if (corner.vertical < 0)
1567 g_value_set_boxed (value, &corner);
1571 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1576 border_corner_radius_value_print (const GValue *value,
1579 GtkCssBorderCornerRadius *corner;
1581 corner = g_value_get_boxed (value);
1585 g_string_append (string, "none");
1589 string_append_double (string, corner->horizontal);
1590 if (corner->horizontal != corner->vertical)
1592 g_string_append_c (string, ' ');
1593 string_append_double (string, corner->vertical);
1598 transparent_color_value_parse (GtkCssParser *parser,
1602 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1604 GdkRGBA transparent = { 0, 0, 0, 0 };
1606 g_value_set_boxed (value, &transparent);
1611 return rgba_value_parse (parser, base, value);
1617 _gtk_style_property_get_count (void)
1619 return __style_property_array ? __style_property_array->len : 0;
1623 _gtk_style_property_get (guint id)
1625 g_assert (__style_property_array);
1627 return g_ptr_array_index (__style_property_array, id);
1631 _gtk_style_property_generate_id (GtkStyleProperty *node)
1633 if (__style_property_array == NULL)
1634 __style_property_array = g_ptr_array_new ();
1636 node->id = __style_property_array->len;
1637 g_ptr_array_add (__style_property_array, node);
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,
1693 pattern_value_print);
1694 register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1695 border_image_repeat_value_parse,
1696 border_image_repeat_value_print);
1697 register_conversion_function (GTK_TYPE_SHADOW,
1699 shadow_value_print);
1700 register_conversion_function (G_TYPE_ENUM,
1703 register_conversion_function (G_TYPE_FLAGS,
1706 register_conversion_function (GTK_TYPE_CSS_BACKGROUND_REPEAT,
1707 background_repeat_value_parse,
1708 background_repeat_value_print);
1712 _gtk_style_property_parse_value (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, "initial", TRUE))
1728 /* the initial value can be explicitly specified with the
1729 * ‘initial’ keyword which all properties accept.
1731 g_value_unset (value);
1732 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
1733 g_value_set_enum (value, GTK_CSS_INITIAL);
1736 else if (_gtk_css_parser_try (parser, "inherit", TRUE))
1738 /* All properties accept the ‘inherit’ value which
1739 * explicitly specifies that the value will be determined
1740 * by inheritance. The ‘inherit’ value can be used to
1741 * strengthen inherited values in the cascade, and it can
1742 * also be used on properties that are not normally inherited.
1744 g_value_unset (value);
1745 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
1746 g_value_set_enum (value, GTK_CSS_INHERIT);
1749 else if (property->property_parse_func)
1751 GError *error = NULL;
1755 value_str = _gtk_css_parser_read_value (parser);
1756 if (value_str == NULL)
1759 success = (*property->property_parse_func) (value_str, value, &error);
1766 func = property->parse_func;
1772 func = g_hash_table_lookup (parse_funcs,
1773 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1775 func = g_hash_table_lookup (parse_funcs,
1776 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1780 _gtk_css_parser_error (parser,
1781 "Cannot convert to type '%s'",
1782 g_type_name (G_VALUE_TYPE (value)));
1786 return (*func) (parser, base, value);
1790 _gtk_style_property_print_value (GtkStyleProperty *property,
1791 const GValue *value,
1794 GtkStylePrintFunc func;
1796 css_string_funcs_init ();
1798 if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
1799 func = enum_value_print;
1801 func = property->print_func;
1806 func = g_hash_table_lookup (print_funcs,
1807 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1809 func = g_hash_table_lookup (print_funcs,
1810 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1814 char *s = g_strdup_value_contents (value);
1815 g_string_append (string, s);
1820 func (value, string);
1824 _gtk_style_property_default_value (GtkStyleProperty *property,
1825 GtkStyleProperties *properties,
1826 GtkStateFlags state,
1829 g_value_copy (&property->initial_value, value);
1833 _gtk_style_property_is_inherit (GtkStyleProperty *property)
1835 g_return_val_if_fail (property != NULL, FALSE);
1837 return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
1841 _gtk_style_property_get_id (GtkStyleProperty *property)
1843 g_return_val_if_fail (property != NULL, FALSE);
1845 return property->id;
1849 resolve_color (GtkStyleProperties *props,
1854 /* Resolve symbolic color to GdkRGBA */
1855 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
1858 /* Store it back, this is where GdkRGBA caching happens */
1859 g_value_unset (value);
1860 g_value_init (value, GDK_TYPE_RGBA);
1861 g_value_set_boxed (value, &color);
1867 resolve_color_rgb (GtkStyleProperties *props,
1870 GdkColor color = { 0 };
1873 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
1876 color.red = rgba.red * 65535. + 0.5;
1877 color.green = rgba.green * 65535. + 0.5;
1878 color.blue = rgba.blue * 65535. + 0.5;
1880 g_value_unset (value);
1881 g_value_init (value, GDK_TYPE_COLOR);
1882 g_value_set_boxed (value, &color);
1888 resolve_win32_theme_part (GtkStyleProperties *props,
1891 GtkStylePropertyContext *context)
1893 GtkWin32ThemePart *part;
1894 cairo_pattern_t *pattern;
1896 part = g_value_get_boxed (value);
1900 pattern = _gtk_win32_theme_part_render (part, context->width, context->height);
1902 g_value_take_boxed (value_out, pattern);
1909 resolve_gradient (GtkStyleProperties *props,
1912 cairo_pattern_t *gradient;
1914 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
1917 /* Store it back, this is where cairo_pattern_t caching happens */
1918 g_value_unset (value);
1919 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
1920 g_value_take_boxed (value, gradient);
1926 resolve_shadow (GtkStyleProperties *props,
1929 GtkShadow *resolved, *base;
1931 base = g_value_get_boxed (value);
1936 if (_gtk_shadow_get_resolved (base))
1939 resolved = _gtk_shadow_resolve (base, props);
1940 if (resolved == NULL)
1943 g_value_take_boxed (value, resolved);
1949 _gtk_style_property_resolve (GtkStyleProperty *property,
1950 GtkStyleProperties *props,
1951 GtkStateFlags state,
1952 GtkStylePropertyContext *context,
1956 if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_SPECIAL_VALUE)
1958 GtkCssSpecialValue special = g_value_get_enum (val);
1960 g_value_unset (val);
1963 case GTK_CSS_CURRENT_COLOR:
1964 g_assert (property->pspec->value_type == GDK_TYPE_RGBA);
1965 gtk_style_properties_get_property (props, "color", state, val);
1967 case GTK_CSS_INHERIT:
1968 case GTK_CSS_INITIAL:
1970 g_assert_not_reached ();
1973 else if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
1975 if (property->pspec->value_type == GDK_TYPE_RGBA)
1977 if (resolve_color (props, val))
1980 else if (property->pspec->value_type == GDK_TYPE_COLOR)
1982 if (resolve_color_rgb (props, val))
1986 g_value_unset (val);
1987 g_value_init (val, property->pspec->value_type);
1988 _gtk_style_property_default_value (property, props, state, val);
1990 else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
1992 if (g_value_get_boxed (val) == NULL)
1993 _gtk_style_property_default_value (property, props, state, val);
1995 else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
1997 g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
1999 if (!resolve_gradient (props, val))
2001 g_value_unset (val);
2002 g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
2003 _gtk_style_property_default_value (property, props, state, val);
2006 else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
2008 if (!resolve_shadow (props, val))
2009 _gtk_style_property_default_value (property, props, state, val);
2011 else if (G_VALUE_TYPE (val) == GTK_TYPE_WIN32_THEME_PART)
2013 if (resolve_win32_theme_part (props, val, val_out, context))
2014 return; /* Don't copy val, this sets val_out */
2015 _gtk_style_property_default_value (property, props, state, val);
2019 g_value_copy (val, val_out);
2023 _gtk_style_property_get_initial_value (GtkStyleProperty *property)
2025 g_return_val_if_fail (property != NULL, NULL);
2027 return &property->initial_value;
2031 _gtk_style_property_unpack (GtkStyleProperty *property,
2032 const GValue *value,
2035 g_return_val_if_fail (property != NULL, NULL);
2036 g_return_val_if_fail (property->unpack_func != NULL, NULL);
2037 g_return_val_if_fail (value != NULL, NULL);
2038 g_return_val_if_fail (n_params != NULL, NULL);
2040 return property->unpack_func (value, n_params);
2044 _gtk_style_property_pack (GtkStyleProperty *property,
2045 GtkStyleProperties *props,
2046 GtkStateFlags state,
2047 GtkStylePropertyContext *context,
2050 g_return_if_fail (property != NULL);
2051 g_return_if_fail (property->pack_func != NULL);
2052 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2053 g_return_if_fail (G_IS_VALUE (value));
2055 property->pack_func (value, props, state, context);
2059 _gtk_style_property_assign (GtkStyleProperty *property,
2060 GtkStyleProperties *props,
2061 GtkStateFlags state,
2062 const GValue *value)
2064 g_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
2065 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2066 g_return_if_fail (value != NULL);
2068 if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
2070 GParameter *parameters;
2071 guint i, n_parameters;
2073 parameters = _gtk_style_property_unpack (property, value, &n_parameters);
2075 for (i = 0; i < n_parameters; i++)
2077 _gtk_style_property_assign (_gtk_style_property_lookup (parameters[i].name),
2080 ¶meters[i].value);
2081 g_value_unset (¶meters[i].value);
2083 g_free (parameters);
2086 else if (GTK_IS_CSS_STYLE_PROPERTY (property))
2088 _gtk_style_properties_set_property_by_property (props,
2095 g_assert_not_reached ();
2100 _gtk_style_property_query (GtkStyleProperty *property,
2101 GtkStyleProperties *props,
2102 GtkStateFlags state,
2103 GtkStylePropertyContext *context,
2108 g_return_if_fail (property != NULL);
2109 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2110 g_return_if_fail (context != NULL);
2111 g_return_if_fail (value != NULL);
2113 val = _gtk_style_properties_peek_property (props, property, state);
2114 g_value_init (value, property->pspec->value_type);
2117 _gtk_style_property_resolve (property, props, state, context, (GValue *) val, value);
2118 else if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
2119 _gtk_style_property_pack (property, props, state, context, value);
2121 _gtk_style_property_default_value (property, props, state, value);
2124 #define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
2125 (rgba)->red = (r); \
2126 (rgba)->green = (g); \
2127 (rgba)->blue = (b); \
2128 (rgba)->alpha = (a); \
2131 gtk_style_property_init_properties (void)
2133 static gboolean initialized = FALSE;
2134 GValue value = { 0, };
2135 char *default_font_family[] = { "Sans", NULL };
2138 if (G_LIKELY (initialized))
2143 g_value_init (&value, GDK_TYPE_RGBA);
2144 rgba_init (&rgba, 1, 1, 1, 1);
2145 g_value_set_boxed (&value, &rgba);
2146 _gtk_style_property_register (g_param_spec_boxed ("color",
2150 GTK_STYLE_PROPERTY_INHERIT,
2155 rgba_init (&rgba, 0, 0, 0, 0);
2156 g_value_set_boxed (&value, &rgba);
2157 _gtk_style_property_register (g_param_spec_boxed ("background-color",
2163 transparent_color_value_parse,
2166 g_value_unset (&value);
2168 g_value_init (&value, G_TYPE_STRV);
2169 g_value_set_boxed (&value, default_font_family);
2170 _gtk_style_property_register (g_param_spec_boxed ("font-family",
2174 GTK_STYLE_PROPERTY_INHERIT,
2177 font_family_value_print,
2179 g_value_unset (&value);
2180 _gtk_style_property_register (g_param_spec_enum ("font-style",
2184 PANGO_STYLE_NORMAL, 0),
2185 GTK_STYLE_PROPERTY_INHERIT,
2190 _gtk_style_property_register (g_param_spec_enum ("font-variant",
2194 PANGO_VARIANT_NORMAL, 0),
2195 GTK_STYLE_PROPERTY_INHERIT,
2200 /* xxx: need to parse this properly, ie parse the numbers */
2201 _gtk_style_property_register (g_param_spec_enum ("font-weight",
2205 PANGO_WEIGHT_NORMAL, 0),
2206 GTK_STYLE_PROPERTY_INHERIT,
2211 g_value_init (&value, G_TYPE_DOUBLE);
2212 g_value_set_double (&value, 10);
2213 _gtk_style_property_register (g_param_spec_double ("font-size",
2216 0, G_MAXDOUBLE, 0, 0),
2217 GTK_STYLE_PROPERTY_INHERIT,
2222 g_value_unset (&value);
2224 _gtk_style_property_register (g_param_spec_boxed ("text-shadow",
2227 GTK_TYPE_SHADOW, 0),
2228 GTK_STYLE_PROPERTY_INHERIT,
2234 _gtk_style_property_register (g_param_spec_boxed ("icon-shadow",
2237 GTK_TYPE_SHADOW, 0),
2238 GTK_STYLE_PROPERTY_INHERIT,
2244 gtk_style_properties_register_property (NULL,
2245 g_param_spec_boxed ("box-shadow",
2248 GTK_TYPE_SHADOW, 0));
2249 gtk_style_properties_register_property (NULL,
2250 g_param_spec_int ("margin-top",
2253 0, G_MAXINT, 0, 0));
2254 gtk_style_properties_register_property (NULL,
2255 g_param_spec_int ("margin-left",
2258 0, G_MAXINT, 0, 0));
2259 gtk_style_properties_register_property (NULL,
2260 g_param_spec_int ("margin-bottom",
2263 0, G_MAXINT, 0, 0));
2264 gtk_style_properties_register_property (NULL,
2265 g_param_spec_int ("margin-right",
2268 0, G_MAXINT, 0, 0));
2269 gtk_style_properties_register_property (NULL,
2270 g_param_spec_int ("padding-top",
2273 0, G_MAXINT, 0, 0));
2274 gtk_style_properties_register_property (NULL,
2275 g_param_spec_int ("padding-left",
2278 0, G_MAXINT, 0, 0));
2279 gtk_style_properties_register_property (NULL,
2280 g_param_spec_int ("padding-bottom",
2282 "Padding at bottom",
2283 0, G_MAXINT, 0, 0));
2284 gtk_style_properties_register_property (NULL,
2285 g_param_spec_int ("padding-right",
2288 0, G_MAXINT, 0, 0));
2289 gtk_style_properties_register_property (NULL,
2290 g_param_spec_int ("border-top-width",
2292 "Border width at top",
2293 0, G_MAXINT, 0, 0));
2294 gtk_style_properties_register_property (NULL,
2295 g_param_spec_int ("border-left-width",
2296 "border left width",
2297 "Border width at left",
2298 0, G_MAXINT, 0, 0));
2299 gtk_style_properties_register_property (NULL,
2300 g_param_spec_int ("border-bottom-width",
2301 "border bottom width",
2302 "Border width at bottom",
2303 0, G_MAXINT, 0, 0));
2304 gtk_style_properties_register_property (NULL,
2305 g_param_spec_int ("border-right-width",
2306 "border right width",
2307 "Border width at right",
2308 0, G_MAXINT, 0, 0));
2310 _gtk_style_property_register (g_param_spec_boxed ("border-top-left-radius",
2311 "Border top left radius",
2312 "Border radius of top left corner, in pixels",
2313 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2316 border_corner_radius_value_parse,
2317 border_corner_radius_value_print,
2319 _gtk_style_property_register (g_param_spec_boxed ("border-top-right-radius",
2320 "Border top right radius",
2321 "Border radius of top right corner, in pixels",
2322 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2325 border_corner_radius_value_parse,
2326 border_corner_radius_value_print,
2328 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-right-radius",
2329 "Border bottom right radius",
2330 "Border radius of bottom right corner, in pixels",
2331 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2334 border_corner_radius_value_parse,
2335 border_corner_radius_value_print,
2337 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-left-radius",
2338 "Border bottom left radius",
2339 "Border radius of bottom left corner, in pixels",
2340 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2343 border_corner_radius_value_parse,
2344 border_corner_radius_value_print,
2347 gtk_style_properties_register_property (NULL,
2348 g_param_spec_enum ("border-style",
2351 GTK_TYPE_BORDER_STYLE,
2352 GTK_BORDER_STYLE_NONE, 0));
2353 gtk_style_properties_register_property (NULL,
2354 g_param_spec_enum ("background-clip",
2358 GTK_CSS_AREA_BORDER_BOX, 0));
2359 gtk_style_properties_register_property (NULL,
2360 g_param_spec_enum ("background-origin",
2361 "Background origin",
2362 "Background origin",
2364 GTK_CSS_AREA_PADDING_BOX, 0));
2365 g_value_init (&value, GTK_TYPE_CSS_SPECIAL_VALUE);
2366 g_value_set_enum (&value, GTK_CSS_CURRENT_COLOR);
2367 _gtk_style_property_register (g_param_spec_boxed ("border-top-color",
2373 transparent_color_value_parse,
2376 _gtk_style_property_register (g_param_spec_boxed ("border-right-color",
2377 "Border right color",
2378 "Border right color",
2382 transparent_color_value_parse,
2385 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-color",
2386 "Border bottom color",
2387 "Border bottom color",
2391 transparent_color_value_parse,
2394 _gtk_style_property_register (g_param_spec_boxed ("border-left-color",
2395 "Border left color",
2396 "Border left color",
2400 transparent_color_value_parse,
2403 g_value_unset (&value);
2405 gtk_style_properties_register_property (NULL,
2406 g_param_spec_boxed ("background-image",
2409 CAIRO_GOBJECT_TYPE_PATTERN, 0));
2410 gtk_style_properties_register_property (NULL,
2411 g_param_spec_boxed ("background-repeat",
2412 "Background repeat",
2413 "Background repeat",
2414 GTK_TYPE_CSS_BACKGROUND_REPEAT, 0));
2416 gtk_style_properties_register_property (NULL,
2417 g_param_spec_boxed ("border-image-source",
2418 "Border image source",
2419 "Border image source",
2420 CAIRO_GOBJECT_TYPE_PATTERN, 0));
2421 gtk_style_properties_register_property (NULL,
2422 g_param_spec_boxed ("border-image-repeat",
2423 "Border image repeat",
2424 "Border image repeat",
2425 GTK_TYPE_CSS_BORDER_IMAGE_REPEAT, 0));
2426 gtk_style_properties_register_property (NULL,
2427 g_param_spec_boxed ("border-image-slice",
2428 "Border image slice",
2429 "Border image slice",
2430 GTK_TYPE_BORDER, 0));
2431 g_value_init (&value, GTK_TYPE_BORDER);
2432 _gtk_style_property_register (g_param_spec_boxed ("border-image-width",
2433 "Border image width",
2434 "Border image width",
2435 GTK_TYPE_BORDER, 0),
2441 g_value_unset (&value);
2442 gtk_style_properties_register_property (NULL,
2443 g_param_spec_object ("engine",
2446 GTK_TYPE_THEMING_ENGINE, 0));
2447 gtk_style_properties_register_property (NULL,
2448 g_param_spec_boxed ("transition",
2449 "Transition animation description",
2450 "Transition animation description",
2451 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
2453 /* Private property holding the binding sets */
2454 _gtk_style_property_register (g_param_spec_boxed ("gtk-key-bindings",
2457 G_TYPE_PTR_ARRAY, 0),
2460 bindings_value_parse,
2461 bindings_value_print,
2464 /* initialize shorthands last, they depend on the real properties existing */
2465 _gtk_css_shorthand_property_init_properties ();
2469 * _gtk_style_property_lookup:
2470 * @name: name of the property to lookup
2472 * Looks up the CSS property with the given @name. If no such
2473 * property exists, %NULL is returned.
2475 * Returns: (transfer none): The property or %NULL if no
2476 * property with the given name exists.
2479 _gtk_style_property_lookup (const char *name)
2481 GtkStylePropertyClass *klass;
2483 g_return_val_if_fail (name != NULL, NULL);
2485 gtk_style_property_init_properties ();
2487 klass = g_type_class_peek (GTK_TYPE_STYLE_PROPERTY);
2489 return g_hash_table_lookup (klass->properties, name);
2493 * _gtk_style_property_get_name:
2494 * @property: the property to query
2496 * Gets the name of the given property.
2498 * Returns: the name of the property
2501 _gtk_style_property_get_name (GtkStyleProperty *property)
2503 g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), NULL);
2505 return property->name;
2509 * _gtk_style_property_get_value_type:
2510 * @property: the property to query
2512 * Gets the value type of the @property, if the property is usable
2513 * in public API via _gtk_style_property_assign() and
2514 * _gtk_style_property_query(). If the @property is not usable in that
2515 * way, %G_TYPE_NONE is returned.
2517 * Returns: the value type in use or %G_TYPE_NONE if none.
2520 _gtk_style_property_get_value_type (GtkStyleProperty *property)
2522 g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), G_TYPE_NONE);
2524 return property->value_type;
2529 _gtk_style_property_register (GParamSpec *pspec,
2530 GtkStylePropertyFlags flags,
2531 GtkStylePropertyParser property_parse_func,
2532 GtkStyleParseFunc parse_func,
2533 GtkStylePrintFunc print_func,
2534 const GValue * initial_value)
2536 GtkStyleProperty *node;
2538 node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
2539 "name", pspec->name,
2540 "value-type", pspec->value_type,
2542 node->flags = flags;
2543 node->pspec = pspec;
2544 node->property_parse_func = property_parse_func;
2545 node->parse_func = parse_func;
2546 node->print_func = print_func;
2548 _gtk_style_property_generate_id (node);
2550 /* initialize the initial value */
2553 g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value));
2554 g_value_copy (initial_value, &node->initial_value);
2558 g_value_init (&node->initial_value, pspec->value_type);
2559 if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
2560 g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
2561 else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
2562 g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10"));
2563 else if (pspec->value_type == GDK_TYPE_RGBA)
2566 gdk_rgba_parse (&color, "pink");
2567 g_value_set_boxed (&node->initial_value, &color);
2569 else if (pspec->value_type == GTK_TYPE_BORDER)
2571 g_value_take_boxed (&node->initial_value, gtk_border_new ());
2574 g_param_value_set_default (pspec, &node->initial_value);