From afa17eaceebf4d266c6bc4aa2fa56169ca3a1a7c Mon Sep 17 00:00:00 2001 From: Mike Kestner Date: Fri, 13 May 2005 17:38:51 +0000 Subject: [PATCH] 2005-05-13 Mike Kestner * gtk/Object.custom : hold refs for all managed subclasses. Release on Destroy. Dispose plain wrappers on Destroy also. * gtk/Widget.custom : remove the parent set hack since it's "handled" on Gtk.Object now. All this will get fixed properly when we have access to owen's toggle_refs. svn path=/trunk/gtk-sharp/; revision=44506 --- ChangeLog | 8 ++++++++ doc/en/Gtk/Object.xml | 29 +++++++++++++++++++++++++++++ gtk/Object.custom | 23 ++++++++++++++++++++++- gtk/Widget.custom | 31 ------------------------------- 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82f2d45e6..bbfb91a6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2005-05-13 Mike Kestner + + * gtk/Object.custom : hold refs for all managed subclasses. Release on + Destroy. Dispose plain wrappers on Destroy also. + * gtk/Widget.custom : remove the parent set hack since it's "handled" + on Gtk.Object now. All this will get fixed properly when we have + access to owen's toggle_refs. + 2005-05-13 Mike Kestner * generator/MethodBody.cs : don't create a new destroy notify diff --git a/doc/en/Gtk/Object.xml b/doc/en/Gtk/Object.xml index 01240a187..bdc8100dc 100644 --- a/doc/en/Gtk/Object.xml +++ b/doc/en/Gtk/Object.xml @@ -451,5 +451,34 @@ The object is only destroyed if all the references to the object are released, t + + + Method + + System.Void + + + + + + + Internal method used by language bindings. + a + a + Should not be called by user code typically. + + + + + Method + + System.Void + + + + Releases object resources. + + + diff --git a/gtk/Object.custom b/gtk/Object.custom index 77142fc02..b9743f50a 100755 --- a/gtk/Object.custom +++ b/gtk/Object.custom @@ -30,12 +30,21 @@ [DllImport("libgobject-2.0-0.dll")] private static extern void g_object_ref (IntPtr raw); + static Hashtable managed_subclasses; + static Hashtable ManagedSubclasses { + get { + if (managed_subclasses == null) + managed_subclasses = new Hashtable (); + return managed_subclasses; + } + } + static void NativeDestroy (object o, EventArgs args) { Gtk.Object obj = o as Gtk.Object; if (obj == null) return; - obj.Destroyed -= NativeDestroyHandler; + ManagedSubclasses.Remove (obj); obj.Dispose (); } @@ -48,6 +57,18 @@ } } + protected override void CreateNativeObject (string[] names, GLib.Value[] vals) + { + base.CreateNativeObject (names, vals); + ManagedSubclasses [this] = this; + } + + public override void Dispose () + { + Destroyed -= NativeDestroyHandler; + base.Dispose (); + } + protected override IntPtr Raw { get { return base.Raw; diff --git a/gtk/Widget.custom b/gtk/Widget.custom index 29223e8dd..1e5cba870 100644 --- a/gtk/Widget.custom +++ b/gtk/Widget.custom @@ -25,9 +25,6 @@ [Obsolete] protected Widget (GLib.GType gtype) : base(gtype) { - IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("parent-set"); - g_signal_connect_data (Handle, name, NativeParentSetHandler, IntPtr.Zero, IntPtr.Zero, 0); - GLib.Marshaller.Free (name); } public override void Destroy () @@ -35,37 +32,9 @@ public override void Destroy () base.Destroy (); } -delegate void NativeParentSetDelegate (IntPtr obj, IntPtr prev, IntPtr data); - -[DllImport("libgobject-2.0-0.dll")] -static extern int g_signal_connect_data (IntPtr raw, IntPtr name, NativeParentSetDelegate hndlr, IntPtr data, IntPtr notify, int flags); - protected override void CreateNativeObject (string[] names, GLib.Value[] vals) { base.CreateNativeObject (names, vals); - IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("parent-set"); - g_signal_connect_data (Handle, name, NativeParentSetHandler, IntPtr.Zero, IntPtr.Zero, 0); - GLib.Marshaller.Free (name); -} - -private static Hashtable ParentedWidgets = new Hashtable (); - -private static NativeParentSetDelegate native_parent_set_handler; -private static NativeParentSetDelegate NativeParentSetHandler { - get { - if (native_parent_set_handler == null) - native_parent_set_handler = new NativeParentSetDelegate (Widget_ParentSet); - return native_parent_set_handler; - } -} - -private static void Widget_ParentSet (IntPtr raw, IntPtr prev, IntPtr data) -{ - Widget w = GLib.Object.GetObject (raw) as Widget; - if (w.Parent == null) - ParentedWidgets.Remove (w); - else - ParentedWidgets[w] = w; } [DllImport("gtksharpglue-2")]