TLW pending delete shouldn't be reported as the top window

Because top windows can (and do) act as parents for certain dialogs, a
window already pending delete shouldn't be explicitly reported as the top
window because all dialogs which would use it as a parent
would be destroyed at nearest idle cycle.

Closes #17982.
This commit is contained in:
Artur Wieczorek
2017-10-31 20:47:45 +01:00
parent b5aaede7b1
commit 1903c9615e

View File

@@ -170,8 +170,25 @@ void wxAppBase::CleanUp()
wxWindow* wxAppBase::GetTopWindow() const wxWindow* wxAppBase::GetTopWindow() const
{ {
wxWindow* window = m_topWindow; wxWindow* window = m_topWindow;
if (window == NULL && wxTopLevelWindows.GetCount() > 0)
window = wxTopLevelWindows.GetFirst()->GetData(); // If there is no top window or it is about to be destroyed,
// we need to search for the first TLW which is not pending delete
if ( !window || wxPendingDelete.Member(window) )
{
window = NULL;
wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
while ( node )
{
wxWindow* win = node->GetData();
if ( !wxPendingDelete.Member(win) )
{
window = win;
break;
}
node = node->GetNext();
}
}
return window; return window;
} }