diff --git a/ChangeLog b/ChangeLog index 444121756..ad330e793 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-05-28 Mike Kestner + + * gtk/Object.custom: move Dispose call to a vm override so that + it runs after all signals and native overrides have run. + * gtk/glue/object.c: destroy override implementation. + 2008-05-28 Lluis Sanchez Gual * gtk/Object.custom: If all destroy handlers have been diff --git a/gtk/Object.custom b/gtk/Object.custom index d52eab9e5..9ba683143 100755 --- a/gtk/Object.custom +++ b/gtk/Object.custom @@ -21,6 +21,30 @@ // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. + [DllImport("gtksharpglue-2")] + private static extern bool gtksharp_object_override_destroy (DestroyVMDelegate handler); + + static DestroyVMDelegate destroy_vm_handler; + + static Object () + { + destroy_vm_handler = new DestroyVMDelegate (DestroyVMCallback); + gtksharp_object_override_destroy (destroy_vm_handler); + } + + [GLib.CDeclCallback] + delegate void DestroyVMDelegate (IntPtr handle); + + static void DestroyVMCallback (IntPtr handle) + { + try { + GLib.Object obj = GLib.Object.GetObject (handle, false); + if (obj != null) + obj.Dispose (); + } catch (Exception) { + } + } + static Hashtable destroy_handlers; static Hashtable DestroyHandlers { get { @@ -46,7 +70,6 @@ handler (this, EventArgs.Empty); DestroyHandlers.Remove (Handle); } - Dispose (); } [GLib.Signal("destroy")] diff --git a/gtk/glue/object.c b/gtk/glue/object.c index 489bad48d..c5518e406 100644 --- a/gtk/glue/object.c +++ b/gtk/glue/object.c @@ -26,6 +26,7 @@ void gtksharp_object_unref_if_floating (GObject *obj); gboolean gtksharp_object_is_floating (GObject *obj); void gtksharp_object_set_floating (GtkObject *obj, gboolean val); +void gtksharp_object_override_destroy (gpointer cb); /* */ void @@ -50,3 +51,24 @@ gtksharp_object_set_floating (GtkObject *obj, gboolean val) gtk_object_sink (obj); } +typedef void (* destroy_func) (GtkObject *obj); + +static destroy_func base_destroy; +static destroy_func managed_destroy; + +static void +my_destroy (GtkObject *obj) +{ + (* managed_destroy) (obj); + (* base_destroy) (obj); +} + +void +gtksharp_object_override_destroy (gpointer cb) +{ + GtkObjectClass *klass = (GtkObjectClass *) g_type_class_ref (GTK_TYPE_OBJECT); + base_destroy = klass->destroy; + managed_destroy = cb; + klass->destroy = my_destroy; +} +