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 "gtkcssimagewin32private.h"
25 #include "gtkcssprovider.h"
27 G_DEFINE_TYPE (GtkCssImageWin32, _gtk_css_image_win32, GTK_TYPE_CSS_IMAGE)
30 gtk_css_image_win32_draw (GtkCssImage *image,
35 GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
36 cairo_surface_t *surface;
38 surface = _gtk_win32_theme_part_create_surface (wimage->theme, wimage->part, wimage->state, wimage->margins,
41 if (wimage->state2 >= 0)
43 cairo_surface_t *surface2;
46 surface2 = _gtk_win32_theme_part_create_surface (wimage->theme, wimage->part2, wimage->state2, wimage->margins,
49 cr = cairo_create (surface);
51 cairo_set_source_surface (cr, surface2, 0, 0);
52 cairo_paint_with_alpha (cr, wimage->over_alpha);
56 cairo_surface_destroy (surface2);
59 cairo_set_source_surface (cr, surface, 0, 0);
60 cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
61 cairo_rectangle (cr, 0, 0, width, height);
64 cairo_surface_destroy (surface);
68 gtk_css_image_win32_parse (GtkCssImage *image,
72 GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
75 if (!_gtk_css_parser_try (parser, "-gtk-win32-theme-part", TRUE))
77 _gtk_css_parser_error (parser, "'-gtk-win32-theme-part'");
81 if (!_gtk_css_parser_try (parser, "(", TRUE))
83 _gtk_css_parser_error (parser,
84 "Expected '(' after '-gtk-win32-theme-part'");
88 class = _gtk_css_parser_try_name (parser, TRUE);
91 _gtk_css_parser_error (parser,
92 "Expected name as first argument to '-gtk-win32-theme-part'");
95 wimage->theme = _gtk_win32_lookup_htheme_by_classname (class);
98 if (! _gtk_css_parser_try (parser, ",", TRUE))
100 _gtk_css_parser_error (parser, "Expected ','");
104 if (!_gtk_css_parser_try_int (parser, &wimage->part))
106 _gtk_css_parser_error (parser, "Expected a valid integer value");
110 if (!_gtk_css_parser_try_int (parser, &wimage->state))
112 _gtk_css_parser_error (parser, "Expected a valid integer value");
116 while ( _gtk_css_parser_try (parser, ",", TRUE))
118 if ( _gtk_css_parser_try (parser, "over", TRUE))
120 if (!_gtk_css_parser_try (parser, "(", TRUE))
122 _gtk_css_parser_error (parser,
123 "Expected '(' after 'over'");
127 if (!_gtk_css_parser_try_int (parser, &wimage->part2))
129 _gtk_css_parser_error (parser, "Expected a valid integer value");
133 if (!_gtk_css_parser_try_int (parser, &wimage->state2))
135 _gtk_css_parser_error (parser, "Expected a valid integer value");
139 if ( _gtk_css_parser_try (parser, ",", TRUE))
141 if (!_gtk_css_parser_try_double (parser, &wimage->over_alpha))
143 _gtk_css_parser_error (parser, "Expected a valid double value");
148 if (!_gtk_css_parser_try (parser, ")", TRUE))
150 _gtk_css_parser_error (parser,
151 "Expected ')' at end of 'over'");
155 else if ( _gtk_css_parser_try (parser, "margins", TRUE))
159 if (!_gtk_css_parser_try (parser, "(", TRUE))
161 _gtk_css_parser_error (parser,
162 "Expected '(' after 'margins'");
166 for (i = 0; i < 4; i++)
168 if (!_gtk_css_parser_try_int (parser, &wimage->margins[i]))
174 _gtk_css_parser_error (parser, "Expected valid margins");
179 wimage->margins[1] = wimage->margins[0];
181 wimage->margins[2] = wimage->margins[1];
183 wimage->margins[3] = wimage->margins[2];
185 if (!_gtk_css_parser_try (parser, ")", TRUE))
187 _gtk_css_parser_error (parser,
188 "Expected ')' at end of 'margins'");
194 _gtk_css_parser_error (parser,
195 "Expected identifier");
200 if (!_gtk_css_parser_try (parser, ")", TRUE))
202 _gtk_css_parser_error (parser,
211 gtk_css_image_win32_print (GtkCssImage *image,
214 g_string_append (string, "none /* printing win32 theme components is not implemented */");
218 _gtk_css_image_win32_class_init (GtkCssImageWin32Class *klass)
220 GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
222 image_class->draw = gtk_css_image_win32_draw;
223 image_class->parse = gtk_css_image_win32_parse;
224 image_class->print = gtk_css_image_win32_print;
228 _gtk_css_image_win32_init (GtkCssImageWin32 *wimage)
230 wimage->over_alpha = 1.0;