From 86b07679f77633e48943c0363fb5fcd2371fcf3c Mon Sep 17 00:00:00 2001 From: Michael Hutchinson Date: Wed, 6 Mar 2013 00:41:14 -0500 Subject: [PATCH] [Mono.Cairo] Use getter methods for returning IDisposables 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 | 82 +++++++++++++++++----- 1 file changed, 66 insertions(+), 16 deletions(-) diff --git a/mcs/class/Mono.Cairo/Mono.Cairo/Context.cs b/mcs/class/Mono.Cairo/Mono.Cairo/Context.cs index 699c079cf2d..1eff46c1ec1 100644 --- a/mcs/class/Mono.Cairo/Mono.Cairo/Context.cs +++ b/mcs/class/Mono.Cairo/Mono.Cairo/Context.cs @@ -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); -- 2.25.1