[gtk+/rendering-cleanup: 16/92] style: Convert draw_focus vfunc to Cairo version



commit ce86e69c2012b98ad8dd3f6c77d80c6209f4ed14
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 16 22:24:46 2010 +0200

    style: Convert draw_focus vfunc to Cairo version

 gtk/gtkstyle.c                       |   71 +++++++++++++++++++++++++---------
 gtk/gtkstyle.h                       |   32 +++++++++------
 modules/engines/pixbuf/pixbuf-draw.c |   10 +---
 3 files changed, 76 insertions(+), 37 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index 9990bda..0cb77b7 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,
@@ -3585,9 +3584,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,
@@ -3595,7 +3593,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";
@@ -3619,10 +3616,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"))
@@ -3659,19 +3652,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);
@@ -5808,13 +5794,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 449dc0e..254ce6f 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 51bd695..711c104 100644
--- a/modules/engines/pixbuf/pixbuf-draw.c
+++ b/modules/engines/pixbuf/pixbuf-draw.c
@@ -820,9 +820,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,
@@ -832,16 +831,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);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]