]> Pileus Git - ~andy/gtk/commitdiff
style: Convert draw_focus vfunc to Cairo version
authorBenjamin Otte <otte@redhat.com>
Mon, 16 Aug 2010 20:24:46 +0000 (22:24 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 26 Sep 2010 13:02:58 +0000 (15:02 +0200)
gtk/gtkstyle.c
gtk/gtkstyle.h
modules/engines/pixbuf/pixbuf-draw.c

index 7e1b0ba408c9cf356620eae92638a67312327052..71bcd2d4841fed11554cfa10b0049a8e7ac303e6 100644 (file)
@@ -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);
 }
 
 /**
index c6268b74ddf1d2563424f76027957ca284fafa21..ad64a9e6fdd21717614a7a7ea8dbca1e95c0aaf1 100644 (file)
@@ -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,
index b371986bc204570dd50a0df1ba8b238a2fd77f13..2dac99dfa5de1f65dffe1b472144d5ea42a9a416 100644 (file)
@@ -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);
 }