]> Pileus Git - ~andy/gtk/commitdiff
style: Convert draw_extension vfunc to Cairo version
authorBenjamin Otte <otte@redhat.com>
Mon, 16 Aug 2010 20:19:56 +0000 (22:19 +0200)
committerBenjamin Otte <otte@redhat.com>
Sun, 26 Sep 2010 13:02:58 +0000 (15:02 +0200)
gtk/gtkstyle.c
gtk/gtkstyle.h
modules/engines/pixbuf/pixbuf-draw.c

index 1d6c348aadf11eb53f4ac1872f73075fdf1fa76f..7e1b0ba408c9cf356620eae92638a67312327052 100644 (file)
@@ -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,
@@ -3440,10 +3439,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,
@@ -3452,21 +3450,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:
@@ -3506,7 +3495,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];
@@ -3607,8 +3595,6 @@ gtk_default_draw_extension (GtkStyle       *style,
           break;
         }
     }
-
-  cairo_destroy (cr);
 }
 
 static void 
@@ -5747,13 +5733,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);
 }
 
 /**
index dcc5cd3f93620418e314c56e1cd204cbb75ffe3e..c6268b74ddf1d2563424f76027957ca284fafa21 100644 (file)
@@ -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,
index d3f1c9c652334c1d5ae75b5183e581dd74a05ed8..b371986bc204570dd50a0df1ba8b238a2fd77f13 100644 (file)
@@ -790,10 +790,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,
@@ -804,9 +803,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;
@@ -814,9 +810,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);
 }