diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index c6f04210f9..092022df0b 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -2883,11 +2883,22 @@ wxWindowGTK::~wxWindowGTK() m_isBeingDeleted = true; m_hasVMT = false; + // destroy children before destroying this window itself + DestroyChildren(); + + // unhook focus handlers to prevent stray events being + // propagated to this (soon to be) dead object + if (m_focusWidget != NULL) + { + gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget), + (GtkSignalFunc) gtk_window_focus_in_callback, (gpointer) this ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget), + (GtkSignalFunc) gtk_window_focus_out_callback, (gpointer) this ); + } + if (m_widget) Show( false ); - DestroyChildren(); - #ifdef HAVE_XIM if (m_ic) gdk_ic_destroy (m_ic); diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index c6f04210f9..092022df0b 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -2883,11 +2883,22 @@ wxWindowGTK::~wxWindowGTK() m_isBeingDeleted = true; m_hasVMT = false; + // destroy children before destroying this window itself + DestroyChildren(); + + // unhook focus handlers to prevent stray events being + // propagated to this (soon to be) dead object + if (m_focusWidget != NULL) + { + gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget), + (GtkSignalFunc) gtk_window_focus_in_callback, (gpointer) this ); + gtk_signal_disconnect_by_func( GTK_OBJECT(m_focusWidget), + (GtkSignalFunc) gtk_window_focus_out_callback, (gpointer) this ); + } + if (m_widget) Show( false ); - DestroyChildren(); - #ifdef HAVE_XIM if (m_ic) gdk_ic_destroy (m_ic);