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



commit 6efcd11d9faedc405d95dc35ff98ce53b5f0124e
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 |  473 +++++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 403 insertions(+), 70 deletions(-)
---
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index a5566e2..0dc5387 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -4528,16 +4528,15 @@ gtk_paint_hline (GtkStyle           *style,
                  gint                x2,
                  gint                y)
 {
+  GtkStyleContext *context;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (cr != NULL);
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_hline != NULL);
-
-  cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_hline (style, cr, state_type,
-                                           widget, detail,
-                                           x1, x2, y);
+  context = gtk_widget_get_style_context (widget);
 
+  cairo_save (cr);
+  gtk_render_line (context, cr, x1, y, x2, y);
   cairo_restore (cr);
 }
 
@@ -4565,16 +4564,15 @@ gtk_paint_vline (GtkStyle           *style,
                  gint                y2_,
                  gint                x)
 {
+  GtkStyleContext *context;
+
   g_return_if_fail (GTK_IS_STYLE (style));
   g_return_if_fail (cr != NULL);
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_vline != NULL);
 
-  cairo_save (cr);
-
-  GTK_STYLE_GET_CLASS (style)->draw_vline (style, cr, state_type,
-                                           widget, detail,
-                                           y1_, y2_, x);
+  context = gtk_widget_get_style_context (widget);
 
+  cairo_save (cr);
+  gtk_render_line (context, cr, x, y1_, x, y2_);
   cairo_restore (cr);
 }
 
@@ -4606,18 +4604,34 @@ gtk_paint_shadow (GtkStyle           *style,
                   gint                width,
                   gint                height)
 {
+  GtkStyleContext *context;
+
   g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_shadow != NULL);
   g_return_if_fail (cr != NULL);
   g_return_if_fail (width >= 0);
   g_return_if_fail (height >= 0);
 
-  cairo_save (cr);
+  context = gtk_widget_get_style_context (widget);
 
-  GTK_STYLE_GET_CLASS (style)->draw_shadow (style, cr, state_type, shadow_type,
-                                            widget, detail,
-                                            x, y, width, height);
+  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;
+    }
 
+  cairo_save (cr);
+  gtk_render_frame (context, cr,
+                    (gdouble) x,
+                    (gdouble) y,
+                    (gdouble) width,
+                    (gdouble) height);
   cairo_restore (cr);
 }
 
@@ -4653,17 +4667,52 @@ gtk_paint_arrow (GtkStyle           *style,
                  gint                width,
                  gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  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 (cr != NULL);
   g_return_if_fail (width >= 0);
   g_return_if_fail (height >= 0);
 
+  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;
+    }
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_arrow (style, cr, state_type, shadow_type,
-                                           widget, detail,
-                                           arrow_type, fill, x, y, width, height);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_arrow (context,
+                    cr, angle,
+                    (gdouble) x,
+                    (gdouble) y,
+                    MIN ((gdouble) width, (gdouble) height));
 
   cairo_restore (cr);
 }
@@ -4738,16 +4787,37 @@ gtk_paint_box (GtkStyle           *style,
                gint                width,
                gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   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);
+  context = gtk_widget_get_style_context (widget);
 
-  GTK_STYLE_GET_CLASS (style)->draw_box (style, cr, state_type, shadow_type,
-                                         widget, detail,
-                                         x, y, width, height);
+  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);
 
+  cairo_save (cr);
+  gtk_render_background (context, cr, x, y, width, height);
+  gtk_render_frame (context, cr, x, y, width, height);
   cairo_restore (cr);
 }
 
@@ -4780,17 +4850,39 @@ gtk_paint_flat_box (GtkStyle           *style,
                     gint                width,
                     gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   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 (cr != NULL);
   g_return_if_fail (width >= 0);
   g_return_if_fail (height >= 0);
 
+  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;
+    }
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_flat_box (style, cr, state_type, shadow_type,
-                                              widget, detail,
-                                              x, y, width, height);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_background (context, cr,
+                         (gdouble) x,
+                         (gdouble) y,
+                         (gdouble) width,
+                         (gdouble) height);
 
   cairo_restore (cr);
 }
@@ -4823,15 +4915,40 @@ gtk_paint_check (GtkStyle           *style,
                  gint                width,
                  gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_check != NULL);
   g_return_if_fail (cr != NULL);
 
+  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;
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_check (style, cr, state_type, shadow_type,
-                                           widget, detail,
-                                           x, y, width, height);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_check (context,
+                    cr, x, y,
+                    width, height);
 
   cairo_restore (cr);
 }
@@ -4864,15 +4981,42 @@ gtk_paint_option (GtkStyle           *style,
                   gint                width,
                   gint                height)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_option != NULL);
   g_return_if_fail (cr != NULL);
 
+  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;
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_option (style, cr, state_type, shadow_type,
-                                            widget, detail,
-                                            x, y, width, height);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_option (context, cr,
+                     (gdouble) x,
+                     (gdouble) y,
+                     (gdouble) width,
+                     (gdouble) height);
 
   cairo_restore (cr);
 }
@@ -4953,17 +5097,45 @@ gtk_paint_shadow_gap (GtkStyle           *style,
                       gint                gap_x,
                       gint                gap_width)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   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 (cr != NULL);
   g_return_if_fail (width >= 0);
   g_return_if_fail (height >= 0);
 
+  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;
+    }
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_shadow_gap (style, cr, state_type, shadow_type,
-                                                widget, detail,
-                                                x, y, width, height, gap_side, gap_x, gap_width);
+  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);
 
   cairo_restore (cr);
 }
@@ -5002,17 +5174,51 @@ gtk_paint_box_gap (GtkStyle           *style,
                    gint                gap_x,
                    gint                gap_width)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   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 (cr != NULL);
   g_return_if_fail (width >= 0);
   g_return_if_fail (height >= 0);
 
+  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;
+    }
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_box_gap (style, cr, state_type, shadow_type,
-                                             widget, detail,
-                                             x, y, width, height, gap_side, gap_x, gap_width);
+  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);
 
   cairo_restore (cr);
 }
@@ -5046,17 +5252,43 @@ gtk_paint_extension (GtkStyle           *style,
                      gint                height,
                      GtkPositionType     gap_side)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   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);
 
+  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;
+    }
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_extension (style, cr, state_type, shadow_type,
-                                               widget, detail,
-                                               x, y, width, height, gap_side);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_extension (context, cr,
+                        (gdouble) x,
+                        (gdouble) y,
+                        (gdouble) width,
+                        (gdouble) height,
+                        gap_side);
 
   cairo_restore (cr);
 }
@@ -5087,17 +5319,22 @@ gtk_paint_focus (GtkStyle           *style,
                  gint                width,
                  gint                height)
 {
+  GtkStyleContext *context;
+
   g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_focus != 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_focus (style, cr, state_type,
-                                           widget, detail,
-                                           x, y, width, height);
+  context = gtk_widget_get_style_context (widget);
+
+  gtk_render_focus (context, cr,
+                    (gdouble) x,
+                    (gdouble) y,
+                    (gdouble) width,
+                    (gdouble) height);
 
   cairo_restore (cr);
 }
@@ -5132,17 +5369,38 @@ gtk_paint_slider (GtkStyle           *style,
                   gint                height,
                   GtkOrientation      orientation)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_slider != NULL);
   g_return_if_fail (cr != NULL);
   g_return_if_fail (width >= 0);
   g_return_if_fail (height >= 0);
 
+  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;
+    }
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_slider (style, cr, state_type, shadow_type,
-                                            widget, detail,
-                                            x, y, width, height, orientation);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_slider (context, cr,  x, y, width, height, orientation);
 
   cairo_restore (cr);
 }
@@ -5176,17 +5434,40 @@ gtk_paint_handle (GtkStyle           *style,
                   gint                height,
                   GtkOrientation      orientation)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_handle != NULL);
   g_return_if_fail (cr != NULL);
   g_return_if_fail (width >= 0);
   g_return_if_fail (height >= 0);
 
+  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;
+    }
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_handle (style, cr, state_type, shadow_type,
-                                            widget, detail,
-                                            x, y, width, height, orientation);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_handle (context, cr,
+                     (gdouble) x,
+                     (gdouble) y,
+                     (gdouble) width,
+                     (gdouble) height,
+                     orientation);
 
   cairo_restore (cr);
 }
@@ -5224,15 +5505,46 @@ gtk_paint_expander (GtkStyle           *style,
                     gint                y,
                     GtkExpanderStyle    expander_style)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+  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 (cr != NULL);
 
+  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;
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_expander (style, cr, state_type,
-                                              widget, detail,
-                                              x, y, expander_style);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_expander (context, cr,
+                       (gdouble) x - (size / 2),
+                       (gdouble) y - (size / 2),
+                       (gdouble) size,
+                       (gdouble) size);
 
   cairo_restore (cr);
 }
@@ -5263,15 +5575,36 @@ gtk_paint_layout (GtkStyle           *style,
                   gint                y,
                   PangoLayout        *layout)
 {
+  GtkStyleContext *context;
+  GtkStateFlags flags = 0;
+
   g_return_if_fail (GTK_IS_STYLE (style));
-  g_return_if_fail (GTK_STYLE_GET_CLASS (style)->draw_layout != NULL);
   g_return_if_fail (cr != NULL);
 
+  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;
+    }
+
   cairo_save (cr);
 
-  GTK_STYLE_GET_CLASS (style)->draw_layout (style, cr, state_type, use_text,
-                                            widget, detail,
-                                            x, y, layout);
+  gtk_style_context_set_state (context, flags);
+  gtk_render_layout (context, cr,
+                     (gdouble) x,
+                     (gdouble) y,
+                     layout);
 
   cairo_restore (cr);
 }



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