Add QPlatformWindow::setWindowModified(bool)
authorBradley T. Hughes <bradley.hughes@nokia.com>
Thu, 12 Apr 2012 10:52:24 +0000 (12:52 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 17 Apr 2012 08:15:44 +0000 (10:15 +0200)
Mac OS X provided a platform API for marking a window/document as
modified. This previously worked in Qt 4, so we need to have an
interface to keep this working in Qt 5. If the platform window does not
provide an implementation, fallback to setting the window title.

Note that this does not add any QWindow API, it's only in
QPlatformWindow.

Change-Id: I84c5a5df8536859157f2b1fa9e4cc647a09fd06d
Reviewed-by: Gunnar Sletta <gunnar.sletta@nokia.com>
src/gui/kernel/qplatformwindow_qpa.cpp
src/gui/kernel/qplatformwindow_qpa.h
src/plugins/platforms/cocoa/qcocoawindow.h
src/plugins/platforms/cocoa/qcocoawindow.mm
src/widgets/kernel/qwidget.cpp
src/widgets/kernel/qwidget_p.h
src/widgets/kernel/qwidget_qpa.cpp

index b36a277..e07ed78 100644 (file)
@@ -311,6 +311,17 @@ bool QPlatformWindow::setMouseGrabEnabled(bool grab)
 }
 
 /*!
+    Reimplement to be able to let Qt indicate that the window has been
+    modified. Return true if the native window supports setting the modified
+    flag, false otherwise.
+*/
+bool QPlatformWindow::setWindowModified(bool modified)
+{
+    Q_UNUSED(modified);
+    return false;
+}
+
+/*!
     Reimplement this method to be able to do any platform specific event
     handling. All events for window() are passed to this function before being
     sent to QWindow::event().
index 31b14ca..aa4d7f5 100644 (file)
@@ -113,6 +113,8 @@ public:
     virtual bool setKeyboardGrabEnabled(bool grab);
     virtual bool setMouseGrabEnabled(bool grab);
 
+    virtual bool setWindowModified(bool modified);
+
     virtual void windowEvent(QEvent *event);
 
 protected:
index 184422a..68cf72b 100644 (file)
@@ -117,6 +117,8 @@ public:
     void setCurrentContext(QCocoaGLContext *context);
     QCocoaGLContext *currentContext() const;
 
+    Q_DECL_OVERRIDE bool setWindowModified(bool modified);
+
 protected:
     // NSWindow handling. The QCocoaWindow/QNSView can either be displayed
     // in an existing NSWindow or in one created by Qt.
index af8f039..f3458c2 100644 (file)
@@ -503,3 +503,10 @@ QCocoaWindow *QCocoaWindow::parentCocoaWindow() const
     return 0;
 }
 
+bool QCocoaWindow::setWindowModified(bool modified)
+{
+    if (!m_nsWindow)
+        return false;
+    [m_nsWindow setDocumentEdited:(modified?YES:NO)];
+    return true;
+}
index 662c9b7..ddab669 100644 (file)
@@ -10322,20 +10322,30 @@ void QWidget::setWindowModified(bool mod)
     Q_D(QWidget);
     setAttribute(Qt::WA_WindowModified, mod);
 
-#ifndef Q_WS_MAC
-    if (!windowTitle().contains(QLatin1String("[*]")) && mod)
-        qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder");
-#endif
-    d->setWindowTitle_helper(windowTitle());
-    d->setWindowIconText_helper(windowIconText());
-#ifdef Q_WS_MAC
-    d->setWindowModified_sys(mod);
-#endif
+    d->setWindowModified_helper();
 
     QEvent e(QEvent::ModifiedChange);
     QApplication::sendEvent(this, &e);
 }
 
+void QWidgetPrivate::setWindowModified_helper()
+{
+    Q_Q(QWidget);
+    QWindow *window = q->windowHandle();
+    if (!window)
+        return;
+    QPlatformWindow *platformWindow = window->handle();
+    if (!platformWindow)
+        return;
+    bool on = q->testAttribute(Qt::WA_WindowModified);
+    if (!platformWindow->setWindowModified(on)) {
+        if (!q->windowTitle().contains(QLatin1String("[*]")) && on)
+            qWarning("QWidget::setWindowModified: The window title does not contain a '[*]' placeholder");
+        setWindowTitle_helper(q->windowTitle());
+        setWindowIconText_helper(q->windowIconText());
+    }
+}
+
 #ifndef QT_NO_TOOLTIP
 /*!
   \property QWidget::toolTip
index d3fcdce..d7c0ec7 100644 (file)
@@ -466,6 +466,7 @@ public:
 
     void setWindowTitle_helper(const QString &cap);
     void setWindowFilePath_helper(const QString &filePath);
+    void setWindowModified_helper();
 
     bool setMinimumSize_helper(int &minw, int &minh);
     bool setMaximumSize_helper(int &maxw, int &maxh);
@@ -745,7 +746,6 @@ public:
     void update_sys(const QRect &rect);
     void update_sys(const QRegion &rgn);
     void setGeometry_sys_helper(int, int, int, int, bool);
-    void setWindowModified_sys(bool b);
     void updateMaximizeButton_sys();
     void setWindowFilePath_sys(const QString &filePath);
     void createWindow_sys();
index 4fe7ad6..6b6dd12 100644 (file)
@@ -140,6 +140,7 @@ void QWidgetPrivate::create_sys(WId window, bool initializeWindow, bool destroyO
             q->setAttribute(Qt::WA_PaintOnScreen, true);
     }
 
+    setWindowModified_helper();
     setWinId(win->winId());
 
 //    first check children. and create them if necessary