[gtk+/gtk-style-context: 82/206] GtkStyle: Use new render methods underneath.



commit b25558984c0e4eae992197a4aee06248f48d3d26
Author: Carlos Garnacho <carlosg gnome org>
Date:   Tue May 4 19:38:39 2010 +0200

    GtkStyle: Use new render methods underneath.
    
    This commit should probably be squashed in the future, when GtkStyleContext
    is on par with it, and GtkStyle is just a shallow object on top of
    GtkStyleContext and calling it in the default implementation methods, so
    all gtk_paint_* and gtk_draw_* would work.

 gtk/gtkstyle.c |  648 +++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 600 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index f836ab1..28db79d 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -4836,13 +4836,28 @@ gtk_paint_hline (GtkStyle           *style,
                  gint                x2,
                  gint                y)
 {
+  GtkStyleContext *context;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_hline (style, window, state_type,
-                                           (GdkRectangle *) area, widget, detail,
-                                           x1, x2, y);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_render_line (context, cr,
+                   x1, y, x2, y);
 }
 
 /**
@@ -4872,13 +4887,28 @@ gtk_paint_vline (GtkStyle           *style,
                  gint                y2_,
                  gint                x)
 {
+  GtkStyleContext *context;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_vline (style, window, state_type,
-                                           (GdkRectangle *) area, widget, detail,
-                                           y1_, y2_, x);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_render_line (context, cr,
+                   x, y1_, x, y2_);
 }
 
 /**
@@ -4912,13 +4942,44 @@ gtk_paint_shadow (GtkStyle           *style,
                   gint                width,
                   gint                height)
 {
+  GtkStyleContext *context;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_shadow (style, window, state_type, shadow_type,
-                                            (GdkRectangle *) area, widget, detail,
-                                            x, y, width, height);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  if (width < 0 || height < 0)
+    {
+      gint w_width, w_height;
+
+      gdk_drawable_get_size (GDK_DRAWABLE (window), &w_width, &w_height);
+
+      if (width < 0)
+        width = w_width;
+
+      if (height < 0)
+        height = w_height;
+    }
+
+  gtk_render_frame (context, cr,
+                    (gdouble) x,
+                    (gdouble) y,
+                    (gdouble) width,
+                    (gdouble) height);
 }
 
 /**
@@ -4956,13 +5017,61 @@ gtk_paint_arrow (GtkStyle           *style,
                  gint                width,
                  gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+  gdouble angle;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_arrow != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_arrow (style, window, state_type, shadow_type,
-                                           (GdkRectangle *) area, widget, detail,
-                                           arrow_type, fill, x, y, width, height);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  if (arrow_type == GTK_ARROW_UP)
+    angle = 0;
+  else if (arrow_type == GTK_ARROW_RIGHT)
+    angle = G_PI / 2;
+  else if (arrow_type == GTK_ARROW_DOWN)
+    angle = G_PI;
+  else
+    angle = 3 * (G_PI / 2);
+
+  switch (state_type)
+    {
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    case GTK_STATE_ACTIVE:
+      flags |= GTK_STATE_FLAG_ACTIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_arrow (context,
+                    cr, angle,
+                    (gdouble) x,
+                    (gdouble) y,
+                    MIN ((gdouble) width, (gdouble) height));
 }
 
 /**
@@ -5035,13 +5144,49 @@ gtk_paint_box (GtkStyle           *style,
                gint                width,
                gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  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,
-                                         x, y, width, height);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_ACTIVE:
+      flags |= GTK_STATE_FLAG_ACTIVE;
+      break;
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+
+  gtk_render_background (context, cr, x, y, width, height);
+  gtk_render_frame (context, cr, x, y, width, height);
 }
 
 /**
@@ -5074,13 +5219,48 @@ gtk_paint_flat_box (GtkStyle           *style,
                     gint                width,
                     gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  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,
-                                              x, y, width, height);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_background (context, cr,
+                         (gdouble) x,
+                         (gdouble) y,
+                         (gdouble) width,
+                         (gdouble) height);
 }
 
 /**
@@ -5114,13 +5294,51 @@ gtk_paint_check (GtkStyle           *style,
                  gint                width,
                  gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_check (style, window, state_type, shadow_type,
-                                           (GdkRectangle *) area, widget, detail,
-                                           x, y, width, height);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  if (shadow_type == GTK_SHADOW_IN)
+    flags |= GTK_STATE_FLAG_ACTIVE;
+  else if (shadow_type == GTK_SHADOW_ETCHED_IN)
+    flags |= GTK_STATE_FLAG_INCONSISTENT;
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_check (context,
+                    cr, x, y,
+                    width, height);
 }
 
 /**
@@ -5154,13 +5372,53 @@ gtk_paint_option (GtkStyle           *style,
                   gint                width,
                   gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_option (style, window, state_type, shadow_type,
-                                            (GdkRectangle *) area, widget, detail,
-                                            x, y, width, height);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  if (shadow_type == GTK_SHADOW_IN)
+    flags |= GTK_STATE_FLAG_ACTIVE;
+  else if (shadow_type == GTK_SHADOW_ETCHED_IN)
+    flags |= GTK_STATE_FLAG_INCONSISTENT;
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_option (context, cr,
+                     (gdouble) x,
+                     (gdouble) y,
+                     (gdouble) width,
+                     (gdouble) height);
 }
 
 /**
@@ -5241,13 +5499,54 @@ gtk_paint_shadow_gap (GtkStyle           *style,
                       gint                gap_x,
                       gint                gap_width)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow_gap != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, window, state_type, shadow_type,
-                                                (GdkRectangle *) area, widget, detail,
-                                                x, y, width, height, gap_side, gap_x, gap_width);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_ACTIVE:
+      flags |= GTK_STATE_ACTIVE;
+      break;
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_frame_gap (context, cr,
+                        (gdouble) x,
+                        (gdouble) y,
+                        (gdouble) width,
+                        (gdouble) height,
+                        gap_side,
+                        (gdouble) gap_x,
+                        (gdouble) gap_x + gap_width);
 }
 
 
@@ -5288,13 +5587,60 @@ gtk_paint_box_gap (GtkStyle           *style,
                    gint                gap_x,
                    gint                gap_width)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_box_gap != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, window, state_type, shadow_type,
-                                             (GdkRectangle *) area, widget, detail,
-                                             x, y, width, height, gap_side, gap_x, gap_width);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_ACTIVE:
+      flags |= GTK_STATE_ACTIVE;
+      break;
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_background (context, cr,
+                         (gdouble) x,
+                         (gdouble) y,
+                         (gdouble) width,
+                         (gdouble) height);
+
+  gtk_render_frame_gap (context, cr,
+                        (gdouble) x,
+                        (gdouble) y,
+                        (gdouble) width,
+                        (gdouble) height,
+                        gap_side,
+                        (gdouble) gap_x,
+                        (gdouble) gap_x + gap_width);
 }
 
 /**
@@ -5329,13 +5675,52 @@ gtk_paint_extension (GtkStyle           *style,
                      gint                height,
                      GtkPositionType     gap_side)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  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,
-                                               x, y, width, height, gap_side);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_ACTIVE:
+      flags |= GTK_STATE_ACTIVE;
+      break;
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_extension (context, cr,
+                        (gdouble) x,
+                        (gdouble) y,
+                        (gdouble) width,
+                        (gdouble) height,
+                        gap_side);
 }
 
 /**
@@ -5367,13 +5752,32 @@ gtk_paint_focus (GtkStyle           *style,
                  gint                width,
                  gint                height)
 {
+  GtkStyleContext *context;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
+  g_return_if_fail (!widget || GTK_IS_WIDGET (widget));
+
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
 
-  GTK_STYLE_GET_CLASS (style)->draw_focus (style, window, state_type,
-                                           (GdkRectangle *) area, widget, detail,
-                                           x, y, width, height);
+  gtk_render_focus (context, cr,
+                    (gdouble) x,
+                    (gdouble) y,
+                    (gdouble) width,
+                    (gdouble) height);
 }
 
 /**
@@ -5409,13 +5813,47 @@ gtk_paint_slider (GtkStyle           *style,
                   gint                height,
                   GtkOrientation      orientation)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_slider (style, window, state_type, shadow_type,
-                                            (GdkRectangle *) area, widget, detail,
-                                            x, y, width, height, orientation);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_ACTIVE:
+      flags |= GTK_STATE_FLAG_ACTIVE;
+      break;
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_slider (context, cr,  x, y, width, height, orientation);
 }
 
 /**
@@ -5450,13 +5888,49 @@ gtk_paint_handle (GtkStyle           *style,
                   gint                height,
                   GtkOrientation      orientation)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_handle (style, window, state_type, shadow_type,
-                                            (GdkRectangle *) area, widget, detail,
-                                            x, y, width, height, orientation);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_handle (context, cr,
+                     (gdouble) x,
+                     (gdouble) y,
+                     (gdouble) width,
+                     (gdouble) height,
+                     orientation);
 }
 
 /**
@@ -5495,13 +5969,57 @@ gtk_paint_expander (GtkStyle           *style,
                     gint                y,
 		    GtkExpanderStyle    expander_style)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+  gint size;
+
   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,
-                                              x, y, expander_style);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  if (widget)
+    gtk_widget_style_get (widget, "expander-size", &size, NULL);
+  else
+    size = 10;
+
+  if (expander_style == GTK_EXPANDER_EXPANDED)
+    flags |= GTK_STATE_FLAG_ACTIVE;
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_expander (context, cr,
+                       (gdouble) x - (size / 2),
+                       (gdouble) y - (size / 2),
+                       (gdouble) size,
+                       (gdouble) size);
 }
 
 /**
@@ -5533,13 +6051,47 @@ gtk_paint_layout (GtkStyle           *style,
                   gint                y,
                   PangoLayout        *layout)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  cairo_t *cr;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
   g_return_if_fail (style->depth == gdk_drawable_get_depth (window));
 
-  GTK_STYLE_GET_CLASS (style)->draw_layout (style, window, state_type, use_text,
-                                            (GdkRectangle *) area, widget, detail,
-                                            x, y, layout);
+  if (!widget)
+    {
+      gpointer window_data;
+
+      gdk_window_get_user_data (window, &window_data);
+      widget = window_data;
+
+      g_return_if_fail (GTK_IS_WIDGET (widget));
+    }
+
+  cr = gdk_cairo_create (window);
+  context = gtk_widget_get_style_context (widget);
+
+  switch (state_type)
+    {
+    case GTK_STATE_PRELIGHT:
+      flags |= GTK_STATE_FLAG_PRELIGHT;
+      break;
+    case GTK_STATE_SELECTED:
+      flags |= GTK_STATE_FLAG_SELECTED;
+      break;
+    case GTK_STATE_INSENSITIVE:
+      flags |= GTK_STATE_FLAG_INSENSITIVE;
+      break;
+    default:
+      break;
+    }
+
+  gtk_style_context_set_state (context, flags);
+  gtk_render_layout (context, cr,
+                     (gdouble) x,
+                     (gdouble) y,
+                     layout);
 }
 
 /**



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