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



commit 9321ee69e2ec87134c7e49266f1da48124ef9ff1
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 16 22:19:56 2010 +0200

    style: Convert draw_extension vfunc to Cairo version

 gtk/gtkstyle.c                       |   76 +++++++++++++++++++++++++--------
 gtk/gtkstyle.h                       |   38 +++++++++++------
 modules/engines/pixbuf/pixbuf-draw.c |   10 +---
 3 files changed, 84 insertions(+), 40 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index fe4ec99..9990bda 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -225,10 +225,9 @@ static void gtk_default_draw_box_gap    (GtkStyle        *style,
 					 gint             gap_x,
 					 gint             gap_width);
 static void gtk_default_draw_extension  (GtkStyle        *style,
-					 GdkWindow       *window,
+					 cairo_t         *cr,
 					 GtkStateType     state_type,
 					 GtkShadowType    shadow_type,
-					 GdkRectangle    *area,
 					 GtkWidget       *widget,
 					 const gchar     *detail,
 					 gint             x,
@@ -3426,10 +3425,9 @@ gtk_default_draw_box_gap (GtkStyle       *style,
 
 static void 
 gtk_default_draw_extension (GtkStyle       *style,
-                            GdkWindow      *window,
+                            cairo_t        *cr,
                             GtkStateType    state_type,
                             GtkShadowType   shadow_type,
-                            GdkRectangle   *area,
                             GtkWidget      *widget,
                             const gchar    *detail,
                             gint            x,
@@ -3438,21 +3436,12 @@ gtk_default_draw_extension (GtkStyle       *style,
                             gint            height,
                             GtkPositionType gap_side)
 {
-  cairo_t *cr;
+  GdkWindow *window = gtk_widget_get_window (widget);
   GdkColor color1;
   GdkColor color2;
   GdkColor color3;
   GdkColor color4;
   
-  sanitize_size (window, &width, &height);
-
-  cr = gdk_cairo_create (window);
-  if (area)
-    {
-      gdk_cairo_rectangle (cr, area);
-      cairo_clip (cr);
-    }
-  
   switch (gap_side)
     {
     case GTK_POS_TOP:
@@ -3492,7 +3481,6 @@ gtk_default_draw_extension (GtkStyle       *style,
   switch (shadow_type)
     {
     case GTK_SHADOW_NONE:
-      cairo_destroy (cr);
       return;
     case GTK_SHADOW_IN:
       color1 = style->dark[state_type];
@@ -3593,8 +3581,6 @@ gtk_default_draw_extension (GtkStyle       *style,
           break;
         }
     }
-
-  cairo_destroy (cr);
 }
 
 static void 
@@ -5732,13 +5718,65 @@ gtk_paint_extension (GtkStyle           *style,
                      gint                height,
                      GtkPositionType     gap_side)
 {
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_extension (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_extension (style, cr, state_type, shadow_type,
+                             widget, detail,
+                             x, y, width, height, gap_side);
+
+  cairo_destroy (cr);
+}
+
+/**
+ * gtk_cairo_paint_extension: 
+ * @style: a #GtkStyle
+ * @cr: a #cairo_t
+ * @state_type: a state
+ * @shadow_type: type of shadow to draw
+ * @widget: (allow-none): the widget
+ * @detail: (allow-none): a style detail
+ * @x: x origin of the extension
+ * @y: y origin of the extension
+ * @width: width of the extension
+ * @height: width of the extension
+ * @gap_side: the side on to which the extension is attached
+ * 
+ * Draws an extension, i.e. a notebook tab.
+ **/
+void
+gtk_cairo_paint_extension (GtkStyle           *style,
+                           cairo_t            *cr,
+                           GtkStateType        state_type,
+                           GtkShadowType       shadow_type,
+                           GtkWidget          *widget,
+                           const gchar        *detail,
+                           gint                x,
+                           gint                y,
+                           gint                width,
+                           gint                height,
+                           GtkPositionType     gap_side)
+{
+  g_return_if_fail (GTK_IS_STYLE (style));
+  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_extension != 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_extension (style, cr, state_type, shadow_type,
+                                               widget, detail,
                                                x, y, width, height, gap_side);
+
+  cairo_restore (cr);
 }
 
 /**
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 6f1df84..449dc0e 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -290,10 +290,9 @@ struct _GtkStyleClass
 				 gint			 gap_x,
 				 gint			 gap_width);
   void (*draw_extension)	(GtkStyle		*style,
-				 GdkWindow		*window,
+				 cairo_t                *cr,
 				 GtkStateType		 state_type,
 				 GtkShadowType		 shadow_type,
-				 GdkRectangle		*area,
 				 GtkWidget		*widget,
 				 const gchar		*detail,
 				 gint			 x,
@@ -702,18 +701,29 @@ void gtk_cairo_paint_box_gap     (GtkStyle           *style,
                                   GtkPositionType     gap_side,
                                   gint                gap_x,
                                   gint                gap_width);
-void gtk_paint_extension   (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,
-			    GtkPositionType     gap_side);
+void gtk_paint_extension         (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,
+                                  GtkPositionType     gap_side);
+void gtk_cairo_paint_extension   (GtkStyle           *style,
+                                  cairo_t            *cr,
+                                  GtkStateType        state_type,
+                                  GtkShadowType       shadow_type,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  gint                x,
+                                  gint                y,
+                                  gint                width,
+                                  gint                height,
+                                  GtkPositionType     gap_side);
 void gtk_paint_focus       (GtkStyle           *style,
 			    GdkWindow          *window,
 			    GtkStateType        state_type,
diff --git a/modules/engines/pixbuf/pixbuf-draw.c b/modules/engines/pixbuf/pixbuf-draw.c
index 12533be..51bd695 100644
--- a/modules/engines/pixbuf/pixbuf-draw.c
+++ b/modules/engines/pixbuf/pixbuf-draw.c
@@ -792,10 +792,9 @@ draw_box_gap (GtkStyle       *style,
 
 static void
 draw_extension (GtkStyle       *style,
-		GdkWindow      *window,
+		cairo_t        *cr,
 		GtkStateType    state,
 		GtkShadowType   shadow,
-		GdkRectangle   *area,
 		GtkWidget      *widget,
 		const gchar    *detail,
 		gint            x,
@@ -806,9 +805,6 @@ draw_extension (GtkStyle       *style,
 {
   ThemeMatchData match_data;
   
-  g_return_if_fail (style != NULL);
-  g_return_if_fail (window != NULL);
-
   match_data.function = TOKEN_D_EXTENSION;
   match_data.detail = (gchar *)detail;
   match_data.flags = THEME_MATCH_SHADOW | THEME_MATCH_STATE | THEME_MATCH_GAP_SIDE;
@@ -816,9 +812,9 @@ draw_extension (GtkStyle       *style,
   match_data.state = state;
   match_data.gap_side = gap_side;
 
-  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_extension (style, window, state, shadow, area, widget, detail,
+    parent_class->draw_extension (style, cr, state, shadow, widget, detail,
 				  x, y, width, height, gap_side);
 }
 



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