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



commit 289c265ed64f60293d95ab627e7671cae01c783d
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 16 21:50:08 2010 +0200

    style: Convert draw_flat_box vfunc to Cairo version

 gtk/gtkstyle.c                       |   81 ++++++++++++++++++++++++----------
 gtk/gtkstyle.h                       |   35 +++++++++-----
 modules/engines/pixbuf/pixbuf-draw.c |   10 +---
 3 files changed, 83 insertions(+), 43 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index 6ea0089..23cff65 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -159,10 +159,9 @@ static void gtk_default_draw_box        (GtkStyle        *style,
 					 gint             width,
 					 gint             height);
 static void gtk_default_draw_flat_box   (GtkStyle        *style,
-					 GdkWindow       *window,
+					 cairo_t         *cr,
 					 GtkStateType     state_type,
 					 GtkShadowType    shadow_type,
-					 GdkRectangle    *area,
 					 GtkWidget       *widget,
 					 const gchar     *detail,
 					 gint             x,
@@ -2570,10 +2569,9 @@ get_darkened (const GdkColor *color,
 
 static void 
 gtk_default_draw_flat_box (GtkStyle      *style,
-                           GdkWindow     *window,
+                           cairo_t       *cr,
                            GtkStateType   state_type,
                            GtkShadowType  shadow_type,
-                           GdkRectangle  *area,
                            GtkWidget     *widget,
                            const gchar   *detail,
                            gint           x,
@@ -2581,22 +2579,11 @@ gtk_default_draw_flat_box (GtkStyle      *style,
                            gint           width,
                            gint           height)
 {
-  cairo_t *cr;
   GdkColor *gc1;
   GdkColor *freeme = NULL;
   
-  sanitize_size (window, &width, &height);
-  
-  cr = gdk_cairo_create (window);
-
   cairo_set_line_width (cr, 1.0);
 
-  if (area)
-    {
-      gdk_cairo_rectangle (cr, area);
-      cairo_clip (cr);
-    }
-
   if (detail)
     {
       if (state_type == GTK_STATE_SELECTED)
@@ -2757,8 +2744,7 @@ gtk_default_draw_flat_box (GtkStyle      *style,
   else
     gc1 = &style->bg[state_type];
   
-  if (!style->bg_pixmap[state_type] || gc1 != &style->bg[state_type] ||
-      GDK_IS_PIXMAP (window))
+  if (!style->bg_pixmap[state_type] || gc1 != &style->bg[state_type])
     {
       _cairo_draw_rectangle (cr, gc1, TRUE,
                              x, y, width, height);
@@ -2768,12 +2754,9 @@ gtk_default_draw_flat_box (GtkStyle      *style,
                                x, y, width - 1, height - 1);
     }
   else
-    gtk_style_apply_default_background (style, cr, window,
+    gtk_style_apply_default_background (style, cr, gtk_widget_get_window (widget),
                                         state_type, x, y, width, height);
 
-
-  cairo_destroy (cr);
-
   if (freeme)
     gdk_color_free (freeme);
 }
@@ -5250,13 +5233,65 @@ gtk_paint_flat_box (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_flat_box != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, window, state_type, shadow_type,
-                                              (GdkRectangle *) area, widget, detail,
+  sanitize_size (window, &width, &height);
+
+  cr = gtk_style_cairo_create (window, area);
+
+  gtk_cairo_paint_flat_box (style, cr, state_type, shadow_type,
+                            widget, detail,
+                            x, y, width, height);
+
+  cairo_destroy (cr);
+}
+
+/**
+ * gtk_cairo_paint_flat_box:
+ * @style: a #GtkStyle
+ * @cr: a #cairo_t
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @area: (allow-none): clip rectangle, or %NULL if the
+ *        output should not be clipped
+ * @widget: (allow-none): the widget
+ * @detail: (allow-none): a style detail
+ * @x: x origin of the box
+ * @y: y origin of the box
+ * @width: the width of the box
+ * @height: the height of the box
+ * 
+ * Draws a flat box on @cr with the given parameters.
+ */
+void
+gtk_cairo_paint_flat_box (GtkStyle           *style,
+                          cairo_t            *cr,
+                          GtkStateType        state_type,
+                          GtkShadowType       shadow_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_flat_box != 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_flat_box (style, cr, state_type, shadow_type,
+                                              widget, detail,
                                               x, y, width, height);
+
+  cairo_restore (cr);
 }
 
 /**
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index daf721c..b709681 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -224,10 +224,9 @@ struct _GtkStyleClass
 				 gint			 width,
 				 gint			 height);
   void (*draw_flat_box)		(GtkStyle		*style,
-				 GdkWindow		*window,
+				 cairo_t                *cr,
 				 GtkStateType		 state_type,
 				 GtkShadowType		 shadow_type,
-				 GdkRectangle		*area,
 				 GtkWidget		*widget,
 				 const gchar		*detail,
 				 gint			 x,
@@ -570,17 +569,27 @@ void gtk_cairo_paint_box         (GtkStyle           *style,
                                   gint                y,
                                   gint                width,
                                   gint                height);
-void gtk_paint_flat_box    (GtkStyle           *style,
-			    GdkWindow          *window,
-			    GtkStateType        state_type,
-			    GtkShadowType       shadow_type,
-			    const GdkRectangle *area,
-			    GtkWidget          *widget,
-			    const gchar        *detail,
-			    gint                x,
-			    gint                y,
-			    gint                width,
-			    gint                height);
+void gtk_paint_flat_box          (GtkStyle           *style,
+                                  GdkWindow          *window,
+                                  GtkStateType        state_type,
+                                  GtkShadowType       shadow_type,
+                                  const GdkRectangle *area,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  gint                x,
+                                  gint                y,
+                                  gint                width,
+                                  gint                height);
+void gtk_cairo_paint_flat_box    (GtkStyle           *style,
+                                  cairo_t            *cr,
+                                  GtkStateType        state_type,
+                                  GtkShadowType       shadow_type,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  gint                x,
+                                  gint                y,
+                                  gint                width,
+                                  gint                height);
 void gtk_paint_check       (GtkStyle           *style,
 			    GdkWindow          *window,
 			    GtkStateType        state_type,
diff --git a/modules/engines/pixbuf/pixbuf-draw.c b/modules/engines/pixbuf/pixbuf-draw.c
index ca16b6b..8002cea 100644
--- a/modules/engines/pixbuf/pixbuf-draw.c
+++ b/modules/engines/pixbuf/pixbuf-draw.c
@@ -665,10 +665,9 @@ draw_box (GtkStyle     *style,
 
 static void
 draw_flat_box (GtkStyle     *style,
-	       GdkWindow    *window,
+	       cairo_t      *cr,
 	       GtkStateType  state,
 	       GtkShadowType shadow,
-	       GdkRectangle *area,
 	       GtkWidget    *widget,
 	       const gchar  *detail,
 	       gint          x,
@@ -678,18 +677,15 @@ draw_flat_box (GtkStyle     *style,
 {
   ThemeMatchData match_data;
   
-  g_return_if_fail(style != NULL);
-  g_return_if_fail(window != NULL);
-
   match_data.function = TOKEN_D_FLAT_BOX;
   match_data.detail = (gchar *)detail;
   match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE;
   match_data.shadow = shadow;
   match_data.state = state;
 
-  if (!draw_simple_image_no_cairo (style, window, area, widget, &match_data, TRUE, TRUE,
+  if (!draw_simple_image (style, cr, widget, &match_data, TRUE, TRUE,
 			  x, y, width, height))
-    parent_class->draw_flat_box (style, window, state, shadow, area, widget, detail,
+    parent_class->draw_flat_box (style, cr, state, shadow, widget, detail,
 				 x, y, width, height);
 }
 



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