]> Pileus Git - ~andy/gtk/blob - gtk/gtkstyleproperty.c
Include C89 fallback code
[~andy/gtk] / gtk / gtkstyleproperty.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 #include "config.h"
21
22 #include "gtkstylepropertyprivate.h"
23
24 #include <errno.h>
25 #include <math.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include <gdk-pixbuf/gdk-pixbuf.h>
30 #include <cairo-gobject.h>
31
32 #include "gtkcssprovider.h"
33 #include "gtkcssparserprivate.h"
34 #include "gtkcsstypesprivate.h"
35
36 /* the actual parsers we have */
37 #include "gtkanimationdescription.h"
38 #include "gtkbindings.h"
39 #include "gtkborderimageprivate.h"
40 #include "gtkgradient.h"
41 #include "gtkshadowprivate.h"
42 #include "gtkthemingengine.h"
43 #include "gtktypebuiltins.h"
44
45 /* this is in case round() is not provided by the compiler, 
46  * such as in the case of C89 compilers, like MSVC
47  */
48 #include "fallback-c89.c"
49
50 static GHashTable *parse_funcs = NULL;
51 static GHashTable *print_funcs = NULL;
52 static GHashTable *properties = NULL;
53
54 static void
55 register_conversion_function (GType             type,
56                               GtkStyleParseFunc parse,
57                               GtkStylePrintFunc print)
58 {
59   if (parse)
60     g_hash_table_insert (parse_funcs, GSIZE_TO_POINTER (type), parse);
61   if (print)
62     g_hash_table_insert (print_funcs, GSIZE_TO_POINTER (type), print);
63 }
64
65 static void
66 string_append_double (GString *string,
67                       double   d)
68 {
69   char buf[G_ASCII_DTOSTR_BUF_SIZE];
70
71   g_ascii_dtostr (buf, sizeof (buf), d);
72   g_string_append (string, buf);
73 }
74
75 static void
76 string_append_string (GString    *str,
77                       const char *string)
78 {
79   gsize len;
80
81   g_string_append_c (str, '"');
82
83   do {
84     len = strcspn (string, "\"\n\r\f");
85     g_string_append (str, string);
86     string += len;
87     switch (*string)
88       {
89       case '\0':
90         break;
91       case '\n':
92         g_string_append (str, "\\A ");
93         break;
94       case '\r':
95         g_string_append (str, "\\D ");
96         break;
97       case '\f':
98         g_string_append (str, "\\C ");
99         break;
100       case '\"':
101         g_string_append (str, "\\\"");
102         break;
103       default:
104         g_assert_not_reached ();
105         break;
106       }
107   } while (*string);
108
109   g_string_append_c (str, '"');
110 }
111
112 /*** IMPLEMENTATIONS ***/
113
114 static gboolean 
115 rgba_value_parse (GtkCssParser *parser,
116                   GFile        *base,
117                   GValue       *value)
118 {
119   GtkSymbolicColor *symbolic;
120   GdkRGBA rgba;
121
122   symbolic = _gtk_css_parser_read_symbolic_color (parser);
123   if (symbolic == NULL)
124     return FALSE;
125
126   if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
127     {
128       g_value_set_boxed (value, &rgba);
129       gtk_symbolic_color_unref (symbolic);
130     }
131   else
132     {
133       g_value_unset (value);
134       g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
135       g_value_take_boxed (value, symbolic);
136     }
137
138   return TRUE;
139 }
140
141 static void
142 rgba_value_print (const GValue *value,
143                   GString      *string)
144 {
145   const GdkRGBA *rgba = g_value_get_boxed (value);
146
147   if (rgba == NULL)
148     g_string_append (string, "none");
149   else
150     {
151       char *s = gdk_rgba_to_string (rgba);
152       g_string_append (string, s);
153       g_free (s);
154     }
155 }
156
157 static gboolean 
158 color_value_parse (GtkCssParser *parser,
159                    GFile        *base,
160                    GValue       *value)
161 {
162   GtkSymbolicColor *symbolic;
163   GdkRGBA rgba;
164
165   symbolic = _gtk_css_parser_read_symbolic_color (parser);
166   if (symbolic == NULL)
167     return FALSE;
168
169   if (gtk_symbolic_color_resolve (symbolic, NULL, &rgba))
170     {
171       GdkColor color;
172
173       color.red = rgba.red * 65535. + 0.5;
174       color.green = rgba.green * 65535. + 0.5;
175       color.blue = rgba.blue * 65535. + 0.5;
176
177       g_value_set_boxed (value, &color);
178     }
179   else
180     {
181       g_value_unset (value);
182       g_value_init (value, GTK_TYPE_SYMBOLIC_COLOR);
183       g_value_take_boxed (value, symbolic);
184     }
185
186   return TRUE;
187 }
188
189 static void
190 color_value_print (const GValue *value,
191                    GString      *string)
192 {
193   const GdkColor *color = g_value_get_boxed (value);
194
195   if (color == NULL)
196     g_string_append (string, "none");
197   else
198     {
199       char *s = gdk_color_to_string (color);
200       g_string_append (string, s);
201       g_free (s);
202     }
203 }
204
205 static gboolean
206 symbolic_color_value_parse (GtkCssParser *parser,
207                             GFile        *base,
208                             GValue       *value)
209 {
210   GtkSymbolicColor *symbolic;
211
212   symbolic = _gtk_css_parser_read_symbolic_color (parser);
213   if (symbolic == NULL)
214     return FALSE;
215
216   g_value_take_boxed (value, symbolic);
217   return TRUE;
218 }
219
220 static void
221 symbolic_color_value_print (const GValue *value,
222                             GString      *string)
223 {
224   GtkSymbolicColor *symbolic = g_value_get_boxed (value);
225
226   if (symbolic == NULL)
227     g_string_append (string, "none");
228   else
229     {
230       char *s = gtk_symbolic_color_to_string (symbolic);
231       g_string_append (string, s);
232       g_free (s);
233     }
234 }
235
236 static gboolean
237 font_family_parse (GtkCssParser *parser,
238                    GFile        *base,
239                    GValue       *value)
240 {
241   GPtrArray *names;
242   char *name;
243
244   /* We don't special case generic families. Pango should do
245    * that for us */
246
247   names = g_ptr_array_new ();
248
249   do {
250     name = _gtk_css_parser_try_ident (parser, TRUE);
251     if (name)
252       {
253         GString *string = g_string_new (name);
254         g_free (name);
255         while ((name = _gtk_css_parser_try_ident (parser, TRUE)))
256           {
257             g_string_append_c (string, ' ');
258             g_string_append (string, name);
259             g_free (name);
260           }
261         name = g_string_free (string, FALSE);
262       }
263     else 
264       {
265         name = _gtk_css_parser_read_string (parser);
266         if (name == NULL)
267           {
268             g_ptr_array_free (names, TRUE);
269             return FALSE;
270           }
271       }
272
273     g_ptr_array_add (names, name);
274   } while (_gtk_css_parser_try (parser, ",", TRUE));
275
276   /* NULL-terminate array */
277   g_ptr_array_add (names, NULL);
278   g_value_set_boxed (value, g_ptr_array_free (names, FALSE));
279   return TRUE;
280 }
281
282 static void
283 font_family_value_print (const GValue *value,
284                          GString      *string)
285 {
286   const char **names = g_value_get_boxed (value);
287
288   if (names == NULL || *names == NULL)
289     {
290       g_string_append (string, "none");
291       return;
292     }
293
294   string_append_string (string, *names);
295   names++;
296   while (*names)
297     {
298       g_string_append (string, ", ");
299       string_append_string (string, *names);
300       names++;
301     }
302 }
303
304 static gboolean 
305 font_description_value_parse (GtkCssParser *parser,
306                               GFile        *base,
307                               GValue       *value)
308 {
309   PangoFontDescription *font_desc;
310   guint mask;
311   char *str;
312
313   str = _gtk_css_parser_read_value (parser);
314   if (str == NULL)
315     return FALSE;
316
317   font_desc = pango_font_description_from_string (str);
318   mask = pango_font_description_get_set_fields (font_desc);
319   /* These values are not really correct,
320    * but the fields must be set, so we set them to something */
321   if ((mask & PANGO_FONT_MASK_FAMILY) == 0)
322     pango_font_description_set_family_static (font_desc, "Sans");
323   if ((mask & PANGO_FONT_MASK_SIZE) == 0)
324     pango_font_description_set_size (font_desc, 10 * PANGO_SCALE);
325   g_free (str);
326   g_value_take_boxed (value, font_desc);
327   return TRUE;
328 }
329
330 static void
331 font_description_value_print (const GValue *value,
332                               GString      *string)
333 {
334   const PangoFontDescription *desc = g_value_get_boxed (value);
335
336   if (desc == NULL)
337     g_string_append (string, "none");
338   else
339     {
340       char *s = pango_font_description_to_string (desc);
341       g_string_append (string, s);
342       g_free (s);
343     }
344 }
345
346 static gboolean 
347 boolean_value_parse (GtkCssParser *parser,
348                      GFile        *base,
349                      GValue       *value)
350 {
351   if (_gtk_css_parser_try (parser, "true", TRUE) ||
352       _gtk_css_parser_try (parser, "1", TRUE))
353     {
354       g_value_set_boolean (value, TRUE);
355       return TRUE;
356     }
357   else if (_gtk_css_parser_try (parser, "false", TRUE) ||
358            _gtk_css_parser_try (parser, "0", TRUE))
359     {
360       g_value_set_boolean (value, FALSE);
361       return TRUE;
362     }
363   else
364     {
365       _gtk_css_parser_error (parser, "Expected a boolean value");
366       return FALSE;
367     }
368 }
369
370 static void
371 boolean_value_print (const GValue *value,
372                      GString      *string)
373 {
374   if (g_value_get_boolean (value))
375     g_string_append (string, "true");
376   else
377     g_string_append (string, "false");
378 }
379
380 static gboolean 
381 int_value_parse (GtkCssParser *parser,
382                  GFile        *base,
383                  GValue       *value)
384 {
385   gint i;
386
387   if (!_gtk_css_parser_try_int (parser, &i))
388     {
389       _gtk_css_parser_error (parser, "Expected a valid integer value");
390       return FALSE;
391     }
392
393   g_value_set_int (value, i);
394   return TRUE;
395 }
396
397 static void
398 int_value_print (const GValue *value,
399                  GString      *string)
400 {
401   g_string_append_printf (string, "%d", g_value_get_int (value));
402 }
403
404 static gboolean 
405 uint_value_parse (GtkCssParser *parser,
406                   GFile        *base,
407                   GValue       *value)
408 {
409   guint u;
410
411   if (!_gtk_css_parser_try_uint (parser, &u))
412     {
413       _gtk_css_parser_error (parser, "Expected a valid unsigned value");
414       return FALSE;
415     }
416
417   g_value_set_uint (value, u);
418   return TRUE;
419 }
420
421 static void
422 uint_value_print (const GValue *value,
423                   GString      *string)
424 {
425   g_string_append_printf (string, "%u", g_value_get_uint (value));
426 }
427
428 static gboolean 
429 double_value_parse (GtkCssParser *parser,
430                     GFile        *base,
431                     GValue       *value)
432 {
433   gdouble d;
434
435   if (!_gtk_css_parser_try_double (parser, &d))
436     {
437       _gtk_css_parser_error (parser, "Expected a number");
438       return FALSE;
439     }
440
441   g_value_set_double (value, d);
442   return TRUE;
443 }
444
445 static void
446 double_value_print (const GValue *value,
447                     GString      *string)
448 {
449   string_append_double (string, g_value_get_double (value));
450 }
451
452 static gboolean 
453 float_value_parse (GtkCssParser *parser,
454                    GFile        *base,
455                    GValue       *value)
456 {
457   gdouble d;
458
459   if (!_gtk_css_parser_try_double (parser, &d))
460     {
461       _gtk_css_parser_error (parser, "Expected a number");
462       return FALSE;
463     }
464
465   g_value_set_float (value, d);
466   return TRUE;
467 }
468
469 static void
470 float_value_print (const GValue *value,
471                    GString      *string)
472 {
473   string_append_double (string, g_value_get_float (value));
474 }
475
476 static gboolean 
477 string_value_parse (GtkCssParser *parser,
478                     GFile        *base,
479                     GValue       *value)
480 {
481   char *str = _gtk_css_parser_read_string (parser);
482
483   if (str == NULL)
484     return FALSE;
485
486   g_value_take_string (value, str);
487   return TRUE;
488 }
489
490 static void
491 string_value_print (const GValue *value,
492                     GString      *str)
493 {
494   string_append_string (str, g_value_get_string (value));
495 }
496
497 static gboolean 
498 theming_engine_value_parse (GtkCssParser *parser,
499                             GFile        *base,
500                             GValue       *value)
501 {
502   GtkThemingEngine *engine;
503   char *str;
504
505   str = _gtk_css_parser_try_ident (parser, TRUE);
506   if (str == NULL)
507     {
508       _gtk_css_parser_error (parser, "Expected a valid theme name");
509       return FALSE;
510     }
511
512   engine = gtk_theming_engine_load (str);
513   if (engine == NULL)
514     {
515       _gtk_css_parser_error (parser, "Themeing engine '%s' not found", str);
516       g_free (str);
517       return FALSE;
518     }
519
520   g_value_set_object (value, engine);
521   g_free (str);
522   return TRUE;
523 }
524
525 static void
526 theming_engine_value_print (const GValue *value,
527                             GString      *string)
528 {
529   GtkThemingEngine *engine;
530   char *name;
531
532   engine = g_value_get_object (value);
533   if (engine == NULL)
534     g_string_append (string, "none");
535   else
536     {
537       /* XXX: gtk_theming_engine_get_name()? */
538       g_object_get (engine, "name", &name, NULL);
539       g_string_append (string, name ? name : "none");
540       g_free (name);
541     }
542 }
543
544 static gboolean 
545 animation_description_value_parse (GtkCssParser *parser,
546                                    GFile        *base,
547                                    GValue       *value)
548 {
549   GtkAnimationDescription *desc;
550   char *str;
551
552   str = _gtk_css_parser_read_value (parser);
553   if (str == NULL)
554     return FALSE;
555
556   desc = _gtk_animation_description_from_string (str);
557   g_free (str);
558
559   if (desc == NULL)
560     {
561       _gtk_css_parser_error (parser, "Invalid animation description");
562       return FALSE;
563     }
564   
565   g_value_take_boxed (value, desc);
566   return TRUE;
567 }
568
569 static void
570 animation_description_value_print (const GValue *value,
571                                    GString      *string)
572 {
573   GtkAnimationDescription *desc = g_value_get_boxed (value);
574
575   if (desc == NULL)
576     g_string_append (string, "none");
577   else
578     _gtk_animation_description_print (desc, string);
579 }
580
581 static gboolean 
582 border_value_parse (GtkCssParser *parser,
583                     GFile        *base,
584                     GValue       *value)
585 {
586   GtkBorder border = { 0, };
587   guint i, numbers[4];
588
589   for (i = 0; i < G_N_ELEMENTS (numbers); i++)
590     {
591       if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
592         break;
593
594       /* XXX: shouldn't allow spaces here? */
595       _gtk_css_parser_try (parser, "px", TRUE);
596     }
597
598   if (i == 0)
599     {
600       _gtk_css_parser_error (parser, "Expected valid border");
601       return FALSE;
602     }
603
604   border.top = numbers[0];
605   if (i > 1)
606     border.right = numbers[1];
607   else
608     border.right = border.top;
609   if (i > 2)
610     border.bottom = numbers[2];
611   else
612     border.bottom = border.top;
613   if (i > 3)
614     border.left = numbers[3];
615   else
616     border.left = border.right;
617
618   g_value_set_boxed (value, &border);
619   return TRUE;
620 }
621
622 static void
623 border_value_print (const GValue *value, GString *string)
624 {
625   const GtkBorder *border = g_value_get_boxed (value);
626
627   if (border == NULL)
628     g_string_append (string, "none");
629   else if (border->left != border->right)
630     g_string_append_printf (string, "%d %d %d %d", border->top, border->right, border->bottom, border->left);
631   else if (border->top != border->bottom)
632     g_string_append_printf (string, "%d %d %d", border->top, border->right, border->bottom);
633   else if (border->top != border->left)
634     g_string_append_printf (string, "%d %d", border->top, border->right);
635   else
636     g_string_append_printf (string, "%d", border->top);
637 }
638
639 static gboolean 
640 gradient_value_parse (GtkCssParser *parser,
641                       GFile        *base,
642                       GValue       *value)
643 {
644   GtkGradient *gradient;
645   cairo_pattern_type_t type;
646   gdouble coords[6];
647   guint i;
648
649   if (!_gtk_css_parser_try (parser, "-gtk-gradient", TRUE))
650     {
651       _gtk_css_parser_error (parser,
652                              "Expected '-gtk-gradient'");
653       return FALSE;
654     }
655
656   if (!_gtk_css_parser_try (parser, "(", TRUE))
657     {
658       _gtk_css_parser_error (parser,
659                              "Expected '(' after '-gtk-gradient'");
660       return FALSE;
661     }
662
663   /* Parse gradient type */
664   if (_gtk_css_parser_try (parser, "linear", TRUE))
665     type = CAIRO_PATTERN_TYPE_LINEAR;
666   else if (_gtk_css_parser_try (parser, "radial", TRUE))
667     type = CAIRO_PATTERN_TYPE_RADIAL;
668   else
669     {
670       _gtk_css_parser_error (parser,
671                              "Gradient type must be 'radial' or 'linear'");
672       return FALSE;
673     }
674
675   /* Parse start/stop position parameters */
676   for (i = 0; i < 2; i++)
677     {
678       if (! _gtk_css_parser_try (parser, ",", TRUE))
679         {
680           _gtk_css_parser_error (parser,
681                                  "Expected ','");
682           return FALSE;
683         }
684
685       if (_gtk_css_parser_try (parser, "left", TRUE))
686         coords[i * 3] = 0;
687       else if (_gtk_css_parser_try (parser, "right", TRUE))
688         coords[i * 3] = 1;
689       else if (_gtk_css_parser_try (parser, "center", TRUE))
690         coords[i * 3] = 0.5;
691       else if (!_gtk_css_parser_try_double (parser, &coords[i * 3]))
692         {
693           _gtk_css_parser_error (parser,
694                                  "Expected a valid X coordinate");
695           return FALSE;
696         }
697
698       if (_gtk_css_parser_try (parser, "top", TRUE))
699         coords[i * 3 + 1] = 0;
700       else if (_gtk_css_parser_try (parser, "bottom", TRUE))
701         coords[i * 3 + 1] = 1;
702       else if (_gtk_css_parser_try (parser, "center", TRUE))
703         coords[i * 3 + 1] = 0.5;
704       else if (!_gtk_css_parser_try_double (parser, &coords[i * 3 + 1]))
705         {
706           _gtk_css_parser_error (parser,
707                                  "Expected a valid Y coordinate");
708           return FALSE;
709         }
710
711       if (type == CAIRO_PATTERN_TYPE_RADIAL)
712         {
713           /* Parse radius */
714           if (! _gtk_css_parser_try (parser, ",", TRUE))
715             {
716               _gtk_css_parser_error (parser,
717                                      "Expected ','");
718               return FALSE;
719             }
720
721           if (! _gtk_css_parser_try_double (parser, &coords[(i * 3) + 2]))
722             {
723               _gtk_css_parser_error (parser,
724                                      "Expected a numer for the radius");
725               return FALSE;
726             }
727         }
728     }
729
730   if (type == CAIRO_PATTERN_TYPE_LINEAR)
731     gradient = gtk_gradient_new_linear (coords[0], coords[1], coords[3], coords[4]);
732   else
733     gradient = gtk_gradient_new_radial (coords[0], coords[1], coords[2],
734                                         coords[3], coords[4], coords[5]);
735
736   while (_gtk_css_parser_try (parser, ",", TRUE))
737     {
738       GtkSymbolicColor *color;
739       gdouble position;
740
741       if (_gtk_css_parser_try (parser, "from", TRUE))
742         {
743           position = 0;
744
745           if (!_gtk_css_parser_try (parser, "(", TRUE))
746             {
747               gtk_gradient_unref (gradient);
748               _gtk_css_parser_error (parser,
749                                      "Expected '('");
750               return FALSE;
751             }
752
753         }
754       else if (_gtk_css_parser_try (parser, "to", TRUE))
755         {
756           position = 1;
757
758           if (!_gtk_css_parser_try (parser, "(", TRUE))
759             {
760               gtk_gradient_unref (gradient);
761               _gtk_css_parser_error (parser,
762                                      "Expected '('");
763               return FALSE;
764             }
765
766         }
767       else if (_gtk_css_parser_try (parser, "color-stop", TRUE))
768         {
769           if (!_gtk_css_parser_try (parser, "(", TRUE))
770             {
771               gtk_gradient_unref (gradient);
772               _gtk_css_parser_error (parser,
773                                      "Expected '('");
774               return FALSE;
775             }
776
777           if (!_gtk_css_parser_try_double (parser, &position))
778             {
779               gtk_gradient_unref (gradient);
780               _gtk_css_parser_error (parser,
781                                      "Expected a valid number");
782               return FALSE;
783             }
784
785           if (!_gtk_css_parser_try (parser, ",", TRUE))
786             {
787               gtk_gradient_unref (gradient);
788               _gtk_css_parser_error (parser,
789                                      "Expected a comma");
790               return FALSE;
791             }
792         }
793       else
794         {
795           gtk_gradient_unref (gradient);
796           _gtk_css_parser_error (parser,
797                                  "Not a valid color-stop definition");
798           return FALSE;
799         }
800
801       color = _gtk_css_parser_read_symbolic_color (parser);
802       if (color == NULL)
803         {
804           gtk_gradient_unref (gradient);
805           return FALSE;
806         }
807
808       gtk_gradient_add_color_stop (gradient, position, color);
809       gtk_symbolic_color_unref (color);
810
811       if (!_gtk_css_parser_try (parser, ")", TRUE))
812         {
813           gtk_gradient_unref (gradient);
814           _gtk_css_parser_error (parser,
815                                  "Expected ')'");
816           return FALSE;
817         }
818     }
819
820   if (!_gtk_css_parser_try (parser, ")", TRUE))
821     {
822       gtk_gradient_unref (gradient);
823       _gtk_css_parser_error (parser,
824                              "Expected ')'");
825       return FALSE;
826     }
827
828   g_value_take_boxed (value, gradient);
829   return TRUE;
830 }
831
832 static void
833 gradient_value_print (const GValue *value,
834                       GString      *string)
835 {
836   GtkGradient *gradient = g_value_get_boxed (value);
837
838   if (gradient == NULL)
839     g_string_append (string, "none");
840   else
841     {
842       char *s = gtk_gradient_to_string (gradient);
843       g_string_append (string, s);
844       g_free (s);
845     }
846 }
847
848 static GFile *
849 gtk_css_parse_url (GtkCssParser *parser,
850                    GFile        *base)
851 {
852   gchar *path;
853   GFile *file;
854
855   if (_gtk_css_parser_try (parser, "url", FALSE))
856     {
857       if (!_gtk_css_parser_try (parser, "(", TRUE))
858         {
859           _gtk_css_parser_skip_whitespace (parser);
860           if (_gtk_css_parser_try (parser, "(", TRUE))
861             {
862               GError *error;
863               
864               error = g_error_new_literal (GTK_CSS_PROVIDER_ERROR,
865                                            GTK_CSS_PROVIDER_ERROR_DEPRECATED,
866                                            "Whitespace between 'url' and '(' is not allowed");
867                              
868               _gtk_css_parser_take_error (parser, error);
869             }
870           else
871             {
872               _gtk_css_parser_error (parser, "Expected '(' after 'url'");
873               return NULL;
874             }
875         }
876
877       path = _gtk_css_parser_read_string (parser);
878       if (path == NULL)
879         return NULL;
880
881       if (!_gtk_css_parser_try (parser, ")", TRUE))
882         {
883           _gtk_css_parser_error (parser, "No closing ')' found for 'url'");
884           g_free (path);
885           return NULL;
886         }
887     }
888   else
889     {
890       path = _gtk_css_parser_try_name (parser, TRUE);
891       if (path == NULL)
892         {
893           _gtk_css_parser_error (parser, "Not a valid url");
894           return NULL;
895         }
896     }
897
898   file = g_file_resolve_relative_path (base, path);
899   g_free (path);
900
901   return file;
902 }
903
904 static gboolean 
905 pattern_value_parse (GtkCssParser *parser,
906                      GFile        *base,
907                      GValue       *value)
908 {
909   if (_gtk_css_parser_begins_with (parser, '-'))
910     {
911       g_value_unset (value);
912       g_value_init (value, GTK_TYPE_GRADIENT);
913       return gradient_value_parse (parser, base, value);
914     }
915   else
916     {
917       GError *error = NULL;
918       gchar *path;
919       GdkPixbuf *pixbuf;
920       GFile *file;
921       cairo_surface_t *surface;
922       cairo_pattern_t *pattern;
923       cairo_t *cr;
924       cairo_matrix_t matrix;
925
926       file = gtk_css_parse_url (parser, base);
927       if (file == NULL)
928         return FALSE;
929
930       path = g_file_get_path (file);
931       g_object_unref (file);
932
933       pixbuf = gdk_pixbuf_new_from_file (path, &error);
934       g_free (path);
935       if (pixbuf == NULL)
936         {
937           _gtk_css_parser_take_error (parser, error);
938           return FALSE;
939         }
940
941       surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
942                                             gdk_pixbuf_get_width (pixbuf),
943                                             gdk_pixbuf_get_height (pixbuf));
944       cr = cairo_create (surface);
945       gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
946       cairo_paint (cr);
947       pattern = cairo_pattern_create_for_surface (surface);
948
949       cairo_matrix_init_scale (&matrix,
950                                gdk_pixbuf_get_width (pixbuf),
951                                gdk_pixbuf_get_height (pixbuf));
952       cairo_pattern_set_matrix (pattern, &matrix);
953
954       cairo_surface_destroy (surface);
955       cairo_destroy (cr);
956       g_object_unref (pixbuf);
957
958       g_value_take_boxed (value, pattern);
959     }
960   
961   return TRUE;
962 }
963
964 static cairo_status_t
965 surface_write (void                *closure,
966                const unsigned char *data,
967                unsigned int         length)
968 {
969   g_byte_array_append (closure, data, length);
970
971   return CAIRO_STATUS_SUCCESS;
972 }
973
974 static void
975 surface_print (cairo_surface_t *surface,
976                GString *        string)
977 {
978 #if CAIRO_HAS_PNG_FUNCTIONS
979   GByteArray *array;
980   char *base64;
981   
982   array = g_byte_array_new ();
983   cairo_surface_write_to_png_stream (surface, surface_write, array);
984   base64 = g_base64_encode (array->data, array->len);
985   g_byte_array_free (array, TRUE);
986
987   g_string_append (string, "url(\"data:image/png;base64,");
988   g_string_append (string, base64);
989   g_string_append (string, "\")");
990
991   g_free (base64);
992 #else
993   g_string_append (string, "none /* you need cairo png functions enabled to make this work */");
994 #endif
995 }
996
997 static void
998 pattern_value_print (const GValue *value,
999                      GString      *string)
1000 {
1001   cairo_pattern_t *pattern;
1002   cairo_surface_t *surface;
1003
1004   pattern = g_value_get_boxed (value);
1005
1006   if (pattern == NULL)
1007     {
1008       g_string_append (string, "none");
1009       return;
1010     }
1011
1012   switch (cairo_pattern_get_type (pattern))
1013     {
1014     case CAIRO_PATTERN_TYPE_SURFACE:
1015       if (cairo_pattern_get_surface (pattern, &surface) != CAIRO_STATUS_SUCCESS)
1016         {
1017           g_assert_not_reached ();
1018         }
1019       surface_print (surface, string);
1020       break;
1021     case CAIRO_PATTERN_TYPE_SOLID:
1022     case CAIRO_PATTERN_TYPE_LINEAR:
1023     case CAIRO_PATTERN_TYPE_RADIAL:
1024     default:
1025       g_assert_not_reached ();
1026       break;
1027     }
1028 }
1029
1030 static gboolean
1031 shadow_value_parse (GtkCssParser *parser,
1032                     GFile *base,
1033                     GValue *value)
1034 {
1035   gboolean have_inset, have_color, have_lengths;
1036   gdouble hoffset, voffset, blur, spread;
1037   GtkSymbolicColor *color;
1038   GtkShadow *shadow;
1039   guint i;
1040
1041   shadow = _gtk_shadow_new ();
1042
1043   do
1044     {
1045       have_inset = have_lengths = have_color = FALSE;
1046
1047       for (i = 0; i < 3; i++)
1048         {
1049           if (!have_inset && 
1050               _gtk_css_parser_try (parser, "inset", TRUE))
1051             {
1052               have_inset = TRUE;
1053               continue;
1054             }
1055             
1056           if (!have_lengths &&
1057               _gtk_css_parser_try_double (parser, &hoffset))
1058             {
1059               have_lengths = TRUE;
1060
1061               if (!_gtk_css_parser_try_double (parser, &voffset))
1062                 {
1063                   _gtk_css_parser_error (parser, "Horizontal and vertical offsets are required");
1064                   _gtk_shadow_unref (shadow);
1065                   return FALSE;
1066                 }
1067
1068               if (!_gtk_css_parser_try_double (parser, &blur))
1069                 blur = 0;
1070
1071               if (!_gtk_css_parser_try_double (parser, &spread))
1072                 spread = 0;
1073
1074               continue;
1075             }
1076
1077           if (!have_color)
1078             {
1079               have_color = TRUE;
1080
1081               /* XXX: the color is optional and UA-defined if it's missing,
1082                * but it doesn't really make sense for us...
1083                */
1084               color = _gtk_css_parser_read_symbolic_color (parser);
1085
1086               if (color == NULL)
1087                 {
1088                   _gtk_shadow_unref (shadow);
1089                   return FALSE;
1090                 }
1091             }
1092         }
1093
1094       if (!have_color || !have_lengths)
1095         {
1096           _gtk_css_parser_error (parser, "Must specify at least color and offsets");
1097           _gtk_shadow_unref (shadow);
1098           return FALSE;
1099         }
1100
1101       _gtk_shadow_append (shadow,
1102                           hoffset, voffset,
1103                           blur, spread,
1104                           have_inset, color);
1105
1106       gtk_symbolic_color_unref (color);
1107
1108     }
1109   while (_gtk_css_parser_try (parser, ",", TRUE));
1110
1111   g_value_take_boxed (value, shadow);
1112   return TRUE;
1113 }
1114
1115 static void
1116 shadow_value_print (const GValue *value,
1117                     GString      *string)
1118 {
1119   GtkShadow *shadow;
1120
1121   shadow = g_value_get_boxed (value);
1122
1123   if (shadow == NULL)
1124     g_string_append (string, "none");
1125   else
1126     _gtk_shadow_print (shadow, string);
1127 }
1128
1129 static gboolean
1130 border_image_repeat_value_parse (GtkCssParser *parser,
1131                                  GFile *file,
1132                                  GValue *value)
1133 {
1134   GtkCssBorderImageRepeat image_repeat;
1135   GtkCssRepeatStyle styles[2];
1136   gint i;
1137
1138   for (i = 0; i < 2; i++)
1139     {
1140       if (_gtk_css_parser_try (parser, "stretch", TRUE))
1141         styles[i] = GTK_CSS_REPEAT_STYLE_NONE;
1142       else if (_gtk_css_parser_try (parser, "repeat", TRUE))
1143         styles[i] = GTK_CSS_REPEAT_STYLE_REPEAT;
1144       else if (_gtk_css_parser_try (parser, "round", TRUE))
1145         styles[i] = GTK_CSS_REPEAT_STYLE_ROUND;
1146       else if (_gtk_css_parser_try (parser, "space", TRUE))
1147         styles[i] = GTK_CSS_REPEAT_STYLE_SPACE;
1148       else if (i == 0)
1149         {
1150           styles[1] = styles[0] = GTK_CSS_REPEAT_STYLE_NONE;
1151           break;
1152         }
1153       else
1154         styles[i] = styles[0];
1155     }
1156
1157   image_repeat.hrepeat = styles[0];
1158   image_repeat.vrepeat = styles[1];
1159
1160   g_value_set_boxed (value, &image_repeat);
1161
1162   return TRUE;
1163 }
1164
1165 static const gchar *
1166 border_image_repeat_style_to_string (GtkCssRepeatStyle repeat)
1167 {
1168   switch (repeat)
1169     {
1170     case GTK_CSS_REPEAT_STYLE_NONE:
1171       return "stretch";
1172     case GTK_CSS_REPEAT_STYLE_REPEAT:
1173       return "repeat";
1174     case GTK_CSS_REPEAT_STYLE_ROUND:
1175       return "round";
1176     case GTK_CSS_REPEAT_STYLE_SPACE:
1177       return "space";
1178     default:
1179       return NULL;
1180     }
1181 }
1182
1183 static void
1184 border_image_repeat_value_print (const GValue *value,
1185                                  GString      *string)
1186 {
1187   GtkCssBorderImageRepeat *image_repeat;
1188
1189   image_repeat = g_value_get_boxed (value);
1190
1191   g_string_append (string, border_image_repeat_style_to_string (image_repeat->hrepeat));
1192   if (image_repeat->hrepeat != image_repeat->vrepeat)
1193     {
1194       g_string_append (string, " ");
1195       g_string_append (string, border_image_repeat_style_to_string (image_repeat->vrepeat));
1196     }
1197 }
1198
1199 static gboolean
1200 border_image_value_parse (GtkCssParser *parser,
1201                           GFile *base,
1202                           GValue *value)
1203 {
1204   GValue temp = { 0, };
1205   cairo_pattern_t *pattern = NULL;
1206   GtkGradient *gradient = NULL;
1207   GtkBorder slice, *width = NULL, *parsed_slice;
1208   GtkCssBorderImageRepeat repeat, *parsed_repeat;
1209   gboolean retval = FALSE;
1210   GtkBorderImage *image = NULL;
1211
1212   g_value_init (&temp, CAIRO_GOBJECT_TYPE_PATTERN);
1213
1214   if (!pattern_value_parse (parser, base, &temp))
1215     return FALSE;
1216
1217   if (G_VALUE_TYPE (&temp) == GTK_TYPE_GRADIENT)
1218     gradient = g_value_dup_boxed (&temp);
1219   else
1220     pattern = g_value_dup_boxed (&temp);
1221
1222   g_value_unset (&temp);
1223   g_value_init (&temp, GTK_TYPE_BORDER);
1224
1225   if (!border_value_parse (parser, base, &temp))
1226     goto out;
1227
1228   parsed_slice = g_value_get_boxed (&temp);
1229   slice = *parsed_slice;
1230
1231   if (_gtk_css_parser_try (parser, "/", TRUE))
1232     {
1233       g_value_unset (&temp);
1234       g_value_init (&temp, GTK_TYPE_BORDER);
1235
1236       if (!border_value_parse (parser, base, &temp))
1237         goto out;
1238
1239       width = g_value_dup_boxed (&temp);
1240     }
1241
1242   g_value_unset (&temp);
1243   g_value_init (&temp, GTK_TYPE_CSS_BORDER_IMAGE_REPEAT);
1244
1245   if (!border_image_repeat_value_parse (parser, base, &temp))
1246     goto out;
1247
1248   parsed_repeat = g_value_get_boxed (&temp);
1249   repeat = *parsed_repeat;
1250
1251   g_value_unset (&temp);
1252
1253   if (gradient != NULL)
1254     image = _gtk_border_image_new_for_gradient (gradient, &slice, width, &repeat);
1255   else if (pattern != NULL)
1256     image = _gtk_border_image_new (pattern, &slice, width, &repeat);
1257
1258   if (image != NULL)
1259     {
1260       retval = TRUE;
1261       g_value_take_boxed (value, image);
1262     }
1263
1264  out:
1265   if (pattern != NULL)
1266     cairo_pattern_destroy (pattern);
1267
1268   if (gradient != NULL)
1269     gtk_gradient_unref (gradient);
1270
1271   if (width != NULL)
1272     gtk_border_free (width);
1273
1274   return retval;
1275 }
1276
1277 static gboolean 
1278 enum_value_parse (GtkCssParser *parser,
1279                   GFile        *base,
1280                   GValue       *value)
1281 {
1282   GEnumClass *enum_class;
1283   GEnumValue *enum_value;
1284   char *str;
1285
1286   str = _gtk_css_parser_try_ident (parser, TRUE);
1287   if (str == NULL)
1288     {
1289       _gtk_css_parser_error (parser, "Expected an identifier");
1290       return FALSE;
1291     }
1292
1293   enum_class = g_type_class_ref (G_VALUE_TYPE (value));
1294   enum_value = g_enum_get_value_by_nick (enum_class, str);
1295
1296   if (enum_value)
1297     g_value_set_enum (value, enum_value->value);
1298   else
1299     _gtk_css_parser_error (parser,
1300                            "Unknown value '%s' for enum type '%s'",
1301                            str, g_type_name (G_VALUE_TYPE (value)));
1302   
1303   g_type_class_unref (enum_class);
1304   g_free (str);
1305
1306   return enum_value != NULL;
1307 }
1308
1309 static void
1310 enum_value_print (const GValue *value,
1311                   GString      *string)
1312 {
1313   GEnumClass *enum_class;
1314   GEnumValue *enum_value;
1315
1316   enum_class = g_type_class_ref (G_VALUE_TYPE (value));
1317   enum_value = g_enum_get_value (enum_class, g_value_get_enum (value));
1318
1319   g_string_append (string, enum_value->value_nick);
1320
1321   g_type_class_unref (enum_class);
1322 }
1323
1324 static gboolean 
1325 flags_value_parse (GtkCssParser *parser,
1326                    GFile        *base,
1327                    GValue       *value)
1328 {
1329   GFlagsClass *flags_class;
1330   GFlagsValue *flag_value;
1331   guint flags = 0;
1332   char *str;
1333
1334   flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1335
1336   do {
1337     str = _gtk_css_parser_try_ident (parser, TRUE);
1338     if (str == NULL)
1339       {
1340         _gtk_css_parser_error (parser, "Expected an identifier");
1341         g_type_class_unref (flags_class);
1342         return FALSE;
1343       }
1344
1345       flag_value = g_flags_get_value_by_nick (flags_class, str);
1346       if (!flag_value)
1347         {
1348           _gtk_css_parser_error (parser,
1349                                  "Unknown flag value '%s' for type '%s'",
1350                                  str, g_type_name (G_VALUE_TYPE (value)));
1351           /* XXX Do we want to return FALSE here? We can get
1352            * forward-compatibility for new values this way
1353            */
1354           g_free (str);
1355           g_type_class_unref (flags_class);
1356           return FALSE;
1357         }
1358
1359       g_free (str);
1360     }
1361   while (_gtk_css_parser_try (parser, ",", FALSE));
1362
1363   g_type_class_unref (flags_class);
1364
1365   g_value_set_enum (value, flags);
1366
1367   return TRUE;
1368 }
1369
1370 static void
1371 flags_value_print (const GValue *value,
1372                    GString      *string)
1373 {
1374   GFlagsClass *flags_class;
1375   guint i, flags;
1376
1377   flags_class = g_type_class_ref (G_VALUE_TYPE (value));
1378   flags = g_value_get_flags (value);
1379
1380   for (i = 0; i < flags_class->n_values; i++)
1381     {
1382       GFlagsValue *flags_value = &flags_class->values[i];
1383
1384       if (flags & flags_value->value)
1385         {
1386           if (string->len != 0)
1387             g_string_append (string, ", ");
1388
1389           g_string_append (string, flags_value->value_nick);
1390         }
1391     }
1392
1393   g_type_class_unref (flags_class);
1394 }
1395
1396 static gboolean 
1397 bindings_value_parse (GtkCssParser *parser,
1398                       GFile        *base,
1399                       GValue       *value)
1400 {
1401   GPtrArray *array;
1402   GtkBindingSet *binding_set;
1403   char *name;
1404
1405   array = g_ptr_array_new ();
1406
1407   do {
1408       name = _gtk_css_parser_try_ident (parser, TRUE);
1409       if (name == NULL)
1410         {
1411           _gtk_css_parser_error (parser, "Not a valid binding name");
1412           g_ptr_array_free (array, TRUE);
1413           return FALSE;
1414         }
1415
1416       binding_set = gtk_binding_set_find (name);
1417
1418       if (!binding_set)
1419         {
1420           _gtk_css_parser_error (parser, "No binding set named '%s'", name);
1421           g_free (name);
1422           continue;
1423         }
1424
1425       g_ptr_array_add (array, binding_set);
1426       g_free (name);
1427     }
1428   while (_gtk_css_parser_try (parser, ",", TRUE));
1429
1430   g_value_take_boxed (value, array);
1431
1432   return TRUE;
1433 }
1434
1435 static void
1436 bindings_value_print (const GValue *value,
1437                       GString      *string)
1438 {
1439   GPtrArray *array;
1440   guint i;
1441
1442   array = g_value_get_boxed (value);
1443
1444   for (i = 0; i < array->len; i++)
1445     {
1446       GtkBindingSet *binding_set = g_ptr_array_index (array, i);
1447
1448       if (i > 0)
1449         g_string_append (string, ", ");
1450       g_string_append (string, binding_set->set_name);
1451     }
1452 }
1453
1454 static gboolean 
1455 border_corner_radius_value_parse (GtkCssParser *parser,
1456                                   GFile        *base,
1457                                   GValue       *value)
1458 {
1459   GtkCssBorderCornerRadius corner;
1460
1461   if (!_gtk_css_parser_try_double (parser, &corner.horizontal))
1462     {
1463       _gtk_css_parser_error (parser, "Expected a number");
1464       return FALSE;
1465     }
1466   else if (corner.horizontal < 0)
1467     goto negative;
1468
1469   if (!_gtk_css_parser_try_double (parser, &corner.vertical))
1470     corner.vertical = corner.horizontal;
1471   else if (corner.vertical < 0)
1472     goto negative;
1473
1474   g_value_set_boxed (value, &corner);
1475   return TRUE;
1476
1477 negative:
1478   _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1479   return FALSE;
1480 }
1481
1482 static void
1483 border_corner_radius_value_print (const GValue *value,
1484                                   GString      *string)
1485 {
1486   GtkCssBorderCornerRadius *corner;
1487
1488   corner = g_value_get_boxed (value);
1489
1490   if (corner == NULL)
1491     {
1492       g_string_append (string, "none");
1493       return;
1494     }
1495
1496   string_append_double (string, corner->horizontal);
1497   if (corner->horizontal != corner->vertical)
1498     {
1499       g_string_append_c (string, ' ');
1500       string_append_double (string, corner->vertical);
1501     }
1502 }
1503
1504 static gboolean 
1505 border_radius_value_parse (GtkCssParser *parser,
1506                            GFile        *base,
1507                            GValue       *value)
1508 {
1509   GtkCssBorderRadius border;
1510
1511   if (!_gtk_css_parser_try_double (parser, &border.top_left.horizontal))
1512     {
1513       _gtk_css_parser_error (parser, "Expected a number");
1514       return FALSE;
1515     }
1516   else if (border.top_left.horizontal < 0)
1517     goto negative;
1518
1519   if (_gtk_css_parser_try_double (parser, &border.top_right.horizontal))
1520     {
1521       if (border.top_right.horizontal < 0)
1522         goto negative;
1523       if (_gtk_css_parser_try_double (parser, &border.bottom_right.horizontal))
1524         {
1525           if (border.bottom_right.horizontal < 0)
1526             goto negative;
1527           if (!_gtk_css_parser_try_double (parser, &border.bottom_left.horizontal))
1528             border.bottom_left.horizontal = border.top_right.horizontal;
1529           else if (border.bottom_left.horizontal < 0)
1530             goto negative;
1531         }
1532       else
1533         {
1534           border.bottom_right.horizontal = border.top_left.horizontal;
1535           border.bottom_left.horizontal = border.top_right.horizontal;
1536         }
1537     }
1538   else
1539     {
1540       border.top_right.horizontal = border.top_left.horizontal;
1541       border.bottom_right.horizontal = border.top_left.horizontal;
1542       border.bottom_left.horizontal = border.top_left.horizontal;
1543     }
1544
1545   if (_gtk_css_parser_try (parser, "/", TRUE))
1546     {
1547       if (!_gtk_css_parser_try_double (parser, &border.top_left.vertical))
1548         {
1549           _gtk_css_parser_error (parser, "Expected a number");
1550           return FALSE;
1551         }
1552       else if (border.top_left.vertical < 0)
1553         goto negative;
1554
1555       if (_gtk_css_parser_try_double (parser, &border.top_right.vertical))
1556         {
1557           if (border.top_right.vertical < 0)
1558             goto negative;
1559           if (_gtk_css_parser_try_double (parser, &border.bottom_right.vertical))
1560             {
1561               if (border.bottom_right.vertical < 0)
1562                 goto negative;
1563               if (!_gtk_css_parser_try_double (parser, &border.bottom_left.vertical))
1564                 border.bottom_left.vertical = border.top_right.vertical;
1565               else if (border.bottom_left.vertical < 0)
1566                 goto negative;
1567             }
1568           else
1569             {
1570               border.bottom_right.vertical = border.top_left.vertical;
1571               border.bottom_left.vertical = border.top_right.vertical;
1572             }
1573         }
1574       else
1575         {
1576           border.top_right.vertical = border.top_left.vertical;
1577           border.bottom_right.vertical = border.top_left.vertical;
1578           border.bottom_left.vertical = border.top_left.vertical;
1579         }
1580     }
1581   else
1582     {
1583       border.top_left.vertical = border.top_left.horizontal;
1584       border.top_right.vertical = border.top_right.horizontal;
1585       border.bottom_right.vertical = border.bottom_right.horizontal;
1586       border.bottom_left.vertical = border.bottom_left.horizontal;
1587     }
1588
1589   /* border-radius is an int property for backwards-compat reasons */
1590   g_value_unset (value);
1591   g_value_init (value, GTK_TYPE_CSS_BORDER_RADIUS);
1592   g_value_set_boxed (value, &border);
1593
1594   return TRUE;
1595
1596 negative:
1597   _gtk_css_parser_error (parser, "Border radius values cannot be negative");
1598   return FALSE;
1599 }
1600
1601 static void
1602 border_radius_value_print (const GValue *value,
1603                            GString      *string)
1604 {
1605   GtkCssBorderRadius *border;
1606
1607   border = g_value_get_boxed (value);
1608
1609   if (border == NULL)
1610     {
1611       g_string_append (string, "none");
1612       return;
1613     }
1614
1615   string_append_double (string, border->top_left.horizontal);
1616   if (border->top_left.horizontal != border->top_right.horizontal ||
1617       border->top_left.horizontal != border->bottom_right.horizontal ||
1618       border->top_left.horizontal != border->bottom_left.horizontal)
1619     {
1620       g_string_append_c (string, ' ');
1621       string_append_double (string, border->top_right.horizontal);
1622       if (border->top_left.horizontal != border->bottom_right.horizontal ||
1623           border->top_right.horizontal != border->bottom_left.horizontal)
1624         {
1625           g_string_append_c (string, ' ');
1626           string_append_double (string, border->bottom_right.horizontal);
1627           if (border->top_right.horizontal != border->bottom_left.horizontal)
1628             {
1629               g_string_append_c (string, ' ');
1630               string_append_double (string, border->bottom_left.horizontal);
1631             }
1632         }
1633     }
1634
1635   if (border->top_left.horizontal != border->top_left.vertical ||
1636       border->top_right.horizontal != border->top_right.vertical ||
1637       border->bottom_right.horizontal != border->bottom_right.vertical ||
1638       border->bottom_left.horizontal != border->bottom_left.vertical)
1639     {
1640       g_string_append (string, " / ");
1641       string_append_double (string, border->top_left.vertical);
1642       if (border->top_left.vertical != border->top_right.vertical ||
1643           border->top_left.vertical != border->bottom_right.vertical ||
1644           border->top_left.vertical != border->bottom_left.vertical)
1645         {
1646           g_string_append_c (string, ' ');
1647           string_append_double (string, border->top_right.vertical);
1648           if (border->top_left.vertical != border->bottom_right.vertical ||
1649               border->top_right.vertical != border->bottom_left.vertical)
1650             {
1651               g_string_append_c (string, ' ');
1652               string_append_double (string, border->bottom_right.vertical);
1653               if (border->top_right.vertical != border->bottom_left.vertical)
1654                 {
1655                   g_string_append_c (string, ' ');
1656                   string_append_double (string, border->bottom_left.vertical);
1657                 }
1658             }
1659         }
1660
1661     }
1662 }
1663
1664 static gboolean 
1665 border_color_value_parse (GtkCssParser *parser,
1666                           GFile        *base,
1667                           GValue       *value)
1668 {
1669   if (_gtk_css_parser_try (parser, "transparent", TRUE))
1670     {
1671       GdkRGBA transparent = { 0, 0, 0, 0 };
1672           
1673       g_value_set_boxed (value, &transparent);
1674
1675       return TRUE;
1676     }
1677
1678   return rgba_value_parse (parser, base, value);
1679 }
1680
1681 static gboolean 
1682 border_color_shorthand_value_parse (GtkCssParser *parser,
1683                                     GFile        *base,
1684                                     GValue       *value)
1685 {
1686   GtkSymbolicColor *symbolic;
1687   GPtrArray *array;
1688
1689   array = g_ptr_array_new_with_free_func ((GDestroyNotify) gtk_symbolic_color_unref);
1690
1691   do
1692     {
1693       if (_gtk_css_parser_try (parser, "transparent", TRUE))
1694         {
1695           GdkRGBA transparent = { 0, 0, 0, 0 };
1696           
1697           symbolic = gtk_symbolic_color_new_literal (&transparent);
1698         }
1699       else
1700         {
1701           symbolic = _gtk_css_parser_read_symbolic_color (parser);
1702       
1703           if (symbolic == NULL)
1704             return FALSE;
1705         }
1706       
1707       g_ptr_array_add (array, symbolic);
1708     }
1709   while (array->len < 4 && 
1710          !_gtk_css_parser_is_eof (parser) &&
1711          !_gtk_css_parser_begins_with (parser, ';') &&
1712          !_gtk_css_parser_begins_with (parser, '}'));
1713
1714   switch (array->len)
1715     {
1716       default:
1717         g_assert_not_reached ();
1718         break;
1719       case 1:
1720         g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 0)));
1721         /* fall through */
1722       case 2:
1723         g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 0)));
1724         /* fall through */
1725       case 3:
1726         g_ptr_array_add (array, gtk_symbolic_color_ref (g_ptr_array_index (array, 1)));
1727         /* fall through */
1728       case 4:
1729         break;
1730     }
1731
1732   g_value_unset (value);
1733   g_value_init (value, G_TYPE_PTR_ARRAY);
1734   g_value_take_boxed (value, array);
1735
1736   return TRUE;
1737 }
1738
1739 /*** PACKING ***/
1740
1741 static GParameter *
1742 unpack_border (const GValue *value,
1743                guint        *n_params,
1744                const char   *top,
1745                const char   *left,
1746                const char   *bottom,
1747                const char   *right)
1748 {
1749   GParameter *parameter = g_new0 (GParameter, 4);
1750   GtkBorder *border = g_value_get_boxed (value);
1751
1752   parameter[0].name = top;
1753   g_value_init (&parameter[0].value, G_TYPE_INT);
1754   g_value_set_int (&parameter[0].value, border->top);
1755   parameter[1].name = left;
1756   g_value_init (&parameter[1].value, G_TYPE_INT);
1757   g_value_set_int (&parameter[1].value, border->left);
1758   parameter[2].name = bottom;
1759   g_value_init (&parameter[2].value, G_TYPE_INT);
1760   g_value_set_int (&parameter[2].value, border->bottom);
1761   parameter[3].name = right;
1762   g_value_init (&parameter[3].value, G_TYPE_INT);
1763   g_value_set_int (&parameter[3].value, border->right);
1764
1765   *n_params = 4;
1766   return parameter;
1767 }
1768
1769 static void
1770 pack_border (GValue             *value,
1771              GtkStyleProperties *props,
1772              GtkStateFlags       state,
1773              const char         *top,
1774              const char         *left,
1775              const char         *bottom,
1776              const char         *right)
1777 {
1778   GtkBorder border;
1779   int t, l, b, r;
1780
1781   gtk_style_properties_get (props,
1782                             state,
1783                             top, &t,
1784                             left, &l,
1785                             bottom, &b,
1786                             right, &r,
1787                             NULL);
1788
1789   border.top = t;
1790   border.left = l;
1791   border.bottom = b;
1792   border.right = r;
1793
1794   g_value_set_boxed (value, &border);
1795 }
1796
1797 static GParameter *
1798 unpack_border_width (const GValue *value,
1799                      guint        *n_params)
1800 {
1801   return unpack_border (value, n_params,
1802                         "border-top-width", "border-left-width",
1803                         "border-bottom-width", "border-right-width");
1804 }
1805
1806 static void
1807 pack_border_width (GValue             *value,
1808                    GtkStyleProperties *props,
1809                    GtkStateFlags       state)
1810 {
1811   pack_border (value, props, state,
1812                "border-top-width", "border-left-width",
1813                "border-bottom-width", "border-right-width");
1814 }
1815
1816 static GParameter *
1817 unpack_padding (const GValue *value,
1818                 guint        *n_params)
1819 {
1820   return unpack_border (value, n_params,
1821                         "padding-top", "padding-left",
1822                         "padding-bottom", "padding-right");
1823 }
1824
1825 static void
1826 pack_padding (GValue             *value,
1827               GtkStyleProperties *props,
1828               GtkStateFlags       state)
1829 {
1830   pack_border (value, props, state,
1831                "padding-top", "padding-left",
1832                "padding-bottom", "padding-right");
1833 }
1834
1835 static GParameter *
1836 unpack_margin (const GValue *value,
1837                guint        *n_params)
1838 {
1839   return unpack_border (value, n_params,
1840                         "margin-top", "margin-left",
1841                         "margin-bottom", "margin-right");
1842 }
1843
1844 static void
1845 pack_margin (GValue             *value,
1846              GtkStyleProperties *props,
1847              GtkStateFlags       state)
1848 {
1849   pack_border (value, props, state,
1850                "margin-top", "margin-left",
1851                "margin-bottom", "margin-right");
1852 }
1853
1854 static GParameter *
1855 unpack_border_radius (const GValue *value,
1856                       guint        *n_params)
1857 {
1858   GParameter *parameter = g_new0 (GParameter, 4);
1859   GtkCssBorderRadius *border;
1860   
1861   if (G_VALUE_HOLDS_BOXED (value))
1862     border = g_value_get_boxed (value);
1863   else
1864     border = NULL;
1865
1866   parameter[0].name = "border-top-left-radius";
1867   g_value_init (&parameter[0].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1868   parameter[1].name = "border-top-right-radius";
1869   g_value_init (&parameter[1].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1870   parameter[2].name = "border-bottom-right-radius";
1871   g_value_init (&parameter[2].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1872   parameter[3].name = "border-bottom-left-radius";
1873   g_value_init (&parameter[3].value, GTK_TYPE_CSS_BORDER_CORNER_RADIUS);
1874   if (border)
1875     {
1876       g_value_set_boxed (&parameter[0].value, &border->top_left);
1877       g_value_set_boxed (&parameter[1].value, &border->top_right);
1878       g_value_set_boxed (&parameter[2].value, &border->bottom_right);
1879       g_value_set_boxed (&parameter[3].value, &border->bottom_left);
1880     }
1881
1882   *n_params = 4;
1883   return parameter;
1884 }
1885
1886 static void
1887 pack_border_radius (GValue             *value,
1888                     GtkStyleProperties *props,
1889                     GtkStateFlags       state)
1890 {
1891   GtkCssBorderCornerRadius *top_left;
1892
1893   /* NB: We are an int property, so we have to resolve to an int here.
1894    * So we just resolve to an int. We pick one and stick to it.
1895    * Lesson learned: Don't query border-radius shorthand, query the 
1896    * real properties instead. */
1897   gtk_style_properties_get (props,
1898                             state,
1899                             "border-top-left-radius", &top_left,
1900                             NULL);
1901
1902   if (top_left)
1903     g_value_set_int (value, top_left->horizontal);
1904
1905   g_free (top_left);
1906 }
1907
1908 static GParameter *
1909 unpack_font_description (const GValue *value,
1910                          guint        *n_params)
1911 {
1912   GParameter *parameter = g_new0 (GParameter, 5);
1913   PangoFontDescription *description;
1914   PangoFontMask mask;
1915   guint n;
1916   
1917   /* For backwards compat, we only unpack values that are indeed set.
1918    * For strict CSS conformance we need to unpack all of them.
1919    * Note that we do set all of them in the parse function, so it
1920    * will not have effects when parsing CSS files. It will though
1921    * for custom style providers.
1922    */
1923
1924   description = g_value_get_boxed (value);
1925   n = 0;
1926
1927   if (description)
1928     mask = pango_font_description_get_set_fields (description);
1929   else
1930     mask = 0;
1931
1932   if (mask & PANGO_FONT_MASK_FAMILY)
1933     {
1934       GPtrArray *strv = g_ptr_array_new ();
1935
1936       g_ptr_array_add (strv, g_strdup (pango_font_description_get_family (description)));
1937       g_ptr_array_add (strv, NULL);
1938       parameter[n].name = "font-family";
1939       g_value_init (&parameter[n].value, G_TYPE_STRV);
1940       g_value_take_boxed (&parameter[n].value,
1941                           g_ptr_array_free (strv, FALSE));
1942       n++;
1943     }
1944
1945   if (mask & PANGO_FONT_MASK_STYLE)
1946     {
1947       parameter[n].name = "font-style";
1948       g_value_init (&parameter[n].value, PANGO_TYPE_STYLE);
1949       g_value_set_enum (&parameter[n].value,
1950                         pango_font_description_get_style (description));
1951       n++;
1952     }
1953
1954   if (mask & PANGO_FONT_MASK_VARIANT)
1955     {
1956       parameter[n].name = "font-variant";
1957       g_value_init (&parameter[n].value, PANGO_TYPE_VARIANT);
1958       g_value_set_enum (&parameter[n].value,
1959                         pango_font_description_get_variant (description));
1960       n++;
1961     }
1962
1963   if (mask & PANGO_FONT_MASK_WEIGHT)
1964     {
1965       parameter[n].name = "font-weight";
1966       g_value_init (&parameter[n].value, PANGO_TYPE_WEIGHT);
1967       g_value_set_enum (&parameter[n].value,
1968                         pango_font_description_get_weight (description));
1969       n++;
1970     }
1971
1972   if (mask & PANGO_FONT_MASK_SIZE)
1973     {
1974       parameter[n].name = "font-size";
1975       g_value_init (&parameter[n].value, G_TYPE_DOUBLE);
1976       g_value_set_double (&parameter[n].value,
1977                           (double) pango_font_description_get_size (description) / PANGO_SCALE);
1978       n++;
1979     }
1980
1981   *n_params = n;
1982
1983   return parameter;
1984 }
1985
1986 static void
1987 pack_font_description (GValue             *value,
1988                        GtkStyleProperties *props,
1989                        GtkStateFlags       state)
1990 {
1991   PangoFontDescription *description;
1992   char **families;
1993   PangoStyle style;
1994   PangoVariant variant;
1995   PangoWeight weight;
1996   double size;
1997
1998   gtk_style_properties_get (props,
1999                             state,
2000                             "font-family", &families,
2001                             "font-style", &style,
2002                             "font-variant", &variant,
2003                             "font-weight", &weight,
2004                             "font-size", &size,
2005                             NULL);
2006
2007   description = pango_font_description_new ();
2008   /* xxx: Can we set all the families here somehow? */
2009   if (families)
2010     pango_font_description_set_family (description, families[0]);
2011   pango_font_description_set_size (description, round (size * PANGO_SCALE));
2012   pango_font_description_set_style (description, style);
2013   pango_font_description_set_variant (description, variant);
2014   pango_font_description_set_weight (description, weight);
2015
2016   g_strfreev (families);
2017
2018   g_value_take_boxed (value, description);
2019 }
2020
2021 static GParameter *
2022 unpack_border_color (const GValue *value,
2023                      guint        *n_params)
2024 {
2025   GParameter *parameter = g_new0 (GParameter, 4);
2026   GType type;
2027   
2028   type = G_VALUE_TYPE (value);
2029   if (type == G_TYPE_PTR_ARRAY)
2030     type = GTK_TYPE_SYMBOLIC_COLOR;
2031
2032   parameter[0].name = "border-top-color";
2033   g_value_init (&parameter[0].value, type);
2034   parameter[1].name = "border-right-color";
2035   g_value_init (&parameter[1].value, type);
2036   parameter[2].name = "border-bottom-color";
2037   g_value_init (&parameter[2].value, type);
2038   parameter[3].name = "border-left-color";
2039   g_value_init (&parameter[3].value, type);
2040
2041   if (G_VALUE_TYPE (value) == G_TYPE_PTR_ARRAY)
2042     {
2043       GPtrArray *array = g_value_get_boxed (value);
2044       guint i;
2045
2046       for (i = 0; i < 4; i++)
2047         g_value_set_boxed (&parameter[i].value, g_ptr_array_index (array, i));
2048     }
2049   else
2050     {
2051       /* can be RGBA or symbolic color */
2052       gpointer p = g_value_get_boxed (value);
2053
2054       g_value_set_boxed (&parameter[0].value, p);
2055       g_value_set_boxed (&parameter[1].value, p);
2056       g_value_set_boxed (&parameter[2].value, p);
2057       g_value_set_boxed (&parameter[3].value, p);
2058     }
2059
2060   *n_params = 4;
2061   return parameter;
2062 }
2063
2064 static void
2065 pack_border_color (GValue             *value,
2066                    GtkStyleProperties *props,
2067                    GtkStateFlags       state)
2068 {
2069   /* NB: We are a color property, so we have to resolve to a color here.
2070    * So we just resolve to a color. We pick one and stick to it.
2071    * Lesson learned: Don't query border-color shorthand, query the 
2072    * real properties instead. */
2073   g_value_unset (value);
2074   gtk_style_properties_get_property (props, "border-top-color", state, value);
2075 }
2076
2077 /*** UNSET FUNCS ***/
2078
2079 static void
2080 unset_font_description (GtkStyleProperties *props,
2081                         GtkStateFlags       state)
2082 {
2083   gtk_style_properties_unset_property (props, "font-family", state);
2084   gtk_style_properties_unset_property (props, "font-style", state);
2085   gtk_style_properties_unset_property (props, "font-variant", state);
2086   gtk_style_properties_unset_property (props, "font-weight", state);
2087   gtk_style_properties_unset_property (props, "font-size", state);
2088 }
2089
2090 static void
2091 unset_margin (GtkStyleProperties *props,
2092               GtkStateFlags       state)
2093 {
2094   gtk_style_properties_unset_property (props, "margin-top", state);
2095   gtk_style_properties_unset_property (props, "margin-right", state);
2096   gtk_style_properties_unset_property (props, "margin-bottom", state);
2097   gtk_style_properties_unset_property (props, "margin-left", state);
2098 }
2099
2100 static void
2101 unset_padding (GtkStyleProperties *props,
2102                GtkStateFlags       state)
2103 {
2104   gtk_style_properties_unset_property (props, "padding-top", state);
2105   gtk_style_properties_unset_property (props, "padding-right", state);
2106   gtk_style_properties_unset_property (props, "padding-bottom", state);
2107   gtk_style_properties_unset_property (props, "padding-left", state);
2108 }
2109
2110 static void
2111 unset_border_width (GtkStyleProperties *props,
2112                     GtkStateFlags       state)
2113 {
2114   gtk_style_properties_unset_property (props, "border-top-width", state);
2115   gtk_style_properties_unset_property (props, "border-right-width", state);
2116   gtk_style_properties_unset_property (props, "border-bottom-width", state);
2117   gtk_style_properties_unset_property (props, "border-left-width", state);
2118 }
2119
2120 static void
2121 unset_border_radius (GtkStyleProperties *props,
2122                      GtkStateFlags       state)
2123 {
2124   gtk_style_properties_unset_property (props, "border-top-right-radius", state);
2125   gtk_style_properties_unset_property (props, "border-bottom-right-radius", state);
2126   gtk_style_properties_unset_property (props, "border-bottom-left-radius", state);
2127   gtk_style_properties_unset_property (props, "border-top-left-radius", state);
2128 }
2129
2130 static void
2131 unset_border_color (GtkStyleProperties *props,
2132                     GtkStateFlags       state)
2133 {
2134   gtk_style_properties_unset_property (props, "border-top-color", state);
2135   gtk_style_properties_unset_property (props, "border-right-color", state);
2136   gtk_style_properties_unset_property (props, "border-bottom-color", state);
2137   gtk_style_properties_unset_property (props, "border-left-color", state);
2138 }
2139
2140 static void
2141 unset_border_image (GtkStyleProperties *props,
2142                     GtkStateFlags       state)
2143 {
2144   gtk_style_properties_unset_property (props, "border-image-source", state);
2145   gtk_style_properties_unset_property (props, "border-image-slice", state);
2146   gtk_style_properties_unset_property (props, "border-image-repeat", state);
2147   gtk_style_properties_unset_property (props, "border-image-width", state);
2148 }
2149
2150 /*** default values ***/
2151
2152 static void
2153 border_image_width_default_value (GtkStyleProperties *props,
2154                                   GtkStateFlags       state,
2155                                   GValue             *value)
2156 {
2157 }
2158
2159 static void
2160 border_color_default_value (GtkStyleProperties *props,
2161                             GtkStateFlags       state,
2162                             GValue             *value)
2163 {
2164   g_value_unset (value);
2165   gtk_style_properties_get_property (props, "color", state, value);
2166 }
2167
2168 /*** API ***/
2169
2170 static void
2171 css_string_funcs_init (void)
2172 {
2173   if (G_LIKELY (parse_funcs != NULL))
2174     return;
2175
2176   parse_funcs = g_hash_table_new (NULL, NULL);
2177   print_funcs = g_hash_table_new (NULL, NULL);
2178
2179   register_conversion_function (GDK_TYPE_RGBA,
2180                                 rgba_value_parse,
2181                                 rgba_value_print);
2182   register_conversion_function (GDK_TYPE_COLOR,
2183                                 color_value_parse,
2184                                 color_value_print);
2185   register_conversion_function (GTK_TYPE_SYMBOLIC_COLOR,
2186                                 symbolic_color_value_parse,
2187                                 symbolic_color_value_print);
2188   register_conversion_function (PANGO_TYPE_FONT_DESCRIPTION,
2189                                 font_description_value_parse,
2190                                 font_description_value_print);
2191   register_conversion_function (G_TYPE_BOOLEAN,
2192                                 boolean_value_parse,
2193                                 boolean_value_print);
2194   register_conversion_function (G_TYPE_INT,
2195                                 int_value_parse,
2196                                 int_value_print);
2197   register_conversion_function (G_TYPE_UINT,
2198                                 uint_value_parse,
2199                                 uint_value_print);
2200   register_conversion_function (G_TYPE_DOUBLE,
2201                                 double_value_parse,
2202                                 double_value_print);
2203   register_conversion_function (G_TYPE_FLOAT,
2204                                 float_value_parse,
2205                                 float_value_print);
2206   register_conversion_function (G_TYPE_STRING,
2207                                 string_value_parse,
2208                                 string_value_print);
2209   register_conversion_function (GTK_TYPE_THEMING_ENGINE,
2210                                 theming_engine_value_parse,
2211                                 theming_engine_value_print);
2212   register_conversion_function (GTK_TYPE_ANIMATION_DESCRIPTION,
2213                                 animation_description_value_parse,
2214                                 animation_description_value_print);
2215   register_conversion_function (GTK_TYPE_BORDER,
2216                                 border_value_parse,
2217                                 border_value_print);
2218   register_conversion_function (GTK_TYPE_GRADIENT,
2219                                 gradient_value_parse,
2220                                 gradient_value_print);
2221   register_conversion_function (CAIRO_GOBJECT_TYPE_PATTERN,
2222                                 pattern_value_parse,
2223                                 pattern_value_print);
2224   register_conversion_function (GTK_TYPE_BORDER_IMAGE,
2225                                 border_image_value_parse,
2226                                 NULL);
2227   register_conversion_function (GTK_TYPE_CSS_BORDER_IMAGE_REPEAT,
2228                                 border_image_repeat_value_parse,
2229                                 border_image_repeat_value_print);
2230   register_conversion_function (GTK_TYPE_SHADOW,
2231                                 shadow_value_parse,
2232                                 shadow_value_print);
2233   register_conversion_function (G_TYPE_ENUM,
2234                                 enum_value_parse,
2235                                 enum_value_print);
2236   register_conversion_function (G_TYPE_FLAGS,
2237                                 flags_value_parse,
2238                                 flags_value_print);
2239 }
2240
2241 gboolean
2242 _gtk_style_property_parse_value (const GtkStyleProperty *property,
2243                                  GValue                 *value,
2244                                  GtkCssParser           *parser,
2245                                  GFile                  *base)
2246 {
2247   GtkStyleParseFunc func;
2248
2249   g_return_val_if_fail (value != NULL, FALSE);
2250   g_return_val_if_fail (parser != NULL, FALSE);
2251
2252   css_string_funcs_init ();
2253
2254   if (property)
2255     {
2256       if (_gtk_css_parser_try (parser, "none", TRUE))
2257         {
2258           /* Insert the default value, so it has an opportunity
2259            * to override other style providers when merged
2260            */
2261           g_param_value_set_default (property->pspec, value);
2262           return TRUE;
2263         }
2264       else if (property->property_parse_func)
2265         {
2266           GError *error = NULL;
2267           char *value_str;
2268           gboolean success;
2269           
2270           value_str = _gtk_css_parser_read_value (parser);
2271           if (value_str == NULL)
2272             return FALSE;
2273           
2274           success = (*property->property_parse_func) (value_str, value, &error);
2275
2276           g_free (value_str);
2277
2278           return success;
2279         }
2280
2281       func = property->parse_func;
2282     }
2283   else
2284     func = NULL;
2285
2286   if (func == NULL)
2287     func = g_hash_table_lookup (parse_funcs,
2288                                 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
2289   if (func == NULL)
2290     func = g_hash_table_lookup (parse_funcs,
2291                                 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
2292
2293   if (func == NULL)
2294     {
2295       _gtk_css_parser_error (parser,
2296                              "Cannot convert to type '%s'",
2297                              g_type_name (G_VALUE_TYPE (value)));
2298       return FALSE;
2299     }
2300
2301   return (*func) (parser, base, value);
2302 }
2303
2304 void
2305 _gtk_style_property_print_value (const GtkStyleProperty *property,
2306                                  const GValue           *value,
2307                                  GString                *string)
2308 {
2309   GtkStylePrintFunc func;
2310
2311   css_string_funcs_init ();
2312
2313   if (property)
2314     func = property->print_func;
2315   else
2316     func = NULL;
2317
2318   if (func == NULL)
2319     func = g_hash_table_lookup (print_funcs,
2320                                 GSIZE_TO_POINTER (G_VALUE_TYPE (value)));
2321   if (func == NULL)
2322     func = g_hash_table_lookup (print_funcs,
2323                                 GSIZE_TO_POINTER (g_type_fundamental (G_VALUE_TYPE (value))));
2324
2325   if (func == NULL)
2326     {
2327       char *s = g_strdup_value_contents (value);
2328       g_string_append (string, s);
2329       g_free (s);
2330       return;
2331     }
2332   
2333   func (value, string);
2334 }
2335
2336 void
2337 _gtk_style_property_default_value (const GtkStyleProperty *property,
2338                                    GtkStyleProperties     *properties,
2339                                    GtkStateFlags           state,
2340                                    GValue                 *value)
2341 {
2342   if (property->default_value_func)
2343     property->default_value_func (properties, state, value);
2344   else if (property->pspec->value_type == GTK_TYPE_THEMING_ENGINE)
2345     g_value_set_object (value, gtk_theming_engine_load (NULL));
2346   else if (property->pspec->value_type == PANGO_TYPE_FONT_DESCRIPTION)
2347     g_value_take_boxed (value, pango_font_description_from_string ("Sans 10"));
2348   else if (property->pspec->value_type == GDK_TYPE_RGBA)
2349     {
2350       GdkRGBA color;
2351       gdk_rgba_parse (&color, "pink");
2352       g_value_set_boxed (value, &color);
2353     }
2354   else if (property->pspec->value_type == GTK_TYPE_BORDER)
2355     {
2356       g_value_take_boxed (value, gtk_border_new ());
2357     }
2358   else
2359     g_param_value_set_default (property->pspec, value);
2360 }
2361
2362 gboolean
2363 _gtk_style_property_is_inherit (const GtkStyleProperty *property)
2364 {
2365   g_return_val_if_fail (property != NULL, FALSE);
2366
2367   return property->flags & GTK_STYLE_PROPERTY_INHERIT ? TRUE : FALSE;
2368 }
2369
2370 static gboolean
2371 resolve_color (GtkStyleProperties *props,
2372                GValue             *value)
2373 {
2374   GdkRGBA color;
2375
2376   /* Resolve symbolic color to GdkRGBA */
2377   if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
2378     return FALSE;
2379
2380   /* Store it back, this is where GdkRGBA caching happens */
2381   g_value_unset (value);
2382   g_value_init (value, GDK_TYPE_RGBA);
2383   g_value_set_boxed (value, &color);
2384
2385   return TRUE;
2386 }
2387
2388 static gboolean
2389 resolve_color_rgb (GtkStyleProperties *props,
2390                    GValue             *value)
2391 {
2392   GdkColor color = { 0 };
2393   GdkRGBA rgba;
2394
2395   if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &rgba))
2396     return FALSE;
2397
2398   color.red = rgba.red * 65535. + 0.5;
2399   color.green = rgba.green * 65535. + 0.5;
2400   color.blue = rgba.blue * 65535. + 0.5;
2401
2402   g_value_unset (value);
2403   g_value_init (value, GDK_TYPE_COLOR);
2404   g_value_set_boxed (value, &color);
2405
2406   return TRUE;
2407 }
2408
2409 static gboolean
2410 resolve_gradient (GtkStyleProperties *props,
2411                   GValue             *value)
2412 {
2413   cairo_pattern_t *gradient;
2414
2415   if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
2416     return FALSE;
2417
2418   /* Store it back, this is where cairo_pattern_t caching happens */
2419   g_value_unset (value);
2420   g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
2421   g_value_take_boxed (value, gradient);
2422
2423   return TRUE;
2424 }
2425
2426 static gboolean
2427 resolve_shadow (GtkStyleProperties *props,
2428                 GValue *value)
2429 {
2430   GtkShadow *resolved, *base;
2431
2432   base = g_value_get_boxed (value);
2433
2434   if (base == NULL)
2435     return TRUE;
2436   
2437   if (_gtk_shadow_get_resolved (base))
2438     return TRUE;
2439
2440   resolved = _gtk_shadow_resolve (base, props);
2441   if (resolved == NULL)
2442     return FALSE;
2443
2444   g_value_take_boxed (value, resolved);
2445
2446   return TRUE;
2447 }
2448
2449 void
2450 _gtk_style_property_resolve (const GtkStyleProperty *property,
2451                              GtkStyleProperties     *props,
2452                              GtkStateFlags           state,
2453                              GValue                 *val)
2454 {
2455   if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
2456     {
2457       if (property->pspec->value_type == GDK_TYPE_RGBA)
2458         {
2459           if (resolve_color (props, val))
2460             return;
2461         }
2462       else if (property->pspec->value_type == GDK_TYPE_COLOR)
2463         {
2464           if (resolve_color_rgb (props, val))
2465             return;
2466         }
2467       
2468       g_value_unset (val);
2469       g_value_init (val, property->pspec->value_type);
2470       _gtk_style_property_default_value (property, props, state, val);
2471     }
2472   else if (G_VALUE_TYPE (val) == GDK_TYPE_RGBA)
2473     {
2474       if (g_value_get_boxed (val) == NULL)
2475         _gtk_style_property_default_value (property, props, state, val);
2476     }
2477   else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
2478     {
2479       g_return_if_fail (property->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN);
2480
2481       if (!resolve_gradient (props, val))
2482         {
2483           g_value_unset (val);
2484           g_value_init (val, CAIRO_GOBJECT_TYPE_PATTERN);
2485           _gtk_style_property_default_value (property, props, state, val);
2486         }
2487     }
2488   else if (G_VALUE_TYPE (val) == GTK_TYPE_SHADOW)
2489     {
2490       if (!resolve_shadow (props, val))
2491         _gtk_style_property_default_value (property, props, state, val);
2492     }
2493 }
2494
2495 gboolean
2496 _gtk_style_property_is_shorthand  (const GtkStyleProperty *property)
2497 {
2498   g_return_val_if_fail (property != NULL, FALSE);
2499
2500   return property->pack_func != NULL;
2501 }
2502
2503 GParameter *
2504 _gtk_style_property_unpack (const GtkStyleProperty *property,
2505                             const GValue           *value,
2506                             guint                  *n_params)
2507 {
2508   g_return_val_if_fail (property != NULL, NULL);
2509   g_return_val_if_fail (property->unpack_func != NULL, NULL);
2510   g_return_val_if_fail (value != NULL, NULL);
2511   g_return_val_if_fail (n_params != NULL, NULL);
2512
2513   return property->unpack_func (value, n_params);
2514 }
2515
2516 void
2517 _gtk_style_property_pack (const GtkStyleProperty *property,
2518                           GtkStyleProperties     *props,
2519                           GtkStateFlags           state,
2520                           GValue                 *value)
2521 {
2522   g_return_if_fail (property != NULL);
2523   g_return_if_fail (property->pack_func != NULL);
2524   g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
2525   g_return_if_fail (G_IS_VALUE (value));
2526
2527   property->pack_func (value, props, state);
2528 }
2529
2530 static void
2531 gtk_style_property_init (void)
2532 {
2533   if (G_LIKELY (properties))
2534     return;
2535
2536   /* stuff is never freed, so no need for free functions */
2537   properties = g_hash_table_new (g_str_hash, g_str_equal);
2538
2539   /* note that gtk_style_properties_register_property() calls this function,
2540    * so make sure we're sanely inited to avoid infloops */
2541
2542   _gtk_style_property_register           (g_param_spec_boxed ("color",
2543                                           "Foreground color",
2544                                           "Foreground color",
2545                                           GDK_TYPE_RGBA, 0),
2546                                           GTK_STYLE_PROPERTY_INHERIT,
2547                                           NULL,
2548                                           NULL,
2549                                           NULL,
2550                                           NULL,
2551                                           NULL,
2552                                           NULL,
2553                                           NULL);
2554
2555   gtk_style_properties_register_property (NULL,
2556                                           g_param_spec_boxed ("background-color",
2557                                                               "Background color",
2558                                                               "Background color",
2559                                                               GDK_TYPE_RGBA, 0));
2560
2561   _gtk_style_property_register           (g_param_spec_boxed ("font-family",
2562                                                               "Font family",
2563                                                               "Font family",
2564                                                               G_TYPE_STRV, 0),
2565                                           GTK_STYLE_PROPERTY_INHERIT,
2566                                           NULL,
2567                                           NULL,
2568                                           NULL,
2569                                           font_family_parse,
2570                                           font_family_value_print,
2571                                           NULL,
2572                                           NULL);
2573   _gtk_style_property_register           (g_param_spec_enum ("font-style",
2574                                                              "Font style",
2575                                                              "Font style",
2576                                                              PANGO_TYPE_STYLE,
2577                                                              PANGO_STYLE_NORMAL, 0),
2578                                           GTK_STYLE_PROPERTY_INHERIT,
2579                                           NULL,
2580                                           NULL,
2581                                           NULL,
2582                                           NULL,
2583                                           NULL,
2584                                           NULL,
2585                                           NULL);
2586   _gtk_style_property_register           (g_param_spec_enum ("font-variant",
2587                                                              "Font variant",
2588                                                              "Font variant",
2589                                                              PANGO_TYPE_VARIANT,
2590                                                              PANGO_VARIANT_NORMAL, 0),
2591                                           GTK_STYLE_PROPERTY_INHERIT,
2592                                           NULL,
2593                                           NULL,
2594                                           NULL,
2595                                           NULL,
2596                                           NULL,
2597                                           NULL,
2598                                           NULL);
2599   /* xxx: need to parse this properly, ie parse the numbers */
2600   _gtk_style_property_register           (g_param_spec_enum ("font-weight",
2601                                                              "Font weight",
2602                                                              "Font weight",
2603                                                              PANGO_TYPE_WEIGHT,
2604                                                              PANGO_WEIGHT_NORMAL, 0),
2605                                           GTK_STYLE_PROPERTY_INHERIT,
2606                                           NULL,
2607                                           NULL,
2608                                           NULL,
2609                                           NULL,
2610                                           NULL,
2611                                           NULL,
2612                                           NULL);
2613   _gtk_style_property_register           (g_param_spec_double ("font-size",
2614                                                                "Font size",
2615                                                                "Font size",
2616                                                                0, G_MAXDOUBLE, 0, 0),
2617                                           GTK_STYLE_PROPERTY_INHERIT,
2618                                           NULL,
2619                                           NULL,
2620                                           NULL,
2621                                           NULL,
2622                                           NULL,
2623                                           NULL,
2624                                           NULL);
2625   _gtk_style_property_register           (g_param_spec_boxed ("font",
2626                                                               "Font Description",
2627                                                               "Font Description",
2628                                                               PANGO_TYPE_FONT_DESCRIPTION, 0),
2629                                           GTK_STYLE_PROPERTY_INHERIT,
2630                                           NULL,
2631                                           unpack_font_description,
2632                                           pack_font_description,
2633                                           font_description_value_parse,
2634                                           font_description_value_print,
2635                                           NULL,
2636                                           unset_font_description);
2637
2638   _gtk_style_property_register           (g_param_spec_boxed ("text-shadow",
2639                                                               "Text shadow",
2640                                                               "Text shadow",
2641                                                               GTK_TYPE_SHADOW, 0),
2642                                           GTK_STYLE_PROPERTY_INHERIT,
2643                                           NULL,
2644                                           NULL,
2645                                           NULL,
2646                                           NULL,
2647                                           NULL,
2648                                           NULL,
2649                                           NULL);
2650
2651   _gtk_style_property_register           (g_param_spec_boxed ("icon-shadow",
2652                                                               "Icon shadow",
2653                                                               "Icon shadow",
2654                                                               GTK_TYPE_SHADOW, 0),
2655                                           GTK_STYLE_PROPERTY_INHERIT,
2656                                           NULL,
2657                                           NULL,
2658                                           NULL,
2659                                           NULL,
2660                                           NULL,
2661                                           NULL,
2662                                           NULL);
2663
2664   gtk_style_properties_register_property (NULL,
2665                                           g_param_spec_boxed ("box-shadow",
2666                                                               "Box shadow",
2667                                                               "Box shadow",
2668                                                               GTK_TYPE_SHADOW, 0));
2669   gtk_style_properties_register_property (NULL,
2670                                           g_param_spec_int ("margin-top",
2671                                                             "margin top",
2672                                                             "Margin at top",
2673                                                             0, G_MAXINT, 0, 0));
2674   gtk_style_properties_register_property (NULL,
2675                                           g_param_spec_int ("margin-left",
2676                                                             "margin left",
2677                                                             "Margin at left",
2678                                                             0, G_MAXINT, 0, 0));
2679   gtk_style_properties_register_property (NULL,
2680                                           g_param_spec_int ("margin-bottom",
2681                                                             "margin bottom",
2682                                                             "Margin at bottom",
2683                                                             0, G_MAXINT, 0, 0));
2684   gtk_style_properties_register_property (NULL,
2685                                           g_param_spec_int ("margin-right",
2686                                                             "margin right",
2687                                                             "Margin at right",
2688                                                             0, G_MAXINT, 0, 0));
2689   _gtk_style_property_register           (g_param_spec_boxed ("margin",
2690                                                               "Margin",
2691                                                               "Margin",
2692                                                               GTK_TYPE_BORDER, 0),
2693                                           0,
2694                                           NULL,
2695                                           unpack_margin,
2696                                           pack_margin,
2697                                           NULL,
2698                                           NULL,
2699                                           NULL,
2700                                           unset_margin);
2701   gtk_style_properties_register_property (NULL,
2702                                           g_param_spec_int ("padding-top",
2703                                                             "padding top",
2704                                                             "Padding at top",
2705                                                             0, G_MAXINT, 0, 0));
2706   gtk_style_properties_register_property (NULL,
2707                                           g_param_spec_int ("padding-left",
2708                                                             "padding left",
2709                                                             "Padding at left",
2710                                                             0, G_MAXINT, 0, 0));
2711   gtk_style_properties_register_property (NULL,
2712                                           g_param_spec_int ("padding-bottom",
2713                                                             "padding bottom",
2714                                                             "Padding at bottom",
2715                                                             0, G_MAXINT, 0, 0));
2716   gtk_style_properties_register_property (NULL,
2717                                           g_param_spec_int ("padding-right",
2718                                                             "padding right",
2719                                                             "Padding at right",
2720                                                             0, G_MAXINT, 0, 0));
2721   _gtk_style_property_register           (g_param_spec_boxed ("padding",
2722                                                               "Padding",
2723                                                               "Padding",
2724                                                               GTK_TYPE_BORDER, 0),
2725                                           0,
2726                                           NULL,
2727                                           unpack_padding,
2728                                           pack_padding,
2729                                           NULL,
2730                                           NULL,
2731                                           NULL,
2732                                           unset_padding);
2733   gtk_style_properties_register_property (NULL,
2734                                           g_param_spec_int ("border-top-width",
2735                                                             "border top width",
2736                                                             "Border width at top",
2737                                                             0, G_MAXINT, 0, 0));
2738   gtk_style_properties_register_property (NULL,
2739                                           g_param_spec_int ("border-left-width",
2740                                                             "border left width",
2741                                                             "Border width at left",
2742                                                             0, G_MAXINT, 0, 0));
2743   gtk_style_properties_register_property (NULL,
2744                                           g_param_spec_int ("border-bottom-width",
2745                                                             "border bottom width",
2746                                                             "Border width at bottom",
2747                                                             0, G_MAXINT, 0, 0));
2748   gtk_style_properties_register_property (NULL,
2749                                           g_param_spec_int ("border-right-width",
2750                                                             "border right width",
2751                                                             "Border width at right",
2752                                                             0, G_MAXINT, 0, 0));
2753   _gtk_style_property_register           (g_param_spec_boxed ("border-width",
2754                                                               "Border width",
2755                                                               "Border width, in pixels",
2756                                                               GTK_TYPE_BORDER, 0),
2757                                           0,
2758                                           NULL,
2759                                           unpack_border_width,
2760                                           pack_border_width,
2761                                           NULL,
2762                                           NULL,
2763                                           NULL,
2764                                           unset_border_width);
2765
2766   _gtk_style_property_register           (g_param_spec_boxed ("border-top-left-radius",
2767                                                               "Border top left radius",
2768                                                               "Border radius of top left corner, in pixels",
2769                                                               GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2770                                           0,
2771                                           NULL,
2772                                           NULL,
2773                                           NULL,
2774                                           border_corner_radius_value_parse,
2775                                           border_corner_radius_value_print,
2776                                           NULL,
2777                                           NULL);
2778   _gtk_style_property_register           (g_param_spec_boxed ("border-top-right-radius",
2779                                                               "Border top right radius",
2780                                                               "Border radius of top right corner, in pixels",
2781                                                               GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2782                                           0,
2783                                           NULL,
2784                                           NULL,
2785                                           NULL,
2786                                           border_corner_radius_value_parse,
2787                                           border_corner_radius_value_print,
2788                                           NULL,
2789                                           NULL);
2790   _gtk_style_property_register           (g_param_spec_boxed ("border-bottom-right-radius",
2791                                                               "Border bottom right radius",
2792                                                               "Border radius of bottom right corner, in pixels",
2793                                                               GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2794                                           0,
2795                                           NULL,
2796                                           NULL,
2797                                           NULL,
2798                                           border_corner_radius_value_parse,
2799                                           border_corner_radius_value_print,
2800                                           NULL,
2801                                           NULL);
2802   _gtk_style_property_register           (g_param_spec_boxed ("border-bottom-left-radius",
2803                                                               "Border bottom left radius",
2804                                                               "Border radius of bottom left corner, in pixels",
2805                                                               GTK_TYPE_CSS_BORDER_CORNER_RADIUS, 0),
2806                                           0,
2807                                           NULL,
2808                                           NULL,
2809                                           NULL,
2810                                           border_corner_radius_value_parse,
2811                                           border_corner_radius_value_print,
2812                                           NULL,
2813                                           NULL);
2814   _gtk_style_property_register           (g_param_spec_int ("border-radius",
2815                                                             "Border radius",
2816                                                             "Border radius, in pixels",
2817                                                             0, G_MAXINT, 0, 0),
2818                                           0,
2819                                           NULL,
2820                                           unpack_border_radius,
2821                                           pack_border_radius,
2822                                           border_radius_value_parse,
2823                                           border_radius_value_print,
2824                                           NULL,
2825                                           unset_border_radius);
2826
2827   gtk_style_properties_register_property (NULL,
2828                                           g_param_spec_enum ("border-style",
2829                                                              "Border style",
2830                                                              "Border style",
2831                                                              GTK_TYPE_BORDER_STYLE,
2832                                                              GTK_BORDER_STYLE_NONE, 0));
2833   _gtk_style_property_register           (g_param_spec_boxed ("border-top-color",
2834                                                               "Border top color",
2835                                                               "Border top color",
2836                                                               GDK_TYPE_RGBA, 0),
2837                                           0,
2838                                           NULL,
2839                                           NULL,
2840                                           NULL,
2841                                           border_color_value_parse,
2842                                           NULL,
2843                                           border_color_default_value,
2844                                           NULL);
2845   _gtk_style_property_register           (g_param_spec_boxed ("border-right-color",
2846                                                               "Border right color",
2847                                                               "Border right color",
2848                                                               GDK_TYPE_RGBA, 0),
2849                                           0,
2850                                           NULL,
2851                                           NULL,
2852                                           NULL,
2853                                           border_color_value_parse,
2854                                           NULL,
2855                                           border_color_default_value,
2856                                           NULL);
2857   _gtk_style_property_register           (g_param_spec_boxed ("border-bottom-color",
2858                                                               "Border bottom color",
2859                                                               "Border bottom color",
2860                                                               GDK_TYPE_RGBA, 0),
2861                                           0,
2862                                           NULL,
2863                                           NULL,
2864                                           NULL,
2865                                           border_color_value_parse,
2866                                           NULL,
2867                                           border_color_default_value,
2868                                           NULL);
2869   _gtk_style_property_register           (g_param_spec_boxed ("border-left-color",
2870                                                               "Border left color",
2871                                                               "Border left color",
2872                                                               GDK_TYPE_RGBA, 0),
2873                                           0,
2874                                           NULL,
2875                                           NULL,
2876                                           NULL,
2877                                           border_color_value_parse,
2878                                           NULL,
2879                                           border_color_default_value,
2880                                           NULL);
2881   _gtk_style_property_register           (g_param_spec_boxed ("border-color",
2882                                                               "Border color",
2883                                                               "Border color",
2884                                                               GDK_TYPE_RGBA, 0),
2885                                           0,
2886                                           NULL,
2887                                           unpack_border_color,
2888                                           pack_border_color,
2889                                           border_color_shorthand_value_parse,
2890                                           NULL,
2891                                           NULL,
2892                                           unset_border_color);
2893
2894   gtk_style_properties_register_property (NULL,
2895                                           g_param_spec_boxed ("background-image",
2896                                                               "Background Image",
2897                                                               "Background Image",
2898                                                               CAIRO_GOBJECT_TYPE_PATTERN, 0));
2899   gtk_style_properties_register_property (NULL,
2900                                           g_param_spec_boxed ("border-image-source",
2901                                                               "Border image source",
2902                                                               "Border image source",
2903                                                               CAIRO_GOBJECT_TYPE_PATTERN, 0));
2904   gtk_style_properties_register_property (NULL,
2905                                           g_param_spec_boxed ("border-image-repeat",
2906                                                               "Border image repeat",
2907                                                               "Border image repeat",
2908                                                               GTK_TYPE_CSS_BORDER_IMAGE_REPEAT, 0));
2909   gtk_style_properties_register_property (NULL,
2910                                           g_param_spec_boxed ("border-image-slice",
2911                                                               "Border image slice",
2912                                                               "Border image slice",
2913                                                               GTK_TYPE_BORDER, 0));
2914   _gtk_style_property_register           (g_param_spec_boxed ("border-image-width",
2915                                                               "Border image width",
2916                                                               "Border image width",
2917                                                               GTK_TYPE_BORDER, 0),
2918                                           0,
2919                                           NULL,
2920                                           NULL,
2921                                           NULL,
2922                                           NULL,
2923                                           NULL,
2924                                           border_image_width_default_value,
2925                                           NULL);
2926   _gtk_style_property_register           (g_param_spec_boxed ("border-image",
2927                                                               "Border Image",
2928                                                               "Border Image",
2929                                                               GTK_TYPE_BORDER_IMAGE, 0),
2930                                           0,
2931                                           NULL,
2932                                           _gtk_border_image_unpack,
2933                                           _gtk_border_image_pack,
2934                                           NULL,
2935                                           NULL,
2936                                           NULL,
2937                                           unset_border_image);
2938   gtk_style_properties_register_property (NULL,
2939                                           g_param_spec_object ("engine",
2940                                                                "Theming Engine",
2941                                                                "Theming Engine",
2942                                                                GTK_TYPE_THEMING_ENGINE, 0));
2943   gtk_style_properties_register_property (NULL,
2944                                           g_param_spec_boxed ("transition",
2945                                                               "Transition animation description",
2946                                                               "Transition animation description",
2947                                                               GTK_TYPE_ANIMATION_DESCRIPTION, 0));
2948
2949   /* Private property holding the binding sets */
2950   _gtk_style_property_register           (g_param_spec_boxed ("gtk-key-bindings",
2951                                                               "Key bindings",
2952                                                               "Key bindings",
2953                                                               G_TYPE_PTR_ARRAY, 0),
2954                                           0,
2955                                           NULL,
2956                                           NULL,
2957                                           NULL,
2958                                           bindings_value_parse,
2959                                           bindings_value_print,
2960                                           NULL,
2961                                           NULL);
2962 }
2963
2964 const GtkStyleProperty *
2965 _gtk_style_property_lookup (const char *name)
2966 {
2967   gtk_style_property_init ();
2968
2969   return g_hash_table_lookup (properties, name);
2970 }
2971
2972 void
2973 _gtk_style_property_register (GParamSpec               *pspec,
2974                               GtkStylePropertyFlags     flags,
2975                               GtkStylePropertyParser    property_parse_func,
2976                               GtkStyleUnpackFunc        unpack_func,
2977                               GtkStylePackFunc          pack_func,
2978                               GtkStyleParseFunc         parse_func,
2979                               GtkStylePrintFunc         print_func,
2980                               GtkStyleDefaultValueFunc  default_value_func,
2981                               GtkStyleUnsetFunc         unset_func)
2982 {
2983   const GtkStyleProperty *existing;
2984   GtkStyleProperty *node;
2985
2986   g_return_if_fail ((pack_func == NULL) == (unpack_func == NULL));
2987
2988   gtk_style_property_init ();
2989
2990   existing = _gtk_style_property_lookup (pspec->name);
2991   if (existing != NULL)
2992     {
2993       g_warning ("Property \"%s\" was already registered with type %s",
2994                  pspec->name, g_type_name (existing->pspec->value_type));
2995       return;
2996     }
2997
2998   node = g_slice_new0 (GtkStyleProperty);
2999   node->flags = flags;
3000   node->pspec = pspec;
3001   node->property_parse_func = property_parse_func;
3002   node->pack_func = pack_func;
3003   node->unpack_func = unpack_func;
3004   node->parse_func = parse_func;
3005   node->print_func = print_func;
3006   node->default_value_func = default_value_func;
3007   node->unset_func = unset_func;
3008
3009   /* pspec owns name */
3010   g_hash_table_insert (properties, (gchar *)pspec->name, node);
3011 }