]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssenginevalue.c
css: Pass property_id to compute function
[~andy/gtk] / gtk / gtkcssenginevalue.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 2011 Red Hat, Inc.
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, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "config.h"
19
20 #include "gtkcssenginevalueprivate.h"
21
22 #include "gtkstylepropertyprivate.h"
23
24 struct _GtkCssValue {
25   GTK_CSS_VALUE_BASE
26   GtkThemingEngine *engine;
27 };
28
29 static void
30 gtk_css_value_engine_free (GtkCssValue *value)
31 {
32   g_object_unref (value->engine);
33
34   g_slice_free (GtkCssValue, value);
35 }
36
37 static GtkCssValue *
38 gtk_css_value_engine_compute (GtkCssValue     *value,
39                               guint            property_id,
40                               GtkStyleContext *context)
41 {
42   return _gtk_css_value_ref (value);
43 }
44
45 static gboolean
46 gtk_css_value_engine_equal (const GtkCssValue *value1,
47                             const GtkCssValue *value2)
48 {
49   return value1->engine == value2->engine;
50 }
51
52 static GtkCssValue *
53 gtk_css_value_engine_transition (GtkCssValue *start,
54                                  GtkCssValue *end,
55                                  double       progress)
56 {
57   return NULL;
58 }
59
60 static void
61 gtk_css_value_engine_print (const GtkCssValue *value,
62                             GString           *string)
63 {
64   char *name;
65
66   g_object_get (value->engine, "name", &name, NULL);
67
68   if (name)
69     g_string_append (string, name);
70   else
71     g_string_append (string, "none");
72
73   g_free (name);
74 }
75
76 static const GtkCssValueClass GTK_CSS_VALUE_ENGINE = {
77   gtk_css_value_engine_free,
78   gtk_css_value_engine_compute,
79   gtk_css_value_engine_equal,
80   gtk_css_value_engine_transition,
81   gtk_css_value_engine_print
82 };
83
84 GtkCssValue *
85 _gtk_css_engine_value_new (GtkThemingEngine *engine)
86 {
87   GtkCssValue *result;
88
89   g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
90
91   result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_ENGINE);
92   result->engine = g_object_ref (engine);
93
94   return result;
95 }
96
97 GtkCssValue *
98 _gtk_css_engine_value_parse (GtkCssParser *parser)
99 {
100   GtkThemingEngine *engine;
101   char *str;
102
103   g_return_val_if_fail (parser != NULL, NULL);
104
105   if (_gtk_css_parser_try (parser, "none", TRUE))
106     return _gtk_css_engine_value_new (gtk_theming_engine_load (NULL));
107
108   str = _gtk_css_parser_try_ident (parser, TRUE);
109   if (str == NULL)
110     {
111       _gtk_css_parser_error (parser, "Expected a valid theme name");
112       return NULL;
113     }
114
115   engine = gtk_theming_engine_load (str);
116
117   if (engine == NULL)
118     {
119       _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
120       g_free (str);
121       return NULL;
122     }
123
124   g_free (str);
125
126   return _gtk_css_engine_value_new (engine);
127 }
128
129 GtkThemingEngine *
130 _gtk_css_engine_value_get_engine (const GtkCssValue *value)
131 {
132   g_return_val_if_fail (value->class == &GTK_CSS_VALUE_ENGINE, NULL);
133
134   return value->engine;
135 }
136