]> Pileus Git - ~andy/gtk/blob - gtk/gtkcsstypedvalue.c
css: Introduce dependencies for value computations
[~andy/gtk] / gtk / gtkcsstypedvalue.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 "gtkcsstypedvalueprivate.h"
21
22 #include "gtkcsscustompropertyprivate.h"
23 #include "gtkcssstylefuncsprivate.h"
24
25 struct _GtkCssValue {
26   GTK_CSS_VALUE_BASE
27   GValue value;
28 };
29
30 static void
31 gtk_css_value_typed_free (GtkCssValue *value)
32 {
33   g_value_unset (&value->value);
34   g_slice_free (GtkCssValue, value);
35 }
36
37 static GtkCssValue *
38 gtk_css_value_typed_compute (GtkCssValue        *value,
39                              guint               property_id,
40                              GtkStyleContext    *context,
41                              GtkCssDependencies *dependencies)
42 {
43   GtkCssCustomProperty *custom = GTK_CSS_CUSTOM_PROPERTY (_gtk_css_style_property_lookup_by_id (property_id));
44
45   *dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
46
47   return _gtk_css_style_compute_value (context, custom->pspec->value_type, value);
48 }
49
50 static gboolean
51 gtk_css_value_typed_equal (const GtkCssValue *value1,
52                            const GtkCssValue *value2)
53 {
54   return FALSE;
55 }
56
57 static GtkCssValue *
58 gtk_css_value_typed_transition (GtkCssValue *start,
59                                 GtkCssValue *end,
60                                 double       progress)
61 {
62   return NULL;
63 }
64
65 static void
66 gtk_css_value_typed_print (const GtkCssValue *value,
67                            GString           *string)
68 {
69   _gtk_css_style_print_value (&value->value, string);
70 }
71
72 static const GtkCssValueClass GTK_CSS_VALUE_TYPED = {
73   gtk_css_value_typed_free,
74   gtk_css_value_typed_compute,
75   gtk_css_value_typed_equal,
76   gtk_css_value_typed_transition,
77   gtk_css_value_typed_print
78 };
79
80 static GtkCssValue *
81 gtk_css_typed_value_new_for_type (GType type)
82 {
83   GtkCssValue *result;
84
85   result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_TYPED);
86
87   g_value_init (&result->value, type);
88
89   return result;
90 }
91
92 GtkCssValue *
93 _gtk_css_typed_value_new (const GValue *value)
94 {
95   GtkCssValue *result;
96
97   g_return_val_if_fail (G_IS_VALUE (value), NULL);
98
99   result = gtk_css_typed_value_new_for_type (G_VALUE_TYPE (value));
100
101   g_value_copy (value, &result->value);
102
103   return result;
104 }
105
106 GtkCssValue *
107 _gtk_css_typed_value_new_take (GValue *value)
108 {
109   GtkCssValue *result;
110
111   g_return_val_if_fail (G_IS_VALUE (value), NULL);
112
113   result = _gtk_css_typed_value_new (value);
114   g_value_unset (value);
115
116   return result;
117 }
118
119 gboolean
120 _gtk_is_css_typed_value_of_type (const GtkCssValue *value,
121                                  GType              type)
122 {
123   if (value->class != &GTK_CSS_VALUE_TYPED)
124     return FALSE;
125
126   return G_VALUE_HOLDS (&value->value, type);
127 }
128
129 const GValue *
130 _gtk_css_typed_value_get (const GtkCssValue *value)
131 {
132   g_return_val_if_fail (value->class == &GTK_CSS_VALUE_TYPED, NULL);
133
134   return &value->value;
135 }