Update the window style when the modality changes on Cocoa
authorAndy Shaw <andy.shaw@digia.com>
Tue, 25 Sep 2012 05:04:01 +0000 (07:04 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 4 Oct 2012 09:58:48 +0000 (11:58 +0200)
On Cocoa if the modality of a dialog changes then the style of the
window needs to change to reflect this. So we add a variable to
cache the windows modality when it is created to compare against when
being made visible.

Task-number: QTBUG-22316
Change-Id: I7bfd016321510a9ec70ccb90672f5203a0f3a468
Reviewed-by: Samuel Rødal <samuel.rodal@digia.com>
src/plugins/platforms/cocoa/qcocoawindow.h
src/plugins/platforms/cocoa/qcocoawindow.mm

index 20648e8..4a14676 100644 (file)
@@ -157,6 +157,7 @@ public: // for QNSView
     NSWindow *m_nsWindow;
     Qt::WindowFlags m_windowFlags;
     Qt::WindowState m_synchedWindowState;
+    Qt::WindowModality m_windowModality;
     QPointer<QWindow> m_activePopupWindow;
 
     bool m_inConstructor;
index 1524c71..4902e31 100644 (file)
@@ -187,6 +187,7 @@ QCocoaWindow::QCocoaWindow(QWindow *tlw)
     : QPlatformWindow(tlw)
     , m_nsWindow(0)
     , m_synchedWindowState(Qt::WindowActive)
+    , m_windowModality(Qt::NonModal)
     , m_inConstructor(true)
     , m_glContext(0)
     , m_menubar(0)
@@ -248,6 +249,9 @@ void QCocoaWindow::setVisible(bool visible)
     qDebug() << "QCocoaWindow::setVisible" << window() << visible;
 #endif
     if (visible) {
+        // We need to recreate if the modality has changed as the style mask will need updating
+        if (m_windowModality != window()->windowModality())
+            recreateWindow(parent());
         QCocoaWindow *parentCocoaWindow = 0;
         if (window()->transientParent()) {
             parentCocoaWindow = static_cast<QCocoaWindow *>(window()->transientParent()->handle());
@@ -359,6 +363,8 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags)
                  Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint;
         if (flags == Qt::Window) {
             styleMask = (NSResizableWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSTitledWindowMask);
+        } else if ((flags & Qt::Dialog) && (window()->windowModality() != Qt::NonModal)) {
+            styleMask = NSTitledWindowMask;
         } else if (!(flags & Qt::FramelessWindowHint)) {
             if (flags & Qt::WindowMaximizeButtonHint)
                 styleMask |= NSResizableWindowMask;
@@ -655,7 +661,7 @@ NSWindow * QCocoaWindow::createNSWindow()
 
     NSInteger level = windowLevel(flags);
     [createdWindow setLevel:level];
-
+    m_windowModality = window()->windowModality();
     return createdWindow;
 }