[gimp/gtk3-port: 145/246] libgimpwidgets: port GimpRuler to GtkStyleContext



commit 2d7704c03e4c0e91f8981321d4406c3e6855e80a
Author: Michael Natterer <mitch gimp org>
Date:   Thu Dec 16 22:12:09 2010 +0100

    libgimpwidgets: port GimpRuler to GtkStyleContext

 libgimpwidgets/gimpruler.c |  141 +++++++++++++++++---------------------------
 1 files changed, 54 insertions(+), 87 deletions(-)
---
diff --git a/libgimpwidgets/gimpruler.c b/libgimpwidgets/gimpruler.c
index 5fc7a6c..ba3596a 100644
--- a/libgimpwidgets/gimpruler.c
+++ b/libgimpwidgets/gimpruler.c
@@ -754,9 +754,8 @@ gimp_ruler_realize (GtkWidget *widget)
   gdk_window_set_user_data (gtk_widget_get_window (widget), ruler);
 
   gtk_widget_style_attach (widget);
-  gtk_style_set_background (gtk_widget_get_style (widget),
-                            gtk_widget_get_window (widget),
-                            GTK_STATE_ACTIVE);
+  gtk_style_context_set_background (gtk_widget_get_style_context (widget),
+                                    gtk_widget_get_window (widget));
 
   gimp_ruler_make_pixmap (ruler);
 }
@@ -812,10 +811,11 @@ static void
 gimp_ruler_size_request (GtkWidget      *widget,
                          GtkRequisition *requisition)
 {
-  GimpRulerPrivate *priv  = GIMP_RULER_GET_PRIVATE (widget);
-  GtkStyle         *style = gtk_widget_get_style (widget);
+  GimpRulerPrivate *priv    = GIMP_RULER_GET_PRIVATE (widget);
+  GtkStyleContext  *context = gtk_widget_get_style_context (widget);
   PangoLayout      *layout;
   PangoRectangle    ink_rect;
+  GtkBorder         border;
   gint              size;
 
   layout = gimp_ruler_get_layout (widget, "0123456789");
@@ -823,15 +823,20 @@ gimp_ruler_size_request (GtkWidget      *widget,
 
   size = 2 + ink_rect.height * 1.7;
 
+  gtk_style_context_get_border (context, 0, &border);
+
+  requisition->width  = border.left + border.right;
+  requisition->height = border.top + border.bottom;
+
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
-      requisition->width  = style->xthickness * 2 + 1;
-      requisition->height = style->ythickness * 2 + size;
+      requisition->width  += 1;
+      requisition->height += size;
     }
   else
     {
-      requisition->width  = style->xthickness * 2 + size;
-      requisition->height = style->ythickness * 2 + 1;
+      requisition->width  += size;
+      requisition->height += 1;
     }
 }
 
@@ -911,16 +916,15 @@ gimp_ruler_draw (GtkWidget *widget,
 static void
 gimp_ruler_draw_ticks (GimpRuler *ruler)
 {
-  GtkWidget        *widget = GTK_WIDGET (ruler);
-  GtkStyle         *style  = gtk_widget_get_style (widget);
-  GimpRulerPrivate *priv   = GIMP_RULER_GET_PRIVATE (ruler);
-  GtkStateType      state  = gtk_widget_get_state (widget);
+  GtkWidget        *widget  = GTK_WIDGET (ruler);
+  GtkStyleContext  *context = gtk_widget_get_style_context (widget);
+  GimpRulerPrivate *priv    = GIMP_RULER_GET_PRIVATE (ruler);
   GtkAllocation     allocation;
+  GtkBorder         border;
+  GdkRGBA           color;
   cairo_t          *cr;
   gint              i;
   gint              width, height;
-  gint              xthickness;
-  gint              ythickness;
   gint              length, ideal_length;
   gdouble           lower, upper;  /* Upper and lower limits, in ruler units */
   gdouble           increment;     /* Number of pixels per unit */
@@ -940,9 +944,7 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
     return;
 
   gtk_widget_get_allocation (widget, &allocation);
-
-  xthickness = style->xthickness;
-  ythickness = style->ythickness;
+  gtk_style_context_get_border (context, 0, &border);
 
   layout = gimp_ruler_get_layout (widget, "0123456789");
   pango_layout_get_extents (layout, &ink_rect, &logical_rect);
@@ -953,46 +955,38 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       width  = allocation.width;
-      height = allocation.height - ythickness * 2;
+      height = allocation.height - (border.top + border.bottom);
     }
   else
     {
       width  = allocation.height;
-      height = allocation.width - ythickness * 2;
+      height = allocation.width - (border.top + border.bottom);
     }
 
   cr = cairo_create (priv->backing_store);
-  gdk_cairo_set_source_color (cr, &style->bg[state]);
-
-#if 0
-  gtk_paint_box (style, priv->backing_store,
-                 GTK_STATE_NORMAL, GTK_SHADOW_OUT,
-                 NULL, widget,
-                 priv->orientation == GTK_ORIENTATION_HORIZONTAL ?
-                 "hruler" : "vruler",
-                 0, 0,
-                 allocation.width, allocation.height);
-#else
-  cairo_paint (cr);
-#endif
 
-  gdk_cairo_set_source_color (cr, &style->fg[state]);
+  gtk_render_background (context, cr, 0, 0, allocation.width, allocation.height);
+  gtk_render_frame (context, cr, 0, 0, allocation.width, allocation.height);
+
+  gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget),
+                               &color);
+  gdk_cairo_set_source_rgba (cr, &color);
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       cairo_rectangle (cr,
-                       xthickness,
-                       height + ythickness,
-                       allocation.width - 2 * xthickness,
+                       border.left,
+                       height + border.top,
+                       allocation.width - (border.left + border.right),
                        1);
     }
   else
     {
       cairo_rectangle (cr,
-                       height + xthickness,
-                       ythickness,
+                       height + border.left,
+                       border.top,
                        1,
-                       allocation.height - 2 * ythickness);
+                       allocation.height - (border.top + border.bottom));
     }
 
   gimp_ruler_get_range (ruler, &lower, &upper, &max_size);
@@ -1070,14 +1064,14 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
           if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
             {
               cairo_rectangle (cr,
-                               pos, height + ythickness - length,
+                               pos, height + border.top - length,
                                1,   length);
             }
           else
             {
               cairo_rectangle (cr,
-                               height + xthickness - length, pos,
-                               length,                       1);
+                               height + border.left - length, pos,
+                               length,                        1);
             }
 
           /* draw label */
@@ -1090,23 +1084,10 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
                   pango_layout_set_text (layout, unit_str, -1);
                   pango_layout_get_extents (layout, &logical_rect, NULL);
 
-#if 0
-                  gtk_paint_layout (style,
-                                    priv->backing_store,
-                                    state,
-                                    FALSE,
-                                    NULL,
-                                    widget,
-                                    "hruler",
-                                    pos + 2,
-                                    ythickness + PANGO_PIXELS (logical_rect.y - digit_offset),
-                                    layout);
-#else
                   cairo_move_to (cr,
                                  pos + 2,
-                                 ythickness + PANGO_PIXELS (logical_rect.y - digit_offset));
+                                 border.top + PANGO_PIXELS (logical_rect.y - digit_offset));
                   pango_cairo_show_layout (cr, layout);
-#endif
                 }
               else
                 {
@@ -1117,23 +1098,10 @@ gimp_ruler_draw_ticks (GimpRuler *ruler)
                       pango_layout_set_text (layout, unit_str + j, 1);
                       pango_layout_get_extents (layout, NULL, &logical_rect);
 
-#if 0
-                      gtk_paint_layout (style,
-                                        priv->backing_store,
-                                        state,
-                                        FALSE,
-                                        NULL,
-                                        widget,
-                                        "vruler",
-                                        xthickness + 1,
-                                        pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset),
-                                        layout);
-#else
                       cairo_move_to (cr,
-                                     xthickness + 1,
+                                     border.left + 1,
                                      pos + digit_height * j + 2 + PANGO_PIXELS (logical_rect.y - digit_offset));
                       pango_cairo_show_layout (cr, layout);
-#endif
                     }
                 }
             }
@@ -1148,29 +1116,26 @@ out:
 static void
 gimp_ruler_draw_pos (GimpRuler *ruler)
 {
-  GtkWidget        *widget = GTK_WIDGET (ruler);
-  GtkStyle         *style  = gtk_widget_get_style (widget);
-  GimpRulerPrivate *priv   = GIMP_RULER_GET_PRIVATE (ruler);
-  GtkStateType      state  = gtk_widget_get_state (widget);
+  GtkWidget        *widget  = GTK_WIDGET (ruler);
+  GtkStyleContext  *context = gtk_widget_get_style_context (widget);
+  GimpRulerPrivate *priv    = GIMP_RULER_GET_PRIVATE (ruler);
   GtkAllocation     allocation;
+  GtkBorder         border;
+  GdkRGBA           color;
   gint              x, y;
   gint              width, height;
   gint              bs_width, bs_height;
-  gint              xthickness;
-  gint              ythickness;
 
   if (! gtk_widget_is_drawable (widget))
     return;
 
   gtk_widget_get_allocation (widget, &allocation);
-
-  xthickness = style->xthickness;
-  ythickness = style->ythickness;
+  gtk_style_context_get_border (context, 0, &border);
 
   if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
     {
       width  = allocation.width;
-      height = allocation.height - ythickness * 2;
+      height = allocation.height - (border.top + border.bottom);
 
       bs_width = height / 2 + 2;
       bs_width |= 1;  /* make sure it's odd */
@@ -1178,7 +1143,7 @@ gimp_ruler_draw_pos (GimpRuler *ruler)
     }
   else
     {
-      width  = allocation.width - xthickness * 2;
+      width  = allocation.width - (border.left + border.right);
       height = allocation.height;
 
       bs_height = width / 2 + 2;
@@ -1210,18 +1175,20 @@ gimp_ruler_draw_pos (GimpRuler *ruler)
         {
           increment = (gdouble) width / (upper - lower);
 
-          x = ROUND ((position - lower) * increment) + (xthickness - bs_width) / 2 - 1;
-          y = (height + bs_height) / 2 + ythickness;
+          x = ROUND ((position - lower) * increment) + (border.left - bs_width) / 2 - 1;
+          y = (height + bs_height) / 2 + border.top;
         }
       else
         {
           increment = (gdouble) height / (upper - lower);
 
-          x = (width + bs_width) / 2 + xthickness;
-          y = ROUND ((position - lower) * increment) + (ythickness - bs_height) / 2 - 1;
+          x = (width + bs_width) / 2 + border.left;
+          y = ROUND ((position - lower) * increment) + (border.top - bs_height) / 2 - 1;
         }
 
-      gdk_cairo_set_source_color (cr, &style->fg[state]);
+      gtk_style_context_get_color (context, gtk_widget_get_state_flags (widget),
+                                   &color);
+      gdk_cairo_set_source_rgba (cr, &color);
 
       cairo_move_to (cr, x, y);
 



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