[hyena/gtk3] Hyena.Gui: Update rendering of various widgets for GTK 3



commit 5d731b0f04005429e9562c9965f4762b7c20e94d
Author: Olivier Dufour <olivier duff gmail com>
Date:   Fri Jul 15 09:29:09 2011 +0200

    Hyena.Gui: Update rendering of various widgets for GTK 3
    
    Do not use GtkColors.GetWidgetColor anymore, use the new StyleContext
    API instead.
    Also move from StateType to StateFlags.
    
    Signed-off-by: Bertrand Lorentz <bertrand lorentz gmail com>

 Hyena.Gui/Hyena.Data.Gui/CellContext.cs            |    2 +-
 Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs             |    2 +-
 Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs     |    4 +-
 Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs       |    2 +-
 Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs         |    3 +-
 .../Hyena.Data.Gui/ListView/ListView_Rendering.cs  |   97 ++++++++++++--------
 Hyena.Gui/Hyena.Gui.Canvas/Slider.cs               |   10 +-
 Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs            |   15 +--
 Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs            |   64 +++----------
 Hyena.Gui/Hyena.Gui.Theming/Theme.cs               |   54 ++++++++----
 10 files changed, 127 insertions(+), 126 deletions(-)
---
diff --git a/Hyena.Gui/Hyena.Data.Gui/CellContext.cs b/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
index d22c25f..8da5c16 100644
--- a/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/CellContext.cs
@@ -43,7 +43,7 @@ namespace Hyena.Data.Gui
         public Pango.Layout Layout { get; set; }
         public Pango.FontDescription FontDescription { get; set; }
         public Gtk.Widget Widget { get; set; }
-        public Gtk.StateType State { get; set; }
+        public Gtk.StateFlags State { get; set; }
         public Gdk.Window Drawable { get; set; }
         public Theme Theme { get; set; }
         public Gdk.Rectangle Area { get; set; }
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
index e342864..9815807 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCell.cs
@@ -84,7 +84,7 @@ namespace Hyena.Data.Gui
             Render (context, context.State, cellWidth, cellHeight);
         }
 
-        public virtual void Render (CellContext context, Gtk.StateType state, double cellWidth, double cellHeight)
+        public virtual void Render (CellContext context, Gtk.StateFlags state, double cellWidth, double cellHeight)
         {
         }
 
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
index 40ecec3..4a06b42 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCellCheckBox.cs
@@ -55,8 +55,8 @@ namespace Hyena.Data.Gui
             int x = context.Area.X + xpad + ((cell_width - Size) / 2);
             int y = context.Area.Y + ypad + ((cell_height - Size) / 2);
 
-            if (context.State == StateType.Normal && last_hover_bound == BoundObjectParent) {
-                context.State = StateType.Prelight;
+            if (context.State == StateFlags.Normal && last_hover_bound == BoundObjectParent) {
+                context.State = StateFlags.Prelight;
             }
             context.Widget.StyleContext.Save ();
             context.Widget.StyleContext.AddClass ("check");
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs
index 96a1c9c..8738e97 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCellRating.cs
@@ -63,7 +63,7 @@ namespace Hyena.Data.Gui
 
             renderer.Value = Value;
             bool is_hovering = hover_bound == BoundObjectParent && hover_bound != null;
-            renderer.Render (context.Context, area, context.Theme.Colors.GetWidgetColor (GtkColorClass.Foreground, context.State),
+            renderer.Render (context.Context, area, CairoExtensions.GdkRGBAToCairoColor (context.Theme.Widget.StyleContext.GetColor (context.State)),
                 is_hovering, is_hovering, hover_value, 0.8, 0.45, 0.35);
 
             // FIXME: Something is hosed in the view when computing cell dimensions
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
index 0c7538f..77e5d85 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
@@ -109,8 +109,7 @@ namespace Hyena.Data.Gui
             //context.Context.Rectangle (0, 0, cellWidth, cellHeight);
             //context.Context.Clip ();
             context.Context.MoveTo (Padding.Left, ((int)cellHeight - text_height) / 2);
-            Cairo.Color color = context.Theme.Colors.GetWidgetColor (
-                GtkColorClass.Foreground, context.State);
+            var color = CairoExtensions.GdkRGBAToCairoColor (context.Theme.Widget.StyleContext.GetColor (context.State));
             color.A = Alpha ?? (context.Opaque ? 1.0 : 0.5);
             context.Context.Color = color;
 
diff --git a/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs b/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
index 00d765e..5bcb3a6 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
@@ -35,7 +35,6 @@ using Gdk;
 using Hyena.Gui;
 using Hyena.Gui.Theming;
 using Hyena.Gui.Canvas;
-using GtkColorClass=Hyena.Gui.Theming.GtkColorClass;
 
 namespace Hyena.Data.Gui
 {
@@ -78,18 +77,8 @@ namespace Hyena.Data.Gui
             set { do_not_render_null_model = value; }
         }
 
-        private bool changing_style = false;
-
         protected override void OnStyleUpdated ()
         {
-            if (changing_style) {
-                return;
-            }
-
-            changing_style = true;
-            GtkUtilities.AdaptGtkRcStyle (this, typeof (TreeView));
-            changing_style = false;
-
             base.OnStyleUpdated ();
 
             // FIXME: legacy list foo
@@ -152,15 +141,21 @@ namespace Hyena.Data.Gui
             if (ViewLayout == null) {
                 OnMeasure ();
             }
+            // treview style
+            StyleContext.AddClass ("view");
 
-            Theme.DrawFrameBackground (cairo_context, Allocation, true);
+            StyleContext.RenderBackground (cairo_context, Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
 
             // FIXME: ViewLayout will never be null in the future but we'll need
             // to deterministically render a header somehow...
             if (header_visible && ViewLayout == null && column_controller != null) {
+                StyleContext.AddRegion ("column-header", RegionFlags.First);
+                //TODO check flags
                 PaintHeader (damage);
+                StyleContext.RemoveRegion ("column-header");
             }
 
+
             if (Model != null) {
                 // FIXME: ViewLayout will never be null in
                 // the future, PaintList will go away
@@ -171,7 +166,7 @@ namespace Hyena.Data.Gui
                 }
             }
 
-            Theme.DrawFrameBorder (cairo_context, Allocation);
+            StyleContext.RenderFrame (cairo_context, Allocation.X, Allocation.Y, Allocation.Width, Allocation.Height);
 
             PaintDraggingColumn (damage);
 
@@ -231,11 +226,17 @@ namespace Hyena.Data.Gui
             }
 
             if (dragging) {
-                Theme.DrawColumnHighlight (cairo_context, area,
-                    CairoExtensions.ColorShade (Theme.Colors.GetWidgetColor (GtkColorClass.Dark, StateType.Normal), 0.9));
+                Cairo.Color dark_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Normal));
+                dark_color = CairoExtensions.ColorShade (dark_color, 0.7);
+
+                Theme.DrawColumnHighlight (cairo_context, area, dark_color);
 
-                Cairo.Color stroke_color = CairoExtensions.ColorShade (Theme.Colors.GetWidgetColor (
-                    GtkColorClass.Base, StateType.Normal), 0.0);
+                StyleContext.Save ();
+                StyleContext.AddClass ("entry");
+                Cairo.Color base_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Normal));
+                StyleContext.Restore ();
+
+                Cairo.Color stroke_color = CairoExtensions.ColorShade (base_color, 0.0);
                 stroke_color.A = 0.3;
 
                 cairo_context.Color = stroke_color;
@@ -252,7 +253,7 @@ namespace Hyena.Data.Gui
                 cairo_context.Save ();
                 cairo_context.Translate (area.X, area.Y);
                 cell_context.Area = area;
-                cell_context.State = StateType.Normal;
+                cell_context.State = StateFlags.Normal;
                 cell.Render (cell_context, area.Width, area.Height);
                 cairo_context.Restore ();
             }
@@ -278,10 +279,12 @@ namespace Hyena.Data.Gui
             // Render the sort effect to the GdkWindow.
             if (sort_column_index != -1 && (!pressed_column_is_dragging || pressed_column_index != sort_column_index)) {
                 CachedColumn col = column_cache[sort_column_index];
-                Theme.DrawRowRule (cairo_context,
+                StyleContext.AddRegion ("column", RegionFlags.Sorted);
+                StyleContext.RenderBackground (cairo_context,
                     list_rendering_alloc.X + col.X1 - HadjustmentValue,
                     header_rendering_alloc.Bottom + Theme.BorderWidth,
                     col.Width, list_rendering_alloc.Height + Theme.InnerBorderWidth * 2);
+                StyleContext.RemoveRegion ("column");
             }
 
             clip.Intersect (list_rendering_alloc);
@@ -322,8 +325,10 @@ namespace Hyena.Data.Gui
                     }
                 } else {
                     if (rules_hint && ri % 2 != 0) {
-                        Theme.DrawRowRule (cairo_context, single_list_alloc.X, single_list_alloc.Y,
+                        StyleContext.AddRegion ("row", RegionFlags.Odd);
+                        StyleContext.RenderBackground (cairo_context, single_list_alloc.X, single_list_alloc.Y,
                             single_list_alloc.Width, single_list_alloc.Height);
+                        StyleContext.RemoveRegion ("row");
                     }
 
                     PaintReorderLine (ri, single_list_alloc);
@@ -342,11 +347,12 @@ namespace Hyena.Data.Gui
                         if (HasFocus && !HeaderFocused) // Cursor out of selection.
                             Theme.DrawRowCursor (cairo_context, single_list_alloc.X, single_list_alloc.Y,
                                                  single_list_alloc.Width, single_list_alloc.Height,
-                                                 CairoExtensions.ColorShade (Theme.Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected), 0.85));
+                                                 CairoExtensions.ColorShade (CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Selected)), 0.85));
                     }
 
                     if (selection_height > 0) {
-                        Cairo.Color selection_color = Theme.Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected);
+                        Cairo.Color selection_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Selected));
+
                         if (!HasFocus || HeaderFocused)
                             selection_color = CairoExtensions.ColorShade (selection_color, 1.1);
 
@@ -355,7 +361,7 @@ namespace Hyena.Data.Gui
                         selection_height = 0;
                     }
 
-                    PaintRow (ri, single_list_alloc, StateType.Normal);
+                    PaintRow (ri, single_list_alloc, StateFlags.Normal);
                 }
 
                 single_list_alloc.Y += single_list_alloc.Height;
@@ -372,14 +378,19 @@ namespace Hyena.Data.Gui
             if (Selection != null && Selection.Count > 1 &&
                 !selected_focus_alloc.Equals (Rectangle.Zero) &&
                 HasFocus && !HeaderFocused) { // Cursor inside selection.
+                // Use entry to get text color
+                StyleContext.Save ();
+                StyleContext.AddClass ("entry");
+                Cairo.Color text_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetColor (StateFlags.Selected));
+                StyleContext.Restore ();
+
                 Theme.DrawRowCursor (cairo_context, selected_focus_alloc.X, selected_focus_alloc.Y,
-                    selected_focus_alloc.Width, selected_focus_alloc.Height,
-                    Theme.Colors.GetWidgetColor (GtkColorClass.Text, StateType.Selected));
+                    selected_focus_alloc.Width, selected_focus_alloc.Height, text_color);
             }
 
             foreach (int ri in selected_rows) {
                 single_list_alloc.Y = offset + ((ri - first_row) * single_list_alloc.Height);
-                PaintRow (ri, single_list_alloc, StateType.Selected);
+                PaintRow (ri, single_list_alloc, StateFlags.Selected);
             }
 
             cairo_context.ResetClip ();
@@ -393,13 +404,18 @@ namespace Hyena.Data.Gui
                 cairo_context.Antialias = Cairo.Antialias.None;
                 cairo_context.MoveTo (single_list_alloc.Left, single_list_alloc.Top);
                 cairo_context.LineTo (single_list_alloc.Right, single_list_alloc.Top);
-                cairo_context.Color = Theme.Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal);
+
+                StyleContext.Save ();
+                StyleContext.AddClass ("entry");
+                cairo_context.Color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetColor (StateFlags.Normal));
+                StyleContext.Restore ();
+
                 cairo_context.Stroke ();
                 cairo_context.Restore ();
             }
         }
 
-        private void PaintRow (int row_index, Rectangle area, StateType state)
+        private void PaintRow (int row_index, Rectangle area, StateFlags state)
         {
             if (column_cache == null) {
                 return;
@@ -436,7 +452,7 @@ namespace Hyena.Data.Gui
         }
 
         private void PaintCell (object item, int column_index, int row_index, Rectangle area, bool opaque, bool bold,
-            StateType state, bool dragging)
+            StateFlags state, bool dragging)
         {
             ColumnCell cell = column_cache[column_index].Column.GetCell (0);
             cell.Bind (item);
@@ -448,7 +464,10 @@ namespace Hyena.Data.Gui
             }
 
             if (dragging) {
-                Cairo.Color fill_color = Theme.Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
+                StyleContext.Save ();
+                StyleContext.AddClass ("entry");
+                Cairo.Color fill_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Normal));
+                StyleContext.Restore ();
                 fill_color.A = 0.5;
                 cairo_context.Color = fill_color;
                 cairo_context.Rectangle (area.X, area.Y, area.Width, area.Height);
@@ -459,7 +478,7 @@ namespace Hyena.Data.Gui
             cairo_context.Translate (area.X, area.Y);
             cell_context.Area = area;
             cell_context.Opaque = opaque;
-            cell_context.State = dragging ? StateType.Normal : state;
+            cell_context.State = dragging ? StateFlags.Normal : state;
             cell.Render (cell_context, area.Width, area.Height);
             cairo_context.Restore ();
 
@@ -476,12 +495,14 @@ namespace Hyena.Data.Gui
 
             int x = pressed_column_x_drag + Allocation.X + 1 - HadjustmentValue;
 
-            Cairo.Color fill_color = Theme.Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
-            fill_color.A = 0.45;
+            StyleContext.Save ();
+            StyleContext.AddClass ("entry");
+            Cairo.Color fill_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Normal));
 
-            Cairo.Color stroke_color = CairoExtensions.ColorShade (Theme.Colors.GetWidgetColor (
-                GtkColorClass.Base, StateType.Normal), 0.0);
+            Cairo.Color stroke_color = CairoExtensions.ColorShade (fill_color, 0.0);
+            fill_color.A = 0.45;
             stroke_color.A = 0.3;
+            StyleContext.Restore ();
 
             cairo_context.Rectangle (x, header_rendering_alloc.Bottom + 1, column.Width - 2,
                 list_rendering_alloc.Bottom - header_rendering_alloc.Bottom - 1);
@@ -524,7 +545,7 @@ namespace Hyena.Data.Gui
                 if (Selection != null && Selection.Contains (ViewLayout.GetModelIndex (layout_child))) {
                     selected_rows.Add (ViewLayout.GetModelIndex (layout_child));
 
-                    var selection_color = Theme.Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected);
+                    var selection_color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetBackgroundColor (StateFlags.Selected));
                     if (!HasFocus || HeaderFocused) {
                         selection_color = CairoExtensions.ColorShade (selection_color, 1.1);
                     }
@@ -534,9 +555,9 @@ namespace Hyena.Data.Gui
                         (int)child_allocation.Width, (int)child_allocation.Height,
                         true, true, selection_color, CairoCorners.All);
 
-                    cell_context.State = StateType.Selected;
+                    cell_context.State = StateFlags.Selected;
                 } else {
-                    cell_context.State = StateType.Normal;
+                    cell_context.State = StateFlags.Normal;
                 }
 
                 //cairo_context.Save ();
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/Slider.cs b/Hyena.Gui/Hyena.Gui.Canvas/Slider.cs
index 0cef220..c9699e4 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/Slider.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/Slider.cs
@@ -153,11 +153,13 @@ namespace Hyena.Gui.Canvas
             double throbber_y = (Allocation.Height - ThrobberSize) / 2.0 - Margin.Top + throbber_r;
             double bar_w = RenderSize.Width * Value;
 
-            cr.Color = Theme.Colors.GetWidgetColor (GtkColorClass.Base, Gtk.StateType.Normal);
-            cr.Rectangle (0, 0, RenderSize.Width, RenderSize.Height);
-            cr.Fill ();
+            Theme.Widget.StyleContext.Save ();
+            Theme.Widget.StyleContext.AddClass ("entry");
+            Theme.Widget.StyleContext.RenderBackground (cr, 0, 0, RenderSize.Width, RenderSize.Height);
+            var color = CairoExtensions.GdkRGBAToCairoColor (Theme.Widget.StyleContext.GetColor (Gtk.StateFlags.Active));
+            Theme.Widget.StyleContext.Restore ();
 
-            Color color = Theme.Colors.GetWidgetColor (GtkColorClass.Dark, Gtk.StateType.Active);
+            // TODO get Dark color
             Color fill_color = CairoExtensions.ColorShade (color, 0.4);
             Color light_fill_color = CairoExtensions.ColorShade (color, 0.3);
             fill_color.A = 1.0;
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs b/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
index 699463d..9024767 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
@@ -178,13 +178,8 @@ namespace Hyena.Gui.Canvas
             }
 
             var cr = context.Context;
-            Foreground = new Brush (context.Theme.Colors.GetWidgetColor (
-                context.TextAsForeground ? GtkColorClass.Foreground : GtkColorClass.Text, context.State));
-
-            Brush foreground = Foreground;
-            if (!foreground.IsValid) {
-                return;
-            }
+            context.Theme.Widget.StyleContext.Save ();
+            context.Theme.Widget.StyleContext.AddClass ("entry");
 
             cr.Rectangle (0, 0, RenderSize.Width, RenderSize.Height);
             cr.Clip ();
@@ -195,8 +190,6 @@ namespace Hyena.Gui.Canvas
                 cr.PushGroup ();
             }
 
-            cr.MoveTo (text_alloc.X, text_alloc.Y);
-            Foreground.Apply (cr);
             UpdateLayout (GetText (), RenderSize.Width, RenderSize.Height, true);
             if (Hyena.PlatformDetection.IsWindows) {
               // FIXME windows; working around some unknown issue with ShowLayout; bgo#644311
@@ -206,7 +199,8 @@ namespace Hyena.Gui.Canvas
             } else {
               PangoCairoHelper.ShowLayout (cr, layout);
             }
-            cr.Fill ();
+
+            context.Theme.Widget.StyleContext.RenderLayout (cr, text_alloc.X, text_alloc.Y, layout);
 
             TooltipMarkup = layout.IsEllipsized ? last_formatted_text : null;
 
@@ -221,6 +215,7 @@ namespace Hyena.Gui.Canvas
             }
 
             cr.ResetClip ();
+            context.Theme.Widget.StyleContext.Restore ();
         }
 
         private Pango.Weight GetPangoFontWeight (FontWeight weight)
diff --git a/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs b/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
index 9449bd3..af63902 100644
--- a/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
+++ b/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
@@ -43,8 +43,8 @@ namespace Hyena.Gui.Theming
 
         public static Cairo.Color GetCairoTextMidColor (Widget widget)
         {
-            Cairo.Color text_color = CairoExtensions.GdkRGBAToCairoColor (widget.StyleContext.GetColor (StateFlags.Normal));
-            Cairo.Color background_color = CairoExtensions.GdkRGBAToCairoColor (widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
+            Color text_color = CairoExtensions.GdkRGBAToCairoColor (widget.StyleContext.GetColor (StateFlags.Normal));
+            Color background_color = CairoExtensions.GdkRGBAToCairoColor (widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
             return CairoExtensions.AlphaBlend (text_color, background_color, 0.5);
         }
 
@@ -55,9 +55,9 @@ namespace Hyena.Gui.Theming
             rule_color = CairoExtensions.ColorShade (ViewFill, 0.95);
 
             // On Windows we use Normal b/c Active incorrectly returns black (at least on XP)
-            border_color = Colors.GetWidgetColor (GtkColorClass.Border,
-              Hyena.PlatformDetection.IsWindows ? StateType.Normal : StateType.Active
-            );
+            // TODO: Check if this is still needed with GTK 3
+            border_color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBorderColor (
+                    Hyena.PlatformDetection.IsWindows ? StateFlags.Normal : StateFlags.Active));
         }
 
         public override void DrawPie (double fraction)
@@ -76,7 +76,8 @@ namespace Hyena.Gui.Theming
             Context.Cairo.LineTo (Context.X, Context.Y);
 
             // Fill the pie
-            Color color_a = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected);
+            Color color_a = CairoExtensions.GdkRGBAToCairoColor (
+                Widget.StyleContext.GetBackgroundColor (StateFlags.Selected));
             Color color_b = CairoExtensions.ColorShade (color_a, 1.4);
 
             RadialGradient fill = new RadialGradient (Context.X, Context.Y, 0,
@@ -97,47 +98,7 @@ namespace Hyena.Gui.Theming
         public override void DrawArrow (Context cr, Gdk.Rectangle alloc, double rotation)
         {
             rotation -= Math.PI / 2.0;
-
-            double x1 = alloc.X;
-            double x2 = alloc.Right;
-            double x3 = alloc.X + alloc.Width / 2.0;
-            double y1 = alloc.Y;
-            double y2 = alloc.Bottom;
-
-            double cx = x3;
-            double cy = alloc.Y + alloc.Height / 2.0;
-
-            if (rotation != 0) {
-                // Rotate about the center of the arrow
-                cr.Translate (cx, cy);
-                cr.Rotate (rotation);
-                cr.Translate (-cx, -cy);
-            }
-
-            cr.LineWidth = 1.0;
-
-            bool hz = (rotation % (Math.PI / 2.0)) == 0;
-            double dx = hz ? 0 : 0.5;
-            double dy = hz ? 0.5 : 0.5;
-            cr.Translate (dx, dy);
-
-            cr.MoveTo (x1, y1);
-            cr.LineTo (x2, y1);
-            cr.LineTo (x3, y2);
-            cr.LineTo (x1, y1);
-
-            cr.Color = Colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
-            cr.FillPreserve ();
-            cr.Color = Colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal);
-            cr.Stroke ();
-
-            cr.Translate (-dx, -dy);
-
-            if (rotation != 0) {
-                cr.Translate (cx, cy);
-                cr.Rotate (-rotation);
-                cr.Translate (-cx, -cy);
-            }
+            Widget.StyleContext.RenderArrow (cr, rotation, alloc.X, alloc.Y, alloc.Width * alloc.Height);
         }
 
         public override void DrawFrameBackground (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color, Cairo.Pattern pattern)
@@ -221,7 +182,8 @@ namespace Hyena.Gui.Theming
 
         public override void DrawHeaderBackground (Cairo.Context cr, Gdk.Rectangle alloc)
         {
-            Cairo.Color gtk_background_color = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal);
+            Cairo.Color gtk_background_color =
+                CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
             Cairo.Color light_color = CairoExtensions.ColorShade (gtk_background_color, 1.1);
             Cairo.Color dark_color = CairoExtensions.ColorShade (gtk_background_color, 0.95);
 
@@ -251,7 +213,8 @@ namespace Hyena.Gui.Theming
             double line_width = 0.7;
 
             Cairo.Color stroke_color = CairoExtensions.ColorShade (
-                Colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected), 0.8);
+                CairoExtensions.GdkRGBAToCairoColor (
+                    Widget.StyleContext.GetBackgroundColor (StateFlags.Selected)), 0.8);
 
             stroke_color.A = 0.1;
             cr.Color = stroke_color;
@@ -279,7 +242,8 @@ namespace Hyena.Gui.Theming
 
         public override void DrawHeaderSeparator (Cairo.Context cr, Gdk.Rectangle alloc, int x)
         {
-            Cairo.Color gtk_background_color = Colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal);
+            Cairo.Color gtk_background_color = CairoExtensions.GdkRGBAToCairoColor (
+                Widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
             Cairo.Color dark_color = CairoExtensions.ColorShade (gtk_background_color, 0.80);
             Cairo.Color light_color = CairoExtensions.ColorShade (gtk_background_color, 1.1);
 
diff --git a/Hyena.Gui/Hyena.Gui.Theming/Theme.cs b/Hyena.Gui/Hyena.Gui.Theming/Theme.cs
index ec0207b..f5d47bc 100644
--- a/Hyena.Gui/Hyena.Gui.Theming/Theme.cs
+++ b/Hyena.Gui/Hyena.Gui.Theming/Theme.cs
@@ -72,17 +72,20 @@ namespace Hyena.Gui.Theming
 
         protected virtual void OnColorsRefreshed ()
         {
-            selection_fill = colors.GetWidgetColor (GtkColorClass.Dark, StateType.Active);
-            selection_stroke = colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected);
+            selection_fill = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Active));
+            selection_fill = CairoExtensions.ColorShade (selection_fill, 0.8);
+            selection_stroke = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Selected));
+
+            Widget.StyleContext.Save ();
+            Widget.StyleContext.AddClass ("entry");
+            view_fill = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
+            var text_color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetColor (StateFlags.Normal));
+            Widget.StyleContext.Restore ();
 
-            view_fill = colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal);
             view_fill_transparent = view_fill;
             view_fill_transparent.A = 0;
 
-            text_mid = CairoExtensions.AlphaBlend (
-                colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal),
-                colors.GetWidgetColor (GtkColorClass.Text, StateType.Normal),
-                0.5);
+            text_mid = CairoExtensions.AlphaBlend (view_fill, text_color, 0.5);
         }
 
 #region Drawing
@@ -110,9 +113,17 @@ namespace Hyena.Gui.Theming
 
         public void DrawFrameBackground (Cairo.Context cr, Gdk.Rectangle alloc, bool baseColor)
         {
-            DrawFrameBackground (cr, alloc,  baseColor
-                ? colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal)
-                : colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal));
+            Cairo.Color fill_color;
+            if (baseColor) {
+                Widget.StyleContext.Save ();
+                Widget.StyleContext.AddClass ("entry");
+                fill_color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
+                Widget.StyleContext.Restore ();
+            } else {
+                fill_color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
+            }
+
+            DrawFrameBackground (cr, alloc, fill_color);
         }
 
         public void DrawFrameBackground (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color)
@@ -137,9 +148,16 @@ namespace Hyena.Gui.Theming
 
         public void DrawListBackground (Cairo.Context cr, Gdk.Rectangle alloc, bool baseColor)
         {
-            DrawListBackground (cr, alloc,  baseColor
-                ? colors.GetWidgetColor (GtkColorClass.Base, StateType.Normal)
-                : colors.GetWidgetColor (GtkColorClass.Background, StateType.Normal));
+            Cairo.Color fill_color;
+            if (baseColor) {
+                Widget.StyleContext.Save ();
+                Widget.StyleContext.AddClass ("entry");
+                fill_color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
+                Widget.StyleContext.Restore ();
+            } else {
+                fill_color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Normal));
+            }
+            DrawListBackground (cr, alloc, fill_color);
         }
 
         public abstract void DrawListBackground (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color);
@@ -154,7 +172,8 @@ namespace Hyena.Gui.Theming
 
         public void DrawColumnHighlight (Cairo.Context cr, Gdk.Rectangle alloc)
         {
-            DrawColumnHighlight (cr, alloc, colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected));
+            Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Selected));
+            DrawColumnHighlight (cr, alloc, color);
         }
 
         public abstract void DrawColumnHighlight (Cairo.Context cr, Gdk.Rectangle alloc, Cairo.Color color);
@@ -166,8 +185,8 @@ namespace Hyena.Gui.Theming
 
         public void DrawRowSelection (Cairo.Context cr, int x, int y, int width, int height, bool filled)
         {
-            DrawRowSelection (cr, x, y, width, height, filled, true,
-                colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected), CairoCorners.All);
+            Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Selected));
+            DrawRowSelection (cr, x, y, width, height, filled, true, color, CairoCorners.All);
         }
 
         public void DrawRowSelection (Cairo.Context cr, int x, int y, int width, int height,
@@ -178,7 +197,8 @@ namespace Hyena.Gui.Theming
 
         public void DrawRowCursor (Cairo.Context cr, int x, int y, int width, int height)
         {
-            DrawRowCursor (cr, x, y, width, height, colors.GetWidgetColor (GtkColorClass.Background, StateType.Selected));
+            Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor (Widget.StyleContext.GetBackgroundColor (StateFlags.Selected));
+            DrawRowCursor (cr, x, y, width, height, color);
         }
 
         public void DrawRowCursor (Cairo.Context cr, int x, int y, int width, int height, Cairo.Color color)



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