[gimp/gtk3-port: 147/215] libgimpwidgets: port GimpRuler to GtkStyleContext



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

    libgimpwidgets: port GimpRuler to GtkStyleContext

 libgimpwidgets/gimpruler.c |  142 +++++++++++++++++---------------------------
 1 files changed, 54 insertions(+), 88 deletions(-)
---
diff --git a/libgimpwidgets/gimpruler.c b/libgimpwidgets/gimpruler.c
index 070d9f8..78a5636 100644
--- a/libgimpwidgets/gimpruler.c
+++ b/libgimpwidgets/gimpruler.c
@@ -536,9 +536,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);
 }
@@ -594,10 +593,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");
@@ -605,15 +605,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;
     }
 }
 
@@ -713,16 +718,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 */
@@ -742,9 +746,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);
@@ -755,46 +757,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);
@@ -872,14 +866,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 */
@@ -892,23 +886,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
                 {
@@ -919,23 +900,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
                     }
                 }
             }
@@ -950,29 +918,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 */
@@ -980,7 +945,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;
@@ -1012,18 +977,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);
 
@@ -1066,7 +1033,6 @@ gimp_ruler_make_pixmap (GimpRuler *ruler)
                                        allocation.height);
 }
 
-
 static PangoLayout *
 gimp_ruler_create_layout (GtkWidget   *widget,
                           const gchar *text)



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