Don't assert in focus code for buttons inside a wxPopupWindow

IsTopLevel() returns true for wxPopupWindow, even if it's not a subclass
of wxTopLevelWindow, so GetTLWParentIfNotBeingDeleted() asserted when
called with a button inside a wxPopupWindow.

Just return null from it instead for now. A better solution could be to
return wxNonOwnedWindow from GetTLWParentIfNotBeingDeleted() (which
would need to be renamed to something more suitable) and move the
{Get,Set}TmpDefaultItem() methods into it.
This commit is contained in:
Vadim Zeitlin
2018-10-20 19:04:02 +02:00
parent 35a9f134cc
commit 17055fb8c6

View File

@@ -252,28 +252,14 @@ wxWindow *wxButton::SetDefault()
// return NULL
static wxTopLevelWindow *GetTLWParentIfNotBeingDeleted(wxWindow *win)
{
for ( ;; )
{
// 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;
wxWindow* const parent = wxGetTopLevelParent(win);
wxASSERT_MSG( parent, wxT("button without top level parent?") );
break;
}
if ( parent->IsBeingDeleted() )
return NULL;
win = parent;
}
wxASSERT_MSG( win, wxT("button without top level parent?") );
wxTopLevelWindow * const tlw = wxDynamicCast(win, wxTopLevelWindow);
wxASSERT_MSG( tlw, wxT("logic error in GetTLWParentIfNotBeingDeleted()") );
return tlw;
// Note that this may still return null for a button inside wxPopupWindow.
return wxDynamicCast(parent, wxTopLevelWindow);
}
// set this button as being currently default