diff --git a/ChangeLog b/ChangeLog index 0178bd423..7cfb71141 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-05-10 Mike Kestner + + * gtk/Object.custom : Dispose on a Destroyed event. + * gtk/Widget.custom : rework the parent_set hack to go direct to + the native signal instead of using the event so we avoid rewrapping of + already destroyed parents. + 2005-05-10 Mike Kestner * gdk/Pixbuf.custom : use non-obsolete PixbufLoader.Write overload. diff --git a/gtk/Object.custom b/gtk/Object.custom index 15968c461..f42479cb7 100755 --- a/gtk/Object.custom +++ b/gtk/Object.custom @@ -30,6 +30,23 @@ [DllImport("libgobject-2.0-0.dll")] private static extern void g_object_ref (IntPtr raw); + static void NativeDestroy (object o, EventArgs args) + { + GLib.Object obj = o as GLib.Object; + if (obj == null) + return; + obj.Dispose (); + } + + static EventHandler native_destroy_handler; + static EventHandler NativeDestroyHandler { + get { + if (native_destroy_handler == null) + native_destroy_handler = new EventHandler (NativeDestroy); + return native_destroy_handler; + } + } + protected override IntPtr Raw { get { return base.Raw; @@ -41,6 +58,7 @@ g_object_ref (value); Sink (); + Destroyed += NativeDestroyHandler; } } @@ -49,7 +67,9 @@ public virtual void Destroy () { + Destroyed -= NativeDestroyHandler; gtk_object_destroy (Handle); + Dispose (); } public bool IsFloating { diff --git a/gtk/Widget.custom b/gtk/Widget.custom index fc98e953a..a24b4040a 100644 --- a/gtk/Widget.custom +++ b/gtk/Widget.custom @@ -25,7 +25,9 @@ [Obsolete] protected Widget (GLib.GType gtype) : base(gtype) { - ParentSet += new ParentSetHandler (Widget_ParentSet); + IntPtr name = GLib.Marshaller.StringToPtrGStrdup ("parent-set"); + g_signal_connect_data (Handle, name, NativeParentSetHandler, IntPtr.Zero, IntPtr.Zero, 0); + GLib.Marshaller.Free (name); } [DllImport("libgtk-win32-2.0-0.dll")] @@ -33,24 +35,41 @@ static extern void gtk_widget_destroy (IntPtr raw); public override void Destroy () { - gtk_widget_destroy (Handle); + 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); - ParentSet += new ParentSetHandler (Widget_ParentSet); + 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 void Widget_ParentSet (object o, ParentSetArgs args) +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 = o as Widget; - if (w.Parent != null && args.PreviousParent == null) - ParentedWidgets[w] = w; - else if (w.Parent == null && args.PreviousParent != null) + Widget w = GLib.Object.GetObject (raw) as Widget; + if (w.Parent == null) ParentedWidgets.Remove (w); + else + ParentedWidgets[w] = w; + Console.WriteLine ("Parenting " + w + " at " + raw); } [DllImport("gtksharpglue-2")]