[gimp/gtk3-port: 144/242] libgimpwidgets: port GimpColorScale to GtkStyleContext



commit 3aabd4b30b2afe6c13ffd4cbc1c0b32769e56c58
Author: Michael Natterer <mitch gimp org>
Date:   Wed Dec 15 15:33:05 2010 +0100

    libgimpwidgets: port GimpColorScale to GtkStyleContext

 libgimpwidgets/gimpcolorscale.c |   58 ++++++++++++++++++++++-----------------
 1 files changed, 33 insertions(+), 25 deletions(-)
---
diff --git a/libgimpwidgets/gimpcolorscale.c b/libgimpwidgets/gimpcolorscale.c
index d3f9c1a..243213c 100644
--- a/libgimpwidgets/gimpcolorscale.c
+++ b/libgimpwidgets/gimpcolorscale.c
@@ -322,7 +322,7 @@ gimp_color_scale_draw (GtkWidget *widget,
 {
   GimpColorScale  *scale     = GIMP_COLOR_SCALE (widget);
   GtkRange        *range     = GTK_RANGE (widget);
-  GtkStyle        *style     = gtk_widget_get_style (widget);
+  GtkStyleContext *context   = gtk_widget_get_style_context (widget);
   gboolean         sensitive = gtk_widget_is_sensitive (widget);
   GdkRectangle     range_rect;
   GdkRectangle     area      = { 0, };
@@ -337,6 +337,10 @@ gimp_color_scale_draw (GtkWidget *widget,
   if (! scale->buf || ! gtk_widget_is_drawable (widget))
     return FALSE;
 
+  gtk_style_context_save (context);
+
+  gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
+
   gtk_widget_style_get (widget,
                         "trough-border", &trough_border,
                         NULL);
@@ -372,11 +376,10 @@ gimp_color_scale_draw (GtkWidget *widget,
       scale->needs_render = FALSE;
     }
 
-  gtk_paint_box (style, cr,
-                 sensitive ? GTK_STATE_ACTIVE : GTK_STATE_INSENSITIVE,
-                 GTK_SHADOW_IN,
-                 widget, "trough",
-                 x, y, w, h);
+  gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget));
+
+  gtk_render_background (context, cr, x, y, w, h);
+  gtk_render_frame (context, cr, x, y, w, h);
 
   buffer = cairo_image_surface_create_for_data (scale->buf,
                                                 CAIRO_FORMAT_RGB24,
@@ -403,12 +406,11 @@ gimp_color_scale_draw (GtkWidget *widget,
   cairo_paint (cr);
 
   if (gtk_widget_has_focus (widget))
-    gtk_paint_focus (style, cr, gtk_widget_get_state (widget),
-                     widget, "trough",
-                     range_rect.x,
-                     range_rect.y,
-                     range_rect.width,
-                     range_rect.height);
+    gtk_render_focus (context, cr,
+                      range_rect.x,
+                      range_rect.y,
+                      range_rect.width,
+                      range_rect.height);
 
   switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)))
     {
@@ -428,9 +430,9 @@ gimp_color_scale_draw (GtkWidget *widget,
     }
 
   if (gtk_widget_is_sensitive (widget))
-    gdk_cairo_set_source_color (cr, &style->black);
+    cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
   else
-    gdk_cairo_set_source_color (cr, &style->dark[GTK_STATE_INSENSITIVE]);
+    cairo_set_source_rgb (cr, 0.2, 0.2, 0.2);
 
   switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)))
     {
@@ -455,9 +457,9 @@ gimp_color_scale_draw (GtkWidget *widget,
   cairo_fill (cr);
 
   if (gtk_widget_is_sensitive (widget))
-    gdk_cairo_set_source_color (cr, &style->white);
+    cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
   else
-    gdk_cairo_set_source_color (cr, &style->light[GTK_STATE_INSENSITIVE]);
+    cairo_set_source_rgb (cr, 0.8, 0.8, 0.8);
 
   switch (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)))
     {
@@ -481,6 +483,8 @@ gimp_color_scale_draw (GtkWidget *widget,
   cairo_close_path (cr);
   cairo_fill (cr);
 
+  gtk_style_context_restore (context);
+
   return FALSE;
 }
 
@@ -819,19 +823,23 @@ gimp_color_scale_render_alpha (GimpColorScale *scale)
 static void
 gimp_color_scale_render_stipple (GimpColorScale *scale)
 {
-  GtkWidget *widget = GTK_WIDGET (scale);
-  GtkStyle  *style  = gtk_widget_get_style (widget);
-  guchar    *buf;
-  guchar     insensitive[4];
-  guint      x, y;
+  GtkWidget       *widget  = GTK_WIDGET (scale);
+  GtkStyleContext *context = gtk_widget_get_style_context (widget);
+  GdkRGBA          color;
+  guchar           r, g, b;
+  guchar          *buf;
+  guchar           insensitive[4];
+  guint            x, y;
 
   if ((buf = scale->buf) == NULL)
     return;
 
-  GIMP_CAIRO_RGB24_SET_PIXEL (insensitive,
-                              style->bg[GTK_STATE_INSENSITIVE].red   >> 8,
-                              style->bg[GTK_STATE_INSENSITIVE].green >> 8,
-                              style->bg[GTK_STATE_INSENSITIVE].blue  >> 8);
+  gtk_style_context_get_background_color (context,
+                                          gtk_widget_get_state_flags (widget),
+                                          &color);
+  gimp_rgb_get_uchar ((GimpRGB *) &color, &r, &g, &b);
+
+  GIMP_CAIRO_RGB24_SET_PIXEL (insensitive, r, g, b);
 
   for (y = 0; y < scale->height; y++, buf += scale->rowstride)
     {



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