[gtk+/rendering-cleanup: 19/142] style: Convert draw_expander vfunc to Cairo version



commit c4e8acef8a2c25164bd2951207f9d879220bef3a
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 16 15:26:19 2010 +0200

    style: Convert draw_expander vfunc to Cairo version

 gtk/gtkstyle.c                       |   72 ++++++++++++++++++++++++++-------
 gtk/gtkstyle.h                       |   29 ++++++++-----
 modules/engines/pixbuf/pixbuf-draw.c |   10 +---
 3 files changed, 77 insertions(+), 34 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index 70c37c2..b270baf 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -267,9 +267,8 @@ static void gtk_default_draw_handle     (GtkStyle        *style,
 					 gint             height,
 					 GtkOrientation   orientation);
 static void gtk_default_draw_expander   (GtkStyle        *style,
-                                         GdkWindow       *window,
+                                         cairo_t         *cr,
                                          GtkStateType     state_type,
-                                         GdkRectangle    *area,
                                          GtkWidget       *widget,
                                          const gchar     *detail,
                                          gint             x,
@@ -3787,9 +3786,8 @@ gtk_default_draw_handle (GtkStyle      *style,
 
 static void
 gtk_default_draw_expander (GtkStyle        *style,
-                           GdkWindow       *window,
+                           cairo_t         *cr,
                            GtkStateType     state_type,
-                           GdkRectangle    *area,
                            GtkWidget       *widget,
                            const gchar     *detail,
                            gint             x,
@@ -3809,14 +3807,6 @@ gtk_default_draw_expander (GtkStyle        *style,
   double x_double, y_double;
   gint degrees = 0;
 
-  cairo_t *cr = gdk_cairo_create (window);
-  
-  if (area)
-    {
-      gdk_cairo_rectangle (cr, area);
-      cairo_clip (cr);
-    }
-
   if (widget &&
       gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
 					    "expander-size"))
@@ -3915,8 +3905,6 @@ gtk_default_draw_expander (GtkStyle        *style,
   
   gdk_cairo_set_source_color (cr, &style->fg[state_type]);
   cairo_stroke (cr);
-  
-  cairo_destroy (cr);
 }
 
 static void
@@ -6058,13 +6046,65 @@ gtk_paint_expander (GtkStyle           *style,
                     gint                y,
 		    GtkExpanderStyle    expander_style)
 {
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_expander (style, window, state_type,
-                                              (GdkRectangle *) area, widget, detail,
+  cr = gtk_style_cairo_create (window, area);
+
+  gtk_cairo_paint_expander (style, cr, state_type,
+                            widget, detail,
+                            x, y, expander_style);
+
+  cairo_destroy (cr);
+}
+
+/**
+ * gtk_cairo_paint_expander:
+ * @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 position to draw the expander at
+ * @y: the y position to draw the expander at
+ * @expander_style: the style to draw the expander in; determines
+ *   whether the expander is collapsed, expanded, or in an
+ *   intermediate state.
+ * 
+ * Draws an expander as used in #GtkTreeView. @x and @y specify the
+ * center the expander. The size of the expander is determined by the
+ * "expander-size" style property of @widget.  (If widget is not
+ * specified or doesn't have an "expander-size" property, an
+ * unspecified default size will be used, since the caller doesn't
+ * have sufficient information to position the expander, this is
+ * likely not useful.) The expander is expander_size pixels tall
+ * in the collapsed position and expander_size pixels wide in the
+ * expanded position.
+ **/
+void
+gtk_cairo_paint_expander (GtkStyle           *style,
+                          cairo_t            *cr,
+                          GtkStateType        state_type,
+                          GtkWidget          *widget,
+                          const gchar        *detail,
+                          gint                x,
+                          gint                y,
+                          GtkExpanderStyle    expander_style)
+{
+  g_return_if_fail (GTK_IS_STYLE (style));
+  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_expander != NULL);
+  g_return_if_fail (cr != NULL);
+
+  cairo_save (cr);
+
+  GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
+                                              widget, detail,
                                               x, y, expander_style);
+
+  cairo_restore (cr);
 }
 
 /**
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index f2ce942..f98fa5f 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -333,9 +333,8 @@ struct _GtkStyleClass
 				 GtkOrientation		 orientation);
 
   void (*draw_expander)		(GtkStyle		*style,
-				 GdkWindow		*window,
+				 cairo_t                *cr,
 				 GtkStateType		 state_type,
-				 GdkRectangle		*area,
 				 GtkWidget		*widget,
 				 const gchar		*detail,
 				 gint			 x,
@@ -786,15 +785,23 @@ void gtk_cairo_paint_handle      (GtkStyle           *style,
                                   gint                width,
                                   gint                height,
                                   GtkOrientation      orientation);
-void gtk_paint_expander    (GtkStyle           *style,
-                            GdkWindow          *window,
-                            GtkStateType        state_type,
-                            const GdkRectangle *area,
-                            GtkWidget          *widget,
-                            const gchar        *detail,
-                            gint                x,
-                            gint                y,
-			    GtkExpanderStyle    expander_style);
+void gtk_paint_expander          (GtkStyle           *style,
+                                  GdkWindow          *window,
+                                  GtkStateType        state_type,
+                                  const GdkRectangle *area,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  gint                x,
+                                  gint                y,
+                                  GtkExpanderStyle    expander_style);
+void gtk_cairo_paint_expander    (GtkStyle           *style,
+                                  cairo_t            *cr,
+                                  GtkStateType        state_type,
+                                  GtkWidget          *widget,
+                                  const gchar        *detail,
+                                  gint                x,
+                                  gint                y,
+                                  GtkExpanderStyle    expander_style);
 void gtk_paint_layout      (GtkStyle           *style,
                             GdkWindow          *window,
                             GtkStateType        state_type,
diff --git a/modules/engines/pixbuf/pixbuf-draw.c b/modules/engines/pixbuf/pixbuf-draw.c
index 39eee9f..d74f5e3 100644
--- a/modules/engines/pixbuf/pixbuf-draw.c
+++ b/modules/engines/pixbuf/pixbuf-draw.c
@@ -904,9 +904,8 @@ draw_handle (GtkStyle      *style,
 
 static void
 draw_expander (GtkStyle      *style,
-	       GdkWindow     *window,
+	       cairo_t       *cr,
 	       GtkStateType   state,
-	       GdkRectangle  *area,
 	       GtkWidget     *widget,
 	       const gchar   *detail,
 	       gint           x,
@@ -919,9 +918,6 @@ draw_expander (GtkStyle      *style,
   gint expander_size;
   gint radius;
   
-  g_return_if_fail (style != NULL);
-  g_return_if_fail (window != NULL);
-
   if (widget &&
       gtk_widget_class_find_style_property (GTK_WIDGET_GET_CLASS (widget),
                                             "expander-size"))
@@ -942,9 +938,9 @@ draw_expander (GtkStyle      *style,
   match_data.state = state;
   match_data.expander_style = expander_style;
 
-  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 - radius, y - radius, expander_size, expander_size))
-    parent_class->draw_expander (style, window, state, area, widget, detail,
+    parent_class->draw_expander (style, cr, state, widget, detail,
 				 x, y, expander_style);
 }
 



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