Cocoa: Handle Qt::WA_ShowWithoutActivating

Forward the flag to QWindow by setting the _q_showWithoutActivating
property on the window in QWidgetPrivate::create_sys().

Implement by refusing to become the key window
or first responder during QCocoaWindow::setVisible().

Task-number: QTBUG-19194
Change-Id: I8446927ec510d7226a5a7b51b7be49d2f9bfd098
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
bb10
Morten Johan Sørvig 2014-04-24 09:46:15 +02:00
parent 3c982a6384
commit cd07830e3b
3 changed files with 16 additions and 0 deletions

View File

@ -271,6 +271,7 @@ public: // for QNSView
bool m_windowUnderMouse;
bool m_inConstructor;
bool m_inSetVisible;
QCocoaGLContext *m_glContext;
QCocoaMenuBar *m_menubar;
NSCursor *m_windowCursor;

View File

@ -372,6 +372,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
, m_windowModality(Qt::NonModal)
, m_windowUnderMouse(false)
, m_inConstructor(true)
, m_inSetVisible(false)
, m_glContext(0)
, m_menubar(0)
, m_windowCursor(0)
@ -618,6 +619,8 @@ void QCocoaWindow::setVisible(bool visible)
if (m_isNSWindowChild && m_hiddenByClipping)
return;
m_inSetVisible = true;
QCocoaAutoReleasePool pool;
QCocoaWindow *parentCocoaWindow = 0;
if (window()->transientParent())
@ -755,6 +758,8 @@ void QCocoaWindow::setVisible(bool visible)
[parentCocoaWindow->m_nsWindow setStyleMask:[parentCocoaWindow->m_nsWindow styleMask] | NSResizableWindowMask];
}
}
m_inSetVisible = false;
}
NSInteger QCocoaWindow::windowLevel(Qt::WindowFlags flags)
@ -1790,6 +1795,12 @@ bool QCocoaWindow::shouldRefuseKeyWindowAndFirstResponder()
if (window()->flags() & Qt::WindowDoesNotAcceptFocus)
return true;
if (m_inSetVisible) {
QVariant showWithoutActivating = window()->property("_q_showWithoutActivating");
if (showWithoutActivating.isValid() && showWithoutActivating.toBool())
return true;
}
return false;
}

View File

@ -115,6 +115,10 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
win->setProperty(propertyName, q->property(propertyName));
}
#ifdef Q_OS_OSX
if (q->testAttribute(Qt::WA_ShowWithoutActivating))
win->setProperty("_q_showWithoutActivating", QVariant(true));
#endif
win->setFlags(data.window_flags);
fixPosIncludesFrame();
if (q->testAttribute(Qt::WA_Moved)