]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssenginevalue.c
cssvalue: Pass property ID to transition 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                               GtkCssDependencies *dependencies)
42 {
43   return _gtk_css_value_ref (value);
44 }
45
46 static gboolean
47 gtk_css_value_engine_equal (const GtkCssValue *value1,
48                             const GtkCssValue *value2)
49 {
50   return value1->engine == value2->engine;
51 }
52
53 static GtkCssValue *
54 gtk_css_value_engine_transition (GtkCssValue *start,
55                                  GtkCssValue *end,
56                                  guint        property_id,
57                                  double       progress)
58 {
59   return NULL;
60 }
61
62 static void
63 gtk_css_value_engine_print (const GtkCssValue *value,
64                             GString           *string)
65 {
66   char *name;
67
68   g_object_get (value->engine, "name", &name, NULL);
69
70   if (name)
71     g_string_append (string, name);
72   else
73     g_string_append (string, "none");
74
75   g_free (name);
76 }
77
78 static const GtkCssValueClass GTK_CSS_VALUE_ENGINE = {
79   gtk_css_value_engine_free,
80   gtk_css_value_engine_compute,
81   gtk_css_value_engine_equal,
82   gtk_css_value_engine_transition,
83   gtk_css_value_engine_print
84 };
85
86 GtkCssValue *
87 _gtk_css_engine_value_new (GtkThemingEngine *engine)
88 {
89   GtkCssValue *result;
90
91   g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
92
93   result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_ENGINE);
94   result->engine = g_object_ref (engine);
95
96   return result;
97 }
98
99 GtkCssValue *
100 _gtk_css_engine_value_parse (GtkCssParser *parser)
101 {
102   GtkThemingEngine *engine;
103   char *str;
104
105   g_return_val_if_fail (parser != NULL, NULL);
106
107   if (_gtk_css_parser_try (parser, "none", TRUE))
108     return _gtk_css_engine_value_new (gtk_theming_engine_load (NULL));
109
110   str = _gtk_css_parser_try_ident (parser, TRUE);
111   if (str == NULL)
112     {
113       _gtk_css_parser_error (parser, "Expected a valid theme name");
114       return NULL;
115     }
116
117   engine = gtk_theming_engine_load (str);
118
119   if (engine == NULL)
120     {
121       _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
122       g_free (str);
123       return NULL;
124     }
125
126   g_free (str);
127
128   return _gtk_css_engine_value_new (engine);
129 }
130
131 GtkThemingEngine *
132 _gtk_css_engine_value_get_engine (const GtkCssValue *value)
133 {
134   g_return_val_if_fail (value->class == &GTK_CSS_VALUE_ENGINE, NULL);
135
136   return value->engine;
137 }
138