X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/047aa29670e4c7ba9e48e967506db4db3fbbf399..3a3dde0d44c43bc70a1e9791381ada04b4953a5d:/src/msw/button.cpp diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 13f270d4c5..1c99e39ef9 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -343,26 +343,45 @@ wxSize wxButtonBase::GetDefaultSize() */ // set this button as the (permanently) default one in its panel -void wxButton::SetDefault() +wxWindow *wxButton::SetDefault() { - wxTopLevelWindow *tlw = wxDynamicCast(wxGetTopLevelParent(this), wxTopLevelWindow); - - wxCHECK_RET( tlw, _T("button without top level window?") ); - // set this one as the default button both for wxWidgets ... - wxWindow *winOldDefault = tlw->SetDefaultItem(this); + wxWindow *winOldDefault = wxButtonBase::SetDefault(); // ... and Windows SetDefaultStyle(wxDynamicCast(winOldDefault, wxButton), false); SetDefaultStyle(this, true); + + 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); @@ -374,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);