[hyena/gtk3] build: fix warnings (which show up when using latest Mono.Cairo)



commit 80734bf3845a4bfff612813f22ca746e2e6137a0
Author: Andrés G. Aragoneses <knocte gmail com>
Date:   Sat Aug 24 13:36:41 2013 +0200

    build: fix warnings (which show up when using latest Mono.Cairo)
    
    The warnings fixed in this commit are:
    - Replace usage of Color setter with the SetSourceColor() method
    - Replace usage of Pattern setter with the SetSource() method
    - Replace usage of Destroy() method, with the using{} block dispose syntax
    
    This is required to be able to enable WarnAsErrors back again in Banshee.

 Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs         |    2 +-
 .../Hyena.Data.Gui/ListView/ListView_Rendering.cs  |   10 +-
 Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs     |    4 +-
 Hyena.Gui/Hyena.Gui.Canvas/Brush.cs                |    2 +-
 Hyena.Gui/Hyena.Gui.Canvas/CanvasHost.cs           |    4 +-
 Hyena.Gui/Hyena.Gui.Canvas/Prelight.cs             |   14 +-
 Hyena.Gui/Hyena.Gui.Canvas/ShadowMarginStyle.cs    |    2 +-
 Hyena.Gui/Hyena.Gui.Canvas/Slider.cs               |   26 ++--
 Hyena.Gui/Hyena.Gui.Canvas/TestTile.cs             |    2 +-
 Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs            |   12 +-
 Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs            |   84 +++++-----
 Hyena.Gui/Hyena.Gui/CairoDamageDebugger.cs         |    2 +-
 Hyena.Gui/Hyena.Gui/CairoExtensions.cs             |    5 +-
 Hyena.Gui/Hyena.Gui/RatingRenderer.cs              |    6 +-
 Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs           |    4 +-
 Hyena.Gui/Hyena.Widgets/PulsingButton.cs           |   22 ++--
 Hyena.Gui/Hyena.Widgets/SegmentedBar.cs            |  176 ++++++++++----------
 17 files changed, 189 insertions(+), 188 deletions(-)
---
diff --git a/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs b/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
index 77e5d85..ec0df02 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ColumnCellText.cs
@@ -111,7 +111,7 @@ namespace Hyena.Data.Gui
             context.Context.MoveTo (Padding.Left, ((int)cellHeight - text_height) / 2);
             var color = CairoExtensions.GdkRGBAToCairoColor (context.Theme.Widget.StyleContext.GetColor 
(context.State));
             color.A = Alpha ?? (context.Opaque ? 1.0 : 0.5);
-            context.Context.Color = color;
+            context.Context.SetSourceColor (color);
 
             PangoCairoHelper.ShowLayout (context.Context, context.Layout);
             //context.Context.ResetClip ();
diff --git a/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs 
b/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
index abe19de..b10608e 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ListView/ListView_Rendering.cs
@@ -225,7 +225,7 @@ namespace Hyena.Data.Gui
                 Cairo.Color stroke_color = CairoExtensions.ColorShade (base_color, 0.0);
                 stroke_color.A = 0.3;
 
-                cr.Color = stroke_color;
+                cr.SetSourceColor (stroke_color);
                 cr.MoveTo (area.X + 0.5, area.Y + 1.0);
                 cr.LineTo (area.X + 0.5, area.Bottom);
                 cr.MoveTo (area.Right - 0.5, area.Y + 1.0);
@@ -407,7 +407,7 @@ namespace Hyena.Data.Gui
 
                 StyleContext.Save ();
                 StyleContext.AddClass ("entry");
-                cr.Color = CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetColor (StateFlags.Normal));
+                cr.SetSourceColor (CairoExtensions.GdkRGBAToCairoColor (StyleContext.GetColor 
(StateFlags.Normal)));
                 StyleContext.Restore ();
 
                 cr.Stroke ();
@@ -470,7 +470,7 @@ namespace Hyena.Data.Gui
                 Cairo.Color fill_color = CairoExtensions.GdkRGBAToCairoColor 
(StyleContext.GetBackgroundColor (StateFlags.Normal));
                 StyleContext.Restore ();
                 fill_color.A = 0.5;
-                cr.Color = fill_color;
+                cr.SetSourceColor (fill_color);
                 cr.Rectangle (area.X, area.Y, area.Width, area.Height);
                 cr.Fill ();
             }
@@ -507,7 +507,7 @@ namespace Hyena.Data.Gui
 
             cr.Rectangle (x, header_rendering_alloc.Bottom + 1, column.Width - 2,
                 list_rendering_alloc.Bottom - header_rendering_alloc.Bottom - 1);
-            cr.Color = fill_color;
+            cr.SetSourceColor (fill_color);
             cr.Fill ();
 
             cr.MoveTo (x - 0.5, header_rendering_alloc.Bottom + 0.5);
@@ -515,7 +515,7 @@ namespace Hyena.Data.Gui
             cr.LineTo (x + column.Width - 1.5, list_rendering_alloc.Bottom + 0.5);
             cr.LineTo (x + column.Width - 1.5, header_rendering_alloc.Bottom + 0.5);
 
-            cr.Color = stroke_color;
+            cr.SetSourceColor (stroke_color);
             cr.LineWidth = 1.0;
             cr.Stroke ();
         }
diff --git a/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs b/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs
index 89ba89a..09ba363 100644
--- a/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs
+++ b/Hyena.Gui/Hyena.Data.Gui/ListViewTestModule.cs
@@ -252,7 +252,7 @@ namespace Hyena.Data.Gui.Tests
             red = !red;
             Cairo.Context cr = context.Context;
             cr.Rectangle (0, 0, cellWidth, cellHeight);
-            cr.Color = CairoExtensions.RgbaToColor (red ? 0xff000099 : 0x00000099);
+            cr.SetSourceColor (CairoExtensions.RgbaToColor (red ? 0xff000099 : 0x00000099));
             cr.Fill ();
 
             List<Gdk.Point> points = Points;
@@ -264,7 +264,7 @@ namespace Hyena.Data.Gui.Tests
                 }
             }
 
-            cr.Color = CairoExtensions.RgbToColor ((uint)random.Next (0xffffff));
+            cr.SetSourceColor (CairoExtensions.RgbToColor ((uint)random.Next (0xffffff)));
             cr.LineWidth = 1;
             cr.Stroke ();
         }
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/Brush.cs b/Hyena.Gui/Hyena.Gui.Canvas/Brush.cs
index 3b453c1..4fbe7ac 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/Brush.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/Brush.cs
@@ -68,7 +68,7 @@ namespace Hyena.Gui.Canvas
 
         public virtual void Apply (Cairo.Context cr)
         {
-            cr.Color = color;
+            cr.SetSourceColor (color);
         }
 
         public static readonly Brush Black = new Brush (0.0, 0.0, 0.0);
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/CanvasHost.cs b/Hyena.Gui/Hyena.Gui.Canvas/CanvasHost.cs
index 2b7af7f..50e22f3 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/CanvasHost.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/CanvasHost.cs
@@ -165,8 +165,8 @@ namespace Hyena.Gui.Canvas
 
                 if (Debug) {
                     cr.LineWidth = 1.0;
-                    cr.Color = CairoExtensions.RgbToColor (
-                        (uint)(rand = rand ?? new Random ()).Next (0, 0xffffff));
+                    cr.SetSourceColor (CairoExtensions.RgbToColor (
+                        (uint)(rand = rand ?? new Random ()).Next (0, 0xffffff)));
                     cr.Rectangle (damage.X + 0.5, damage.Y + 0.5, damage.Width - 1, damage.Height - 1);
                     cr.Stroke ();
                 }
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/Prelight.cs b/Hyena.Gui/Hyena.Gui.Canvas/Prelight.cs
index 01c4e38..63a0629 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/Prelight.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/Prelight.cs
@@ -41,13 +41,13 @@ namespace Hyena.Gui.Canvas
 
             var x = rect.Width / 2.0;
             var y = rect.Height / 2.0;
-            var grad = new Cairo.RadialGradient (x, y, 0, x, y, rect.Width / 2.0);
-            grad.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.1 * opacity));
-            grad.AddColorStop (1, new Cairo.Color (0, 0, 0, 0.35 * opacity));
-            cr.Pattern = grad;
-            CairoExtensions.RoundedRectangle (cr, rect.X, rect.Y, rect.Width, rect.Height, 
theme.Context.Radius);
-            cr.Fill ();
-            grad.Destroy ();
+            using (var grad = new Cairo.RadialGradient (x, y, 0, x, y, rect.Width / 2.0)) {
+                grad.AddColorStop (0, new Cairo.Color (0, 0, 0, 0.1 * opacity));
+                grad.AddColorStop (1, new Cairo.Color (0, 0, 0, 0.35 * opacity));
+                cr.SetSource (grad);
+                CairoExtensions.RoundedRectangle (cr, rect.X, rect.Y, rect.Width, rect.Height, 
theme.Context.Radius);
+                cr.Fill ();
+            }
 
             cr.Restore ();
         }
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/ShadowMarginStyle.cs b/Hyena.Gui/Hyena.Gui.Canvas/ShadowMarginStyle.cs
index 63648d6..0397d24 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/ShadowMarginStyle.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/ShadowMarginStyle.cs
@@ -66,7 +66,7 @@ namespace Hyena.Gui.Canvas
                     steps - i);
 
                 color.A = opacity_step * (i + 1);
-                cr.Color = color;
+                cr.SetSourceColor (color);
                 cr.Stroke ();
             }
         }
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/Slider.cs b/Hyena.Gui/Hyena.Gui.Canvas/Slider.cs
index 29c7de8..2e6713e 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/Slider.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/Slider.cs
@@ -165,19 +165,19 @@ namespace Hyena.Gui.Canvas
             fill_color.A = 1.0;
             light_fill_color.A = 1.0;
 
-            LinearGradient fill = new LinearGradient (0, 0, 0, RenderSize.Height);
-            fill.AddColorStop (0, light_fill_color);
-            fill.AddColorStop (0.5, fill_color);
-            fill.AddColorStop (1, light_fill_color);
-
-            cr.Rectangle (0, 0, bar_w, RenderSize.Height);
-            cr.Pattern = fill;
-            cr.Fill ();
-
-            cr.Color = fill_color;
-            cr.Arc (throbber_x, throbber_y, throbber_r, 0, Math.PI * 2);
-            cr.Fill ();
-            fill.Destroy ();
+            using (var fill = new LinearGradient (0, 0, 0, RenderSize.Height)) {
+                fill.AddColorStop (0, light_fill_color);
+                fill.AddColorStop (0.5, fill_color);
+                fill.AddColorStop (1, light_fill_color);
+
+                cr.Rectangle (0, 0, bar_w, RenderSize.Height);
+                cr.SetSource (fill);
+                cr.Fill ();
+
+                cr.SetSourceColor (fill_color);
+                cr.Arc (throbber_x, throbber_y, throbber_r, 0, Math.PI * 2);
+                cr.Fill ();
+            }
         }
 
         public override Size Measure (Size available)
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/TestTile.cs b/Hyena.Gui/Hyena.Gui.Canvas/TestTile.cs
index 3d58654..22d78ee 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/TestTile.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/TestTile.cs
@@ -55,7 +55,7 @@ namespace Hyena.Gui.Canvas
             }
 
             CairoExtensions.RoundedRectangle (cr, 0, 0, RenderSize.Width, RenderSize.Height, 5);
-            cr.Color = color;
+            cr.SetSourceColor (color);
             cr.Fill ();
         }
     }
diff --git a/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs b/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
index 911aad9..43c9788 100644
--- a/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
+++ b/Hyena.Gui/Hyena.Gui.Canvas/TextBlock.cs
@@ -214,13 +214,13 @@ namespace Hyena.Gui.Canvas
             TooltipMarkup = layout.IsEllipsized ? last_formatted_text : null;
 
             if (fade) {
-                LinearGradient mask = new LinearGradient (RenderSize.Width - 20, 0, RenderSize.Width, 0);
-                mask.AddColorStop (0, new Color (0, 0, 0, 1));
-                mask.AddColorStop (1, new Color (0, 0, 0, 0));
+                using (var mask = new LinearGradient (RenderSize.Width - 20, 0, RenderSize.Width, 0)) {
+                    mask.AddColorStop (0, new Color (0, 0, 0, 1));
+                    mask.AddColorStop (1, new Color (0, 0, 0, 0));
 
-                cr.PopGroupToSource ();
-                cr.Mask (mask);
-                mask.Destroy ();
+                    cr.PopGroupToSource ();
+                    cr.Mask (mask);
+                }
             }
 
             cr.ResetClip ();
diff --git a/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs b/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
index 6fefbdc..760e759 100644
--- a/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
+++ b/Hyena.Gui/Hyena.Gui.Theming/GtkTheme.cs
@@ -80,17 +80,17 @@ namespace Hyena.Gui.Theming
                 Widget.StyleContext.GetBackgroundColor (StateFlags.Selected));
             Color color_b = CairoExtensions.ColorShade (color_a, 1.4);
 
-            RadialGradient fill = new RadialGradient (Context.X, Context.Y, 0,
-                Context.X, Context.Y, 2.0 * Context.Radius);
-            fill.AddColorStop (0, color_a);
-            fill.AddColorStop (1, color_b);
-            Context.Cairo.Pattern = fill;
+            using (var fill = new RadialGradient (Context.X, Context.Y, 0, Context.X, Context.Y,
+                                                  2.0 * Context.Radius)) {
+                fill.AddColorStop (0, color_a);
+                fill.AddColorStop (1, color_b);
+                Context.Cairo.SetSource (fill);
 
-            Context.Cairo.FillPreserve ();
-            fill.Destroy ();
+                Context.Cairo.FillPreserve ();
+            }
 
             // Stroke the pie
-            Context.Cairo.Color = CairoExtensions.ColorShade (color_a, 0.8);
+            Context.Cairo.SetSourceColor (CairoExtensions.ColorShade (color_a, 0.8));
             Context.Cairo.LineWidth = Context.LineWidth;
             Context.Cairo.Stroke ();
         }
@@ -109,9 +109,9 @@ namespace Hyena.Gui.Theming
         {
             color.A = Context.FillAlpha;
             if (pattern != null) {
-                cr.Pattern = pattern;
+                cr.SetSource (pattern);
             } else {
-                cr.Color = color;
+                cr.SetSourceColor (color);
             }
             CairoExtensions.RoundedRectangle (cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, 
Context.Radius, CairoCorners.All);
             cr.Fill ();
@@ -150,10 +150,10 @@ namespace Hyena.Gui.Theming
             // FIXME Windows; shading the color by .8 makes it blend into the bg
             if (Widget.HasFocus && !Hyena.PlatformDetection.IsWindows) {
                 cr.LineWidth = BorderWidth * 1.5;
-                cr.Color = CairoExtensions.ColorShade (border_color, 0.8);
+                cr.SetSourceColor (CairoExtensions.ColorShade (border_color, 0.8));
             } else {
                 cr.LineWidth = BorderWidth;
-                cr.Color = border_color;
+                cr.SetSourceColor (border_color);
             }
 
             double offset = (double)cr.LineWidth / 2.0;
@@ -174,14 +174,14 @@ namespace Hyena.Gui.Theming
             Cairo.Color light_color = CairoExtensions.ColorShade (color, 1.6);
             Cairo.Color dark_color = CairoExtensions.ColorShade (color, 1.3);
 
-            LinearGradient grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom - 1);
-            grad.AddColorStop (0, light_color);
-            grad.AddColorStop (1, dark_color);
+            using (var grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom - 1)) {
+                grad.AddColorStop (0, light_color);
+                grad.AddColorStop (1, dark_color);
 
-            cr.Pattern = grad;
-            cr.Rectangle (alloc.X + 1.5, alloc.Y + 1.5, alloc.Width - 3, alloc.Height - 2);
-            cr.Fill ();
-            grad.Destroy ();
+                cr.SetSource (grad);
+                cr.Rectangle (alloc.X + 1.5, alloc.Y + 1.5, alloc.Width - 3, alloc.Height - 2);
+                cr.Fill ();
+            }
         }
 
         public override void DrawHeaderBackground (Cairo.Context cr, Gdk.Rectangle alloc)
@@ -193,19 +193,19 @@ namespace Hyena.Gui.Theming
 
             CairoCorners corners = CairoCorners.TopLeft | CairoCorners.TopRight;
 
-            LinearGradient grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom);
-            grad.AddColorStop (0, light_color);
-            grad.AddColorStop (0.75, dark_color);
-            grad.AddColorStop (0, light_color);
+            using (var grad = new LinearGradient (alloc.X, alloc.Y, alloc.X, alloc.Bottom)) {
+                grad.AddColorStop (0, light_color);
+                grad.AddColorStop (0.75, dark_color);
+                grad.AddColorStop (0, light_color);
 
-            cr.Pattern = grad;
-            CairoExtensions.RoundedRectangle (cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, 
Context.Radius, corners);
-            cr.Fill ();
+                cr.SetSource (grad);
+                CairoExtensions.RoundedRectangle (cr, alloc.X, alloc.Y, alloc.Width, alloc.Height, 
Context.Radius, corners);
+                cr.Fill ();
 
-            cr.Color = border_color;
-            cr.Rectangle (alloc.X, alloc.Bottom, alloc.Width, BorderWidth);
-            cr.Fill ();
-            grad.Destroy ();
+                cr.SetSourceColor (border_color);
+                cr.Rectangle (alloc.X, alloc.Bottom, alloc.Width, BorderWidth);
+                cr.Fill ();
+            }
         }
 
         public override void DrawColumnHeaderFocus (Cairo.Context cr, Gdk.Rectangle alloc)
@@ -221,7 +221,7 @@ namespace Hyena.Gui.Theming
                     Widget.StyleContext.GetBackgroundColor (StateFlags.Selected)), 0.8);
 
             stroke_color.A = 0.1;
-            cr.Color = stroke_color;
+            cr.SetSourceColor (stroke_color);
 
             CairoExtensions.RoundedRectangle (cr,
                 alloc.X + margin + line_width + right_offset,
@@ -234,7 +234,7 @@ namespace Hyena.Gui.Theming
 
             stroke_color.A = 1.0;
             cr.LineWidth = line_width;
-            cr.Color = stroke_color;
+            cr.SetSourceColor (stroke_color);
             CairoExtensions.RoundedRectangle (cr,
                 alloc.X + margin + line_width + right_offset,
                 alloc.Y + margin + line_width + top_offset,
@@ -257,12 +257,12 @@ namespace Hyena.Gui.Theming
             cr.LineWidth = 1;
             cr.Antialias = Cairo.Antialias.None;
 
-            cr.Color = dark_color;
+            cr.SetSourceColor (dark_color);
             cr.MoveTo (x, y_1);
             cr.LineTo (x, y_2);
             cr.Stroke ();
 
-            cr.Color = light_color;
+            cr.SetSourceColor (light_color);
             cr.MoveTo (x + 1, y_1);
             cr.LineTo (x + 1, y_2);
             cr.Stroke ();
@@ -273,7 +273,7 @@ namespace Hyena.Gui.Theming
         public override void DrawListBackground (Context cr, Gdk.Rectangle alloc, Color color)
         {
             color.A = Context.FillAlpha;
-            cr.Color = color;
+            cr.SetSourceColor (color);
             cr.Rectangle (alloc.X, alloc.Y, alloc.Width, alloc.Height);
             cr.Fill ();
         }
@@ -282,7 +282,7 @@ namespace Hyena.Gui.Theming
                                             Cairo.Color color, CairoCorners corners)
         {
             cr.LineWidth = 1.25;
-            cr.Color = color;
+            cr.SetSourceColor (color);
             CairoExtensions.RoundedRectangle (cr, x + cr.LineWidth/2.0, y + cr.LineWidth/2.0,
                 width - cr.LineWidth, height - cr.LineWidth, Context.Radius, corners, true);
             cr.Stroke ();
@@ -306,7 +306,7 @@ namespace Hyena.Gui.Theming
 
             if (filled) {
                 if (flat_fill) {
-                    cr.Color = selection_color;
+                    cr.SetSourceColor (selection_color);
                 } else {
                     Cairo.Color selection_fill_light = CairoExtensions.ColorShade (selection_color, 1.12);
                     Cairo.Color selection_fill_dark = selection_color;
@@ -319,20 +319,20 @@ namespace Hyena.Gui.Theming
                     grad.AddColorStop (0.4, selection_fill_dark);
                     grad.AddColorStop (1, selection_fill_light);
 
-                    cr.Pattern = grad;
+                    cr.SetSource (grad);
                 }
 
                 CairoExtensions.RoundedRectangle (cr, x, y, width, height, Context.Radius, corners, true);
                 cr.Fill ();
 
                 if (grad != null) {
-                    grad.Destroy ();
+                    grad.Dispose ();
                 }
             }
 
             if (filled && stroked) {
                 cr.LineWidth = 1.0;
-                cr.Color = selection_highlight;
+                cr.SetSourceColor (selection_highlight);
                 CairoExtensions.RoundedRectangle (cr, x + 1.5, y + 1.5, width - 3, height - 3,
                     Context.Radius - 1, corners, true);
                 cr.Stroke ();
@@ -340,7 +340,7 @@ namespace Hyena.Gui.Theming
 
             if (stroked) {
                 cr.LineWidth = 1.0;
-                cr.Color = selection_stroke;
+                cr.SetSourceColor (selection_stroke);
                 CairoExtensions.RoundedRectangle (cr, x + 0.5, y + 0.5, width - 1, height - 1,
                     Context.Radius, corners, true);
                 cr.Stroke ();
@@ -349,7 +349,7 @@ namespace Hyena.Gui.Theming
 
         public override void DrawRowRule (Cairo.Context cr, int x, int y, int width, int height)
         {
-            cr.Color = new Cairo.Color (rule_color.R, rule_color.G, rule_color.B, Context.FillAlpha);
+            cr.SetSourceColor (new Cairo.Color (rule_color.R, rule_color.G, rule_color.B, 
Context.FillAlpha));
             cr.Rectangle (x, y, width, height);
             cr.Fill ();
         }
diff --git a/Hyena.Gui/Hyena.Gui/CairoDamageDebugger.cs b/Hyena.Gui/Hyena.Gui/CairoDamageDebugger.cs
index 8f35fa1..47a44f1 100644
--- a/Hyena.Gui/Hyena.Gui/CairoDamageDebugger.cs
+++ b/Hyena.Gui/Hyena.Gui/CairoDamageDebugger.cs
@@ -49,7 +49,7 @@ namespace Hyena.Gui
         {
             cr.Save ();
             cr.LineWidth = 1.0;
-            cr.Color = CairoExtensions.RgbToColor ((uint)rand.Next (0, 0xffffff));
+            cr.SetSourceColor (CairoExtensions.RgbToColor ((uint)rand.Next (0, 0xffffff)));
             cr.Rectangle (x + 0.5, y + 0.5, w - 1, h - 1);
             cr.Stroke ();
             cr.Restore ();
diff --git a/Hyena.Gui/Hyena.Gui/CairoExtensions.cs b/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
index 811f129..4012b5e 100644
--- a/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
+++ b/Hyena.Gui/Hyena.Gui/CairoExtensions.cs
@@ -67,7 +67,8 @@ namespace Hyena.Gui
 
         public static Surface CreateSurfaceForPixbuf (Cairo.Context cr, Gdk.Pixbuf pixbuf)
         {
-            Surface surface = cr.Target.CreateSimilar (cr.Target.Content, pixbuf.Width, pixbuf.Height);
+            var target = cr.GetTarget ();
+            Surface surface = target.CreateSimilar (target.Content, pixbuf.Width, pixbuf.Height);
             Cairo.Context surface_cr = new Context (surface);
             Gdk.CairoHelper.SetSourcePixbuf (surface_cr, pixbuf, 0.0, 0.0);
             surface_cr.Paint ();
@@ -324,7 +325,7 @@ namespace Hyena.Gui
 
         public static void DisposeContext (Cairo.Context cr)
         {
-            ((IDisposable)cr.Target).Dispose ();
+            ((IDisposable)cr.GetTarget ()).Dispose ();
             ((IDisposable)cr).Dispose ();
         }
 
diff --git a/Hyena.Gui/Hyena.Gui/RatingRenderer.cs b/Hyena.Gui/Hyena.Gui/RatingRenderer.cs
index 9600cc8..ef1c6a9 100644
--- a/Hyena.Gui/Hyena.Gui/RatingRenderer.cs
+++ b/Hyena.Gui/Hyena.Gui/RatingRenderer.cs
@@ -93,13 +93,13 @@ namespace Hyena.Gui
 
                 if (fill || hover_fill) {
                     if (!isHovering || hoverValue >= Value) {
-                        cr.Color = fill ? fill_color : hover_fill_color;
+                        cr.SetSourceColor (fill ? fill_color : hover_fill_color);
                     } else {
-                        cr.Color = hover_fill ? fill_color : hover_fill_color;
+                        cr.SetSourceColor (hover_fill ? fill_color : hover_fill_color);
                     }
                     cr.Fill ();
                 } else {
-                    cr.Color = stroke_color;
+                    cr.SetSourceColor (stroke_color);
                     cr.Stroke ();
                 }
             }
diff --git a/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs b/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
index 00a3e0d..35e4b43 100644
--- a/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
+++ b/Hyena.Gui/Hyena.Gui/ShadingTestWindow.cs
@@ -57,7 +57,7 @@ namespace Hyena.Gui
                     double y = yi * step_height;
 
                     cr.Rectangle (x, y, step_width, step_height);
-                    cr.Color = CairoExtensions.ColorFromHsb (h, s, bg_b);
+                    cr.SetSourceColor (CairoExtensions.ColorFromHsb (h, s, bg_b));
                     cr.Fill ();
 
                     int tw, th;
@@ -67,7 +67,7 @@ namespace Hyena.Gui
 
                     cr.Translate (0.5, 0.5);
                     cr.MoveTo (x + (step_width - tw) / 2.0, y + (step_height - th) / 2.0);
-                    cr.Color = CairoExtensions.ColorFromHsb (h, s, fg_b);
+                    cr.SetSourceColor (CairoExtensions.ColorFromHsb (h, s, fg_b));
                     PangoCairoHelper.ShowLayout (cr, layout);
                     cr.Translate (-0.5, -0.5);
                 }
diff --git a/Hyena.Gui/Hyena.Widgets/PulsingButton.cs b/Hyena.Gui/Hyena.Widgets/PulsingButton.cs
index b010a44..50af4ca 100644
--- a/Hyena.Gui/Hyena.Widgets/PulsingButton.cs
+++ b/Hyena.Gui/Hyena.Widgets/PulsingButton.cs
@@ -95,17 +95,17 @@ namespace Hyena.Widgets
 
             Gdk.RGBA rgba = StyleContext.GetBackgroundColor (StateFlags.Selected);
             Cairo.Color color = CairoExtensions.GdkRGBAToCairoColor (rgba);
-            Cairo.RadialGradient fill = new Cairo.RadialGradient (x, y, 0, x, y, r);
-            color.A = alpha;
-            fill.AddColorStop (0, color);
-            fill.AddColorStop (0.5, color);
-            color.A = 0;
-            fill.AddColorStop (1, color);
-
-            cr.Arc (x, y, r, 0, 2 * Math.PI);
-            cr.Pattern = fill;
-            cr.Fill ();
-            fill.Destroy ();
+            using (var fill = new Cairo.RadialGradient (x, y, 0, x, y, r)) {
+                color.A = alpha;
+                fill.AddColorStop (0, color);
+                fill.AddColorStop (0.5, color);
+                color.A = 0;
+                fill.AddColorStop (1, color);
+
+                cr.Arc (x, y, r, 0, 2 * Math.PI);
+                cr.SetSource (fill);
+                cr.Fill ();
+            }
 
             return base.OnDrawn (cr);
         }
diff --git a/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs b/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
index 72ac1b9..bd69793 100644
--- a/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
+++ b/Hyena.Gui/Hyena.Widgets/SegmentedBar.cs
@@ -332,64 +332,65 @@ namespace Hyena.Widgets
                 bar_height + bar_label_spacing + layout_height));
             cr.Clip ();
 
-            Pattern bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height);
+            using (var bar = RenderBar (Allocation.Width - 2 * h_padding, bar_height)) {
 
-            cr.Save ();
-            cr.Source = bar;
-            cr.Paint ();
-            cr.Restore ();
-
-            if (reflect) {
                 cr.Save ();
+                cr.SetSource (bar);
+                cr.Paint ();
+                cr.Restore ();
 
-                cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height);
-                cr.Clip ();
+                if (reflect) {
+                    cr.Save ();
 
-                Matrix matrix = new Matrix ();
-                matrix.InitScale (1, -1);
-                matrix.Translate (0, -(2 * bar_height) + 1);
-                cr.Transform (matrix);
+                    cr.Rectangle (0, bar_height, Allocation.Width - h_padding, bar_height);
+                    cr.Clip ();
 
-                cr.Pattern = bar;
+                    Matrix matrix = new Matrix ();
+                    matrix.InitScale (1, -1);
+                    matrix.Translate (0, -(2 * bar_height) + 1);
+                    cr.Transform (matrix);
 
-                LinearGradient mask = new LinearGradient (0, 0, 0, bar_height);
+                    cr.SetSource (bar);
 
-                mask.AddColorStop (0.25, new Color (0, 0, 0, 0));
-                mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125));
-                mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4));
-                mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7));
+                    using (var mask = new LinearGradient (0, 0, 0, bar_height)) {
 
-                cr.Mask (mask);
-                mask.Destroy ();
+                        mask.AddColorStop (0.25, new Color (0, 0, 0, 0));
+                        mask.AddColorStop (0.5, new Color (0, 0, 0, 0.125));
+                        mask.AddColorStop (0.75, new Color (0, 0, 0, 0.4));
+                        mask.AddColorStop (1.0, new Color (0, 0, 0, 0.7));
 
-                cr.Restore ();
+                        cr.Mask (mask);
+                    }
 
-                CairoExtensions.PopGroupToSource (cr);
-                cr.Paint ();
-            }
+                    cr.Restore ();
 
-            if (show_labels) {
-                cr.Translate ((reflect ? 0 : -h_padding) + (Allocation.Width - layout_width) / 2,
-                     bar_height + bar_label_spacing);
-                RenderLabels (cr);
-            }
+                    CairoExtensions.PopGroupToSource (cr);
+                    cr.Paint ();
+                }
 
-            bar.Destroy ();
+                if (show_labels) {
+                    cr.Translate ((reflect ? 0 : -h_padding) + (Allocation.Width - layout_width) / 2,
+                              bar_height + bar_label_spacing);
+                    RenderLabels (cr);
+                }
+
+            }
 
             return true;
         }
 
         private Pattern RenderBar (int w, int h)
         {
-            ImageSurface s = new ImageSurface (Format.Argb32, w, h);
-            Context cr = new Context (s);
-            RenderBar (cr, w, h, h / 2);
+            Pattern pattern;
+            using (var s = new ImageSurface (Format.Argb32, w, h)) {
+                using (var cr = new Context (s)) {
+                    RenderBar (cr, w, h, h / 2);
 // TODO Implement the new ctor - see http://bugzilla.gnome.org/show_bug.cgi?id=561394
 #pragma warning disable 0618
-            Pattern pattern = new Pattern (s);
+                    pattern = new Pattern (s);
 #pragma warning restore 0618
-            s.Destroy ();
-            ((IDisposable)cr).Dispose ();
+                }
+            }
             return pattern;
         }
 
@@ -401,63 +402,62 @@ namespace Hyena.Widgets
 
         private void RenderBarSegments (Context cr, int w, int h, int r)
         {
-            LinearGradient grad = new LinearGradient (0, 0, w, 0);
-            double last = 0.0;
-
-            foreach (Segment segment in segments) {
-                if (segment.Percent > 0) {
-                    grad.AddColorStop (last, segment.Color);
-                    grad.AddColorStop (last += segment.Percent, segment.Color);
+            using (var grad = new LinearGradient (0, 0, w, 0)) {
+                double last = 0.0;
+
+                foreach (Segment segment in segments) {
+                    if (segment.Percent > 0) {
+                        grad.AddColorStop (last, segment.Color);
+                        grad.AddColorStop (last += segment.Percent, segment.Color);
+                    }
                 }
-            }
 
-            CairoExtensions.RoundedRectangle (cr, 0, 0, w, h, r);
-            cr.Pattern = grad;
-            cr.FillPreserve ();
-            cr.Pattern.Destroy ();
+                CairoExtensions.RoundedRectangle (cr, 0, 0, w, h, r);
+                cr.SetSource (grad);
+                cr.FillPreserve ();
+            }
 
-            grad = new LinearGradient (0, 0, 0, h);
-            grad.AddColorStop (0.0, new Color (1, 1, 1, 0.125));
-            grad.AddColorStop (0.35, new Color (1, 1, 1, 0.255));
-            grad.AddColorStop (1, new Color (0, 0, 0, 0.4));
+            using (var grad = new LinearGradient (0, 0, 0, h)) {
+                grad.AddColorStop (0.0, new Color (1, 1, 1, 0.125));
+                grad.AddColorStop (0.35, new Color (1, 1, 1, 0.255));
+                grad.AddColorStop (1, new Color (0, 0, 0, 0.4));
 
-            cr.Pattern = grad;
-            cr.Fill ();
-            cr.Pattern.Destroy ();
+                cr.SetSource (grad);
+                cr.Fill ();
+            }
         }
 
         private void RenderBarStrokes (Context cr, int w, int h, int r)
         {
-            LinearGradient stroke = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0x00000040));
-            LinearGradient seg_sep_light = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0xffffff20));
-            LinearGradient seg_sep_dark = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0x00000020));
-
-            cr.LineWidth = 1;
+            using (var stroke = MakeSegmentGradient (h, CairoExtensions.RgbaToColor (0x00000040))) {
+                using (var seg_sep_light = MakeSegmentGradient (h, CairoExtensions.RgbaToColor 
(0xffffff20))) {
+                    using (var seg_sep_dark = MakeSegmentGradient (h, CairoExtensions.RgbaToColor 
(0x00000020))) {
 
-            double seg_w = 20;
-            double x = seg_w > r ? seg_w : r;
+                        cr.LineWidth = 1;
 
-            while (x <= w - r) {
-                cr.MoveTo (x - 0.5, 1);
-                cr.LineTo (x - 0.5, h - 1);
-                cr.Pattern = seg_sep_light;
-                cr.Stroke ();
+                        double seg_w = 20;
+                        double x = seg_w > r ? seg_w : r;
 
-                cr.MoveTo (x + 0.5, 1);
-                cr.LineTo (x + 0.5, h - 1);
-                cr.Pattern = seg_sep_dark;
-                cr.Stroke ();
+                        while (x <= w - r) {
+                            cr.MoveTo (x - 0.5, 1);
+                            cr.LineTo (x - 0.5, h - 1);
+                            cr.SetSource (seg_sep_light);
+                            cr.Stroke ();
 
-                x += seg_w;
-            }
+                            cr.MoveTo (x + 0.5, 1);
+                            cr.LineTo (x + 0.5, h - 1);
+                            cr.SetSource (seg_sep_dark);
+                            cr.Stroke ();
 
-            CairoExtensions.RoundedRectangle (cr, 0.5, 0.5, w - 1, h - 1, r);
-            cr.Pattern = stroke;
-            cr.Stroke ();
+                            x += seg_w;
+                        }
 
-            stroke.Destroy ();
-            seg_sep_light.Destroy ();
-            seg_sep_dark.Destroy ();
+                        CairoExtensions.RoundedRectangle (cr, 0.5, 0.5, w - 1, h - 1, r);
+                        cr.SetSource (stroke);
+                        cr.Stroke ();
+                    }
+                }
+            }
         }
 
         private LinearGradient MakeSegmentGradient (int h, Color color)
@@ -490,12 +490,12 @@ namespace Hyena.Widgets
             foreach (Segment segment in segments) {
                 cr.LineWidth = 1;
                 cr.Rectangle (x + 0.5, 2 + 0.5, segment_box_size - 1, segment_box_size - 1);
-                LinearGradient grad = MakeSegmentGradient (segment_box_size, segment.Color, true);
-                cr.Pattern = grad;
-                cr.FillPreserve ();
-                cr.Color = box_stroke_color;
-                cr.Stroke ();
-                grad.Destroy ();
+                using (var grad = MakeSegmentGradient (segment_box_size, segment.Color, true)) {
+                    cr.SetSource (grad);
+                    cr.FillPreserve ();
+                    cr.SetSourceColor (box_stroke_color);
+                    cr.Stroke ();
+                }
 
                 x += segment_box_size + segment_box_spacing;
 
@@ -506,7 +506,7 @@ namespace Hyena.Widgets
 
                 cr.MoveTo (x, 0);
                 text_color.A = 0.9;
-                cr.Color = text_color;
+                cr.SetSourceColor (text_color);
                 PangoCairoHelper.ShowLayout (cr, layout);
                 cr.Fill ();
 
@@ -515,7 +515,7 @@ namespace Hyena.Widgets
 
                 cr.MoveTo (x, lh);
                 text_color.A = 0.75;
-                cr.Color = text_color;
+                cr.SetSourceColor (text_color);
                 PangoCairoHelper.ShowLayout (cr, layout);
                 cr.Fill ();
 


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