Fix MacReopenApp() in presence of hidden windows

wxOSX's wxApp::MacReopenApp() previously contained logic to unhide
hidden windows, but this code was commended out since 2013 as
problematic - it was showing windows like closed, but not yet
destroyed, non-modal dialogs.

Unfortunately while this part was commented out, the rest of the code
that handled existence of hidden windows was not, resulting in a bug
where nothing happened after clicking app icon in the Dock if the
application didn't have any visible window at the moment, but had a
"technical" hidden one, e.g. after opening and closing
wxPreferencesEditor.

Fixed by simplyfing and removing all (functionally commented-out) code
related to hidden windows. Instead, the logic is now:
1. do nothing if some window is already visible
2. restore an iconized window if there's one
3. call MacNewFile() if neither happened
This commit is contained in:
Václav Slavík
2020-06-18 10:58:50 +02:00
parent 895424ecc0
commit c8f4d5e669

View File

@@ -157,50 +157,39 @@ void wxApp::MacReopenApp()
// if there is no open window -> create a new one
// if all windows are hidden -> show the first
// if some windows are not hidden -> do nothing
//
// Showing hidden windows is not really always a good solution, also non-modal dialogs when closed end up
// as hidden TLWs, so do preferences and some classes like wxTaskBarIconWindow use placeholder TLWs.
// We don't want to reshow those, so let's just reopen the minimized a.k.a. iconized TLWs.
wxTopLevelWindow* firstIconized = NULL;
wxWindowList::compatibility_iterator node = wxTopLevelWindows.GetFirst();
if ( !node )
{
MacNewFile() ;
}
else
{
wxTopLevelWindow* firstIconized = NULL ;
wxTopLevelWindow* firstHidden = NULL ;
while (node)
{
wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData();
if ( !win->IsShown() )
{
// make sure we don't show 'virtual toplevel windows' like wxTaskBarIconWindow
if ( firstHidden == NULL && ( wxDynamicCast( win, wxFrame ) || wxDynamicCast( win, wxDialog ) ) )
firstHidden = win ;
}
else if ( win->IsIconized() )
{
if ( firstIconized == NULL )
firstIconized = win ;
}
else
{
// we do have a visible, non-iconized toplevelwindow -> do nothing
return;
}
node = node->GetNext();
while (node)
{
wxTopLevelWindow* win = (wxTopLevelWindow*) node->GetData();
if ( win->IsShown() )
{
// we do have a visible, non-iconized toplevelwindow -> do nothing
return;
}
else if ( win->IsIconized() )
{
if ( firstIconized == NULL )
firstIconized = win;
}
if ( firstIconized )
firstIconized->Iconize( false ) ;
// showing hidden windows is not really always a good solution, also non-modal dialogs when closed end up
// as hidden tlws, we don't want to reshow those, so let's just reopen the minimized a.k.a. iconized tlws
// unless we find a regression ...
#if 0
else if ( firstHidden )
firstHidden->Show( true );
#endif
node = node->GetNext();
}
if ( firstIconized )
{
firstIconized->Iconize(false);
return;
}
// no window was shown, we need to create a new one
MacNewFile();
}
#if wxOSX_USE_COCOA_OR_IPHONE