From 79ac0cd19921ec8a98b5d59da4ed5b14fdd8eddf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 2 Jun 2007 13:25:43 +0000 Subject: [PATCH] fix crash after destroying a default button in a backwards compatible way (patch 1727956) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@46272 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 11 ++--------- src/common/wincmn.cpp | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 2487ba62c9..09b0140a6b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -91,16 +91,9 @@ Major new features in 2.8 release 2.8.5 ----- -All: - - -All (Unix): - - -All (GUI): - - wxMSW: + +- Fix crash when destroying a default button (Tim Kosse) - Correct problem with page setup dialog when using landscape mode - Added msw.font.no-proof-quality system option, see manual for description - Fix appearance of notebook with non-top tabs under Windows Vista diff --git a/src/common/wincmn.cpp b/src/common/wincmn.cpp index 41c8a455bd..65c33625ae 100644 --- a/src/common/wincmn.cpp +++ b/src/common/wincmn.cpp @@ -324,10 +324,27 @@ wxWindowBase::~wxWindowBase() wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent((wxWindow*)this), wxTopLevelWindow); - if ( tlw && tlw->GetDefaultItem() == this ) - tlw->SetDefaultItem(NULL); - if ( tlw && tlw->GetTmpDefaultItem() == this ) - tlw->SetTmpDefaultItem(NULL); + if ( tlw ) + { + wxWindow* tmpDefaultItem = tlw->GetTmpDefaultItem(); + if ( tmpDefaultItem == this ) + tlw->SetTmpDefaultItem(NULL); + else if ( tmpDefaultItem ) + { + // A temporary default item masks the real default item, so + // temporarily unset the temporary default item so we can access the + // real default item. + tlw->SetTmpDefaultItem(NULL); + + if ( tlw->GetDefaultItem() == this ) + tlw->SetDefaultItem(NULL); + + // Set the temporary default item back. + tlw->SetTmpDefaultItem(tmpDefaultItem); + } + else if ( tlw->GetDefaultItem() == this ) + tlw->SetDefaultItem(NULL); + } } // reset the dangling pointer our parent window may keep to us