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
gtk_css_value_typed_free(GtkCssValue * value)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 *
gtk_css_value_typed_compute(GtkCssValue * value,guint property_id,GtkStyleProviderPrivate * provider,GtkCssStyle * style,GtkCssStyle * parent_style)38 gtk_css_value_typed_compute (GtkCssValue *value,
39 guint property_id,
40 GtkStyleProviderPrivate *provider,
41 GtkCssStyle *style,
42 GtkCssStyle *parent_style)
43 {
44 GtkCssCustomProperty *custom = GTK_CSS_CUSTOM_PROPERTY (_gtk_css_style_property_lookup_by_id (property_id));
45
46 return _gtk_css_style_funcs_compute_value (provider, style, parent_style, custom->pspec->value_type, value);
47 }
48
49 static gboolean
gtk_css_value_typed_equal(const GtkCssValue * value1,const GtkCssValue * value2)50 gtk_css_value_typed_equal (const GtkCssValue *value1,
51 const GtkCssValue *value2)
52 {
53 return FALSE;
54 }
55
56 static GtkCssValue *
gtk_css_value_typed_transition(GtkCssValue * start,GtkCssValue * end,guint property_id,double progress)57 gtk_css_value_typed_transition (GtkCssValue *start,
58 GtkCssValue *end,
59 guint property_id,
60 double progress)
61 {
62 return NULL;
63 }
64
65 static void
gtk_css_value_typed_print(const GtkCssValue * value,GString * string)66 gtk_css_value_typed_print (const GtkCssValue *value,
67 GString *string)
68 {
69 _gtk_css_style_funcs_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 *
gtk_css_typed_value_new_for_type(GType type)81 gtk_css_typed_value_new_for_type (GType type)
82 {
83 GtkCssValue *result;
84
85 result = _gtk_css_value_new (GtkCssValue, >K_CSS_VALUE_TYPED);
86
87 g_value_init (&result->value, type);
88
89 return result;
90 }
91
92 GtkCssValue *
_gtk_css_typed_value_new(const GValue * value)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 *
_gtk_css_typed_value_new_take(GValue * value)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
_gtk_is_css_typed_value_of_type(const GtkCssValue * value,GType type)120 _gtk_is_css_typed_value_of_type (const GtkCssValue *value,
121 GType type)
122 {
123 if (value->class != >K_CSS_VALUE_TYPED)
124 return FALSE;
125
126 return G_VALUE_HOLDS (&value->value, type);
127 }
128
129 const GValue *
_gtk_css_typed_value_get(const GtkCssValue * value)130 _gtk_css_typed_value_get (const GtkCssValue *value)
131 {
132 g_return_val_if_fail (value->class == >K_CSS_VALUE_TYPED, NULL);
133
134 return &value->value;
135 }
136