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 "gtkcssimagevalueprivate.h"
21
22#include "gtkcssimagecrossfadeprivate.h"
23
24struct _GtkCssValue {
25 GTK_CSS_VALUE_BASE
26 GtkCssImage *image;
27};
28
29static void
30gtk_css_value_image_free (GtkCssValue *value)
31{
32 g_object_unref (object: value->image);
33 g_slice_free (GtkCssValue, value);
34}
35
36static GtkCssValue *
37gtk_css_value_image_compute (GtkCssValue *value,
38 guint property_id,
39 GtkStyleProvider *provider,
40 GtkCssStyle *style,
41 GtkCssStyle *parent_style)
42{
43 GtkCssImage *image, *computed;
44
45 image = _gtk_css_image_value_get_image (image: value);
46
47 if (image == NULL)
48 return _gtk_css_value_ref (value);
49
50 computed = _gtk_css_image_compute (image, property_id, provider, style, parent_style);
51
52 if (computed == image)
53 {
54 g_object_unref (object: computed);
55 return _gtk_css_value_ref (value);
56 }
57
58 return _gtk_css_image_value_new (image: computed);
59}
60
61static gboolean
62gtk_css_value_image_equal (const GtkCssValue *value1,
63 const GtkCssValue *value2)
64{
65 return _gtk_css_image_equal (image1: value1->image, image2: value2->image);
66}
67
68static GtkCssValue *
69gtk_css_value_image_transition (GtkCssValue *start,
70 GtkCssValue *end,
71 guint property_id,
72 double progress)
73{
74 GtkCssImage *transition;
75
76 transition = _gtk_css_image_transition (start: _gtk_css_image_value_get_image (image: start),
77 end: _gtk_css_image_value_get_image (image: end),
78 property_id,
79 progress);
80
81 return _gtk_css_image_value_new (image: transition);
82}
83
84static gboolean
85gtk_css_value_image_is_dynamic (const GtkCssValue *value)
86{
87 GtkCssImage *image = _gtk_css_image_value_get_image (image: value);
88
89 if (image == NULL)
90 return FALSE;
91
92 return gtk_css_image_is_dynamic (image);
93}
94
95static GtkCssValue *
96gtk_css_value_image_get_dynamic_value (GtkCssValue *value,
97 gint64 monotonic_time)
98{
99 GtkCssImage *image, *dynamic;
100
101 image = _gtk_css_image_value_get_image (image: value);
102 if (image == NULL)
103 return gtk_css_value_ref (value);
104
105 dynamic = gtk_css_image_get_dynamic_image (image, monotonic_time);
106 if (dynamic == image)
107 {
108 g_object_unref (object: dynamic);
109 return gtk_css_value_ref (value);
110 }
111
112 return _gtk_css_image_value_new (image: dynamic);
113}
114
115static void
116gtk_css_value_image_print (const GtkCssValue *value,
117 GString *string)
118{
119 if (value->image)
120 _gtk_css_image_print (image: value->image, string);
121 else
122 g_string_append (string, val: "none");
123}
124
125static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
126 "GtkCssImageValue",
127 gtk_css_value_image_free,
128 gtk_css_value_image_compute,
129 gtk_css_value_image_equal,
130 gtk_css_value_image_transition,
131 gtk_css_value_image_is_dynamic,
132 gtk_css_value_image_get_dynamic_value,
133 gtk_css_value_image_print
134};
135
136GtkCssValue *
137_gtk_css_image_value_new (GtkCssImage *image)
138{
139 static GtkCssValue image_none_singleton = { &GTK_CSS_VALUE_IMAGE, 1, TRUE, NULL };
140 GtkCssValue *value;
141
142 if (image == NULL)
143 return _gtk_css_value_ref (value: &image_none_singleton);
144
145 value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IMAGE);
146 value->image = image;
147 value->is_computed = gtk_css_image_is_computed (image);
148
149 return value;
150}
151
152GtkCssImage *
153_gtk_css_image_value_get_image (const GtkCssValue *value)
154{
155 g_return_val_if_fail (value->class == &GTK_CSS_VALUE_IMAGE, NULL);
156
157 return value->image;
158}
159
160

source code of gtk/gtk/gtkcssimagevalue.c