From 17055fb8c6fdbba5fb92b6519b801da7a7e77491 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Oct 2018 19:04:02 +0200 Subject: [PATCH] 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. --- src/msw/button.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/src/msw/button.cpp b/src/msw/button.cpp index 8211259dcb..ae3cf19601 100644 --- a/src/msw/button.cpp +++ b/src/msw/button.cpp @@ -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