summaryrefslogtreecommitdiff
path: root/gtk/gtkcssimagewin32.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2011-12-20 14:44:53 +0100
committerBenjamin Otte <otte@redhat.com>2012-01-09 18:37:56 +0100
commit2a6c168235902b1db9d06fc4bf8702e5d1ccedca (patch)
treec76768c5dffbd432eeb0fe6e83e9e55629ebdc1d /gtk/gtkcssimagewin32.c
parentf7eea0b86e24ee60957c86d7dd6ab1d031211bab (diff)
downloadgtk+-2a6c168235902b1db9d06fc4bf8702e5d1ccedca.tar.gz
win32: Add a CssImage implementation
Diffstat (limited to 'gtk/gtkcssimagewin32.c')
-rw-r--r--gtk/gtkcssimagewin32.c234
1 files changed, 234 insertions, 0 deletions
diff --git a/gtk/gtkcssimagewin32.c b/gtk/gtkcssimagewin32.c
new file mode 100644
index 0000000000..3b89f90cfd
--- /dev/null
+++ b/gtk/gtkcssimagewin32.c
@@ -0,0 +1,234 @@
+/*
+ * Copyright © 2011 Red Hat Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Authors: Benjamin Otte <otte@gnome.org>
+ */
+
+#include "config.h"
+
+#include "gtkcssimagewin32private.h"
+
+#include "gtkcssprovider.h"
+
+G_DEFINE_TYPE (GtkCssImageWin32, _gtk_css_image_win32, GTK_TYPE_CSS_IMAGE)
+
+static void
+gtk_css_image_win32_draw (GtkCssImage *image,
+ cairo_t *cr,
+ double width,
+ double height)
+{
+ GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
+ cairo_surface_t *surface;
+
+ surface = _gtk_win32_theme_part_create_surface (wimage->theme, wimage->part, wimage->state, wimage->margins,
+ width, height);
+
+ if (wimage->state2 >= 0)
+ {
+ cairo_surface_t *surface2;
+ cairo_t *cr;
+
+ surface2 = _gtk_win32_theme_part_create_surface (wimage->theme, wimage->part2, wimage->state2, wimage->margins,
+ width, height);
+
+ cr = cairo_create (surface);
+
+ cairo_set_source_surface (cr, surface2, 0, 0);
+ cairo_paint_with_alpha (cr, wimage->over_alpha);
+
+ cairo_destroy (cr);
+
+ cairo_surface_destroy (surface2);
+ }
+
+ cairo_set_source_surface (cr, surface, 0, 0);
+ cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_PAD);
+ cairo_rectangle (cr, 0, 0, width, height);
+ cairo_fill (cr);
+
+ cairo_surface_destroy (surface);
+}
+
+static gboolean
+gtk_css_image_win32_parse (GtkCssImage *image,
+ GtkCssParser *parser,
+ GFile *base)
+{
+ GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
+ char *class;
+
+ if (!_gtk_css_parser_try (parser, "-gtk-win32-theme-part", TRUE))
+ {
+ _gtk_css_parser_error (parser, "'-gtk-win32-theme-part'");
+ return FALSE;
+ }
+
+ if (!_gtk_css_parser_try (parser, "(", TRUE))
+ {
+ _gtk_css_parser_error (parser,
+ "Expected '(' after '-gtk-win32-theme-part'");
+ return FALSE;
+ }
+
+ class = _gtk_css_parser_try_name (parser, TRUE);
+ if (class == NULL)
+ {
+ _gtk_css_parser_error (parser,
+ "Expected name as first argument to '-gtk-win32-theme-part'");
+ return FALSE;
+ }
+ wimage->theme = _gtk_win32_lookup_htheme_by_classname (class);
+ g_free (class);
+
+ if (! _gtk_css_parser_try (parser, ",", TRUE))
+ {
+ _gtk_css_parser_error (parser, "Expected ','");
+ return FALSE;
+ }
+
+ if (!_gtk_css_parser_try_int (parser, &wimage->part))
+ {
+ _gtk_css_parser_error (parser, "Expected a valid integer value");
+ return FALSE;
+ }
+
+ if (!_gtk_css_parser_try_int (parser, &wimage->state))
+ {
+ _gtk_css_parser_error (parser, "Expected a valid integer value");
+ return FALSE;
+ }
+
+ while ( _gtk_css_parser_try (parser, ",", TRUE))
+ {
+ if ( _gtk_css_parser_try (parser, "over", TRUE))
+ {
+ if (!_gtk_css_parser_try (parser, "(", TRUE))
+ {
+ _gtk_css_parser_error (parser,
+ "Expected '(' after 'over'");
+ return FALSE;
+ }
+
+ if (!_gtk_css_parser_try_int (parser, &wimage->part2))
+ {
+ _gtk_css_parser_error (parser, "Expected a valid integer value");
+ return FALSE;
+ }
+
+ if (!_gtk_css_parser_try_int (parser, &wimage->state2))
+ {
+ _gtk_css_parser_error (parser, "Expected a valid integer value");
+ return FALSE;
+ }
+
+ if ( _gtk_css_parser_try (parser, ",", TRUE))
+ {
+ if (!_gtk_css_parser_try_double (parser, &wimage->over_alpha))
+ {
+ _gtk_css_parser_error (parser, "Expected a valid double value");
+ return FALSE;
+ }
+ }
+
+ if (!_gtk_css_parser_try (parser, ")", TRUE))
+ {
+ _gtk_css_parser_error (parser,
+ "Expected ')' at end of 'over'");
+ return FALSE;
+ }
+ }
+ else if ( _gtk_css_parser_try (parser, "margins", TRUE))
+ {
+ guint i;
+
+ if (!_gtk_css_parser_try (parser, "(", TRUE))
+ {
+ _gtk_css_parser_error (parser,
+ "Expected '(' after 'margins'");
+ return FALSE;
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ if (!_gtk_css_parser_try_int (parser, &wimage->margins[i]))
+ break;
+ }
+
+ if (i == 0)
+ {
+ _gtk_css_parser_error (parser, "Expected valid margins");
+ return FALSE;
+ }
+
+ if (i == 1)
+ wimage->margins[1] = wimage->margins[0];
+ if (i <= 2)
+ wimage->margins[2] = wimage->margins[1];
+ if (i <= 3)
+ wimage->margins[3] = wimage->margins[2];
+
+ if (!_gtk_css_parser_try (parser, ")", TRUE))
+ {
+ _gtk_css_parser_error (parser,
+ "Expected ')' at end of 'margins'");
+ return FALSE;
+ }
+ }
+ else
+ {
+ _gtk_css_parser_error (parser,
+ "Expected identifier");
+ return FALSE;
+ }
+ }
+
+ if (!_gtk_css_parser_try (parser, ")", TRUE))
+ {
+ _gtk_css_parser_error (parser,
+ "Expected ')'");
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+gtk_css_image_win32_print (GtkCssImage *image,
+ GString *string)
+{
+ g_string_append (string, "none /* printing win32 theme components is not implemented */");
+}
+
+static void
+_gtk_css_image_win32_class_init (GtkCssImageWin32Class *klass)
+{
+ GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
+
+ image_class->draw = gtk_css_image_win32_draw;
+ image_class->parse = gtk_css_image_win32_parse;
+ image_class->print = gtk_css_image_win32_print;
+}
+
+static void
+_gtk_css_image_win32_init (GtkCssImageWin32 *wimage)
+{
+ wimage->over_alpha = 1.0;
+ wimage->part2 = -1;
+ wimage->state2 = -1;
+}
+