From 05c5f281440ccd7f76f2b91a7d337667206b9ef4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 11 May 2007 12:58:55 +0000 Subject: [PATCH] don't try to update TLW default button in WM_SET/KILLFOCUS handlers if the TLW is being deleted (bug 1660913) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45956 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/button.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 1470b0c044..1c99e39ef9 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -355,12 +355,33 @@ wxWindow *wxButton::SetDefault() return winOldDefault; } +// 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 +static wxTopLevelWindow *GetTLWParentIfNotBeingDeleted(wxWindow *win) +{ + for ( ; win; win = win->GetParent() ) + { + if ( win->IsBeingDeleted() ) + return NULL; + + if ( win->IsTopLevel() ) + break; + } + + wxASSERT_MSG( win, _T("button without top level parent?") ); + + return wxDynamicCast(win, wxTopLevelWindow); +} + // set this button as being currently default void wxButton::SetTmpDefault() { - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - - wxCHECK_RET( tlw, _T("button without top level window?") ); + wxTopLevelWindow * const tlw = GetTLWParentIfNotBeingDeleted(GetParent()); + if ( !tlw ) + return; wxWindow *winOldDefault = tlw->GetDefaultItem(); tlw->SetTmpDefaultItem(this); @@ -372,9 +393,9 @@ void wxButton::SetTmpDefault() // unset this button as currently default, it may still stay permanent default void wxButton::UnsetTmpDefault() { - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - - wxCHECK_RET( tlw, _T("button without top level window?") ); + wxTopLevelWindow * const tlw = GetTLWParentIfNotBeingDeleted(GetParent()); + if ( !tlw ) + return; tlw->SetTmpDefaultItem(NULL); -- 2.45.2