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;
64 G_DEFINE_ABSTRACT_TYPE (GtkStyleProperty, _gtk_style_property, G_TYPE_OBJECT)
67 gtk_style_property_finalize (GObject *object)
69 GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
71 g_warning ("finalizing %s `%s', how could this happen?", G_OBJECT_TYPE_NAME (object), property->name);
73 G_OBJECT_CLASS (_gtk_style_property_parent_class)->finalize (object);
77 gtk_style_property_set_property (GObject *object,
82 GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
83 GtkStylePropertyClass *klass = GTK_STYLE_PROPERTY_GET_CLASS (property);
88 property->name = g_value_dup_string (value);
89 g_assert (property->name);
90 g_assert (g_hash_table_lookup (klass->properties, property->name) == NULL);
91 g_hash_table_insert (klass->properties, property->name, property);
94 property->value_type = g_value_get_gtype (value);
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
103 gtk_style_property_get_property (GObject *object,
108 GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
113 g_value_set_string (value, property->name);
115 case PROP_VALUE_TYPE:
116 g_value_set_gtype (value, property->value_type);
119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
125 _gtk_style_property_class_init (GtkStylePropertyClass *klass)
127 GObjectClass *object_class = G_OBJECT_CLASS (klass);
129 object_class->finalize = gtk_style_property_finalize;
130 object_class->set_property = gtk_style_property_set_property;
131 object_class->get_property = gtk_style_property_get_property;
133 g_object_class_install_property (object_class,
135 g_param_spec_string ("name",
137 P_("The name of the property"),
139 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
140 g_object_class_install_property (object_class,
142 g_param_spec_gtype ("value-type",
144 P_("The value type returned by GtkStyleContext"),
146 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
148 klass->properties = g_hash_table_new (g_str_hash, g_str_equal);
152 _gtk_style_property_init (GtkStyleProperty *property)
154 property->value_type = G_TYPE_NONE;
158 register_conversion_function (GType type,
159 GtkStyleParseFunc parse,
160 GtkStylePrintFunc print)
163 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
165 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
169 string_append_double (GString *string,
172 char buf[G_ASCII_DTOSTR_BUF_SIZE];
174 g_ascii_dtostr (buf, sizeof (buf), d);
175 g_string_append (string, buf);
179 string_append_string (GString *str,
184 g_string_append_c (str, '"');
187 len = strcspn (string, "\"\n\r\f");
188 g_string_append (str, string);
195 g_string_append (str, "\\A ");
198 g_string_append (str, "\\D ");
201 g_string_append (str, "\\C ");
204 g_string_append (str, "\\\"");
207 g_assert_not_reached ();
212 g_string_append_c (str, '"');
215 /*** IMPLEMENTATIONS ***/
218 enum_parse (GtkCssParser *parser,
224 if (_gtk_css_parser_try_enum (parser, type, res))
227 str = _gtk_css_parser_try_ident (parser, TRUE);
230 _gtk_css_parser_error (parser, "Expected an identifier");
234 _gtk_css_parser_error (parser,
235 "Unknown value '%s' for enum type '%s'",
236 str, g_type_name (type));
243 enum_print (int value,
247 GEnumClass *enum_class;
248 GEnumValue *enum_value;
250 enum_class = g_type_class_ref (type);
251 enum_value = g_enum_get_value (enum_class, value);
253 g_string_append (string, enum_value->value_nick);
255 g_type_class_unref (enum_class);
259 rgba_value_parse (GtkCssParser *parser,
263 GtkSymbolicColor *symbolic;
266 symbolic = _gtk_css_parser_read_symbolic_color (parser);
267 if (symbolic == NULL)
270 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
272 g_value_set_boxed (value, &rgba);
273 gtk_symbolic_color_unref (symbolic);
277 g_value_unset (value);
278 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
279 g_value_take_boxed (value, symbolic);
286 rgba_value_print (const GValue *value,
289 const GdkRGBA *rgba = g_value_get_boxed (value);
292 g_string_append (string, "none");
295 char *s = gdk_rgba_to_string (rgba);
296 g_string_append (string, s);
302 color_value_parse (GtkCssParser *parser,
306 GtkSymbolicColor *symbolic;
309 symbolic = _gtk_css_parser_read_symbolic_color (parser);
310 if (symbolic == NULL)
313 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
317 color.red = rgba.red * 65535. + 0.5;
318 color.green = rgba.green * 65535. + 0.5;
319 color.blue = rgba.blue * 65535. + 0.5;
321 g_value_set_boxed (value, &color);
325 g_value_unset (value);
326 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
327 g_value_take_boxed (value, symbolic);
334 color_value_print (const GValue *value,
337 const GdkColor *color = g_value_get_boxed (value);
340 g_string_append (string, "none");
343 char *s = gdk_color_to_string (color);
344 g_string_append (string, s);
350 symbolic_color_value_parse (GtkCssParser *parser,
354 GtkSymbolicColor *symbolic;
356 symbolic = _gtk_css_parser_read_symbolic_color (parser);
357 if (symbolic == NULL)
360 g_value_take_boxed (value, symbolic);
365 symbolic_color_value_print (const GValue *value,
368 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
370 if (symbolic == NULL)
371 g_string_append (string, "none");
374 char *s = gtk_symbolic_color_to_string (symbolic);
375 g_string_append (string, s);
381 font_family_parse (GtkCssParser *parser,
388 /* We don't special case generic families. Pango should do
391 names = g_ptr_array_new ();
394 name = _gtk_css_parser_try_ident (parser, TRUE);
397 GString *string = g_string_new (name);
399 while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
401 g_string_append_c (string, ' ');
402 g_string_append (string, name);
405 name = g_string_free (string, FALSE);
409 name = _gtk_css_parser_read_string (parser);
412 g_ptr_array_free (names, TRUE);
417 g_ptr_array_add (names, name);
418 } while (_gtk_css_parser_try (parser, ",", TRUE));
420 /* NULL-terminate array */
421 g_ptr_array_add (names, NULL);
422 g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
427 font_family_value_print (const GValue *value,
430 const char **names = g_value_get_boxed (value);
432 if (names == NULL || *names == NULL)
434 g_string_append (string, "none");
438 string_append_string (string, *names);
442 g_string_append (string, ", ");
443 string_append_string (string, *names);
449 font_description_value_parse (GtkCssParser *parser,
453 PangoFontDescription *font_desc;
457 str = _gtk_css_parser_read_value (parser);
461 font_desc = pango_font_description_from_string (str);
462 mask = pango_font_description_get_set_fields (font_desc);
463 /* These values are not really correct,
464 * but the fields must be set, so we set them to something */
465 if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
466 pango_font_description_set_family_static (font_desc, "Sans");
467 if ((mask & PANGO_FONT_MASK_SIZE) == 0)
468 pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
470 g_value_take_boxed (value, font_desc);
475 font_description_value_print (const GValue *value,
478 const PangoFontDescription *desc = g_value_get_boxed (value);
481 g_string_append (string, "none");
484 char *s = pango_font_description_to_string (desc);
485 g_string_append (string, s);
491 boolean_value_parse (GtkCssParser *parser,
495 if (_gtk_css_parser_try (parser, "true", TRUE) ||
496 _gtk_css_parser_try (parser, "1", TRUE))
498 g_value_set_boolean (value, TRUE);
501 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
502 _gtk_css_parser_try (parser, "0", TRUE))
504 g_value_set_boolean (value, FALSE);
509 _gtk_css_parser_error (parser, "Expected a boolean value");
515 boolean_value_print (const GValue *value,
518 if (g_value_get_boolean (value))
519 g_string_append (string, "true");
521 g_string_append (string, "false");
525 int_value_parse (GtkCssParser *parser,
531 if (_gtk_css_parser_begins_with (parser, '-'))
533 int res = _gtk_win32_theme_int_parse (parser, base, &i);
536 g_value_set_int (value, i);
539 /* < 0 => continue */
542 if (!_gtk_css_parser_try_int (parser, &i))
544 _gtk_css_parser_error (parser, "Expected a valid integer value");
548 g_value_set_int (value, i);
553 int_value_print (const GValue *value,
556 g_string_append_printf (string, "%d", g_value_get_int (value));
560 uint_value_parse (GtkCssParser *parser,
566 if (!_gtk_css_parser_try_uint (parser, &u))
568 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
572 g_value_set_uint (value, u);
577 uint_value_print (const GValue *value,
580 g_string_append_printf (string, "%u", g_value_get_uint (value));
584 double_value_parse (GtkCssParser *parser,
590 if (!_gtk_css_parser_try_double (parser, &d))
592 _gtk_css_parser_error (parser, "Expected a number");
596 g_value_set_double (value, d);
601 double_value_print (const GValue *value,
604 string_append_double (string, g_value_get_double (value));
608 float_value_parse (GtkCssParser *parser,
614 if (!_gtk_css_parser_try_double (parser, &d))
616 _gtk_css_parser_error (parser, "Expected a number");
620 g_value_set_float (value, d);
625 float_value_print (const GValue *value,
628 string_append_double (string, g_value_get_float (value));
632 string_value_parse (GtkCssParser *parser,
636 char *str = _gtk_css_parser_read_string (parser);
641 g_value_take_string (value, str);
646 string_value_print (const GValue *value,
649 string_append_string (str, g_value_get_string (value));
653 theming_engine_value_parse (GtkCssParser *parser,
657 GtkThemingEngine *engine;
660 if (_gtk_css_parser_try (parser, "none", TRUE))
662 g_value_set_object (value, gtk_theming_engine_load (NULL));
666 str = _gtk_css_parser_try_ident (parser, TRUE);
669 _gtk_css_parser_error (parser, "Expected a valid theme name");
673 engine = gtk_theming_engine_load (str);
677 _gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
682 g_value_set_object (value, engine);
688 theming_engine_value_print (const GValue *value,
691 GtkThemingEngine *engine;
694 engine = g_value_get_object (value);
696 g_string_append (string, "none");
699 /* XXX: gtk_theming_engine_get_name()? */
700 g_object_get (engine, "name", &name, NULL);
701 g_string_append (string, name ? name : "none");
707 animation_description_value_parse (GtkCssParser *parser,
711 GtkAnimationDescription *desc;
714 str = _gtk_css_parser_read_value (parser);
718 desc = _gtk_animation_description_from_string (str);
723 _gtk_css_parser_error (parser, "Invalid animation description");
727 g_value_take_boxed (value, desc);
732 animation_description_value_print (const GValue *value,
735 GtkAnimationDescription *desc = g_value_get_boxed (value);
738 g_string_append (string, "none");
740 _gtk_animation_description_print (desc, string);
744 border_value_parse (GtkCssParser *parser,
748 GtkBorder border = { 0, };
751 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
753 if (_gtk_css_parser_begins_with (parser, '-'))
755 /* These are strictly speaking signed, but we want to be able to use them
756 for unsigned types too, as the actual ranges of values make this safe */
757 int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
759 if (res == 0) /* Parse error, report */
762 if (res < 0) /* Nothing known to expand */
767 if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
770 /* XXX: shouldn't allow spaces here? */
771 _gtk_css_parser_try (parser, "px", TRUE);
777 _gtk_css_parser_error (parser, "Expected valid border");
781 border.top = numbers[0];
783 border.right = numbers[1];
785 border.right = border.top;
787 border.bottom = numbers[2];
789 border.bottom = border.top;
791 border.left = numbers[3];
793 border.left = border.right;
795 g_value_set_boxed (value, &border);
800 border_value_print (const GValue *value, GString *string)
802 const GtkBorder *border = g_value_get_boxed (value);
805 g_string_append (string, "none");
806 else if (border->left != border->right)
807 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
808 else if (border->top != border->bottom)
809 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
810 else if (border->top != border->left)
811 g_string_append_printf (string, "%d %d", border->top, border->right);
813 g_string_append_printf (string, "%d", border->top);
817 gradient_value_parse (GtkCssParser *parser,
821 GtkGradient *gradient;
822 cairo_pattern_type_t type;
826 if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
828 _gtk_css_parser_error (parser,
829 "Expected '-gtk-gradient'");
833 if (!_gtk_css_parser_try (parser, "(", TRUE))
835 _gtk_css_parser_error (parser,
836 "Expected '(' after '-gtk-gradient'");
840 /* Parse gradient type */
841 if (_gtk_css_parser_try (parser, "linear", TRUE))
842 type = CAIRO_PATTERN_TYPE_LINEAR;
843 else if (_gtk_css_parser_try (parser, "radial", TRUE))
844 type = CAIRO_PATTERN_TYPE_RADIAL;
847 _gtk_css_parser_error (parser,
848 "Gradient type must be 'radial' or 'linear'");
852 /* Parse start/stop position parameters */
853 for (i = 0; i < 2; i++)
855 if (! _gtk_css_parser_try (parser, ",", TRUE))
857 _gtk_css_parser_error (parser,
862 if (_gtk_css_parser_try (parser, "left", TRUE))
864 else if (_gtk_css_parser_try (parser, "right", TRUE))
866 else if (_gtk_css_parser_try (parser, "center", TRUE))
868 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
870 _gtk_css_parser_error (parser,
871 "Expected a valid X coordinate");
875 if (_gtk_css_parser_try (parser, "top", TRUE))
876 coords[i * 3 + 1] = 0;
877 else if (_gtk_css_parser_try (parser, "bottom", TRUE))
878 coords[i * 3 + 1] = 1;
879 else if (_gtk_css_parser_try (parser, "center", TRUE))
880 coords[i * 3 + 1] = 0.5;
881 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
883 _gtk_css_parser_error (parser,
884 "Expected a valid Y coordinate");
888 if (type == CAIRO_PATTERN_TYPE_RADIAL)
891 if (! _gtk_css_parser_try (parser, ",", TRUE))
893 _gtk_css_parser_error (parser,
898 if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
900 _gtk_css_parser_error (parser,
901 "Expected a numer for the radius");
907 if (type == CAIRO_PATTERN_TYPE_LINEAR)
908 gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
910 gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
911 coords[3], coords[4], coords[5]);
913 while (_gtk_css_parser_try (parser, ",", TRUE))
915 GtkSymbolicColor *color;
918 if (_gtk_css_parser_try (parser, "from", TRUE))
922 if (!_gtk_css_parser_try (parser, "(", TRUE))
924 gtk_gradient_unref (gradient);
925 _gtk_css_parser_error (parser,
931 else if (_gtk_css_parser_try (parser, "to", TRUE))
935 if (!_gtk_css_parser_try (parser, "(", TRUE))
937 gtk_gradient_unref (gradient);
938 _gtk_css_parser_error (parser,
944 else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
946 if (!_gtk_css_parser_try (parser, "(", TRUE))
948 gtk_gradient_unref (gradient);
949 _gtk_css_parser_error (parser,
954 if (!_gtk_css_parser_try_double (parser, &position))
956 gtk_gradient_unref (gradient);
957 _gtk_css_parser_error (parser,
958 "Expected a valid number");
962 if (!_gtk_css_parser_try (parser, ",", TRUE))
964 gtk_gradient_unref (gradient);
965 _gtk_css_parser_error (parser,
972 gtk_gradient_unref (gradient);
973 _gtk_css_parser_error (parser,
974 "Not a valid color-stop definition");
978 color = _gtk_css_parser_read_symbolic_color (parser);
981 gtk_gradient_unref (gradient);
985 gtk_gradient_add_color_stop (gradient, position, color);
986 gtk_symbolic_color_unref (color);
988 if (!_gtk_css_parser_try (parser, ")", TRUE))
990 gtk_gradient_unref (gradient);
991 _gtk_css_parser_error (parser,
997 if (!_gtk_css_parser_try (parser, ")", TRUE))
999 gtk_gradient_unref (gradient);
1000 _gtk_css_parser_error (parser,
1005 g_value_take_boxed (value, gradient);
1010 gradient_value_print (const GValue *value,
1013 GtkGradient *gradient = g_value_get_boxed (value);
1015 if (gradient == NULL)
1016 g_string_append (string, "none");
1019 char *s = gtk_gradient_to_string (gradient);
1020 g_string_append (string, s);
1026 gtk_css_parse_url (GtkCssParser *parser,
1032 if (_gtk_css_parser_try (parser, "url", FALSE))
1034 if (!_gtk_css_parser_try (parser, "(", TRUE))
1036 _gtk_css_parser_skip_whitespace (parser);
1037 if (_gtk_css_parser_try (parser, "(", TRUE))
1041 error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
1042 GTK_CSS_PROVIDER_ERROR_DEPRECATED,
1043 "Whitespace between 'url' and '(' is deprecated");
1045 _gtk_css_parser_take_error (parser, error);
1049 _gtk_css_parser_error (parser, "Expected '(' after 'url'");
1054 path = _gtk_css_parser_read_string (parser);
1058 if (!_gtk_css_parser_try (parser, ")", TRUE))
1060 _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
1067 path = _gtk_css_parser_try_name (parser, TRUE);
1070 _gtk_css_parser_error (parser, "Not a valid url");
1075 file = g_file_resolve_relative_path (base, path);
1082 pattern_value_parse (GtkCssParser *parser,
1086 if (_gtk_css_parser_try (parser, "none", TRUE))
1088 /* nothing to do here */
1090 else if (_gtk_css_parser_begins_with (parser, '-'))
1093 res = _gtk_win32_theme_part_parse (parser, base, value);
1096 /* < 0 => continue */
1097 g_value_unset (value);
1098 g_value_init (value, GTK_TYPE_GRADIENT);
1099 return gradient_value_parse (parser, base, value);
1103 GError *error = NULL;
1107 cairo_surface_t *surface;
1108 cairo_pattern_t *pattern;
1110 cairo_matrix_t matrix;
1112 file = gtk_css_parse_url (parser, base);
1116 path = g_file_get_path (file);
1117 g_object_unref (file);
1119 pixbuf = gdk_pixbuf_new_from_file (path, &error);
1123 _gtk_css_parser_take_error (parser, error);
1127 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1128 gdk_pixbuf_get_width (pixbuf),
1129 gdk_pixbuf_get_height (pixbuf));
1130 cr = cairo_create (surface);
1131 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
1133 pattern = cairo_pattern_create_for_surface (surface);
1135 cairo_matrix_init_scale (&matrix,
1136 gdk_pixbuf_get_width (pixbuf),
1137 gdk_pixbuf_get_height (pixbuf));
1138 cairo_pattern_set_matrix (pattern, &matrix);
1140 cairo_surface_destroy (surface);
1142 g_object_unref (pixbuf);
1144 g_value_take_boxed (value, pattern);
1150 static cairo_status_t
1151 surface_write (void *closure,
1152 const unsigned char *data,
1153 unsigned int length)
1155 g_byte_array_append (closure, data, length);
1157 return CAIRO_STATUS_SUCCESS;
1161 surface_print (cairo_surface_t *surface,
1164 #if CAIRO_HAS_PNG_FUNCTIONS
1168 array = g_byte_array_new ();
1169 cairo_surface_write_to_png_stream (surface, surface_write, array);
1170 base64 = g_base64_encode (array->data, array->len);
1171 g_byte_array_free (array, TRUE);
1173 g_string_append (string, "url(\"data:image/png;base64,");
1174 g_string_append (string, base64);
1175 g_string_append (string, "\")");
1179 g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
1184 pattern_value_print (const GValue *value,
1187 cairo_pattern_t *pattern;
1188 cairo_surface_t *surface;
1190 pattern = g_value_get_boxed (value);
1192 if (pattern == NULL)
1194 g_string_append (string, "none");
1198 switch (cairo_pattern_get_type (pattern))
1200 case CAIRO_PATTERN_TYPE_SURFACE:
1201 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
1203 g_assert_not_reached ();
1205 surface_print (surface, string);
1207 case CAIRO_PATTERN_TYPE_SOLID:
1208 case CAIRO_PATTERN_TYPE_LINEAR:
1209 case CAIRO_PATTERN_TYPE_RADIAL:
1211 g_assert_not_reached ();
1217 shadow_value_parse (GtkCssParser *parser,
1221 gboolean have_inset, have_color, have_lengths;
1222 gdouble hoffset, voffset, blur, spread;
1223 GtkSymbolicColor *color;
1227 shadow = _gtk_shadow_new ();
1229 if (_gtk_css_parser_try (parser, "none", TRUE))
1234 have_inset = have_lengths = have_color = FALSE;
1236 for (i = 0; i < 3; i++)
1239 _gtk_css_parser_try (parser, "inset", TRUE))
1245 if (!have_lengths &&
1246 _gtk_css_parser_try_double (parser, &hoffset))
1248 have_lengths = TRUE;
1250 if (!_gtk_css_parser_try_double (parser, &voffset))
1252 _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
1253 _gtk_shadow_unref (shadow);
1257 if (!_gtk_css_parser_try_double (parser, &blur))
1260 if (!_gtk_css_parser_try_double (parser, &spread))
1270 /* XXX: the color is optional and UA-defined if it's missing,
1271 * but it doesn't really make sense for us...
1273 color = _gtk_css_parser_read_symbolic_color (parser);
1277 _gtk_shadow_unref (shadow);
1283 if (!have_color || !have_lengths)
1285 _gtk_css_parser_error (parser, "Must specify at least color and offsets");
1286 _gtk_shadow_unref (shadow);
1290 _gtk_shadow_append (shadow,
1295 gtk_symbolic_color_unref (color);
1298 while (_gtk_css_parser_try (parser, ",", TRUE));
1300 g_value_take_boxed (value, shadow);
1305 shadow_value_print (const GValue *value,
1310 shadow = g_value_get_boxed (value);
1313 g_string_append (string, "none");
1315 _gtk_shadow_print (shadow, string);
1319 background_repeat_value_parse (GtkCssParser *parser,
1323 GtkCssBackgroundRepeat repeat;
1326 if (!enum_parse (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, &style))
1329 repeat.repeat = style;
1331 g_value_set_boxed (value, &repeat);
1337 background_repeat_value_print (const GValue *value,
1340 GtkCssBackgroundRepeat *repeat;
1342 repeat = g_value_get_boxed (value);
1344 enum_print (repeat->repeat, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, string);
1348 border_image_repeat_value_parse (GtkCssParser *parser,
1352 GtkCssBorderImageRepeat image_repeat;
1353 GtkCssBorderRepeatStyle styles[2];
1356 for (i = 0; i < 2; i++)
1358 if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
1362 styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
1366 styles[i] = styles[0];
1369 image_repeat.hrepeat = styles[0];
1370 image_repeat.vrepeat = styles[1];
1372 g_value_set_boxed (value, &image_repeat);
1378 border_image_repeat_value_print (const GValue *value,
1381 GtkCssBorderImageRepeat *image_repeat;
1383 image_repeat = g_value_get_boxed (value);
1385 enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1386 if (image_repeat->hrepeat != image_repeat->vrepeat)
1388 g_string_append (string, " ");
1389 enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1394 enum_value_parse (GtkCssParser *parser,
1400 if (enum_parse (parser, G_VALUE_TYPE (value), &v))
1402 g_value_set_enum (value, v);
1410 enum_value_print (const GValue *value,
1413 enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
1417 flags_value_parse (GtkCssParser *parser,
1421 GFlagsClass *flags_class;
1422 GFlagsValue *flag_value;
1426 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1429 str = _gtk_css_parser_try_ident (parser, TRUE);
1432 _gtk_css_parser_error (parser, "Expected an identifier");
1433 g_type_class_unref (flags_class);
1437 flag_value = g_flags_get_value_by_nick (flags_class, str);
1440 _gtk_css_parser_error (parser,
1441 "Unknown flag value '%s' for type '%s'",
1442 str, g_type_name (G_VALUE_TYPE (value)));
1443 /* XXX Do we want to return FALSE here? We can get
1444 * forward-compatibility for new values this way
1447 g_type_class_unref (flags_class);
1453 while (_gtk_css_parser_try (parser, ",", FALSE));
1455 g_type_class_unref (flags_class);
1457 g_value_set_enum (value, flags);
1463 flags_value_print (const GValue *value,
1466 GFlagsClass *flags_class;
1469 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1470 flags = g_value_get_flags (value);
1472 for (i = 0; i < flags_class->n_values; i++)
1474 GFlagsValue *flags_value = &flags_class->values[i];
1476 if (flags & flags_value->value)
1478 if (string->len != 0)
1479 g_string_append (string, ", ");
1481 g_string_append (string, flags_value->value_nick);
1485 g_type_class_unref (flags_class);
1489 bindings_value_parse (GtkCssParser *parser,
1494 GtkBindingSet *binding_set;
1497 array = g_ptr_array_new ();
1500 name = _gtk_css_parser_try_ident (parser, TRUE);
1503 _gtk_css_parser_error (parser, "Not a valid binding name");
1504 g_ptr_array_free (array, TRUE);
1508 binding_set = gtk_binding_set_find (name);
1512 _gtk_css_parser_error (parser, "No binding set named '%s'", name);
1517 g_ptr_array_add (array, binding_set);
1520 while (_gtk_css_parser_try (parser, ",", TRUE));
1522 g_value_take_boxed (value, array);
1528 bindings_value_print (const GValue *value,
1534 array = g_value_get_boxed (value);
1536 for (i = 0; i < array->len; i++)
1538 GtkBindingSet *binding_set = g_ptr_array_index (array, i);
1541 g_string_append (string, ", ");
1542 g_string_append (string, binding_set->set_name);
1547 border_corner_radius_value_parse (GtkCssParser *parser,
1551 GtkCssBorderCornerRadius corner;
1553 if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
1555 _gtk_css_parser_error (parser, "Expected a number");
1558 else if (corner.horizontal < 0)
1561 if (!_gtk_css_parser_try_double (parser, &corner.vertical))
1562 corner.vertical = corner.horizontal;
1563 else if (corner.vertical < 0)
1566 g_value_set_boxed (value, &corner);
1570 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1575 border_corner_radius_value_print (const GValue *value,
1578 GtkCssBorderCornerRadius *corner;
1580 corner = g_value_get_boxed (value);
1584 g_string_append (string, "none");
1588 string_append_double (string, corner->horizontal);
1589 if (corner->horizontal != corner->vertical)
1591 g_string_append_c (string, ' ');
1592 string_append_double (string, corner->vertical);
1597 transparent_color_value_parse (GtkCssParser *parser,
1601 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1603 GdkRGBA transparent = { 0, 0, 0, 0 };
1605 g_value_set_boxed (value, &transparent);
1610 return rgba_value_parse (parser, base, value);
1616 css_string_funcs_init (void)
1618 if (G_LIKELY (parse_funcs != NULL))
1621 parse_funcs = g_hash_table_new (NULL, NULL);
1622 print_funcs = g_hash_table_new (NULL, NULL);
1624 register_conversion_function (GDK_TYPE_RGBA,
1627 register_conversion_function (GDK_TYPE_COLOR,
1630 register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
1631 symbolic_color_value_parse,
1632 symbolic_color_value_print);
1633 register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
1634 font_description_value_parse,
1635 font_description_value_print);
1636 register_conversion_function (G_TYPE_BOOLEAN,
1637 boolean_value_parse,
1638 boolean_value_print);
1639 register_conversion_function (G_TYPE_INT,
1642 register_conversion_function (G_TYPE_UINT,
1645 register_conversion_function (G_TYPE_DOUBLE,
1647 double_value_print);
1648 register_conversion_function (G_TYPE_FLOAT,
1651 register_conversion_function (G_TYPE_STRING,
1653 string_value_print);
1654 register_conversion_function (GTK_TYPE_THEMING_ENGINE,
1655 theming_engine_value_parse,
1656 theming_engine_value_print);
1657 register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
1658 animation_description_value_parse,
1659 animation_description_value_print);
1660 register_conversion_function (GTK_TYPE_BORDER,
1662 border_value_print);
1663 register_conversion_function (GTK_TYPE_GRADIENT,
1664 gradient_value_parse,
1665 gradient_value_print);
1666 register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
1667 pattern_value_parse,
1668 pattern_value_print);
1669 register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1670 border_image_repeat_value_parse,
1671 border_image_repeat_value_print);
1672 register_conversion_function (GTK_TYPE_SHADOW,
1674 shadow_value_print);
1675 register_conversion_function (G_TYPE_ENUM,
1678 register_conversion_function (G_TYPE_FLAGS,
1681 register_conversion_function (GTK_TYPE_CSS_BACKGROUND_REPEAT,
1682 background_repeat_value_parse,
1683 background_repeat_value_print);
1687 _gtk_style_property_parse_value (GtkStyleProperty *property,
1689 GtkCssParser *parser,
1692 GtkStyleParseFunc func;
1694 g_return_val_if_fail (value != NULL, FALSE);
1695 g_return_val_if_fail (parser != NULL, FALSE);
1697 css_string_funcs_init ();
1701 if (_gtk_css_parser_try (parser, "initial", TRUE))
1703 /* the initial value can be explicitly specified with the
1704 * ‘initial’ keyword which all properties accept.
1706 g_value_unset (value);
1707 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
1708 g_value_set_enum (value, GTK_CSS_INITIAL);
1711 else if (_gtk_css_parser_try (parser, "inherit", TRUE))
1713 /* All properties accept the ‘inherit’ value which
1714 * explicitly specifies that the value will be determined
1715 * by inheritance. The ‘inherit’ value can be used to
1716 * strengthen inherited values in the cascade, and it can
1717 * also be used on properties that are not normally inherited.
1719 g_value_unset (value);
1720 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
1721 g_value_set_enum (value, GTK_CSS_INHERIT);
1724 else if (property->property_parse_func)
1726 GError *error = NULL;
1730 value_str = _gtk_css_parser_read_value (parser);
1731 if (value_str == NULL)
1734 success = (*property->property_parse_func) (value_str, value, &error);
1741 func = property->parse_func;
1747 func = g_hash_table_lookup (parse_funcs,
1748 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1750 func = g_hash_table_lookup (parse_funcs,
1751 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1755 _gtk_css_parser_error (parser,
1756 "Cannot convert to type '%s'",
1757 g_type_name (G_VALUE_TYPE (value)));
1761 return (*func) (parser, base, value);
1765 _gtk_style_property_print_value (GtkStyleProperty *property,
1766 const GValue *value,
1769 GtkStylePrintFunc func;
1771 css_string_funcs_init ();
1773 if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
1774 func = enum_value_print;
1776 func = property->print_func;
1781 func = g_hash_table_lookup (print_funcs,
1782 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1784 func = g_hash_table_lookup (print_funcs,
1785 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1789 char *s = g_strdup_value_contents (value);
1790 g_string_append (string, s);
1795 func (value, string);
1799 _gtk_style_property_default_value (GtkStyleProperty *property,
1800 GtkStyleProperties *properties,
1801 GtkStateFlags state,
1804 g_value_copy (&property->initial_value, value);
1808 resolve_color (GtkStyleProperties *props,
1813 /* Resolve symbolic color to GdkRGBA */
1814 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
1817 /* Store it back, this is where GdkRGBA caching happens */
1818 g_value_unset (value);
1819 g_value_init (value, GDK_TYPE_RGBA);
1820 g_value_set_boxed (value, &color);
1826 resolve_color_rgb (GtkStyleProperties *props,
1829 GdkColor color = { 0 };
1832 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
1835 color.red = rgba.red * 65535. + 0.5;
1836 color.green = rgba.green * 65535. + 0.5;
1837 color.blue = rgba.blue * 65535. + 0.5;
1839 g_value_unset (value);
1840 g_value_init (value, GDK_TYPE_COLOR);
1841 g_value_set_boxed (value, &color);
1847 resolve_win32_theme_part (GtkStyleProperties *props,
1850 GtkStylePropertyContext *context)
1852 GtkWin32ThemePart *part;
1853 cairo_pattern_t *pattern;
1855 part = g_value_get_boxed (value);
1859 pattern = _gtk_win32_theme_part_render (part, context->width, context->height);
1861 g_value_take_boxed (value_out, pattern);
1868 resolve_gradient (GtkStyleProperties *props,
1871 cairo_pattern_t *gradient;
1873 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
1876 /* Store it back, this is where cairo_pattern_t caching happens */
1877 g_value_unset (value);
1878 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
1879 g_value_take_boxed (value, gradient);
1885 resolve_shadow (GtkStyleProperties *props,
1888 GtkShadow *resolved, *base;
1890 base = g_value_get_boxed (value);
1895 if (_gtk_shadow_get_resolved (base))
1898 resolved = _gtk_shadow_resolve (base, props);
1899 if (resolved == NULL)
1902 g_value_take_boxed (value, resolved);
1908 _gtk_style_property_resolve (GtkStyleProperty *property,
1909 GtkStyleProperties *props,
1910 GtkStateFlags state,
1911 GtkStylePropertyContext *context,
1915 if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_SPECIAL_VALUE)
1917 GtkCssSpecialValue special = g_value_get_enum (val);
1919 g_value_unset (val);
1922 case GTK_CSS_CURRENT_COLOR:
1923 g_assert (property->pspec->value_type == GDK_TYPE_RGBA);
1924 gtk_style_properties_get_property (props, "color", state, val);
1926 case GTK_CSS_INHERIT:
1927 case GTK_CSS_INITIAL:
1929 g_assert_not_reached ();
1932 else if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
1934 if (property->pspec->value_type == GDK_TYPE_RGBA)
1936 if (resolve_color (props, val))
1939 else if (property->pspec->value_type == GDK_TYPE_COLOR)
1941 if (resolve_color_rgb (props, val))
1945 g_value_unset (val);
1946 g_value_init (val, property->pspec->value_type);
1947 _gtk_style_property_default_value (property, props, state, val);
1949 else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
1951 if (g_value_get_boxed (val) == NULL)
1952 _gtk_style_property_default_value (property, props, state, val);
1954 else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
1956 g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
1958 if (!resolve_gradient (props, val))
1960 g_value_unset (val);
1961 g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
1962 _gtk_style_property_default_value (property, props, state, val);
1965 else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
1967 if (!resolve_shadow (props, val))
1968 _gtk_style_property_default_value (property, props, state, val);
1970 else if (G_VALUE_TYPE (val) == GTK_TYPE_WIN32_THEME_PART)
1972 if (resolve_win32_theme_part (props, val, val_out, context))
1973 return; /* Don't copy val, this sets val_out */
1974 _gtk_style_property_default_value (property, props, state, val);
1978 g_value_copy (val, val_out);
1982 _gtk_style_property_unpack (GtkStyleProperty *property,
1983 const GValue *value,
1986 g_return_val_if_fail (property != NULL, NULL);
1987 g_return_val_if_fail (property->unpack_func != NULL, NULL);
1988 g_return_val_if_fail (value != NULL, NULL);
1989 g_return_val_if_fail (n_params != NULL, NULL);
1991 return property->unpack_func (value, n_params);
1995 _gtk_style_property_pack (GtkStyleProperty *property,
1996 GtkStyleProperties *props,
1997 GtkStateFlags state,
1998 GtkStylePropertyContext *context,
2001 g_return_if_fail (property != NULL);
2002 g_return_if_fail (property->pack_func != NULL);
2003 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2004 g_return_if_fail (G_IS_VALUE (value));
2006 property->pack_func (value, props, state, context);
2010 _gtk_style_property_assign (GtkStyleProperty *property,
2011 GtkStyleProperties *props,
2012 GtkStateFlags state,
2013 const GValue *value)
2015 g_return_if_fail (GTK_IS_STYLE_PROPERTY (property));
2016 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2017 g_return_if_fail (value != NULL);
2019 if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
2021 GParameter *parameters;
2022 guint i, n_parameters;
2024 parameters = _gtk_style_property_unpack (property, value, &n_parameters);
2026 for (i = 0; i < n_parameters; i++)
2028 _gtk_style_property_assign (_gtk_style_property_lookup (parameters[i].name),
2031 ¶meters[i].value);
2032 g_value_unset (¶meters[i].value);
2034 g_free (parameters);
2037 else if (GTK_IS_CSS_STYLE_PROPERTY (property))
2039 _gtk_style_properties_set_property_by_property (props,
2040 GTK_CSS_STYLE_PROPERTY (property),
2046 g_assert_not_reached ();
2051 _gtk_style_property_query (GtkStyleProperty *property,
2052 GtkStyleProperties *props,
2053 GtkStateFlags state,
2054 GtkStylePropertyContext *context,
2058 g_return_if_fail (property != NULL);
2059 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2060 g_return_if_fail (context != NULL);
2061 g_return_if_fail (value != NULL);
2063 g_value_init (value, property->pspec->value_type);
2065 if (GTK_IS_CSS_STYLE_PROPERTY (property))
2069 val = _gtk_style_properties_peek_property (props, GTK_CSS_STYLE_PROPERTY (property), state);
2071 _gtk_style_property_resolve (property, props, state, context, (GValue *) val, value);
2073 _gtk_style_property_default_value (property, props, state, value);
2075 else if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
2077 _gtk_style_property_pack (property, props, state, context, value);
2081 g_assert_not_reached ();
2085 #define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
2086 (rgba)->red = (r); \
2087 (rgba)->green = (g); \
2088 (rgba)->blue = (b); \
2089 (rgba)->alpha = (a); \
2092 gtk_style_property_init_properties (void)
2094 static gboolean initialized = FALSE;
2095 GValue value = { 0, };
2096 char *default_font_family[] = { "Sans", NULL };
2099 if (G_LIKELY (initialized))
2104 g_value_init (&value, GDK_TYPE_RGBA);
2105 rgba_init (&rgba, 1, 1, 1, 1);
2106 g_value_set_boxed (&value, &rgba);
2107 _gtk_style_property_register (g_param_spec_boxed ("color",
2111 GTK_STYLE_PROPERTY_INHERIT,
2116 rgba_init (&rgba, 0, 0, 0, 0);
2117 g_value_set_boxed (&value, &rgba);
2118 _gtk_style_property_register (g_param_spec_boxed ("background-color",
2124 transparent_color_value_parse,
2127 g_value_unset (&value);
2129 g_value_init (&value, G_TYPE_STRV);
2130 g_value_set_boxed (&value, default_font_family);
2131 _gtk_style_property_register (g_param_spec_boxed ("font-family",
2135 GTK_STYLE_PROPERTY_INHERIT,
2138 font_family_value_print,
2140 g_value_unset (&value);
2141 _gtk_style_property_register (g_param_spec_enum ("font-style",
2145 PANGO_STYLE_NORMAL, 0),
2146 GTK_STYLE_PROPERTY_INHERIT,
2151 _gtk_style_property_register (g_param_spec_enum ("font-variant",
2155 PANGO_VARIANT_NORMAL, 0),
2156 GTK_STYLE_PROPERTY_INHERIT,
2161 /* xxx: need to parse this properly, ie parse the numbers */
2162 _gtk_style_property_register (g_param_spec_enum ("font-weight",
2166 PANGO_WEIGHT_NORMAL, 0),
2167 GTK_STYLE_PROPERTY_INHERIT,
2172 g_value_init (&value, G_TYPE_DOUBLE);
2173 g_value_set_double (&value, 10);
2174 _gtk_style_property_register (g_param_spec_double ("font-size",
2177 0, G_MAXDOUBLE, 0, 0),
2178 GTK_STYLE_PROPERTY_INHERIT,
2183 g_value_unset (&value);
2185 _gtk_style_property_register (g_param_spec_boxed ("text-shadow",
2188 GTK_TYPE_SHADOW, 0),
2189 GTK_STYLE_PROPERTY_INHERIT,
2195 _gtk_style_property_register (g_param_spec_boxed ("icon-shadow",
2198 GTK_TYPE_SHADOW, 0),
2199 GTK_STYLE_PROPERTY_INHERIT,
2205 gtk_style_properties_register_property (NULL,
2206 g_param_spec_boxed ("box-shadow",
2209 GTK_TYPE_SHADOW, 0));
2210 gtk_style_properties_register_property (NULL,
2211 g_param_spec_int ("margin-top",
2214 0, G_MAXINT, 0, 0));
2215 gtk_style_properties_register_property (NULL,
2216 g_param_spec_int ("margin-left",
2219 0, G_MAXINT, 0, 0));
2220 gtk_style_properties_register_property (NULL,
2221 g_param_spec_int ("margin-bottom",
2224 0, G_MAXINT, 0, 0));
2225 gtk_style_properties_register_property (NULL,
2226 g_param_spec_int ("margin-right",
2229 0, G_MAXINT, 0, 0));
2230 gtk_style_properties_register_property (NULL,
2231 g_param_spec_int ("padding-top",
2234 0, G_MAXINT, 0, 0));
2235 gtk_style_properties_register_property (NULL,
2236 g_param_spec_int ("padding-left",
2239 0, G_MAXINT, 0, 0));
2240 gtk_style_properties_register_property (NULL,
2241 g_param_spec_int ("padding-bottom",
2243 "Padding at bottom",
2244 0, G_MAXINT, 0, 0));
2245 gtk_style_properties_register_property (NULL,
2246 g_param_spec_int ("padding-right",
2249 0, G_MAXINT, 0, 0));
2250 gtk_style_properties_register_property (NULL,
2251 g_param_spec_int ("border-top-width",
2253 "Border width at top",
2254 0, G_MAXINT, 0, 0));
2255 gtk_style_properties_register_property (NULL,
2256 g_param_spec_int ("border-left-width",
2257 "border left width",
2258 "Border width at left",
2259 0, G_MAXINT, 0, 0));
2260 gtk_style_properties_register_property (NULL,
2261 g_param_spec_int ("border-bottom-width",
2262 "border bottom width",
2263 "Border width at bottom",
2264 0, G_MAXINT, 0, 0));
2265 gtk_style_properties_register_property (NULL,
2266 g_param_spec_int ("border-right-width",
2267 "border right width",
2268 "Border width at right",
2269 0, G_MAXINT, 0, 0));
2271 _gtk_style_property_register (g_param_spec_boxed ("border-top-left-radius",
2272 "Border top left radius",
2273 "Border radius of top left corner, in pixels",
2274 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2277 border_corner_radius_value_parse,
2278 border_corner_radius_value_print,
2280 _gtk_style_property_register (g_param_spec_boxed ("border-top-right-radius",
2281 "Border top right radius",
2282 "Border radius of top right corner, in pixels",
2283 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2286 border_corner_radius_value_parse,
2287 border_corner_radius_value_print,
2289 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-right-radius",
2290 "Border bottom right radius",
2291 "Border radius of bottom right corner, in pixels",
2292 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2295 border_corner_radius_value_parse,
2296 border_corner_radius_value_print,
2298 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-left-radius",
2299 "Border bottom left radius",
2300 "Border radius of bottom left corner, in pixels",
2301 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2304 border_corner_radius_value_parse,
2305 border_corner_radius_value_print,
2308 gtk_style_properties_register_property (NULL,
2309 g_param_spec_enum ("border-style",
2312 GTK_TYPE_BORDER_STYLE,
2313 GTK_BORDER_STYLE_NONE, 0));
2314 gtk_style_properties_register_property (NULL,
2315 g_param_spec_enum ("background-clip",
2319 GTK_CSS_AREA_BORDER_BOX, 0));
2320 gtk_style_properties_register_property (NULL,
2321 g_param_spec_enum ("background-origin",
2322 "Background origin",
2323 "Background origin",
2325 GTK_CSS_AREA_PADDING_BOX, 0));
2326 g_value_init (&value, GTK_TYPE_CSS_SPECIAL_VALUE);
2327 g_value_set_enum (&value, GTK_CSS_CURRENT_COLOR);
2328 _gtk_style_property_register (g_param_spec_boxed ("border-top-color",
2334 transparent_color_value_parse,
2337 _gtk_style_property_register (g_param_spec_boxed ("border-right-color",
2338 "Border right color",
2339 "Border right color",
2343 transparent_color_value_parse,
2346 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-color",
2347 "Border bottom color",
2348 "Border bottom color",
2352 transparent_color_value_parse,
2355 _gtk_style_property_register (g_param_spec_boxed ("border-left-color",
2356 "Border left color",
2357 "Border left color",
2361 transparent_color_value_parse,
2364 g_value_unset (&value);
2366 gtk_style_properties_register_property (NULL,
2367 g_param_spec_boxed ("background-image",
2370 CAIRO_GOBJECT_TYPE_PATTERN, 0));
2371 gtk_style_properties_register_property (NULL,
2372 g_param_spec_boxed ("background-repeat",
2373 "Background repeat",
2374 "Background repeat",
2375 GTK_TYPE_CSS_BACKGROUND_REPEAT, 0));
2377 gtk_style_properties_register_property (NULL,
2378 g_param_spec_boxed ("border-image-source",
2379 "Border image source",
2380 "Border image source",
2381 CAIRO_GOBJECT_TYPE_PATTERN, 0));
2382 gtk_style_properties_register_property (NULL,
2383 g_param_spec_boxed ("border-image-repeat",
2384 "Border image repeat",
2385 "Border image repeat",
2386 GTK_TYPE_CSS_BORDER_IMAGE_REPEAT, 0));
2387 gtk_style_properties_register_property (NULL,
2388 g_param_spec_boxed ("border-image-slice",
2389 "Border image slice",
2390 "Border image slice",
2391 GTK_TYPE_BORDER, 0));
2392 g_value_init (&value, GTK_TYPE_BORDER);
2393 _gtk_style_property_register (g_param_spec_boxed ("border-image-width",
2394 "Border image width",
2395 "Border image width",
2396 GTK_TYPE_BORDER, 0),
2402 g_value_unset (&value);
2403 gtk_style_properties_register_property (NULL,
2404 g_param_spec_object ("engine",
2407 GTK_TYPE_THEMING_ENGINE, 0));
2408 gtk_style_properties_register_property (NULL,
2409 g_param_spec_boxed ("transition",
2410 "Transition animation description",
2411 "Transition animation description",
2412 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
2414 /* Private property holding the binding sets */
2415 _gtk_style_property_register (g_param_spec_boxed ("gtk-key-bindings",
2418 G_TYPE_PTR_ARRAY, 0),
2421 bindings_value_parse,
2422 bindings_value_print,
2425 /* initialize shorthands last, they depend on the real properties existing */
2426 _gtk_css_shorthand_property_init_properties ();
2430 * _gtk_style_property_lookup:
2431 * @name: name of the property to lookup
2433 * Looks up the CSS property with the given @name. If no such
2434 * property exists, %NULL is returned.
2436 * Returns: (transfer none): The property or %NULL if no
2437 * property with the given name exists.
2440 _gtk_style_property_lookup (const char *name)
2442 GtkStylePropertyClass *klass;
2444 g_return_val_if_fail (name != NULL, NULL);
2446 gtk_style_property_init_properties ();
2448 klass = g_type_class_peek (GTK_TYPE_STYLE_PROPERTY);
2450 return g_hash_table_lookup (klass->properties, name);
2454 * _gtk_style_property_get_name:
2455 * @property: the property to query
2457 * Gets the name of the given property.
2459 * Returns: the name of the property
2462 _gtk_style_property_get_name (GtkStyleProperty *property)
2464 g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), NULL);
2466 return property->name;
2470 * _gtk_style_property_get_value_type:
2471 * @property: the property to query
2473 * Gets the value type of the @property, if the property is usable
2474 * in public API via _gtk_style_property_assign() and
2475 * _gtk_style_property_query(). If the @property is not usable in that
2476 * way, %G_TYPE_NONE is returned.
2478 * Returns: the value type in use or %G_TYPE_NONE if none.
2481 _gtk_style_property_get_value_type (GtkStyleProperty *property)
2483 g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), G_TYPE_NONE);
2485 return property->value_type;
2490 _gtk_style_property_register (GParamSpec *pspec,
2491 GtkStylePropertyFlags flags,
2492 GtkStylePropertyParser property_parse_func,
2493 GtkStyleParseFunc parse_func,
2494 GtkStylePrintFunc print_func,
2495 const GValue * initial_value)
2497 GtkStyleProperty *node;
2499 node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
2500 "name", pspec->name,
2501 "value-type", pspec->value_type,
2503 node->flags = flags;
2504 node->pspec = pspec;
2505 node->property_parse_func = property_parse_func;
2506 node->parse_func = parse_func;
2507 node->print_func = print_func;
2509 /* initialize the initial value */
2512 g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value));
2513 g_value_copy (initial_value, &node->initial_value);
2517 g_value_init (&node->initial_value, pspec->value_type);
2518 if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
2519 g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
2520 else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
2521 g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10"));
2522 else if (pspec->value_type == GDK_TYPE_RGBA)
2525 gdk_rgba_parse (&color, "pink");
2526 g_value_set_boxed (&node->initial_value, &color);
2528 else if (pspec->value_type == GTK_TYPE_BORDER)
2530 g_value_take_boxed (&node->initial_value, gtk_border_new ());
2533 g_param_value_set_default (pspec, &node->initial_value);