From a06235f02f6876e2066341645d5814071c5cd00d Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Thu, 19 Jul 2007 15:35:28 +0000 Subject: [PATCH] 2007-07-19 Mike Kestner * generator/OpaqueGen.cs : override the new Copy vm if a Copy method exists for the type. * glib/Opaque.cs : add a virtual method to allow subclasses with Copy methods to override. Use the method in GetOpaque for unowned instantiations to try to obtain an owned instance. [Fixes #82037] svn path=/trunk/gtk-sharp/; revision=82293 --- ChangeLog | 8 ++++++++ generator/OpaqueGen.cs | 10 ++++++++++ glib/Opaque.cs | 8 +++++++- 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0c5d1e18f..12ab7de72 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2007-07-19 Mike Kestner + + * generator/OpaqueGen.cs : override the new Copy vm if a Copy method + exists for the type. + * glib/Opaque.cs : add a virtual method to allow subclasses with + Copy methods to override. Use the method in GetOpaque for unowned + instantiations to try to obtain an owned instance. [Fixes #82037] + 2007-07-18 Mike Kestner * gdk/EventExpose.cs : return a pointer from the get_area glue diff --git a/generator/OpaqueGen.cs b/generator/OpaqueGen.cs index 410d22173..80a8e3d9d 100644 --- a/generator/OpaqueGen.cs +++ b/generator/OpaqueGen.cs @@ -129,6 +129,16 @@ namespace GtkSharp.Generation { } } + Method copy = Methods ["Copy"] as Method; + if (copy != null) { + sw.WriteLine ("\t\tprotected override GLib.Opaque Copy (IntPtr raw)"); + sw.WriteLine ("\t\t{"); + sw.WriteLine ("\t\t\tGLib.Opaque result = new " + QualifiedName + " (" + copy.CName + " (raw));"); + sw.WriteLine ("\t\t\tresult.Owned = true;"); + sw.WriteLine ("\t\t\treturn result;"); + sw.WriteLine ("\t\t}"); + sw.WriteLine (); + } sw.WriteLine ("#endregion"); AppendCustom(sw, gen_info.CustomDir); diff --git a/glib/Opaque.cs b/glib/Opaque.cs index 5b268407e..357eacddc 100644 --- a/glib/Opaque.cs +++ b/glib/Opaque.cs @@ -51,7 +51,9 @@ namespace GLib { opaque.Unref (o); } opaque.owned = true; - } + } else + opaque = opaque.Copy (o); + return opaque; } @@ -100,6 +102,10 @@ namespace GLib { protected virtual void Ref (IntPtr raw) {} protected virtual void Unref (IntPtr raw) {} protected virtual void Free (IntPtr raw) {} + protected virtual Opaque Copy (IntPtr raw) + { + return this; + } public IntPtr Handle { get {