diff options
author | Benjamin Otte <otte@redhat.com> | 2016-02-17 04:18:29 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2016-02-17 04:36:18 +0100 |
commit | c98007f9fd3db6d27c6916f28d2b1867c93bd072 (patch) | |
tree | 35fc068829bed1bd7138263f00164b26a3741427 /gtk | |
parent | 37e3ccb2f67729ecdef6605455e6bf2b8b0279d7 (diff) | |
download | gtk+-c98007f9fd3db6d27c6916f28d2b1867c93bd072.tar.gz |
win32: Add fallback code to draw theme parts
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkwin32draw.c | 139 | ||||
-rw-r--r-- | gtk/gtkwin32drawprivate.h | 17 | ||||
-rw-r--r-- | gtk/gtkwin32theme.c | 11 |
3 files changed, 156 insertions, 11 deletions
diff --git a/gtk/gtkwin32draw.c b/gtk/gtkwin32draw.c index d80d274b7f..1c761f2c31 100644 --- a/gtk/gtkwin32draw.c +++ b/gtk/gtkwin32draw.c @@ -19,6 +19,145 @@ #include "gtkwin32drawprivate.h" +static void +gtk_cairo_set_source_sys_color (cairo_t *cr, + gint id) +{ + GdkRGBA rgba; + + gtk_win32_get_sys_color (id, &rgba); + gdk_cairo_set_source_rgba (cr, &rgba); +} + +static void +draw_button (cairo_t *cr, + int part, + int state, + int width, + int height) +{ + gboolean is_down = (state == 3); + int top_color = is_down ? GTK_WIN32_SYS_COLOR_BTNSHADOW : GTK_WIN32_SYS_COLOR_BTNHIGHLIGHT; + int bot_color = is_down ? GTK_WIN32_SYS_COLOR_BTNHIGHLIGHT : GTK_WIN32_SYS_COLOR_BTNSHADOW; + + gtk_cairo_set_source_sys_color (cr, top_color); + cairo_rectangle (cr, 0, 0, width - 1, 1); + cairo_rectangle (cr, 0, 1, 1, height - 1); + cairo_fill (cr); + + gtk_cairo_set_source_sys_color (cr, bot_color); + cairo_rectangle (cr, width - 1, 0, 1, height -1); + cairo_rectangle (cr, 0, height - 1, width, 1); + cairo_fill (cr); + + gtk_cairo_set_source_sys_color (cr, GTK_WIN32_SYS_COLOR_BTNFACE); + cairo_rectangle (cr, 1, 1, width - 2, height - 2); + cairo_fill (cr); +} + +static void +draw_check (cairo_t *cr, + int part, + int state, + int width, + int height) +{ + gtk_cairo_set_source_sys_color (cr, GTK_WIN32_SYS_COLOR_BTNHIGHLIGHT); + cairo_set_line_width (cr, 1.0); + cairo_rectangle (cr, 0.5, 0.5, width - 1.0, height - 1.0); + cairo_stroke (cr); +} + +static void +draw_radio (cairo_t *cr, + int part, + int state, + int width, + int height) +{ + gtk_cairo_set_source_sys_color (cr, GTK_WIN32_SYS_COLOR_BTNHIGHLIGHT); + cairo_set_line_width (cr, 1.0); + cairo_arc (cr, width / 2.0, height / 2.0, MIN (width, height) / 2.0 - 0.5, 0, G_PI * 2); + cairo_stroke (cr); +} + +typedef struct _GtkWin32ThemePart GtkWin32ThemePart; +struct _GtkWin32ThemePart { + const char *class_name; + gint part; + gint size; + void (* draw_func) (cairo_t *cr, + int part, + int state, + int width, + int height); +}; + +static GtkWin32ThemePart theme_parts[] = { + { "button", 1, 0, draw_button }, + { "button", 2, 13, draw_radio }, + { "button", 3, 13, draw_check } +}; + +static const GtkWin32ThemePart * +get_theme_part (const char *class_name, + gint part) +{ + gsize i; + + for (i = 0; i < G_N_ELEMENTS (theme_parts); i++) + { + if (g_str_equal (theme_parts[i].class_name, class_name) && + theme_parts[i].part == part) + return &theme_parts[i]; + } + + return NULL; +} + +void +gtk_win32_draw_theme_background (cairo_t *cr, + const char *class_name, + int part, + int state, + int width, + int height) +{ + const GtkWin32ThemePart *theme_part; + + theme_part = get_theme_part (class_name, part); + + if (theme_part) + theme_part->draw_func (cr, part, state, width, height); +} + +void +gtk_win32_get_theme_part_size (const char *class_name, + int part, + int state, + int *width, + int *height) +{ + const GtkWin32ThemePart *theme_part; + + theme_part = get_theme_part (class_name, part); + + if (theme_part) + { + if (width) + *width = theme_part->size; + if (height) + *height = theme_part->size; + } + else + { + if (width) + *width = 1; + if (height) + *height = 1; + } +} + struct { const char *name; GdkRGBA rgba; diff --git a/gtk/gtkwin32drawprivate.h b/gtk/gtkwin32drawprivate.h index fc57cb73d6..f8a11ca2ea 100644 --- a/gtk/gtkwin32drawprivate.h +++ b/gtk/gtkwin32drawprivate.h @@ -19,6 +19,7 @@ #define __GTK_WIN32_DRAW_H__ #include <gdk/gdk.h> +#include <cairo.h> G_BEGIN_DECLS @@ -56,8 +57,20 @@ enum { GTK_WIN32_SYS_COLOR_MENUBAR }; -void gtk_win32_get_sys_color (gint id, - GdkRGBA *color); +void gtk_win32_draw_theme_background (cairo_t *cr, + const char *class_name, + int part, + int state, + int width, + int height); +void gtk_win32_get_theme_part_size (const char *class_name, + int part, + int state, + int *width, + int *height); + +void gtk_win32_get_sys_color (gint id, + GdkRGBA *color); G_END_DECLS diff --git a/gtk/gtkwin32theme.c b/gtk/gtkwin32theme.c index 8288f5d94d..dced7c7f10 100644 --- a/gtk/gtkwin32theme.c +++ b/gtk/gtkwin32theme.c @@ -310,7 +310,6 @@ gtk_win32_theme_create_surface (GtkWin32Theme *theme, int *y_offs_out) { cairo_surface_t *surface; - GdkRGBA color; cairo_t *cr; int x_offs; int y_offs; @@ -378,10 +377,7 @@ gtk_win32_theme_create_surface (GtkWin32Theme *theme, cr = cairo_create (surface); - /* XXX: Do something better here (like printing the theme parts) */ - gdk_rgba_parse (&color, "pink"); - gdk_cairo_set_source_rgba (cr, &color); - cairo_paint (cr); + gtk_win32_draw_theme_background (cr, theme->class_name, xp_part, state, width, height); cairo_destroy (cr); @@ -432,10 +428,7 @@ gtk_win32_theme_get_part_size (GtkWin32Theme *theme, } #endif - if (width) - *width = 1; - if (height) - *height = 1; + gtk_win32_get_theme_part_size (theme->class_name, part, state, width, height); } int |