[Mono.Cairo] Use getter methods for returning IDisposables
authorMichael Hutchinson <m.j.hutchinson@gmail.com>
Wed, 6 Mar 2013 05:41:14 +0000 (00:41 -0500)
committerMichael Hutchinson <m.j.hutchinson@gmail.com>
Wed, 19 Jun 2013 22:37:36 +0000 (18:37 -0400)
This makes it a bit clearer that the caller is responsible for
disposing IDisposable objects returned from any method.

mcs/class/Mono.Cairo/Mono.Cairo/Context.cs

index 699c079cf2df242e03356611603f8cdabcca94fa..1eff46c1ec19e6c177469166a5e07290c456db03 100644 (file)
@@ -230,28 +230,38 @@ namespace Cairo {
                        NativeMethods.cairo_set_dash (handle, dashes, dashes.Length, offset);
                }
 
-               [Obsolete("Use Source")]
+               [Obsolete("Use GetSource/GetSource")]
                public Pattern Pattern {
                        set {
-                               Source = value;
+                               SetSource (value);
                        }
-
                        get {
-                               return Source;
+                               return GetSource ();
                        }
                }
 
+               //This is obsolete because it wasn't obvious it needed to be disposed
+               [Obsolete("Use GetSource/GetSource")]
                public Pattern Source {
                        set {
-                               NativeMethods.cairo_set_source (handle, value.Handle);
+                               SetSource (value);
                        }
-
                        get {
-                               var ptr = NativeMethods.cairo_get_source (handle);
-                               return Cairo.Pattern.Lookup (ptr, false);
+                               return GetSource ();
                        }
                }
 
+               public void SetSource (Pattern source)
+               {
+                       NativeMethods.cairo_set_source (handle, source.Handle);
+               }
+
+               public Pattern GetSource ()
+               {
+                       var ptr = NativeMethods.cairo_get_source (handle);
+                       return Cairo.Pattern.Lookup (ptr, false);
+               }
+
                public double MiterLimit {
                        set {
                                NativeMethods.cairo_set_miter_limit (handle, value);
@@ -270,6 +280,7 @@ namespace Cairo {
                        }
                }
 
+               [Obsolete ("Use GetTarget/SetTarget")]
                public Cairo.Surface Target {
                        set {
                                if (handle != IntPtr.Zero)
@@ -279,20 +290,43 @@ namespace Cairo {
                        }
 
                        get {
-                               return Surface.Lookup (NativeMethods.cairo_get_target (handle), false);
+                               return GetTarget ();
                        }
                }
 
+               public Surface GetTarget ()
+               {
+                       return Surface.Lookup (NativeMethods.cairo_get_target (handle), false);
+               }
+
+               public void SetTarget (Surface target)
+               {
+                       if (handle != IntPtr.Zero)
+                               NativeMethods.cairo_destroy (handle);
+                       handle = NativeMethods.cairo_create (target.Handle);
+               }
+
+               [Obsolete("Use GetScaledFont/SetScaledFont")]
                public ScaledFont ScaledFont {
                        set {
-                               NativeMethods.cairo_set_scaled_font (handle, value.Handle);
+                               SetScaledFont (value);
                        }
 
                        get {
-                               return new ScaledFont (NativeMethods.cairo_get_scaled_font (handle), false);
+                               return GetScaledFont ();
                        }
                }
 
+               public ScaledFont GetScaledFont ()
+               {
+                       return new ScaledFont (NativeMethods.cairo_get_scaled_font (handle), false);
+               }
+
+               public void SetScaledFont (ScaledFont font)
+               {
+                       NativeMethods.cairo_set_scaled_font (handle, font.Handle);
+               }
+
                public uint ReferenceCount {
                        get { return NativeMethods.cairo_get_reference_count (handle); }
                }
@@ -544,13 +578,19 @@ namespace Cairo {
                        NativeMethods.cairo_push_group_with_content (handle, content);
                }
 
+               [Obsolete ("Use GetGroupTarget()")]
                public Surface GroupTarget {
                        get {
-                               IntPtr surface = NativeMethods.cairo_get_group_target (handle);
-                               return Surface.Lookup (surface, false);
+                               return GetGroupTarget ();
                        }
                }
 
+               public Surface GetGroupTarget ()
+               {
+                       IntPtr surface = NativeMethods.cairo_get_group_target (handle);
+                       return Surface.Lookup (surface, false);
+               }
+
                public void Rotate (double angle)
                {
                        NativeMethods.cairo_rotate (handle, angle);
@@ -756,16 +796,26 @@ namespace Cairo {
                        SelectFontFace (family, slant, weight);
                }
 
+               [Obsolete("Use GetFontFace/SetFontFace")]
                public FontFace ContextFontFace {
                        get {
-                               return Cairo.FontFace.Lookup (NativeMethods.cairo_get_font_face (handle), false);
+                               return GetContextFontFace ();
                        }
-
                        set {
-                               NativeMethods.cairo_set_font_face (handle, value == null ? IntPtr.Zero : value.Handle);
+                               SetContextFontFace (value);
                        }
                }
 
+               public FontFace GetContextFontFace ()
+               {
+                       return Cairo.FontFace.Lookup (NativeMethods.cairo_get_font_face (handle), false);
+               }
+
+               public void SetContextFontFace (FontFace value)
+               {
+                       NativeMethods.cairo_set_font_face (handle, value == null ? IntPtr.Zero : value.Handle);
+               }
+
                public void SelectFontFace (string family, FontSlant slant, FontWeight weight)
                {
                        NativeMethods.cairo_select_font_face (handle, family, slant, weight);