]> Pileus Git - ~andy/gtk/blob - gtk/gtkcsstypedvalue.c
stylecontext: Do invalidation on first resize container
[~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                              GtkStyleProviderPrivate *provider,
41                              GtkCssComputedValues    *values,
42                              GtkCssComputedValues    *parent_values,
43                              GtkCssDependencies      *dependencies)
44 {
45   GtkCssCustomProperty *custom = GTK_CSS_CUSTOM_PROPERTY (_gtk_css_style_property_lookup_by_id (property_id));
46
47   return _gtk_css_style_compute_value (provider, values, parent_values, custom->pspec->value_type, value, dependencies);
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                                 guint        property_id,
61                                 double       progress)
62 {
63   return NULL;
64 }
65
66 static void
67 gtk_css_value_typed_print (const GtkCssValue *value,
68                            GString           *string)
69 {
70   _gtk_css_style_print_value (&value->value, string);
71 }
72
73 static const GtkCssValueClass GTK_CSS_VALUE_TYPED = {
74   gtk_css_value_typed_free,
75   gtk_css_value_typed_compute,
76   gtk_css_value_typed_equal,
77   gtk_css_value_typed_transition,
78   gtk_css_value_typed_print
79 };
80
81 static GtkCssValue *
82 gtk_css_typed_value_new_for_type (GType type)
83 {
84   GtkCssValue *result;
85
86   result = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_TYPED);
87
88   g_value_init (&result->value, type);
89
90   return result;
91 }
92
93 GtkCssValue *
94 _gtk_css_typed_value_new (const GValue *value)
95 {
96   GtkCssValue *result;
97
98   g_return_val_if_fail (G_IS_VALUE (value), NULL);
99
100   result = gtk_css_typed_value_new_for_type (G_VALUE_TYPE (value));
101
102   g_value_copy (value, &result->value);
103
104   return result;
105 }
106
107 GtkCssValue *
108 _gtk_css_typed_value_new_take (GValue *value)
109 {
110   GtkCssValue *result;
111
112   g_return_val_if_fail (G_IS_VALUE (value), NULL);
113
114   result = _gtk_css_typed_value_new (value);
115   g_value_unset (value);
116
117   return result;
118 }
119
120 gboolean
121 _gtk_is_css_typed_value_of_type (const GtkCssValue *value,
122                                  GType              type)
123 {
124   if (value->class != &GTK_CSS_VALUE_TYPED)
125     return FALSE;
126
127   return G_VALUE_HOLDS (&value->value, type);
128 }
129
130 const GValue *
131 _gtk_css_typed_value_get (const GtkCssValue *value)
132 {
133   g_return_val_if_fail (value->class == &GTK_CSS_VALUE_TYPED, NULL);
134
135   return &value->value;
136 }