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.
This commit is contained in:
Bertrand Lorentz 2013-07-26 14:56:26 -05:00
parent bdc2cfdf1d
commit 36e2a12bfc

View File

@ -227,28 +227,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);
@ -267,10 +277,7 @@ namespace Cairo {
}
}
public bool HasCurrentPoint {
get { return NativeMethods.cairo_has_current_point (handle); }
}
[Obsolete ("Use GetTarget/SetTarget")]
public Cairo.Surface Target {
set {
if (handle != IntPtr.Zero)
@ -280,20 +287,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 Cairo.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); }
}
@ -555,13 +585,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);
@ -767,16 +803,27 @@ 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);
@ -821,5 +868,9 @@ namespace Cairo {
{
return NativeMethods.cairo_format_stride_for_width (format, width);
}
public bool HasCurrentPoint {
get { return NativeMethods.cairo_has_current_point (handle); }
}
}
}