[gtk+/win32-theme] win32-theme: Support -gtk-win32-size CSS value
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/win32-theme] win32-theme: Support -gtk-win32-size CSS value
- Date: Wed, 16 Nov 2011 12:09:49 +0000 (UTC)
commit 7d2ed8ffbb76a8a4e37cfd8b610063a8bff0869d
Author: Alexander Larsson <alexl redhat com>
Date: Wed Nov 16 12:19:20 2011 +0100
win32-theme: Support -gtk-win32-size CSS value
gtk/gtkstyleproperty.c | 36 +++++++++++++++++++---
gtk/gtkwin32theme.c | 71 ++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkwin32themeprivate.h | 3 ++
3 files changed, 105 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 7c302ad..f511c71 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -385,6 +385,17 @@ int_value_parse (GtkCssParser *parser,
{
gint i;
+ if (_gtk_css_parser_begins_with (parser, '-'))
+ {
+ int res = _gtk_win32_theme_int_parse (parser, base, &i);
+ if (res >= 0)
+ {
+ g_value_set_int (value, i);
+ return res > 0;
+ }
+ /* < 0 => continue */
+ }
+
if (!_gtk_css_parser_try_int (parser, &i))
{
_gtk_css_parser_error (parser, "Expected a valid integer value");
@@ -589,11 +600,26 @@ border_value_parse (GtkCssParser *parser,
for (i = 0; i < G_N_ELEMENTS (numbers); i++)
{
- if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
- break;
+ if (_gtk_css_parser_begins_with (parser, '-'))
+ {
+ /* These are strictly speaking signed, but we want to be able to use them
+ for unsigned types too, as the actual ranges of values make this safe */
+ int res = _gtk_win32_theme_int_parse (parser, base, (int *)&numbers[i]);
+
+ if (res == 0) /* Parse error, report */
+ return FALSE;
+
+ if (res < 0) /* Nothing known to expand */
+ break;
+ }
+ else
+ {
+ if (!_gtk_css_parser_try_uint (parser, &numbers[i]))
+ break;
- /* XXX: shouldn't allow spaces here? */
- _gtk_css_parser_try (parser, "px", TRUE);
+ /* XXX: shouldn't allow spaces here? */
+ _gtk_css_parser_try (parser, "px", TRUE);
+ }
}
if (i == 0)
diff --git a/gtk/gtkwin32theme.c b/gtk/gtkwin32theme.c
index 71f7ad2..78ac8963 100644
--- a/gtk/gtkwin32theme.c
+++ b/gtk/gtkwin32theme.c
@@ -365,3 +365,74 @@ _gtk_win32_theme_part_render (GtkWin32ThemePart *part,
return cairo_pattern_create_rgb (color.red, color.green, color.blue);
#endif
}
+
+int
+_gtk_win32_theme_int_parse (GtkCssParser *parser,
+ GFile *base,
+ int *value)
+{
+ char *class;
+ int arg;
+
+ if (_gtk_css_parser_try (parser,
+ "-gtk-win32-size",
+ TRUE))
+ {
+ if (!_gtk_css_parser_try (parser, "(", TRUE))
+ {
+ _gtk_css_parser_error (parser,
+ "Expected '(' after '-gtk-win32-size'");
+ return 0;
+ }
+
+ class = _gtk_css_parser_try_name (parser, TRUE);
+ if (class == NULL)
+ {
+ _gtk_css_parser_error (parser,
+ "Expected name as first argument to '-gtk-win32-size'");
+ return 0;
+ }
+
+ if (! _gtk_css_parser_try (parser, ",", TRUE))
+ {
+ g_free (class);
+ _gtk_css_parser_error (parser,
+ "Expected ','");
+ return 0;
+ }
+
+ if (!_gtk_css_parser_try_int (parser, &arg))
+ {
+ g_free (class);
+ _gtk_css_parser_error (parser, "Expected a valid integer value");
+ return 0;
+ }
+
+ if (!_gtk_css_parser_try (parser, ")", TRUE))
+ {
+ _gtk_css_parser_error (parser,
+ "Expected ')'");
+ return 0;
+ }
+
+#ifdef G_OS_WIN32
+ if (use_xp_theme && get_theme_sys_metric != NULL)
+ {
+ HTHEME theme = lookup_htheme_by_classname (class);
+
+ /* If theme is NULL it will just return the GetSystemMetrics value */
+ *value = get_theme_sys_metric (theme, arg);
+ }
+ else
+ *value = GetSystemMetrics (arg);
+#else
+ *value = 1;
+#endif
+
+ g_free (class);
+
+ return 1;
+ }
+
+ return -1;
+}
diff --git a/gtk/gtkwin32themeprivate.h b/gtk/gtkwin32themeprivate.h
index adad562..b066d9a 100644
--- a/gtk/gtkwin32themeprivate.h
+++ b/gtk/gtkwin32themeprivate.h
@@ -42,6 +42,9 @@ int _gtk_win32_theme_part_parse (GtkCssParser *parser,
cairo_pattern_t *_gtk_win32_theme_part_render (GtkWin32ThemePart *part,
int width,
int height);
+int _gtk_win32_theme_int_parse (GtkCssParser *parser,
+ GFile *base,
+ int *value);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]