]> Pileus Git - ~andy/gtk/blob - gtk/gtkcssimagevalue.c
[Bug 675501] gtkquartz.h is not in the gtk+-3.5.2.tar.xz archive
[~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 gboolean
37 gtk_css_value_image_equal (const GtkCssValue *value1,
38                            const GtkCssValue *value2)
39 {
40   return value1->image == value2->image;
41 }
42
43 static GtkCssValue *
44 gtk_css_value_image_transition (GtkCssValue *start,
45                                 GtkCssValue *end,
46                                 double       progress)
47 {
48   GtkCssImage *fade;
49
50   fade = _gtk_css_image_cross_fade_new (_gtk_css_image_value_get_image (start),
51                                         _gtk_css_image_value_get_image (end),
52                                         progress);
53       
54   return _gtk_css_image_value_new (fade);
55 }
56
57 static void
58 gtk_css_value_image_print (const GtkCssValue *value,
59                            GString           *string)
60 {
61   if (value->image)
62     _gtk_css_image_print (value->image, string);
63   else
64     g_string_append (string, "none");
65 }
66
67 static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
68   gtk_css_value_image_free,
69   gtk_css_value_image_equal,
70   gtk_css_value_image_transition,
71   gtk_css_value_image_print
72 };
73
74 GtkCssValue *
75 _gtk_css_image_value_new (GtkCssImage *image)
76 {
77   static GtkCssValue none_singleton = { &GTK_CSS_VALUE_IMAGE, 1, NULL };
78   GtkCssValue *value;
79
80   if (image == NULL)
81     return _gtk_css_value_ref (&none_singleton);
82
83   value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IMAGE);
84   value->image = image;
85
86   return value;
87 }
88
89 GtkCssImage *
90 _gtk_css_image_value_get_image (const GtkCssValue *value)
91 {
92   g_return_val_if_fail (value->class == &GTK_CSS_VALUE_IMAGE, NULL);
93
94   return value->image;
95 }
96