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 #define GDK_DISABLE_DEPRECATION_WARNINGS
21 #include "gtkcssenginevalueprivate.h"
22
23 #include "gtkstylepropertyprivate.h"
24
25 struct _GtkCssValue {
26 GTK_CSS_VALUE_BASE
27 GtkThemingEngine *engine;
28 };
29
30 static void
gtk_css_value_engine_free(GtkCssValue * value)31 gtk_css_value_engine_free (GtkCssValue *value)
32 {
33 g_object_unref (value->engine);
34
35 g_slice_free (GtkCssValue, value);
36 }
37
38 static GtkCssValue *
gtk_css_value_engine_compute(GtkCssValue * value,guint property_id,GtkStyleProviderPrivate * provider,GtkCssStyle * style,GtkCssStyle * parent_style)39 gtk_css_value_engine_compute (GtkCssValue *value,
40 guint property_id,
41 GtkStyleProviderPrivate *provider,
42 GtkCssStyle *style,
43 GtkCssStyle *parent_style)
44 {
45 return _gtk_css_value_ref (value);
46 }
47
48 static gboolean
gtk_css_value_engine_equal(const GtkCssValue * value1,const GtkCssValue * value2)49 gtk_css_value_engine_equal (const GtkCssValue *value1,
50 const GtkCssValue *value2)
51 {
52 return value1->engine == value2->engine;
53 }
54
55 static GtkCssValue *
gtk_css_value_engine_transition(GtkCssValue * start,GtkCssValue * end,guint property_id,double progress)56 gtk_css_value_engine_transition (GtkCssValue *start,
57 GtkCssValue *end,
58 guint property_id,
59 double progress)
60 {
61 return NULL;
62 }
63
64 static void
gtk_css_value_engine_print(const GtkCssValue * value,GString * string)65 gtk_css_value_engine_print (const GtkCssValue *value,
66 GString *string)
67 {
68 char *name;
69
70 g_object_get (value->engine, "name", &name, NULL);
71
72 if (name)
73 g_string_append (string, name);
74 else
75 g_string_append (string, "none");
76
77 g_free (name);
78 }
79
80 static const GtkCssValueClass GTK_CSS_VALUE_ENGINE = {
81 gtk_css_value_engine_free,
82 gtk_css_value_engine_compute,
83 gtk_css_value_engine_equal,
84 gtk_css_value_engine_transition,
85 gtk_css_value_engine_print
86 };
87
88 GtkCssValue *
_gtk_css_engine_value_new(GtkThemingEngine * engine)89 _gtk_css_engine_value_new (GtkThemingEngine *engine)
90 {
91 GtkCssValue *result;
92
93 g_return_val_if_fail (GTK_IS_THEMING_ENGINE (engine), NULL);
94
95 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_ENGINE);
96 result->engine = g_object_ref (engine);
97
98 return result;
99 }
100
101 GtkCssValue *
_gtk_css_engine_value_parse(GtkCssParser * parser)102 _gtk_css_engine_value_parse (GtkCssParser *parser)
103 {
104 GtkThemingEngine *engine;
105 char *str;
106
107 g_return_val_if_fail (parser != NULL, NULL);
108
109 if (_gtk_css_parser_try (parser, "none", TRUE))
110 return _gtk_css_engine_value_new (gtk_theming_engine_load (NULL));
111
112 str = _gtk_css_parser_try_ident (parser, TRUE);
113 if (str == NULL)
114 {
115 _gtk_css_parser_error (parser, "Expected a valid theme name");
116 return NULL;
117 }
118
119 engine = gtk_theming_engine_load (str);
120
121 if (engine == NULL)
122 {
123 _gtk_css_parser_error (parser, "Theming engine '%s' not found", str);
124 g_free (str);
125 return NULL;
126 }
127
128 g_free (str);
129
130 return _gtk_css_engine_value_new (engine);
131 }
132
133 GtkThemingEngine *
_gtk_css_engine_value_get_engine(const GtkCssValue * value)134 _gtk_css_engine_value_get_engine (const GtkCssValue *value)
135 {
136 g_return_val_if_fail (value->class == >K_CSS_VALUE_ENGINE, NULL);
137
138 return value->engine;
139 }
140
141