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