[gtk+/cairo-style: 7/21] style: Convert draw_box vfunc to Cairo version



commit 1713e756d784931ab000a6bd2d725be26513bd1a
Author: Benjamin Otte <otte redhat com>
Date:   Tue Aug 17 00:57:21 2010 +0200

    style: Convert draw_box vfunc to Cairo version

 gtk/gtkstyle.c |   99 ++++++++++++++++++++++++++++++++++---------------------
 gtk/gtkstyle.h |   35 ++++++++++++-------
 2 files changed, 83 insertions(+), 51 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index ce0d10d..2491d47 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -149,10 +149,9 @@ static void gtk_default_draw_diamond    (GtkStyle        *style,
 					 gint             width,
 					 gint             height);
 static void gtk_default_draw_box        (GtkStyle        *style,
-					 GdkWindow       *window,
+					 cairo_t         *cr,
 					 GtkStateType     state_type,
 					 GtkShadowType    shadow_type,
-					 GdkRectangle    *area,
 					 GtkWidget       *widget,
 					 const gchar     *detail,
 					 gint             x,
@@ -2452,10 +2451,9 @@ option_menu_get_props (GtkWidget      *widget,
 
 static void 
 gtk_default_draw_box (GtkStyle      *style,
-		      GdkWindow     *window,
+		      cairo_t       *cr,
 		      GtkStateType   state_type,
 		      GtkShadowType  shadow_type,
-		      GdkRectangle  *area,
 		      GtkWidget     *widget,
 		      const gchar   *detail,
 		      gint           x,
@@ -2463,11 +2461,8 @@ gtk_default_draw_box (GtkStyle      *style,
 		      gint           width,
 		      gint           height)
 {
-  cairo_t *cr;
   gboolean is_spinbutton_box = FALSE;
   
-  sanitize_size (window, &width, &height);
-
   if (GTK_IS_SPIN_BUTTON (widget) && detail)
     {
       if (strcmp (detail, "spinbutton_up") == 0)
@@ -2497,16 +2492,7 @@ gtk_default_draw_box (GtkStyle      *style,
 	}
     }
   
-  cr = gdk_cairo_create (window);
-
-  if (area)
-    {
-      gdk_cairo_rectangle (cr, area);
-      cairo_clip (cr);
-    }
-
-  if (!style->bg_pixmap[state_type] || 
-      GDK_IS_PIXMAP (window))
+  if (!style->bg_pixmap[state_type])
     {
       GdkColor *gc = &style->bg[state_type];
 
@@ -2520,7 +2506,7 @@ gtk_default_draw_box (GtkStyle      *style,
                              x, y, width, height);
     }
   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);
 
 
@@ -2535,23 +2521,14 @@ gtk_default_draw_box (GtkStyle      *style,
       else
 	upper = &style->dark[state_type];
 
-      if (area)
-	{
-          gdk_cairo_rectangle (cr, area);
-          cairo_clip (cr);
-	}
-      
       _cairo_draw_line (cr, upper, x, y, x + width - 1, y);
       _cairo_draw_line (cr, lower, x, y + height - 1, x + width - 1, y + height - 1);
 
-      cairo_destroy (cr);
       return;
     }
 
-  cairo_destroy (cr);
-
-  gtk_paint_shadow (style, window, state_type, shadow_type, area, widget, detail,
-                    x, y, width, height);
+  gtk_cairo_paint_shadow (style, cr, state_type, shadow_type, widget, detail,
+                          x, y, width, height);
 
   if (detail && strcmp (detail, "optionmenu") == 0)
     {
@@ -2561,18 +2538,16 @@ gtk_default_draw_box (GtkStyle      *style,
 
       option_menu_get_props (widget, &indicator_size, &indicator_spacing);
 
-      sanitize_size (window, &width, &height);
-
       if (get_direction (widget) == GTK_TEXT_DIR_RTL)
 	vline_x = x + indicator_size.width + indicator_spacing.left + indicator_spacing.right;
       else 
 	vline_x = x + width - (indicator_size.width + indicator_spacing.left + indicator_spacing.right) - style->xthickness;
 
-      gtk_paint_vline (style, window, state_type, area, widget,
-		       detail,
-		       y + style->ythickness + 1,
-		       y + height - style->ythickness - 3,
-		       vline_x);
+      gtk_cairo_paint_vline (style, cr, state_type, widget,
+                             detail,
+                             y + style->ythickness + 1,
+                             y + height - style->ythickness - 3,
+                             vline_x);
     }
 }
 
@@ -5188,13 +5163,61 @@ gtk_paint_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_box != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_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_box (style, cr, state_type, shadow_type,
+                       widget, detail,
+                       x, y, width, height);
+
+  cairo_destroy (cr);
+}
+
+/**
+ * gtk_cairo_paint_box:
+ * @style: a #GtkStyle
+ * @cr: a #cairo_t
+ * @state_type: a state
+ * @shadow_type: the type of shadow to draw
+ * @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 box on @cr with the given parameters.
+ */
+void
+gtk_cairo_paint_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_box != NULL);
+  g_return_if_fail (cr != NULL);
+
+  cairo_save (cr);
+
+  GTK_STYLE_GET_CLASS (style)->draw_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 898db38..daf721c 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -214,10 +214,9 @@ struct _GtkStyleClass
 				 gint			 width,
 				 gint			 height);
   void (*draw_box)		(GtkStyle		*style,
-				 GdkWindow		*window,
+				 cairo_t                *cr,
 				 GtkStateType		 state_type,
 				 GtkShadowType		 shadow_type,
-				 GdkRectangle		*area,
 				 GtkWidget		*widget,
 				 const gchar		*detail,
 				 gint			 x,
@@ -550,17 +549,27 @@ void gtk_cairo_paint_diamond     (GtkStyle           *style,
                                   gint                y,
                                   gint                width,
                                   gint                height);
-void gtk_paint_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_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_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_flat_box    (GtkStyle           *style,
 			    GdkWindow          *window,
 			    GtkStateType        state_type,



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