2 * Copyright © 2011 Red Hat Inc.
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.1 of the License, or (at your option) any later version.
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.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Benjamin Otte <otte@gnome.org>
23 #include "gtkcssimageprivate.h"
25 /* for the types only */
26 #include "gtk/gtkcssimagegradientprivate.h"
27 #include "gtk/gtkcssimageurlprivate.h"
28 #include "gtk/gtkcssimagewin32private.h"
30 G_DEFINE_ABSTRACT_TYPE (GtkCssImage, _gtk_css_image, G_TYPE_OBJECT)
33 gtk_css_image_real_get_width (GtkCssImage *image)
39 gtk_css_image_real_get_height (GtkCssImage *image)
45 gtk_css_image_real_get_aspect_ratio (GtkCssImage *image)
49 width = _gtk_css_image_get_width (image);
50 height = _gtk_css_image_get_height (image);
53 return (double) width / height;
59 gtk_css_image_real_compute (GtkCssImage *image,
60 GtkStyleContext *context)
62 return g_object_ref (image);
66 _gtk_css_image_class_init (GtkCssImageClass *klass)
68 klass->get_width = gtk_css_image_real_get_width;
69 klass->get_height = gtk_css_image_real_get_height;
70 klass->get_aspect_ratio = gtk_css_image_real_get_aspect_ratio;
71 klass->compute = gtk_css_image_real_compute;
75 _gtk_css_image_init (GtkCssImage *image)
80 _gtk_css_image_get_width (GtkCssImage *image)
82 GtkCssImageClass *klass;
84 g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), 0);
86 klass = GTK_CSS_IMAGE_GET_CLASS (image);
88 return klass->get_width (image);
92 _gtk_css_image_get_height (GtkCssImage *image)
94 GtkCssImageClass *klass;
96 g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), 0);
98 klass = GTK_CSS_IMAGE_GET_CLASS (image);
100 return klass->get_height (image);
104 _gtk_css_image_get_aspect_ratio (GtkCssImage *image)
106 GtkCssImageClass *klass;
108 g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), 0);
110 klass = GTK_CSS_IMAGE_GET_CLASS (image);
112 return klass->get_aspect_ratio (image);
116 _gtk_css_image_compute (GtkCssImage *image,
117 GtkStyleContext *context)
119 GtkCssImageClass *klass;
121 g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
122 g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
124 klass = GTK_CSS_IMAGE_GET_CLASS (image);
126 return klass->compute (image, context);
130 _gtk_css_image_draw (GtkCssImage *image,
135 GtkCssImageClass *klass;
137 g_return_if_fail (GTK_IS_CSS_IMAGE (image));
138 g_return_if_fail (cr != NULL);
142 klass = GTK_CSS_IMAGE_GET_CLASS (image);
144 klass->draw (image, cr, width, height);
150 _gtk_css_image_print (GtkCssImage *image,
153 GtkCssImageClass *klass;
155 g_return_if_fail (GTK_IS_CSS_IMAGE (image));
156 g_return_if_fail (string != NULL);
158 klass = GTK_CSS_IMAGE_GET_CLASS (image);
160 klass->print (image, string);
164 _gtk_css_image_new_parse (GtkCssParser *parser,
167 static const struct {
169 GType (* type_func) (void);
171 { "url", _gtk_css_image_url_get_type },
172 { "-gtk-gradient", _gtk_css_image_gradient_get_type },
173 { "-gtk-win32-theme-part", _gtk_css_image_win32_get_type }
177 g_return_val_if_fail (parser != NULL, NULL);
178 g_return_val_if_fail (G_IS_FILE (base), NULL);
180 for (i = 0; i < G_N_ELEMENTS (image_types); i++)
182 if (_gtk_css_parser_has_prefix (parser, image_types[i].prefix))
185 GtkCssImageClass *klass;
187 image = g_object_new (image_types[i].type_func (), NULL);
189 klass = GTK_CSS_IMAGE_GET_CLASS (image);
190 if (!klass->parse (image, parser, base))
192 g_object_unref (image);
200 _gtk_css_parser_error (parser, "Not a valid image");