]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssenginevalue.c
stylecontext: Do invalidation on first resize container
[~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                               GtkStyleProviderPrivate *provider,
41                               GtkCssComputedValues    *values,
42                               GtkCssComputedValues    *parent_values,
43                               GtkCssDependencies      *dependencies)
44 {
45   return _gtk_css_value_ref (value);
46 }
47
48 static gboolean
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 *
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
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 *
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, &GTK_CSS_VALUE_ENGINE);
96   result->engine = g_object_ref (engine);
97
98   return result;
99 }
100
101 GtkCssValue *
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 *
134 _gtk_css_engine_value_get_engine (const GtkCssValue *value)
135 {
136   g_return_val_if_fail (value->class == &GTK_CSS_VALUE_ENGINE, NULL);
137
138   return value->engine;
139 }
140