]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssimagevalue.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkcssimagevalue.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 "gtkcssimagevalueprivate.h"
21
22 #include "gtkcssimagecrossfadeprivate.h"
23
24 struct _GtkCssValue {
25   GTK_CSS_VALUE_BASE
26   GtkCssImage *image;
27 };
28
29 static void
30 gtk_css_value_image_free (GtkCssValue *value)
31 {
32   g_object_unref (value->image);
33   g_slice_free (GtkCssValue, value);
34 }
35
36 static GtkCssValue *
37 gtk_css_value_image_compute (GtkCssValue             *value,
38                              guint                    property_id,
39                              GtkStyleProviderPrivate *provider,
40                              GtkCssComputedValues    *values,
41                              GtkCssComputedValues    *parent_values,
42                              GtkCssDependencies      *dependencies)
43 {
44   GtkCssImage *image, *computed;
45   
46   image = _gtk_css_image_value_get_image (value);
47
48   if (image == NULL)
49     return _gtk_css_value_ref (value);
50
51   computed = _gtk_css_image_compute (image, property_id, provider, values, parent_values, dependencies);
52
53   if (computed == image)
54     {
55       g_object_unref (computed);
56       return _gtk_css_value_ref (value);
57     }
58
59   return _gtk_css_image_value_new (computed);
60 }
61
62 static gboolean
63 gtk_css_value_image_equal (const GtkCssValue *value1,
64                            const GtkCssValue *value2)
65 {
66   return _gtk_css_image_equal (value1->image, value2->image);
67 }
68
69 static GtkCssValue *
70 gtk_css_value_image_transition (GtkCssValue *start,
71                                 GtkCssValue *end,
72                                 guint        property_id,
73                                 double       progress)
74 {
75   GtkCssImage *transition;
76
77   transition = _gtk_css_image_transition (_gtk_css_image_value_get_image (start),
78                                           _gtk_css_image_value_get_image (end),
79                                           property_id,
80                                           progress);
81       
82   return _gtk_css_image_value_new (transition);
83 }
84
85 static void
86 gtk_css_value_image_print (const GtkCssValue *value,
87                            GString           *string)
88 {
89   if (value->image)
90     _gtk_css_image_print (value->image, string);
91   else
92     g_string_append (string, "none");
93 }
94
95 static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
96   gtk_css_value_image_free,
97   gtk_css_value_image_compute,
98   gtk_css_value_image_equal,
99   gtk_css_value_image_transition,
100   gtk_css_value_image_print
101 };
102
103 GtkCssValue *
104 _gtk_css_image_value_new (GtkCssImage *image)
105 {
106   static GtkCssValue none_singleton = { &GTK_CSS_VALUE_IMAGE, 1, NULL };
107   GtkCssValue *value;
108
109   if (image == NULL)
110     return _gtk_css_value_ref (&none_singleton);
111
112   value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IMAGE);
113   value->image = image;
114
115   return value;
116 }
117
118 GtkCssImage *
119 _gtk_css_image_value_get_image (const GtkCssValue *value)
120 {
121   g_return_val_if_fail (value->class == &GTK_CSS_VALUE_IMAGE, NULL);
122
123   return value->image;
124 }
125