[gimp/gtk3-port: 124/227] app: port GimpFgBgEditor to GtkStyleContext



commit 6ac563fdf0a1c71433a1404bc3ba909728eb2db5
Author: Michael Natterer <mitch gimp org>
Date:   Sun Dec 19 14:10:43 2010 +0100

    app: port GimpFgBgEditor to GtkStyleContext

 app/widgets/gimpfgbgeditor.c |   63 ++++++++++++++++++++++++++----------------
 1 files changed, 39 insertions(+), 24 deletions(-)
---
diff --git a/app/widgets/gimpfgbgeditor.c b/app/widgets/gimpfgbgeditor.c
index 0820dcc..17fc09c 100644
--- a/app/widgets/gimpfgbgeditor.c
+++ b/app/widgets/gimpfgbgeditor.c
@@ -225,20 +225,27 @@ static gboolean
 gimp_fg_bg_editor_draw (GtkWidget *widget,
                         cairo_t   *cr)
 {
-  GimpFgBgEditor *editor = GIMP_FG_BG_EDITOR (widget);
-  GtkStyle       *style  = gtk_widget_get_style (widget);
-  GtkAllocation   allocation;
-  gint            width, height;
-  gint            default_w, default_h;
-  gint            swap_w, swap_h;
-  gint            rect_w, rect_h;
-  GimpRGB         color;
+  GimpFgBgEditor  *editor = GIMP_FG_BG_EDITOR (widget);
+  GtkStyleContext *style  = gtk_widget_get_style_context (widget);
+  GtkAllocation    allocation;
+  GtkBorder        border;
+  gint             width, height;
+  gint             default_w, default_h;
+  gint             swap_w, swap_h;
+  gint             rect_w, rect_h;
+  GimpRGB          color;
 
   if (! gtk_widget_is_drawable (widget))
     return FALSE;
 
   gtk_widget_get_allocation (widget, &allocation);
 
+  gtk_style_context_save (style);
+  gtk_style_context_add_class (style, GTK_STYLE_CLASS_BUTTON);
+
+  gtk_style_context_get_border (style, gtk_widget_get_state_flags (widget),
+                                &border);
+
   width  = allocation.width;
   height = allocation.height;
 
@@ -303,19 +310,21 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
       gimp_cairo_set_source_rgb (cr, &color);
 
       cairo_rectangle (cr,
-                       width - rect_w,
-                       height - rect_h,
-                       rect_w,
-                       rect_h);
+                       width  - rect_w + border.left,
+                       height - rect_h + border.top,
+                       rect_w - (border.left + border.right),
+                       rect_h - (border.top + border.bottom));
       cairo_fill (cr);
     }
 
-  gtk_paint_shadow (style, cr, GTK_STATE_NORMAL,
-                    editor->active_color == GIMP_ACTIVE_COLOR_FOREGROUND ?
-                    GTK_SHADOW_OUT : GTK_SHADOW_IN,
-                    widget, NULL,
-                    (width - rect_w),
-                    (height - rect_h),
+  gtk_style_context_set_state (style,
+                               editor->active_color ==
+                               GIMP_ACTIVE_COLOR_FOREGROUND ?
+                               0 : GTK_STATE_FLAG_ACTIVE);
+
+  gtk_render_frame (style, cr,
+                    width  - rect_w,
+                    height - rect_h,
                     rect_w, rect_h);
 
 
@@ -327,18 +336,24 @@ gimp_fg_bg_editor_draw (GtkWidget *widget,
       gimp_cairo_set_source_rgb (cr, &color);
 
       cairo_rectangle (cr,
-                       0, 0,
-                       rect_w, rect_h);
+                       border.left,
+                       border.top,
+                       rect_w - (border.left + border.right),
+                       rect_h - (border.top + border.bottom));
       cairo_fill (cr);
     }
 
-  gtk_paint_shadow (style, cr, GTK_STATE_NORMAL,
-                    editor->active_color == GIMP_ACTIVE_COLOR_BACKGROUND ?
-                    GTK_SHADOW_OUT : GTK_SHADOW_IN,
-                    widget, NULL,
+  gtk_style_context_set_state (style,
+                               editor->active_color ==
+                               GIMP_ACTIVE_COLOR_BACKGROUND ?
+                               0 : GTK_STATE_FLAG_ACTIVE);
+
+  gtk_render_frame (style, cr,
                     0, 0,
                     rect_w, rect_h);
 
+  gtk_style_context_restore (style);
+
   return TRUE;
 }
 



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