From: Benjamin Otte Date: Mon, 16 Aug 2010 20:24:46 +0000 (+0200) Subject: style: Convert draw_focus vfunc to Cairo version X-Git-Url: http://pileus.org/git/?p=~andy%2Fgtk;a=commitdiff_plain;h=24304a2e93b5e7728e386626c08edcc7223aeade style: Convert draw_focus vfunc to Cairo version --- diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c index 7e1b0ba40..71bcd2d48 100644 --- a/gtk/gtkstyle.c +++ b/gtk/gtkstyle.c @@ -236,9 +236,8 @@ static void gtk_default_draw_extension (GtkStyle *style, gint height, GtkPositionType gap_side); static void gtk_default_draw_focus (GtkStyle *style, - GdkWindow *window, + cairo_t *cr, GtkStateType state_type, - GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint x, @@ -3599,9 +3598,8 @@ gtk_default_draw_extension (GtkStyle *style, static void gtk_default_draw_focus (GtkStyle *style, - GdkWindow *window, + cairo_t *cr, GtkStateType state_type, - GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint x, @@ -3609,7 +3607,6 @@ gtk_default_draw_focus (GtkStyle *style, gint width, gint height) { - cairo_t *cr; gboolean free_dash_list = FALSE; gint line_width = 1; gint8 *dash_list = (gint8 *) "\1\1"; @@ -3633,10 +3630,6 @@ gtk_default_draw_focus (GtkStyle *style, free_dash_list = FALSE; } - sanitize_size (window, &width, &height); - - cr = gdk_cairo_create (window); - if (detail && !strcmp (detail, "colorwheel_light")) cairo_set_source_rgb (cr, 0., 0., 0.); else if (detail && !strcmp (detail, "colorwheel_dark")) @@ -3673,19 +3666,12 @@ gtk_default_draw_focus (GtkStyle *style, g_free (dashes); } - if (area) - { - gdk_cairo_rectangle (cr, area); - cairo_clip (cr); - } - cairo_rectangle (cr, x + line_width / 2., y + line_width / 2., width - line_width, height - line_width); cairo_stroke (cr); - cairo_destroy (cr); if (free_dash_list) g_free (dash_list); @@ -5823,13 +5809,62 @@ gtk_paint_focus (GtkStyle *style, gint width, gint height) { + cairo_t *cr; + g_return_if_fail (GTK_IS_STYLE (style)); g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL); g_return_if_fail (style->depth == gdk_drawable_get_depth (window)); - GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type, - (GdkRectangle *) area, widget, detail, + sanitize_size (window, &width, &height); + + cr = gtk_style_cairo_create (window, area); + + gtk_cairo_paint_focus (style, cr, state_type, + widget, detail, + x, y, width, height); + + cairo_destroy (cr); +} + +/** + * gtk_cairo_paint_focus: + * @style: a #GtkStyle + * @cr: a #cairo_t + * @state_type: a state + * @widget: (allow-none): the widget + * @detail: (allow-none): a style detail + * @x: the x origin of the rectangle around which to draw a focus indicator + * @y: the y origin of the rectangle around which to draw a focus indicator + * @width: the width of the rectangle around which to draw a focus indicator + * @height: the height of the rectangle around which to draw a focus indicator + * + * Draws a focus indicator around the given rectangle on @cr using the + * given style. + */ +void +gtk_cairo_paint_focus (GtkStyle *style, + cairo_t *cr, + GtkStateType state_type, + GtkWidget *widget, + const gchar *detail, + gint x, + gint y, + gint width, + gint height) +{ + g_return_if_fail (GTK_IS_STYLE (style)); + g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL); + g_return_if_fail (cr != NULL); + g_return_if_fail (width >= 0); + g_return_if_fail (height >= 0); + + cairo_save (cr); + + GTK_STYLE_GET_CLASS (style)->draw_focus (style, cr, state_type, + widget, detail, x, y, width, height); + + cairo_restore (cr); } /** diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h index c6268b74d..ad64a9e6f 100644 --- a/gtk/gtkstyle.h +++ b/gtk/gtkstyle.h @@ -301,9 +301,8 @@ struct _GtkStyleClass gint height, GtkPositionType gap_side); void (*draw_focus) (GtkStyle *style, - GdkWindow *window, + cairo_t *cr, GtkStateType state_type, - GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint x, @@ -724,16 +723,25 @@ void gtk_cairo_paint_extension (GtkStyle *style, gint width, gint height, GtkPositionType gap_side); -void gtk_paint_focus (GtkStyle *style, - GdkWindow *window, - GtkStateType state_type, - const GdkRectangle *area, - GtkWidget *widget, - const gchar *detail, - gint x, - gint y, - gint width, - gint height); +void gtk_paint_focus (GtkStyle *style, + GdkWindow *window, + GtkStateType state_type, + const GdkRectangle *area, + GtkWidget *widget, + const gchar *detail, + gint x, + gint y, + gint width, + gint height); +void gtk_cairo_paint_focus (GtkStyle *style, + cairo_t *cr, + GtkStateType state_type, + GtkWidget *widget, + const gchar *detail, + gint x, + gint y, + gint width, + gint height); void gtk_paint_slider (GtkStyle *style, GdkWindow *window, GtkStateType state_type, diff --git a/modules/engines/pixbuf/pixbuf-draw.c b/modules/engines/pixbuf/pixbuf-draw.c index b371986bc..2dac99dfa 100644 --- a/modules/engines/pixbuf/pixbuf-draw.c +++ b/modules/engines/pixbuf/pixbuf-draw.c @@ -818,9 +818,8 @@ draw_extension (GtkStyle *style, static void draw_focus (GtkStyle *style, - GdkWindow *window, + cairo_t *cr, GtkStateType state_type, - GdkRectangle *area, GtkWidget *widget, const gchar *detail, gint x, @@ -830,16 +829,13 @@ draw_focus (GtkStyle *style, { ThemeMatchData match_data; - g_return_if_fail (style != NULL); - g_return_if_fail (window != NULL); - match_data.function = TOKEN_D_FOCUS; match_data.detail = (gchar *)detail; match_data.flags = 0; - if (!draw_simple_image_no_cairo (style, window, area, widget, &match_data, TRUE, FALSE, + if (!draw_simple_image (style, cr, widget, &match_data, TRUE, FALSE, x, y, width, height)) - parent_class->draw_focus (style, window, state_type, area, widget, detail, + parent_class->draw_focus (style, cr, state_type, widget, detail, x, y, width, height); }