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"
60 static GHashTable *parse_funcs = NULL;
61 static GHashTable *print_funcs = NULL;
62 static GPtrArray *__style_property_array = 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 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
100 gtk_style_property_get_property (GObject *object,
105 GtkStyleProperty *property = GTK_STYLE_PROPERTY (object);
110 g_value_set_string (value, property->name);
113 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
119 _gtk_style_property_class_init (GtkStylePropertyClass *klass)
121 GObjectClass *object_class = G_OBJECT_CLASS (klass);
123 object_class->finalize = gtk_style_property_finalize;
124 object_class->set_property = gtk_style_property_set_property;
125 object_class->get_property = gtk_style_property_get_property;
127 g_object_class_install_property (object_class,
129 g_param_spec_string ("name",
131 P_("The name of the property"),
133 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
135 klass->properties = g_hash_table_new (g_str_hash, g_str_equal);
139 _gtk_style_property_init (GtkStyleProperty *property)
144 register_conversion_function (GType type,
145 GtkStyleParseFunc parse,
146 GtkStylePrintFunc print)
149 g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
151 g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
155 string_append_double (GString *string,
158 char buf[G_ASCII_DTOSTR_BUF_SIZE];
160 g_ascii_dtostr (buf, sizeof (buf), d);
161 g_string_append (string, buf);
165 string_append_string (GString *str,
170 g_string_append_c (str, '"');
173 len = strcspn (string, "\"\n\r\f");
174 g_string_append (str, string);
181 g_string_append (str, "\\A ");
184 g_string_append (str, "\\D ");
187 g_string_append (str, "\\C ");
190 g_string_append (str, "\\\"");
193 g_assert_not_reached ();
198 g_string_append_c (str, '"');
201 /*** IMPLEMENTATIONS ***/
204 enum_parse (GtkCssParser *parser,
210 if (_gtk_css_parser_try_enum (parser, type, res))
213 str = _gtk_css_parser_try_ident (parser, TRUE);
216 _gtk_css_parser_error (parser, "Expected an identifier");
220 _gtk_css_parser_error (parser,
221 "Unknown value '%s' for enum type '%s'",
222 str, g_type_name (type));
229 enum_print (int value,
233 GEnumClass *enum_class;
234 GEnumValue *enum_value;
236 enum_class = g_type_class_ref (type);
237 enum_value = g_enum_get_value (enum_class, value);
239 g_string_append (string, enum_value->value_nick);
241 g_type_class_unref (enum_class);
245 rgba_value_parse (GtkCssParser *parser,
249 GtkSymbolicColor *symbolic;
252 symbolic = _gtk_css_parser_read_symbolic_color (parser);
253 if (symbolic == NULL)
256 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
258 g_value_set_boxed (value, &rgba);
259 gtk_symbolic_color_unref (symbolic);
263 g_value_unset (value);
264 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
265 g_value_take_boxed (value, symbolic);
272 rgba_value_print (const GValue *value,
275 const GdkRGBA *rgba = g_value_get_boxed (value);
278 g_string_append (string, "none");
281 char *s = gdk_rgba_to_string (rgba);
282 g_string_append (string, s);
288 color_value_parse (GtkCssParser *parser,
292 GtkSymbolicColor *symbolic;
295 symbolic = _gtk_css_parser_read_symbolic_color (parser);
296 if (symbolic == NULL)
299 if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
303 color.red = rgba.red * 65535. + 0.5;
304 color.green = rgba.green * 65535. + 0.5;
305 color.blue = rgba.blue * 65535. + 0.5;
307 g_value_set_boxed (value, &color);
311 g_value_unset (value);
312 g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
313 g_value_take_boxed (value, symbolic);
320 color_value_print (const GValue *value,
323 const GdkColor *color = g_value_get_boxed (value);
326 g_string_append (string, "none");
329 char *s = gdk_color_to_string (color);
330 g_string_append (string, s);
336 symbolic_color_value_parse (GtkCssParser *parser,
340 GtkSymbolicColor *symbolic;
342 symbolic = _gtk_css_parser_read_symbolic_color (parser);
343 if (symbolic == NULL)
346 g_value_take_boxed (value, symbolic);
351 symbolic_color_value_print (const GValue *value,
354 GtkSymbolicColor *symbolic = g_value_get_boxed (value);
356 if (symbolic == NULL)
357 g_string_append (string, "none");
360 char *s = gtk_symbolic_color_to_string (symbolic);
361 g_string_append (string, s);
367 font_family_parse (GtkCssParser *parser,
374 /* We don't special case generic families. Pango should do
377 names = g_ptr_array_new ();
380 name = _gtk_css_parser_try_ident (parser, TRUE);
383 GString *string = g_string_new (name);
385 while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
387 g_string_append_c (string, ' ');
388 g_string_append (string, name);
391 name = g_string_free (string, FALSE);
395 name = _gtk_css_parser_read_string (parser);
398 g_ptr_array_free (names, TRUE);
403 g_ptr_array_add (names, name);
404 } while (_gtk_css_parser_try (parser, ",", TRUE));
406 /* NULL-terminate array */
407 g_ptr_array_add (names, NULL);
408 g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
413 font_family_value_print (const GValue *value,
416 const char **names = g_value_get_boxed (value);
418 if (names == NULL || *names == NULL)
420 g_string_append (string, "none");
424 string_append_string (string, *names);
428 g_string_append (string, ", ");
429 string_append_string (string, *names);
435 font_description_value_parse (GtkCssParser *parser,
439 PangoFontDescription *font_desc;
443 str = _gtk_css_parser_read_value (parser);
447 font_desc = pango_font_description_from_string (str);
448 mask = pango_font_description_get_set_fields (font_desc);
449 /* These values are not really correct,
450 * but the fields must be set, so we set them to something */
451 if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
452 pango_font_description_set_family_static (font_desc, "Sans");
453 if ((mask & PANGO_FONT_MASK_SIZE) == 0)
454 pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
456 g_value_take_boxed (value, font_desc);
461 font_description_value_print (const GValue *value,
464 const PangoFontDescription *desc = g_value_get_boxed (value);
467 g_string_append (string, "none");
470 char *s = pango_font_description_to_string (desc);
471 g_string_append (string, s);
477 boolean_value_parse (GtkCssParser *parser,
481 if (_gtk_css_parser_try (parser, "true", TRUE) ||
482 _gtk_css_parser_try (parser, "1", TRUE))
484 g_value_set_boolean (value, TRUE);
487 else if (_gtk_css_parser_try (parser, "false", TRUE) ||
488 _gtk_css_parser_try (parser, "0", TRUE))
490 g_value_set_boolean (value, FALSE);
495 _gtk_css_parser_error (parser, "Expected a boolean value");
501 boolean_value_print (const GValue *value,
504 if (g_value_get_boolean (value))
505 g_string_append (string, "true");
507 g_string_append (string, "false");
511 int_value_parse (GtkCssParser *parser,
517 if (_gtk_css_parser_begins_with (parser, '-'))
519 int res = _gtk_win32_theme_int_parse (parser, base, &i);
522 g_value_set_int (value, i);
525 /* < 0 => continue */
528 if (!_gtk_css_parser_try_int (parser, &i))
530 _gtk_css_parser_error (parser, "Expected a valid integer value");
534 g_value_set_int (value, i);
539 int_value_print (const GValue *value,
542 g_string_append_printf (string, "%d", g_value_get_int (value));
546 uint_value_parse (GtkCssParser *parser,
552 if (!_gtk_css_parser_try_uint (parser, &u))
554 _gtk_css_parser_error (parser, "Expected a valid unsigned value");
558 g_value_set_uint (value, u);
563 uint_value_print (const GValue *value,
566 g_string_append_printf (string, "%u", g_value_get_uint (value));
570 double_value_parse (GtkCssParser *parser,
576 if (!_gtk_css_parser_try_double (parser, &d))
578 _gtk_css_parser_error (parser, "Expected a number");
582 g_value_set_double (value, d);
587 double_value_print (const GValue *value,
590 string_append_double (string, g_value_get_double (value));
594 float_value_parse (GtkCssParser *parser,
600 if (!_gtk_css_parser_try_double (parser, &d))
602 _gtk_css_parser_error (parser, "Expected a number");
606 g_value_set_float (value, d);
611 float_value_print (const GValue *value,
614 string_append_double (string, g_value_get_float (value));
618 string_value_parse (GtkCssParser *parser,
622 char *str = _gtk_css_parser_read_string (parser);
627 g_value_take_string (value, str);
632 string_value_print (const GValue *value,
635 string_append_string (str, g_value_get_string (value));
639 theming_engine_value_parse (GtkCssParser *parser,
643 GtkThemingEngine *engine;
646 if (_gtk_css_parser_try (parser, "none", TRUE))
648 g_value_set_object (value, gtk_theming_engine_load (NULL));
652 str = _gtk_css_parser_try_ident (parser, TRUE);
655 _gtk_css_parser_error (parser, "Expected a valid theme name");
659 engine = gtk_theming_engine_load (str);
663 _gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
668 g_value_set_object (value, engine);
674 theming_engine_value_print (const GValue *value,
677 GtkThemingEngine *engine;
680 engine = g_value_get_object (value);
682 g_string_append (string, "none");
685 /* XXX: gtk_theming_engine_get_name()? */
686 g_object_get (engine, "name", &name, NULL);
687 g_string_append (string, name ? name : "none");
693 animation_description_value_parse (GtkCssParser *parser,
697 GtkAnimationDescription *desc;
700 str = _gtk_css_parser_read_value (parser);
704 desc = _gtk_animation_description_from_string (str);
709 _gtk_css_parser_error (parser, "Invalid animation description");
713 g_value_take_boxed (value, desc);
718 animation_description_value_print (const GValue *value,
721 GtkAnimationDescription *desc = g_value_get_boxed (value);
724 g_string_append (string, "none");
726 _gtk_animation_description_print (desc, string);
730 border_value_parse (GtkCssParser *parser,
734 GtkBorder border = { 0, };
737 for (i = 0; i < G_N_ELEMENTS (numbers); i++)
739 if (_gtk_css_parser_begins_with (parser, '-'))
741 /* These are strictly speaking signed, but we want to be able to use them
742 for unsigned types too, as the actual ranges of values make this safe */
743 int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
745 if (res == 0) /* Parse error, report */
748 if (res < 0) /* Nothing known to expand */
753 if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
756 /* XXX: shouldn't allow spaces here? */
757 _gtk_css_parser_try (parser, "px", TRUE);
763 _gtk_css_parser_error (parser, "Expected valid border");
767 border.top = numbers[0];
769 border.right = numbers[1];
771 border.right = border.top;
773 border.bottom = numbers[2];
775 border.bottom = border.top;
777 border.left = numbers[3];
779 border.left = border.right;
781 g_value_set_boxed (value, &border);
786 border_value_print (const GValue *value, GString *string)
788 const GtkBorder *border = g_value_get_boxed (value);
791 g_string_append (string, "none");
792 else if (border->left != border->right)
793 g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
794 else if (border->top != border->bottom)
795 g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
796 else if (border->top != border->left)
797 g_string_append_printf (string, "%d %d", border->top, border->right);
799 g_string_append_printf (string, "%d", border->top);
803 gradient_value_parse (GtkCssParser *parser,
807 GtkGradient *gradient;
808 cairo_pattern_type_t type;
812 if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
814 _gtk_css_parser_error (parser,
815 "Expected '-gtk-gradient'");
819 if (!_gtk_css_parser_try (parser, "(", TRUE))
821 _gtk_css_parser_error (parser,
822 "Expected '(' after '-gtk-gradient'");
826 /* Parse gradient type */
827 if (_gtk_css_parser_try (parser, "linear", TRUE))
828 type = CAIRO_PATTERN_TYPE_LINEAR;
829 else if (_gtk_css_parser_try (parser, "radial", TRUE))
830 type = CAIRO_PATTERN_TYPE_RADIAL;
833 _gtk_css_parser_error (parser,
834 "Gradient type must be 'radial' or 'linear'");
838 /* Parse start/stop position parameters */
839 for (i = 0; i < 2; i++)
841 if (! _gtk_css_parser_try (parser, ",", TRUE))
843 _gtk_css_parser_error (parser,
848 if (_gtk_css_parser_try (parser, "left", TRUE))
850 else if (_gtk_css_parser_try (parser, "right", TRUE))
852 else if (_gtk_css_parser_try (parser, "center", TRUE))
854 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
856 _gtk_css_parser_error (parser,
857 "Expected a valid X coordinate");
861 if (_gtk_css_parser_try (parser, "top", TRUE))
862 coords[i * 3 + 1] = 0;
863 else if (_gtk_css_parser_try (parser, "bottom", TRUE))
864 coords[i * 3 + 1] = 1;
865 else if (_gtk_css_parser_try (parser, "center", TRUE))
866 coords[i * 3 + 1] = 0.5;
867 else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
869 _gtk_css_parser_error (parser,
870 "Expected a valid Y coordinate");
874 if (type == CAIRO_PATTERN_TYPE_RADIAL)
877 if (! _gtk_css_parser_try (parser, ",", TRUE))
879 _gtk_css_parser_error (parser,
884 if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
886 _gtk_css_parser_error (parser,
887 "Expected a numer for the radius");
893 if (type == CAIRO_PATTERN_TYPE_LINEAR)
894 gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
896 gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
897 coords[3], coords[4], coords[5]);
899 while (_gtk_css_parser_try (parser, ",", TRUE))
901 GtkSymbolicColor *color;
904 if (_gtk_css_parser_try (parser, "from", TRUE))
908 if (!_gtk_css_parser_try (parser, "(", TRUE))
910 gtk_gradient_unref (gradient);
911 _gtk_css_parser_error (parser,
917 else if (_gtk_css_parser_try (parser, "to", TRUE))
921 if (!_gtk_css_parser_try (parser, "(", TRUE))
923 gtk_gradient_unref (gradient);
924 _gtk_css_parser_error (parser,
930 else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
932 if (!_gtk_css_parser_try (parser, "(", TRUE))
934 gtk_gradient_unref (gradient);
935 _gtk_css_parser_error (parser,
940 if (!_gtk_css_parser_try_double (parser, &position))
942 gtk_gradient_unref (gradient);
943 _gtk_css_parser_error (parser,
944 "Expected a valid number");
948 if (!_gtk_css_parser_try (parser, ",", TRUE))
950 gtk_gradient_unref (gradient);
951 _gtk_css_parser_error (parser,
958 gtk_gradient_unref (gradient);
959 _gtk_css_parser_error (parser,
960 "Not a valid color-stop definition");
964 color = _gtk_css_parser_read_symbolic_color (parser);
967 gtk_gradient_unref (gradient);
971 gtk_gradient_add_color_stop (gradient, position, color);
972 gtk_symbolic_color_unref (color);
974 if (!_gtk_css_parser_try (parser, ")", TRUE))
976 gtk_gradient_unref (gradient);
977 _gtk_css_parser_error (parser,
983 if (!_gtk_css_parser_try (parser, ")", TRUE))
985 gtk_gradient_unref (gradient);
986 _gtk_css_parser_error (parser,
991 g_value_take_boxed (value, gradient);
996 gradient_value_print (const GValue *value,
999 GtkGradient *gradient = g_value_get_boxed (value);
1001 if (gradient == NULL)
1002 g_string_append (string, "none");
1005 char *s = gtk_gradient_to_string (gradient);
1006 g_string_append (string, s);
1012 gtk_css_parse_url (GtkCssParser *parser,
1018 if (_gtk_css_parser_try (parser, "url", FALSE))
1020 if (!_gtk_css_parser_try (parser, "(", TRUE))
1022 _gtk_css_parser_skip_whitespace (parser);
1023 if (_gtk_css_parser_try (parser, "(", TRUE))
1027 error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
1028 GTK_CSS_PROVIDER_ERROR_DEPRECATED,
1029 "Whitespace between 'url' and '(' is deprecated");
1031 _gtk_css_parser_take_error (parser, error);
1035 _gtk_css_parser_error (parser, "Expected '(' after 'url'");
1040 path = _gtk_css_parser_read_string (parser);
1044 if (!_gtk_css_parser_try (parser, ")", TRUE))
1046 _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
1053 path = _gtk_css_parser_try_name (parser, TRUE);
1056 _gtk_css_parser_error (parser, "Not a valid url");
1061 file = g_file_resolve_relative_path (base, path);
1068 pattern_value_parse (GtkCssParser *parser,
1072 if (_gtk_css_parser_try (parser, "none", TRUE))
1074 /* nothing to do here */
1076 else if (_gtk_css_parser_begins_with (parser, '-'))
1079 res = _gtk_win32_theme_part_parse (parser, base, value);
1082 /* < 0 => continue */
1083 g_value_unset (value);
1084 g_value_init (value, GTK_TYPE_GRADIENT);
1085 return gradient_value_parse (parser, base, value);
1089 GError *error = NULL;
1093 cairo_surface_t *surface;
1094 cairo_pattern_t *pattern;
1096 cairo_matrix_t matrix;
1098 file = gtk_css_parse_url (parser, base);
1102 path = g_file_get_path (file);
1103 g_object_unref (file);
1105 pixbuf = gdk_pixbuf_new_from_file (path, &error);
1109 _gtk_css_parser_take_error (parser, error);
1113 surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
1114 gdk_pixbuf_get_width (pixbuf),
1115 gdk_pixbuf_get_height (pixbuf));
1116 cr = cairo_create (surface);
1117 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
1119 pattern = cairo_pattern_create_for_surface (surface);
1121 cairo_matrix_init_scale (&matrix,
1122 gdk_pixbuf_get_width (pixbuf),
1123 gdk_pixbuf_get_height (pixbuf));
1124 cairo_pattern_set_matrix (pattern, &matrix);
1126 cairo_surface_destroy (surface);
1128 g_object_unref (pixbuf);
1130 g_value_take_boxed (value, pattern);
1136 static cairo_status_t
1137 surface_write (void *closure,
1138 const unsigned char *data,
1139 unsigned int length)
1141 g_byte_array_append (closure, data, length);
1143 return CAIRO_STATUS_SUCCESS;
1147 surface_print (cairo_surface_t *surface,
1150 #if CAIRO_HAS_PNG_FUNCTIONS
1154 array = g_byte_array_new ();
1155 cairo_surface_write_to_png_stream (surface, surface_write, array);
1156 base64 = g_base64_encode (array->data, array->len);
1157 g_byte_array_free (array, TRUE);
1159 g_string_append (string, "url(\"data:image/png;base64,");
1160 g_string_append (string, base64);
1161 g_string_append (string, "\")");
1165 g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
1170 pattern_value_print (const GValue *value,
1173 cairo_pattern_t *pattern;
1174 cairo_surface_t *surface;
1176 pattern = g_value_get_boxed (value);
1178 if (pattern == NULL)
1180 g_string_append (string, "none");
1184 switch (cairo_pattern_get_type (pattern))
1186 case CAIRO_PATTERN_TYPE_SURFACE:
1187 if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
1189 g_assert_not_reached ();
1191 surface_print (surface, string);
1193 case CAIRO_PATTERN_TYPE_SOLID:
1194 case CAIRO_PATTERN_TYPE_LINEAR:
1195 case CAIRO_PATTERN_TYPE_RADIAL:
1197 g_assert_not_reached ();
1203 shadow_value_parse (GtkCssParser *parser,
1207 gboolean have_inset, have_color, have_lengths;
1208 gdouble hoffset, voffset, blur, spread;
1209 GtkSymbolicColor *color;
1213 shadow = _gtk_shadow_new ();
1215 if (_gtk_css_parser_try (parser, "none", TRUE))
1220 have_inset = have_lengths = have_color = FALSE;
1222 for (i = 0; i < 3; i++)
1225 _gtk_css_parser_try (parser, "inset", TRUE))
1231 if (!have_lengths &&
1232 _gtk_css_parser_try_double (parser, &hoffset))
1234 have_lengths = TRUE;
1236 if (!_gtk_css_parser_try_double (parser, &voffset))
1238 _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
1239 _gtk_shadow_unref (shadow);
1243 if (!_gtk_css_parser_try_double (parser, &blur))
1246 if (!_gtk_css_parser_try_double (parser, &spread))
1256 /* XXX: the color is optional and UA-defined if it's missing,
1257 * but it doesn't really make sense for us...
1259 color = _gtk_css_parser_read_symbolic_color (parser);
1263 _gtk_shadow_unref (shadow);
1269 if (!have_color || !have_lengths)
1271 _gtk_css_parser_error (parser, "Must specify at least color and offsets");
1272 _gtk_shadow_unref (shadow);
1276 _gtk_shadow_append (shadow,
1281 gtk_symbolic_color_unref (color);
1284 while (_gtk_css_parser_try (parser, ",", TRUE));
1286 g_value_take_boxed (value, shadow);
1291 shadow_value_print (const GValue *value,
1296 shadow = g_value_get_boxed (value);
1299 g_string_append (string, "none");
1301 _gtk_shadow_print (shadow, string);
1305 background_repeat_value_parse (GtkCssParser *parser,
1309 GtkCssBackgroundRepeat repeat;
1312 if (!enum_parse (parser, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, &style))
1315 repeat.repeat = style;
1317 g_value_set_boxed (value, &repeat);
1323 background_repeat_value_print (const GValue *value,
1326 GtkCssBackgroundRepeat *repeat;
1328 repeat = g_value_get_boxed (value);
1330 enum_print (repeat->repeat, GTK_TYPE_CSS_BACKGROUND_REPEAT_STYLE, string);
1334 border_image_repeat_value_parse (GtkCssParser *parser,
1338 GtkCssBorderImageRepeat image_repeat;
1339 GtkCssBorderRepeatStyle styles[2];
1342 for (i = 0; i < 2; i++)
1344 if (_gtk_css_parser_try_enum (parser, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, &v))
1348 styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_STRETCH;
1352 styles[i] = styles[0];
1355 image_repeat.hrepeat = styles[0];
1356 image_repeat.vrepeat = styles[1];
1358 g_value_set_boxed (value, &image_repeat);
1364 border_image_repeat_value_print (const GValue *value,
1367 GtkCssBorderImageRepeat *image_repeat;
1369 image_repeat = g_value_get_boxed (value);
1371 enum_print (image_repeat->hrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1372 if (image_repeat->hrepeat != image_repeat->vrepeat)
1374 g_string_append (string, " ");
1375 enum_print (image_repeat->vrepeat, GTK_TYPE_CSS_BORDER_REPEAT_STYLE, string);
1380 enum_value_parse (GtkCssParser *parser,
1386 if (enum_parse (parser, G_VALUE_TYPE (value), &v))
1388 g_value_set_enum (value, v);
1396 enum_value_print (const GValue *value,
1399 enum_print (g_value_get_enum (value), G_VALUE_TYPE (value), string);
1403 flags_value_parse (GtkCssParser *parser,
1407 GFlagsClass *flags_class;
1408 GFlagsValue *flag_value;
1412 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1415 str = _gtk_css_parser_try_ident (parser, TRUE);
1418 _gtk_css_parser_error (parser, "Expected an identifier");
1419 g_type_class_unref (flags_class);
1423 flag_value = g_flags_get_value_by_nick (flags_class, str);
1426 _gtk_css_parser_error (parser,
1427 "Unknown flag value '%s' for type '%s'",
1428 str, g_type_name (G_VALUE_TYPE (value)));
1429 /* XXX Do we want to return FALSE here? We can get
1430 * forward-compatibility for new values this way
1433 g_type_class_unref (flags_class);
1439 while (_gtk_css_parser_try (parser, ",", FALSE));
1441 g_type_class_unref (flags_class);
1443 g_value_set_enum (value, flags);
1449 flags_value_print (const GValue *value,
1452 GFlagsClass *flags_class;
1455 flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1456 flags = g_value_get_flags (value);
1458 for (i = 0; i < flags_class->n_values; i++)
1460 GFlagsValue *flags_value = &flags_class->values[i];
1462 if (flags & flags_value->value)
1464 if (string->len != 0)
1465 g_string_append (string, ", ");
1467 g_string_append (string, flags_value->value_nick);
1471 g_type_class_unref (flags_class);
1475 bindings_value_parse (GtkCssParser *parser,
1480 GtkBindingSet *binding_set;
1483 array = g_ptr_array_new ();
1486 name = _gtk_css_parser_try_ident (parser, TRUE);
1489 _gtk_css_parser_error (parser, "Not a valid binding name");
1490 g_ptr_array_free (array, TRUE);
1494 binding_set = gtk_binding_set_find (name);
1498 _gtk_css_parser_error (parser, "No binding set named '%s'", name);
1503 g_ptr_array_add (array, binding_set);
1506 while (_gtk_css_parser_try (parser, ",", TRUE));
1508 g_value_take_boxed (value, array);
1514 bindings_value_print (const GValue *value,
1520 array = g_value_get_boxed (value);
1522 for (i = 0; i < array->len; i++)
1524 GtkBindingSet *binding_set = g_ptr_array_index (array, i);
1527 g_string_append (string, ", ");
1528 g_string_append (string, binding_set->set_name);
1533 border_corner_radius_value_parse (GtkCssParser *parser,
1537 GtkCssBorderCornerRadius corner;
1539 if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
1541 _gtk_css_parser_error (parser, "Expected a number");
1544 else if (corner.horizontal < 0)
1547 if (!_gtk_css_parser_try_double (parser, &corner.vertical))
1548 corner.vertical = corner.horizontal;
1549 else if (corner.vertical < 0)
1552 g_value_set_boxed (value, &corner);
1556 _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1561 border_corner_radius_value_print (const GValue *value,
1564 GtkCssBorderCornerRadius *corner;
1566 corner = g_value_get_boxed (value);
1570 g_string_append (string, "none");
1574 string_append_double (string, corner->horizontal);
1575 if (corner->horizontal != corner->vertical)
1577 g_string_append_c (string, ' ');
1578 string_append_double (string, corner->vertical);
1583 transparent_color_value_parse (GtkCssParser *parser,
1587 if (_gtk_css_parser_try (parser, "transparent", TRUE))
1589 GdkRGBA transparent = { 0, 0, 0, 0 };
1591 g_value_set_boxed (value, &transparent);
1596 return rgba_value_parse (parser, base, value);
1602 _gtk_style_property_get_count (void)
1604 return __style_property_array ? __style_property_array->len : 0;
1607 const GtkStyleProperty *
1608 _gtk_style_property_get (guint id)
1610 g_assert (__style_property_array);
1612 return g_ptr_array_index (__style_property_array, id);
1616 _gtk_style_property_generate_id (GtkStyleProperty *node)
1618 if (__style_property_array == NULL)
1619 __style_property_array = g_ptr_array_new ();
1621 node->id = __style_property_array->len;
1622 g_ptr_array_add (__style_property_array, node);
1626 css_string_funcs_init (void)
1628 if (G_LIKELY (parse_funcs != NULL))
1631 parse_funcs = g_hash_table_new (NULL, NULL);
1632 print_funcs = g_hash_table_new (NULL, NULL);
1634 register_conversion_function (GDK_TYPE_RGBA,
1637 register_conversion_function (GDK_TYPE_COLOR,
1640 register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
1641 symbolic_color_value_parse,
1642 symbolic_color_value_print);
1643 register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
1644 font_description_value_parse,
1645 font_description_value_print);
1646 register_conversion_function (G_TYPE_BOOLEAN,
1647 boolean_value_parse,
1648 boolean_value_print);
1649 register_conversion_function (G_TYPE_INT,
1652 register_conversion_function (G_TYPE_UINT,
1655 register_conversion_function (G_TYPE_DOUBLE,
1657 double_value_print);
1658 register_conversion_function (G_TYPE_FLOAT,
1661 register_conversion_function (G_TYPE_STRING,
1663 string_value_print);
1664 register_conversion_function (GTK_TYPE_THEMING_ENGINE,
1665 theming_engine_value_parse,
1666 theming_engine_value_print);
1667 register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
1668 animation_description_value_parse,
1669 animation_description_value_print);
1670 register_conversion_function (GTK_TYPE_BORDER,
1672 border_value_print);
1673 register_conversion_function (GTK_TYPE_GRADIENT,
1674 gradient_value_parse,
1675 gradient_value_print);
1676 register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
1677 pattern_value_parse,
1678 pattern_value_print);
1679 register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
1680 border_image_repeat_value_parse,
1681 border_image_repeat_value_print);
1682 register_conversion_function (GTK_TYPE_SHADOW,
1684 shadow_value_print);
1685 register_conversion_function (G_TYPE_ENUM,
1688 register_conversion_function (G_TYPE_FLAGS,
1691 register_conversion_function (GTK_TYPE_CSS_BACKGROUND_REPEAT,
1692 background_repeat_value_parse,
1693 background_repeat_value_print);
1697 _gtk_style_property_parse_value (const GtkStyleProperty *property,
1699 GtkCssParser *parser,
1702 GtkStyleParseFunc func;
1704 g_return_val_if_fail (value != NULL, FALSE);
1705 g_return_val_if_fail (parser != NULL, FALSE);
1707 css_string_funcs_init ();
1711 if (_gtk_css_parser_try (parser, "initial", TRUE))
1713 /* the initial value can be explicitly specified with the
1714 * ‘initial’ keyword which all properties accept.
1716 g_value_unset (value);
1717 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
1718 g_value_set_enum (value, GTK_CSS_INITIAL);
1721 else if (_gtk_css_parser_try (parser, "inherit", TRUE))
1723 /* All properties accept the ‘inherit’ value which
1724 * explicitly specifies that the value will be determined
1725 * by inheritance. The ‘inherit’ value can be used to
1726 * strengthen inherited values in the cascade, and it can
1727 * also be used on properties that are not normally inherited.
1729 g_value_unset (value);
1730 g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
1731 g_value_set_enum (value, GTK_CSS_INHERIT);
1734 else if (property->property_parse_func)
1736 GError *error = NULL;
1740 value_str = _gtk_css_parser_read_value (parser);
1741 if (value_str == NULL)
1744 success = (*property->property_parse_func) (value_str, value, &error);
1751 func = property->parse_func;
1757 func = g_hash_table_lookup (parse_funcs,
1758 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1760 func = g_hash_table_lookup (parse_funcs,
1761 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1765 _gtk_css_parser_error (parser,
1766 "Cannot convert to type '%s'",
1767 g_type_name (G_VALUE_TYPE (value)));
1771 return (*func) (parser, base, value);
1775 _gtk_style_property_print_value (const GtkStyleProperty *property,
1776 const GValue *value,
1779 GtkStylePrintFunc func;
1781 css_string_funcs_init ();
1783 if (G_VALUE_HOLDS (value, GTK_TYPE_CSS_SPECIAL_VALUE))
1784 func = enum_value_print;
1786 func = property->print_func;
1791 func = g_hash_table_lookup (print_funcs,
1792 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
1794 func = g_hash_table_lookup (print_funcs,
1795 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
1799 char *s = g_strdup_value_contents (value);
1800 g_string_append (string, s);
1805 func (value, string);
1809 _gtk_style_property_default_value (const GtkStyleProperty *property,
1810 GtkStyleProperties *properties,
1811 GtkStateFlags state,
1814 g_value_copy (&property->initial_value, value);
1818 _gtk_style_property_is_inherit (const GtkStyleProperty *property)
1820 g_return_val_if_fail (property != NULL, FALSE);
1822 return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
1826 _gtk_style_property_get_id (const GtkStyleProperty *property)
1828 g_return_val_if_fail (property != NULL, FALSE);
1830 return property->id;
1834 resolve_color (GtkStyleProperties *props,
1839 /* Resolve symbolic color to GdkRGBA */
1840 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
1843 /* Store it back, this is where GdkRGBA caching happens */
1844 g_value_unset (value);
1845 g_value_init (value, GDK_TYPE_RGBA);
1846 g_value_set_boxed (value, &color);
1852 resolve_color_rgb (GtkStyleProperties *props,
1855 GdkColor color = { 0 };
1858 if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
1861 color.red = rgba.red * 65535. + 0.5;
1862 color.green = rgba.green * 65535. + 0.5;
1863 color.blue = rgba.blue * 65535. + 0.5;
1865 g_value_unset (value);
1866 g_value_init (value, GDK_TYPE_COLOR);
1867 g_value_set_boxed (value, &color);
1873 resolve_win32_theme_part (GtkStyleProperties *props,
1876 GtkStylePropertyContext *context)
1878 GtkWin32ThemePart *part;
1879 cairo_pattern_t *pattern;
1881 part = g_value_get_boxed (value);
1885 pattern = _gtk_win32_theme_part_render (part, context->width, context->height);
1887 g_value_take_boxed (value_out, pattern);
1894 resolve_gradient (GtkStyleProperties *props,
1897 cairo_pattern_t *gradient;
1899 if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
1902 /* Store it back, this is where cairo_pattern_t caching happens */
1903 g_value_unset (value);
1904 g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
1905 g_value_take_boxed (value, gradient);
1911 resolve_shadow (GtkStyleProperties *props,
1914 GtkShadow *resolved, *base;
1916 base = g_value_get_boxed (value);
1921 if (_gtk_shadow_get_resolved (base))
1924 resolved = _gtk_shadow_resolve (base, props);
1925 if (resolved == NULL)
1928 g_value_take_boxed (value, resolved);
1934 _gtk_style_property_resolve (const GtkStyleProperty *property,
1935 GtkStyleProperties *props,
1936 GtkStateFlags state,
1937 GtkStylePropertyContext *context,
1941 if (G_VALUE_TYPE (val) == GTK_TYPE_CSS_SPECIAL_VALUE)
1943 GtkCssSpecialValue special = g_value_get_enum (val);
1945 g_value_unset (val);
1948 case GTK_CSS_CURRENT_COLOR:
1949 g_assert (property->pspec->value_type == GDK_TYPE_RGBA);
1950 gtk_style_properties_get_property (props, "color", state, val);
1952 case GTK_CSS_INHERIT:
1953 case GTK_CSS_INITIAL:
1955 g_assert_not_reached ();
1958 else if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
1960 if (property->pspec->value_type == GDK_TYPE_RGBA)
1962 if (resolve_color (props, val))
1965 else if (property->pspec->value_type == GDK_TYPE_COLOR)
1967 if (resolve_color_rgb (props, val))
1971 g_value_unset (val);
1972 g_value_init (val, property->pspec->value_type);
1973 _gtk_style_property_default_value (property, props, state, val);
1975 else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
1977 if (g_value_get_boxed (val) == NULL)
1978 _gtk_style_property_default_value (property, props, state, val);
1980 else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
1982 g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
1984 if (!resolve_gradient (props, val))
1986 g_value_unset (val);
1987 g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
1988 _gtk_style_property_default_value (property, props, state, val);
1991 else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
1993 if (!resolve_shadow (props, val))
1994 _gtk_style_property_default_value (property, props, state, val);
1996 else if (G_VALUE_TYPE (val) == GTK_TYPE_WIN32_THEME_PART)
1998 if (resolve_win32_theme_part (props, val, val_out, context))
1999 return; /* Don't copy val, this sets val_out */
2000 _gtk_style_property_default_value (property, props, state, val);
2004 g_value_copy (val, val_out);
2008 _gtk_style_property_get_initial_value (const GtkStyleProperty *property)
2010 g_return_val_if_fail (property != NULL, NULL);
2012 return &property->initial_value;
2016 _gtk_style_property_unpack (const GtkStyleProperty *property,
2017 const GValue *value,
2020 g_return_val_if_fail (property != NULL, NULL);
2021 g_return_val_if_fail (property->unpack_func != NULL, NULL);
2022 g_return_val_if_fail (value != NULL, NULL);
2023 g_return_val_if_fail (n_params != NULL, NULL);
2025 return property->unpack_func (value, n_params);
2029 _gtk_style_property_pack (const GtkStyleProperty *property,
2030 GtkStyleProperties *props,
2031 GtkStateFlags state,
2032 GtkStylePropertyContext *context,
2035 g_return_if_fail (property != NULL);
2036 g_return_if_fail (property->pack_func != NULL);
2037 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2038 g_return_if_fail (G_IS_VALUE (value));
2040 property->pack_func (value, props, state, context);
2044 _gtk_style_property_query (const GtkStyleProperty *property,
2045 GtkStyleProperties *props,
2046 GtkStateFlags state,
2047 GtkStylePropertyContext *context,
2052 g_return_if_fail (property != NULL);
2053 g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2054 g_return_if_fail (context != NULL);
2055 g_return_if_fail (value != NULL);
2057 val = _gtk_style_properties_peek_property (props, property, state);
2058 g_value_init (value, property->pspec->value_type);
2061 _gtk_style_property_resolve (property, props, state, context, (GValue *) val, value);
2062 else if (GTK_IS_CSS_SHORTHAND_PROPERTY (property))
2063 _gtk_style_property_pack (property, props, state, context, value);
2065 _gtk_style_property_default_value (property, props, state, value);
2068 #define rgba_init(rgba, r, g, b, a) G_STMT_START{ \
2069 (rgba)->red = (r); \
2070 (rgba)->green = (g); \
2071 (rgba)->blue = (b); \
2072 (rgba)->alpha = (a); \
2075 gtk_style_property_init_properties (void)
2077 static gboolean initialized = FALSE;
2078 GValue value = { 0, };
2079 char *default_font_family[] = { "Sans", NULL };
2082 if (G_LIKELY (initialized))
2087 g_value_init (&value, GDK_TYPE_RGBA);
2088 rgba_init (&rgba, 1, 1, 1, 1);
2089 g_value_set_boxed (&value, &rgba);
2090 _gtk_style_property_register (g_param_spec_boxed ("color",
2094 GTK_STYLE_PROPERTY_INHERIT,
2099 rgba_init (&rgba, 0, 0, 0, 0);
2100 g_value_set_boxed (&value, &rgba);
2101 _gtk_style_property_register (g_param_spec_boxed ("background-color",
2107 transparent_color_value_parse,
2110 g_value_unset (&value);
2112 g_value_init (&value, G_TYPE_STRV);
2113 g_value_set_boxed (&value, default_font_family);
2114 _gtk_style_property_register (g_param_spec_boxed ("font-family",
2118 GTK_STYLE_PROPERTY_INHERIT,
2121 font_family_value_print,
2123 g_value_unset (&value);
2124 _gtk_style_property_register (g_param_spec_enum ("font-style",
2128 PANGO_STYLE_NORMAL, 0),
2129 GTK_STYLE_PROPERTY_INHERIT,
2134 _gtk_style_property_register (g_param_spec_enum ("font-variant",
2138 PANGO_VARIANT_NORMAL, 0),
2139 GTK_STYLE_PROPERTY_INHERIT,
2144 /* xxx: need to parse this properly, ie parse the numbers */
2145 _gtk_style_property_register (g_param_spec_enum ("font-weight",
2149 PANGO_WEIGHT_NORMAL, 0),
2150 GTK_STYLE_PROPERTY_INHERIT,
2155 g_value_init (&value, G_TYPE_DOUBLE);
2156 g_value_set_double (&value, 10);
2157 _gtk_style_property_register (g_param_spec_double ("font-size",
2160 0, G_MAXDOUBLE, 0, 0),
2161 GTK_STYLE_PROPERTY_INHERIT,
2166 g_value_unset (&value);
2168 _gtk_style_property_register (g_param_spec_boxed ("text-shadow",
2171 GTK_TYPE_SHADOW, 0),
2172 GTK_STYLE_PROPERTY_INHERIT,
2178 _gtk_style_property_register (g_param_spec_boxed ("icon-shadow",
2181 GTK_TYPE_SHADOW, 0),
2182 GTK_STYLE_PROPERTY_INHERIT,
2188 gtk_style_properties_register_property (NULL,
2189 g_param_spec_boxed ("box-shadow",
2192 GTK_TYPE_SHADOW, 0));
2193 gtk_style_properties_register_property (NULL,
2194 g_param_spec_int ("margin-top",
2197 0, G_MAXINT, 0, 0));
2198 gtk_style_properties_register_property (NULL,
2199 g_param_spec_int ("margin-left",
2202 0, G_MAXINT, 0, 0));
2203 gtk_style_properties_register_property (NULL,
2204 g_param_spec_int ("margin-bottom",
2207 0, G_MAXINT, 0, 0));
2208 gtk_style_properties_register_property (NULL,
2209 g_param_spec_int ("margin-right",
2212 0, G_MAXINT, 0, 0));
2213 gtk_style_properties_register_property (NULL,
2214 g_param_spec_int ("padding-top",
2217 0, G_MAXINT, 0, 0));
2218 gtk_style_properties_register_property (NULL,
2219 g_param_spec_int ("padding-left",
2222 0, G_MAXINT, 0, 0));
2223 gtk_style_properties_register_property (NULL,
2224 g_param_spec_int ("padding-bottom",
2226 "Padding at bottom",
2227 0, G_MAXINT, 0, 0));
2228 gtk_style_properties_register_property (NULL,
2229 g_param_spec_int ("padding-right",
2232 0, G_MAXINT, 0, 0));
2233 gtk_style_properties_register_property (NULL,
2234 g_param_spec_int ("border-top-width",
2236 "Border width at top",
2237 0, G_MAXINT, 0, 0));
2238 gtk_style_properties_register_property (NULL,
2239 g_param_spec_int ("border-left-width",
2240 "border left width",
2241 "Border width at left",
2242 0, G_MAXINT, 0, 0));
2243 gtk_style_properties_register_property (NULL,
2244 g_param_spec_int ("border-bottom-width",
2245 "border bottom width",
2246 "Border width at bottom",
2247 0, G_MAXINT, 0, 0));
2248 gtk_style_properties_register_property (NULL,
2249 g_param_spec_int ("border-right-width",
2250 "border right width",
2251 "Border width at right",
2252 0, G_MAXINT, 0, 0));
2254 _gtk_style_property_register (g_param_spec_boxed ("border-top-left-radius",
2255 "Border top left radius",
2256 "Border radius of top left corner, in pixels",
2257 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2260 border_corner_radius_value_parse,
2261 border_corner_radius_value_print,
2263 _gtk_style_property_register (g_param_spec_boxed ("border-top-right-radius",
2264 "Border top right radius",
2265 "Border radius of top right corner, in pixels",
2266 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2269 border_corner_radius_value_parse,
2270 border_corner_radius_value_print,
2272 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-right-radius",
2273 "Border bottom right radius",
2274 "Border radius of bottom right corner, in pixels",
2275 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2278 border_corner_radius_value_parse,
2279 border_corner_radius_value_print,
2281 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-left-radius",
2282 "Border bottom left radius",
2283 "Border radius of bottom left corner, in pixels",
2284 GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2287 border_corner_radius_value_parse,
2288 border_corner_radius_value_print,
2291 gtk_style_properties_register_property (NULL,
2292 g_param_spec_enum ("border-style",
2295 GTK_TYPE_BORDER_STYLE,
2296 GTK_BORDER_STYLE_NONE, 0));
2297 gtk_style_properties_register_property (NULL,
2298 g_param_spec_enum ("background-clip",
2302 GTK_CSS_AREA_BORDER_BOX, 0));
2303 gtk_style_properties_register_property (NULL,
2304 g_param_spec_enum ("background-origin",
2305 "Background origin",
2306 "Background origin",
2308 GTK_CSS_AREA_PADDING_BOX, 0));
2309 g_value_init (&value, GTK_TYPE_CSS_SPECIAL_VALUE);
2310 g_value_set_enum (&value, GTK_CSS_CURRENT_COLOR);
2311 _gtk_style_property_register (g_param_spec_boxed ("border-top-color",
2317 transparent_color_value_parse,
2320 _gtk_style_property_register (g_param_spec_boxed ("border-right-color",
2321 "Border right color",
2322 "Border right color",
2326 transparent_color_value_parse,
2329 _gtk_style_property_register (g_param_spec_boxed ("border-bottom-color",
2330 "Border bottom color",
2331 "Border bottom color",
2335 transparent_color_value_parse,
2338 _gtk_style_property_register (g_param_spec_boxed ("border-left-color",
2339 "Border left color",
2340 "Border left color",
2344 transparent_color_value_parse,
2347 g_value_unset (&value);
2349 gtk_style_properties_register_property (NULL,
2350 g_param_spec_boxed ("background-image",
2353 CAIRO_GOBJECT_TYPE_PATTERN, 0));
2354 gtk_style_properties_register_property (NULL,
2355 g_param_spec_boxed ("background-repeat",
2356 "Background repeat",
2357 "Background repeat",
2358 GTK_TYPE_CSS_BACKGROUND_REPEAT, 0));
2360 gtk_style_properties_register_property (NULL,
2361 g_param_spec_boxed ("border-image-source",
2362 "Border image source",
2363 "Border image source",
2364 CAIRO_GOBJECT_TYPE_PATTERN, 0));
2365 gtk_style_properties_register_property (NULL,
2366 g_param_spec_boxed ("border-image-repeat",
2367 "Border image repeat",
2368 "Border image repeat",
2369 GTK_TYPE_CSS_BORDER_IMAGE_REPEAT, 0));
2370 gtk_style_properties_register_property (NULL,
2371 g_param_spec_boxed ("border-image-slice",
2372 "Border image slice",
2373 "Border image slice",
2374 GTK_TYPE_BORDER, 0));
2375 g_value_init (&value, GTK_TYPE_BORDER);
2376 _gtk_style_property_register (g_param_spec_boxed ("border-image-width",
2377 "Border image width",
2378 "Border image width",
2379 GTK_TYPE_BORDER, 0),
2385 g_value_unset (&value);
2386 gtk_style_properties_register_property (NULL,
2387 g_param_spec_object ("engine",
2390 GTK_TYPE_THEMING_ENGINE, 0));
2391 gtk_style_properties_register_property (NULL,
2392 g_param_spec_boxed ("transition",
2393 "Transition animation description",
2394 "Transition animation description",
2395 GTK_TYPE_ANIMATION_DESCRIPTION, 0));
2397 /* Private property holding the binding sets */
2398 _gtk_style_property_register (g_param_spec_boxed ("gtk-key-bindings",
2401 G_TYPE_PTR_ARRAY, 0),
2404 bindings_value_parse,
2405 bindings_value_print,
2408 /* initialize shorthands last, they depend on the real properties existing */
2409 _gtk_css_shorthand_property_init_properties ();
2413 * _gtk_style_property_lookup:
2414 * @name: name of the property to lookup
2416 * Looks up the CSS property with the given @name. If no such
2417 * property exists, %NULL is returned.
2419 * Returns: (transfer none): The property or %NULL if no
2420 * property with the given name exists.
2422 const GtkStyleProperty *
2423 _gtk_style_property_lookup (const char *name)
2425 GtkStylePropertyClass *klass;
2427 g_return_val_if_fail (name != NULL, NULL);
2429 gtk_style_property_init_properties ();
2431 klass = g_type_class_peek (GTK_TYPE_STYLE_PROPERTY);
2433 return g_hash_table_lookup (klass->properties, name);
2437 * _gtk_style_property_get_name:
2438 * @property: the property to query
2440 * Gets the name of the given property.
2442 * Returns: the name of the property
2445 _gtk_style_property_get_name (GtkStyleProperty *property)
2447 g_return_val_if_fail (GTK_IS_STYLE_PROPERTY (property), NULL);
2449 return property->name;
2454 _gtk_style_property_register (GParamSpec *pspec,
2455 GtkStylePropertyFlags flags,
2456 GtkStylePropertyParser property_parse_func,
2457 GtkStyleParseFunc parse_func,
2458 GtkStylePrintFunc print_func,
2459 const GValue * initial_value)
2461 GtkStyleProperty *node;
2463 node = g_object_new (GTK_TYPE_CSS_STYLE_PROPERTY,
2464 "name", pspec->name,
2466 node->flags = flags;
2467 node->pspec = pspec;
2468 node->property_parse_func = property_parse_func;
2469 node->parse_func = parse_func;
2470 node->print_func = print_func;
2472 _gtk_style_property_generate_id (node);
2474 /* initialize the initial value */
2477 g_value_init (&node->initial_value, G_VALUE_TYPE (initial_value));
2478 g_value_copy (initial_value, &node->initial_value);
2482 g_value_init (&node->initial_value, pspec->value_type);
2483 if (pspec->value_type == GTK_TYPE_THEMING_ENGINE)
2484 g_value_set_object (&node->initial_value, gtk_theming_engine_load (NULL));
2485 else if (pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
2486 g_value_take_boxed (&node->initial_value, pango_font_description_from_string ("Sans 10"));
2487 else if (pspec->value_type == GDK_TYPE_RGBA)
2490 gdk_rgba_parse (&color, "pink");
2491 g_value_set_boxed (&node->initial_value, &color);
2493 else if (pspec->value_type == GTK_TYPE_BORDER)
2495 g_value_take_boxed (&node->initial_value, gtk_border_new ());
2498 g_param_value_set_default (pspec, &node->initial_value);