From 66ddd74d23a25e85b89960a5163dc5e7db8cb2ca Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 30 Jan 2009 08:01:41 +0000 Subject: [PATCH] guarding against events sent to semi-destroyed instances, fixes #10418 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@58509 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/window.cpp | 52 ++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index db2d495f42..a574163f8c 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -344,42 +344,48 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl ControlPartCode currentControlPart = cEvent.GetParameter(kEventParamControlCurrentPart , typeControlPartCode ); if ( currentControlPart == 0 ) { - // kill focus + if ( thisWindow->IsBeingDeleted() == false ) + { + // kill focus #if wxUSE_CARET - if ( thisWindow->GetCaret() ) - thisWindow->GetCaret()->OnKillFocus(); + if ( thisWindow->GetCaret() ) + thisWindow->GetCaret()->OnKillFocus(); #endif - wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow)); + wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow)); - // remove this as soon as posting the synthesized event works properly - static bool inKillFocusEvent = false ; + // remove this as soon as posting the synthesized event works properly + static bool inKillFocusEvent = false ; - if ( !inKillFocusEvent ) - { - inKillFocusEvent = true ; - wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); - event.SetEventObject(thisWindow); - thisWindow->GetEventHandler()->ProcessEvent(event) ; - inKillFocusEvent = false ; + if ( !inKillFocusEvent ) + { + inKillFocusEvent = true ; + wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); + event.SetEventObject(thisWindow); + thisWindow->GetEventHandler()->ProcessEvent(event) ; + inKillFocusEvent = false ; + } } } else if ( previousControlPart == 0 ) { - // set focus - // panel wants to track the window which was the last to have focus in it - wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow)); - wxChildFocusEvent eventFocus((wxWindow*)thisWindow); - thisWindow->GetEventHandler()->ProcessEvent(eventFocus); + if ( thisWindow->IsBeingDeleted() == false ) + { + // set focus + // panel wants to track the window which was the last to have focus in it + wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow)); + wxChildFocusEvent eventFocus((wxWindow*)thisWindow); + thisWindow->GetEventHandler()->ProcessEvent(eventFocus); #if wxUSE_CARET - if ( thisWindow->GetCaret() ) - thisWindow->GetCaret()->OnSetFocus(); + if ( thisWindow->GetCaret() ) + thisWindow->GetCaret()->OnSetFocus(); #endif - wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); - event.SetEventObject(thisWindow); - thisWindow->GetEventHandler()->ProcessEvent(event) ; + wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); + event.SetEventObject(thisWindow); + thisWindow->GetEventHandler()->ProcessEvent(event) ; + } } } break;