From 3d4b579bd8037d791c102fc0f5426a281aec6213 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 6 Feb 2008 19:58:30 +0000 Subject: [PATCH] correction after the previous commit which introduced bug 1888014 [backport of r51574 from trunk] git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@51575 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/button.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 4a244235b0..e27bd01f84 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -357,26 +357,32 @@ void wxButton::SetDefault() SetDefaultStyle(this, true); } -// special version of wxGetTopLevelParent() which is safe to call when the -// parent is being destroyed: wxGetTopLevelParent() would just return NULL in -// this case because wxWindow version of IsTopLevel() is used when it's called -// during window destruction instead of wxTLW one, but we want to distinguish -// between these cases +// return the top level parent window if it's not being deleted yet, otherwise +// return NULL static wxTopLevelWindow *GetTLWParentIfNotBeingDeleted(wxWindow *win) { - for ( ; win; win = win->GetParent() ) + for ( ;; ) { - if ( win->IsTopLevel() ) + // IsTopLevel() will return false for a wxTLW being deleted, so we also + // need the parent test for this case + wxWindow * const parent = win->GetParent(); + if ( !parent || win->IsTopLevel() ) { if ( win->IsBeingDeleted() ) return NULL; + break; } + + win = parent; } wxASSERT_MSG( win, _T("button without top level parent?") ); - return wxDynamicCast(win, wxTopLevelWindow); + wxTopLevelWindow * const tlw = wxDynamicCast(win, wxTopLevelWindow); + wxASSERT_MSG( tlw, _T("logic error in GetTLWParentIfNotBeingDeleted()") ); + + return tlw; } // set this button as being currently default