diff --git a/cairo/Context.cs b/cairo/Context.cs index fc1f015ef..ced669ce7 100644 --- a/cairo/Context.cs +++ b/cairo/Context.cs @@ -184,9 +184,11 @@ namespace Cairo { state = NativeMethods.cairo_create (surface.Handle); } - public Context (IntPtr state) + public Context (IntPtr state) : this (state, true) {} + + public Context (IntPtr state, bool owned) { - this.state = NativeMethods.cairo_reference (state); + this.state = owned ? state : NativeMethods.cairo_reference (state); } ~Context () diff --git a/cairo/cairo-api.xml b/cairo/cairo-api.xml index 8ca55713d..8ae93c016 100644 --- a/cairo/cairo-api.xml +++ b/cairo/cairo-api.xml @@ -3,7 +3,7 @@ - + diff --git a/generator/HandleBase.cs b/generator/HandleBase.cs index 70ab8e7ac..c3c45a396 100644 --- a/generator/HandleBase.cs +++ b/generator/HandleBase.cs @@ -25,7 +25,7 @@ namespace GtkSharp.Generation { using System.IO; using System.Xml; - public abstract class HandleBase : ClassBase, IAccessor { + public abstract class HandleBase : ClassBase, IAccessor, IOwnable { protected HandleBase (XmlElement ns, XmlElement elem) : base (ns, elem) {} diff --git a/generator/IOwnable.cs b/generator/IOwnable.cs new file mode 100644 index 000000000..e243da942 --- /dev/null +++ b/generator/IOwnable.cs @@ -0,0 +1,24 @@ +// Copyright (c) 2011 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +namespace GtkSharp.Generation { + + public interface IOwnable { + + string FromNative (string var, bool owned); + } +} diff --git a/generator/Makefile.am b/generator/Makefile.am index d6b10db4b..ca061f05d 100644 --- a/generator/Makefile.am +++ b/generator/Makefile.am @@ -31,6 +31,7 @@ sources = \ IManualMarshaler.cs \ InterfaceGen.cs \ InterfaceVM.cs \ + IOwnable.cs \ LogWriter.cs \ LPGen.cs \ LPUGen.cs \ @@ -44,6 +45,7 @@ sources = \ ObjectBase.cs \ ObjectGen.cs \ OpaqueGen.cs \ + OwnableGen.cs \ Parameters.cs \ Parser.cs \ Property.cs \ diff --git a/generator/OwnableGen.cs b/generator/OwnableGen.cs new file mode 100644 index 000000000..96a2a826c --- /dev/null +++ b/generator/OwnableGen.cs @@ -0,0 +1,51 @@ +// GtkSharp.Generation.ManualGen.cs - Ungenerated handle type Generatable. +// +// Author: Mike Kestner +// +// Copyright (c) 2003 Mike Kestner +// Copyright (c) 2004 Novell, Inc. +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of version 2 of the GNU General Public +// License as published by the Free Software Foundation. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. +// +// You should have received a copy of the GNU General Public +// License along with this program; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. + + +namespace GtkSharp.Generation { + + using System; + + public class OwnableGen : SimpleBase, IOwnable { + + public OwnableGen (string ctype, string type) : base (ctype, type, "null") {} + + public override string MarshalType { + get { return "IntPtr"; } + } + + public override string CallByName (string var_name) + { + return var_name + " == null ? IntPtr.Zero : " + var_name + ".Handle"; + } + + public override string FromNative (string var) + { + return String.Format ("new {0} ({1})", QualifiedName, var); + } + + public string FromNative (string var, bool owned) + { + return String.Format ("new {0} ({1}, {2})", QualifiedName, var, owned ? "true" : "false"); + } + } +} + diff --git a/generator/Parameters.cs b/generator/Parameters.cs index 7af599d50..a1ba61f1e 100644 --- a/generator/Parameters.cs +++ b/generator/Parameters.cs @@ -283,8 +283,8 @@ namespace GtkSharp.Generation { result [i] = (gen as IManualMarshaler).ReleaseNative ("native_" + CallName) + ";"; return result; } else if (PassAs != String.Empty && MarshalType != CSType) - if (gen is HandleBase) - return new string [] { CallName + " = " + (gen as HandleBase).FromNative ("native_" + CallName, Owned) + ";" }; + if (gen is IOwnable) + return new string [] { CallName + " = " + (gen as IOwnable).FromNative ("native_" + CallName, Owned) + ";" }; else return new string [] { CallName + " = " + gen.FromNative ("native_" + CallName) + ";" }; return new string [0]; @@ -295,8 +295,8 @@ namespace GtkSharp.Generation { { if (Generatable == null) return String.Empty; - else if (Generatable is HandleBase) - return ((HandleBase)Generatable).FromNative (var, Owned); + else if (Generatable is IOwnable) + return ((IOwnable)Generatable).FromNative (var, Owned); else return Generatable.FromNative (var); } diff --git a/generator/Parser.cs b/generator/Parser.cs index 415647a2b..99581fc52 100644 --- a/generator/Parser.cs +++ b/generator/Parser.cs @@ -169,6 +169,8 @@ namespace GtkSharp.Generation { } } else if (type == "manual") result = new ManualGen (cname, name); + else if (type == "ownable") + result = new OwnableGen (cname, name); else if (type == "alias") result = new AliasGen (cname, name); else if (type == "marshal") { diff --git a/generator/ReturnValue.cs b/generator/ReturnValue.cs index e30171e36..cf7f25308 100644 --- a/generator/ReturnValue.cs +++ b/generator/ReturnValue.cs @@ -129,8 +129,8 @@ namespace GtkSharp.Generation { return String.Format ("({0}[]) GLib.Marshaller.PtrArrayToArray ({1}, {2}, typeof({0}))", ElementType, var, args); else return String.Format ("({0}[]) GLib.Marshaller.ListPtrToArray ({1}, typeof({2}), {3}, typeof({4}))", ElementType, var, IGen.QualifiedName, args, element_ctype == "gfilename*" ? "GLib.ListBase.FilenameString" : ElementType); - } else if (IGen is HandleBase) - return ((HandleBase)IGen).FromNative (var, owned); + } else if (IGen is IOwnable) + return ((IOwnable)IGen).FromNative (var, owned); else if (is_null_term) return String.Format ("GLib.Marshaller.NullTermPtrToStringArray ({0}, {1})", var, owned ? "true" : "false"); else