Fixing popup windows with a modal dialog as parent

When having a certain creation sequence, these popup windows were not focused correctly, see https://github.com/wxWidgets/wxWidgets/pull/672 , commit d2265136e359df4d14054860a68bbc7f4910279d , revert this change if problems arise to see whether this is a recursion
This commit is contained in:
Stefan Csomor 2018-01-21 20:41:52 +01:00
parent aae23be946
commit ce90336dff
2 changed files with 41 additions and 25 deletions

View File

@ -288,6 +288,10 @@ protected :
CGWindowLevel m_macWindowLevel;
WXWindow m_macWindow;
void * m_macFullScreenData ;
private:
void SetUpForModalParent();
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxNonOwnedWindowCocoaImpl);
};

View File

@ -733,31 +733,9 @@ long style, long extraStyle, const wxString& WXUNUSED(name) )
[[m_macWindow standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
}
// If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
// to be in NSModalPanelWindowLevel and not NSFloatingWindowLevel to stay
// above the parent.
wxDialog * const parentDialog = parent == NULL ? NULL : wxDynamicCast(parent->MacGetTopLevelWindow(), wxDialog);
if (parentDialog && parentDialog->IsModal())
{
if (level == NSFloatingWindowLevel)
{
level = NSModalPanelWindowLevel;
}
// Cocoa's modal loop does not process other windows by default, but
// don't call this on normal window levels so nested modal dialogs will
// still behave modally.
if (level != NSNormalWindowLevel)
{
if ([m_macWindow isKindOfClass:[NSPanel class]])
{
[(NSPanel*)m_macWindow setWorksWhenModal:YES];
}
}
}
[m_macWindow setLevel:level];
m_macWindowLevel = level;
SetUpForModalParent();
[m_macWindow setLevel:m_macWindowLevel];
[m_macWindow setDelegate:controller];
@ -791,8 +769,41 @@ void wxNonOwnedWindowCocoaImpl::Lower()
[m_macWindow orderWindow:NSWindowBelow relativeTo:0];
}
void wxNonOwnedWindowCocoaImpl::SetUpForModalParent()
{
wxNonOwnedWindow* wxpeer = GetWXPeer();
if (wxpeer)
{
// If the parent is modal, windows with wxFRAME_FLOAT_ON_PARENT style need
// to be in NSModalPanelWindowLevel and not NSFloatingWindowLevel to stay
// above the parent.
wxDialog* const parentDialog = wxDynamicCast(wxGetTopLevelParent(wxpeer->GetParent()), wxDialog);
if (parentDialog && parentDialog->IsModal())
{
if (m_macWindowLevel == NSFloatingWindowLevel)
{
m_macWindowLevel = NSModalPanelWindowLevel;
if ([m_macWindow level] == NSFloatingWindowLevel)
[m_macWindow setLevel:m_macWindowLevel];
}
// Cocoa's modal loop does not process other windows by default, but
// don't call this on normal window levels so nested modal dialogs will
// still behave modally.
if (m_macWindowLevel != NSNormalWindowLevel)
{
if ([m_macWindow isKindOfClass:[NSPanel class]])
{
[(NSPanel*)m_macWindow setWorksWhenModal:YES];
}
}
}
}
}
void wxNonOwnedWindowCocoaImpl::ShowWithoutActivating()
{
SetUpForModalParent();
[m_macWindow orderFront:nil];
[[m_macWindow contentView] setNeedsDisplay: YES];
}
@ -826,6 +837,7 @@ bool wxNonOwnedWindowCocoaImpl::Show(bool show)
}
}
SetUpForModalParent();
if (!(wxpeer->GetWindowStyle() & wxFRAME_TOOL_WINDOW))
[m_macWindow makeKeyAndOrderFront:nil];
else