From: Stefan Csomor Date: Fri, 25 Dec 2009 09:47:30 +0000 (+0000) Subject: removing event handlers on non-owned windows when the destroy event is sent X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/0aaa6ace7ede4240453251d6a1c84c918c54c321?ds=sidebyside removing event handlers on non-owned windows when the destroy event is sent git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62985 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/osx/carbon/private.h b/include/wx/osx/carbon/private.h index e63edd4891..c677e83316 100644 --- a/include/wx/osx/carbon/private.h +++ b/include/wx/osx/carbon/private.h @@ -1005,7 +1005,7 @@ public : wxNonOwnedWindowCarbonImpl(); virtual ~wxNonOwnedWindowCarbonImpl(); - virtual void Destroy() ; + virtual void WillBeDestroyed() ; void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size, long style, long extraStyle, const wxString& name ) ; diff --git a/include/wx/osx/cocoa/private.h b/include/wx/osx/cocoa/private.h index dabd225172..dc7478372c 100644 --- a/include/wx/osx/cocoa/private.h +++ b/include/wx/osx/cocoa/private.h @@ -193,7 +193,7 @@ public : virtual ~wxNonOwnedWindowCocoaImpl(); - virtual void Destroy() ; + virtual void WillBeDestroyed() ; void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size, long style, long extraStyle, const wxString& name ) ; diff --git a/include/wx/osx/core/private.h b/include/wx/osx/core/private.h index 6f64bc39c1..c0de78f269 100644 --- a/include/wx/osx/core/private.h +++ b/include/wx/osx/core/private.h @@ -653,7 +653,7 @@ public : { } - virtual void Destroy() + virtual void WillBeDestroyed() { } diff --git a/include/wx/osx/iphone/private.h b/include/wx/osx/iphone/private.h index 4faad3d7bf..5db08c64aa 100644 --- a/include/wx/osx/iphone/private.h +++ b/include/wx/osx/iphone/private.h @@ -125,7 +125,7 @@ public : virtual ~wxNonOwnedWindowIPhoneImpl(); - virtual void Destroy() ; + virtual void WillBeDestroyed() ; void Create( wxWindow* parent, const wxPoint& pos, const wxSize& size, long style, long extraStyle, const wxString& name ) ; diff --git a/include/wx/osx/nonownedwnd.h b/include/wx/osx/nonownedwnd.h index cf537e15ec..da7ede4551 100644 --- a/include/wx/osx/nonownedwnd.h +++ b/include/wx/osx/nonownedwnd.h @@ -116,6 +116,8 @@ protected: virtual bool OSXShowWithEffect(bool show, wxShowEffect effect, unsigned timeout); + + void OnWindowDestroy( wxWindowDestroyEvent &event); wxNonOwnedWindowImpl* m_nowpeer ; diff --git a/src/osx/carbon/nonownedwnd.cpp b/src/osx/carbon/nonownedwnd.cpp index 75077bc46e..192f8f5a24 100644 --- a/src/osx/carbon/nonownedwnd.cpp +++ b/src/osx/carbon/nonownedwnd.cpp @@ -1144,15 +1144,13 @@ wxNonOwnedWindowCarbonImpl::~wxNonOwnedWindowCarbonImpl() } -void wxNonOwnedWindowCarbonImpl::Destroy() +void wxNonOwnedWindowCarbonImpl::WillBeDestroyed() { if ( m_macEventHandler ) { ::RemoveEventHandler((EventHandlerRef) m_macEventHandler); m_macEventHandler = NULL ; } - - wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ) ; } void wxNonOwnedWindowInstallTopLevelWindowEventHandler(WindowRef window, EventHandlerRef* handler, void *ref) diff --git a/src/osx/cocoa/nonownedwnd.mm b/src/osx/cocoa/nonownedwnd.mm index 9ed1300159..76e2f4b9d5 100644 --- a/src/osx/cocoa/nonownedwnd.mm +++ b/src/osx/cocoa/nonownedwnd.mm @@ -351,9 +351,9 @@ wxNonOwnedWindowCocoaImpl::~wxNonOwnedWindowCocoaImpl() [m_macWindow release]; } -void wxNonOwnedWindowCocoaImpl::Destroy() +void wxNonOwnedWindowCocoaImpl::WillBeDestroyed() { - wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ); + [m_macWindow setDelegate:nil]; } void wxNonOwnedWindowCocoaImpl::Create( wxWindow* WXUNUSED(parent), const wxPoint& pos, const wxSize& size, diff --git a/src/osx/iphone/nonownedwnd.mm b/src/osx/iphone/nonownedwnd.mm index a1dbf134b8..d50c0cfc31 100644 --- a/src/osx/iphone/nonownedwnd.mm +++ b/src/osx/iphone/nonownedwnd.mm @@ -90,9 +90,8 @@ wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl() [m_macWindow release]; } -void wxNonOwnedWindowIPhoneImpl::Destroy() +void wxNonOwnedWindowIPhoneImpl::WillBeDestroyed() { - wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ); } void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size, diff --git a/src/osx/nonownedwnd_osx.cpp b/src/osx/nonownedwnd_osx.cpp index 9adc5647d5..12d8d61aab 100644 --- a/src/osx/nonownedwnd_osx.cpp +++ b/src/osx/nonownedwnd_osx.cpp @@ -147,6 +147,9 @@ bool wxNonOwnedWindow::Create(wxWindow *parent, if ( parent ) parent->AddChild(this); + wxBIND_OR_CONNECT_HACK(this, wxEVT_DESTROY, wxWindowDestroyEventHandler, + wxNonOwnedWindow::OnWindowDestroy, this); + return true; } @@ -159,12 +162,21 @@ wxNonOwnedWindow::~wxNonOwnedWindow() DestroyChildren(); delete m_nowpeer; + m_nowpeer = NULL; // avoid dangling refs if ( s_macDeactivateWindow == this ) s_macDeactivateWindow = NULL; } +void wxNonOwnedWindow::OnWindowDestroy( wxWindowDestroyEvent &event) +{ + event.Skip(); + + if ( m_nowpeer ) + m_nowpeer->WillBeDestroyed(); +} + // ---------------------------------------------------------------------------- // wxNonOwnedWindow misc // ----------------------------------------------------------------------------