diff options
-rw-r--r-- | gtk/gtkstyleproperty.c | 34 | ||||
-rw-r--r-- | gtk/gtkwin32theme.c | 71 | ||||
-rw-r--r-- | gtk/gtkwin32themeprivate.h | 3 |
3 files changed, 104 insertions, 4 deletions
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c index 7c302ada74..f511c717a4 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 71f7ad2321..78ac896313 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 adad562254..b066d9ab14 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 |