2011-12-20 13:44:53 +00:00
|
|
|
/*
|
|
|
|
* 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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-12-20 13:44:53 +00:00
|
|
|
*
|
|
|
|
* 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
|
2018-02-14 01:30:42 +00:00
|
|
|
gtk_css_image_win32_snapshot (GtkCssImage *image,
|
|
|
|
GtkSnapshot *snapshot,
|
|
|
|
double width,
|
|
|
|
double height)
|
2011-12-20 13:44:53 +00:00
|
|
|
{
|
|
|
|
GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
|
|
|
|
cairo_surface_t *surface;
|
2012-03-09 15:37:11 +00:00
|
|
|
int dx, dy;
|
2018-02-14 01:30:42 +00:00
|
|
|
cairo_t *cr;
|
|
|
|
|
|
|
|
cr = gtk_snapshot_append_cairo (snapshot,
|
|
|
|
&GRAPHENE_RECT_INIT (0, 0, width, height),
|
|
|
|
"Fallback<%s>", G_OBJECT_TYPE_NAME (image));
|
2011-12-20 13:44:53 +00:00
|
|
|
|
2016-02-08 03:07:40 +00:00
|
|
|
surface = gtk_win32_theme_create_surface (wimage->theme, wimage->part, wimage->state, wimage->margins,
|
|
|
|
width, height, &dx, &dy);
|
2011-12-20 13:44:53 +00:00
|
|
|
|
|
|
|
if (wimage->state2 >= 0)
|
|
|
|
{
|
|
|
|
cairo_surface_t *surface2;
|
2015-05-31 01:24:48 +00:00
|
|
|
cairo_t *cr2;
|
2012-03-09 15:37:11 +00:00
|
|
|
int dx2, dy2;
|
2011-12-20 13:44:53 +00:00
|
|
|
|
2016-02-08 03:07:40 +00:00
|
|
|
surface2 = gtk_win32_theme_create_surface (wimage->theme, wimage->part2, wimage->state2, wimage->margins,
|
|
|
|
width, height, &dx2, &dy2);
|
2011-12-20 13:44:53 +00:00
|
|
|
|
2015-05-31 01:24:48 +00:00
|
|
|
cr2 = cairo_create (surface);
|
2011-12-20 13:44:53 +00:00
|
|
|
|
2015-05-31 01:24:48 +00:00
|
|
|
cairo_set_source_surface (cr2, surface2, dx2 - dx, dy2-dy);
|
|
|
|
cairo_paint_with_alpha (cr2, wimage->over_alpha);
|
|
|
|
|
|
|
|
cairo_destroy (cr2);
|
2011-12-20 13:44:53 +00:00
|
|
|
|
|
|
|
cairo_surface_destroy (surface2);
|
|
|
|
}
|
|
|
|
|
2012-03-09 15:37:11 +00:00
|
|
|
cairo_set_source_surface (cr, surface, dx, dy);
|
|
|
|
cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_NONE);
|
2011-12-20 13:44:53 +00:00
|
|
|
cairo_rectangle (cr, 0, 0, width, height);
|
|
|
|
cairo_fill (cr);
|
|
|
|
|
|
|
|
cairo_surface_destroy (surface);
|
2018-02-14 01:30:42 +00:00
|
|
|
|
|
|
|
cairo_destroy (cr);
|
2011-12-20 13:44:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_css_image_win32_parse (GtkCssImage *image,
|
2012-04-18 19:44:08 +00:00
|
|
|
GtkCssParser *parser)
|
2011-12-20 13:44:53 +00:00
|
|
|
{
|
|
|
|
GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-14 00:11:57 +00:00
|
|
|
wimage->theme = gtk_win32_theme_parse (parser);
|
|
|
|
if (wimage->theme == NULL)
|
|
|
|
return FALSE;
|
2011-12-20 13:44:53 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-17 01:42:35 +00:00
|
|
|
if (! _gtk_css_parser_try (parser, ",", TRUE))
|
|
|
|
{
|
|
|
|
_gtk_css_parser_error (parser, "Expected ','");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-12-20 13:44:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-17 01:42:35 +00:00
|
|
|
if (! _gtk_css_parser_try (parser, ",", TRUE))
|
|
|
|
{
|
|
|
|
_gtk_css_parser_error (parser, "Expected ','");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-12-20 13:44:53 +00:00
|
|
|
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)
|
|
|
|
{
|
2016-02-26 23:40:09 +00:00
|
|
|
GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (image);
|
|
|
|
|
|
|
|
g_string_append (string, "-gtk-win32-theme-part(");
|
|
|
|
gtk_win32_theme_print (wimage->theme, string);
|
|
|
|
g_string_append_printf (string, ", %d, %d)", wimage->part, wimage->state);
|
2011-12-20 13:44:53 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 03:07:40 +00:00
|
|
|
static void
|
|
|
|
gtk_css_image_win32_finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkCssImageWin32 *wimage = GTK_CSS_IMAGE_WIN32 (object);
|
|
|
|
|
|
|
|
if (wimage->theme)
|
|
|
|
gtk_win32_theme_unref (wimage->theme);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (_gtk_css_image_win32_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2011-12-20 13:44:53 +00:00
|
|
|
static void
|
|
|
|
_gtk_css_image_win32_class_init (GtkCssImageWin32Class *klass)
|
|
|
|
{
|
|
|
|
GtkCssImageClass *image_class = GTK_CSS_IMAGE_CLASS (klass);
|
2016-02-08 03:07:40 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->finalize = gtk_css_image_win32_finalize;
|
2011-12-20 13:44:53 +00:00
|
|
|
|
2018-02-14 01:30:42 +00:00
|
|
|
image_class->snapshot = gtk_css_image_win32_snapshot;
|
2011-12-20 13:44:53 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|