summaryrefslogtreecommitdiffstats
path: root/src/plugins
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2014-01-20 12:08:49 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-10 12:49:06 +0100
commit3d08681169b5194cdc9e61fbf6fac9c4346147d8 (patch)
treeed8d0c83e7171b94f8ddb75df41df9288633b0bd /src/plugins
parentdf86721bb4028ae09c5ce7d71a89808b8f2ccdcd (diff)
Cocoa: Add setNSToolbar(QWindow *, NSToolBar *)
Calling this function associates the given native toolbar with the QWindow. QWindow will then set it on the native NSWindow at the appropriate time during window creation. Change-Id: I2a50f79b2a0453cc739f8d68e965e37b95998083 Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.h5
-rw-r--r--src/plugins/platforms/cocoa/qcocoaintegration.mm25
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.h5
-rw-r--r--src/plugins/platforms/cocoa/qcocoanativeinterface.mm15
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.h1
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm19
6 files changed, 70 insertions, 0 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h
index 8babfcf8ae..b1b73e5f08 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.h
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.h
@@ -134,6 +134,9 @@ public:
void updateScreens();
QCocoaScreen *screenAtIndex(int index);
+ void setToolbar(QWindow *window, NSToolbar *toolbar);
+ NSToolbar *toolbar(QWindow *window) const;
+ void clearToolbars();
private:
static QCocoaIntegration *mInstance;
@@ -150,6 +153,8 @@ private:
QScopedPointer<QCocoaNativeInterface> mNativeInterface;
QScopedPointer<QCocoaServices> mServices;
QScopedPointer<QCocoaKeyMapper> mKeyboardMapper;
+
+ QHash<QWindow *, NSToolbar *> mToolbars;
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm
index e8cf5ca69b..0c1ddf9ad8 100644
--- a/src/plugins/platforms/cocoa/qcocoaintegration.mm
+++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm
@@ -301,6 +301,8 @@ QCocoaIntegration::~QCocoaIntegration()
while (!mScreens.isEmpty()) {
delete mScreens.takeLast();
}
+
+ clearToolbars();
}
QCocoaIntegration *QCocoaIntegration::instance()
@@ -466,4 +468,27 @@ QList<int> QCocoaIntegration::possibleKeys(const QKeyEvent *event) const
return mKeyboardMapper->possibleKeys(event);
}
+void QCocoaIntegration::setToolbar(QWindow *window, NSToolbar *toolbar)
+{
+ if (NSToolbar *prevToolbar = mToolbars.value(window))
+ [prevToolbar release];
+
+ [toolbar retain];
+ mToolbars.insert(window, toolbar);
+}
+
+NSToolbar *QCocoaIntegration::toolbar(QWindow *window) const
+{
+ return mToolbars.value(window);
+}
+
+void QCocoaIntegration::clearToolbars()
+{
+ QHash<QWindow *, NSToolbar *>::const_iterator it = mToolbars.constBegin();
+ while (it != mToolbars.constEnd()) {
+ [it.value() release];
+ }
+ mToolbars.clear();
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.h b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
index 4bcb348acb..bf7e85619a 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.h
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.h
@@ -135,6 +135,11 @@ private:
// Request a unified title and toolbar look for the window.
static void setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness);
+
+ // Sets a NSToolbar instance for the given QWindow. The
+ // toolbar will be attached to the native NSWindow when
+ // that is created;
+ static void setNSToolbar(QWindow *window, void *nsToolbar);
};
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
index eb520b97c9..85ce96a8b6 100644
--- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
+++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm
@@ -47,6 +47,7 @@
#include "qmacmime.h"
#include "qcocoahelpers.h"
#include "qcocoaapplication.h"
+#include "qcocoaintegration.h"
#include <qbytearray.h>
#include <qwindow.h>
@@ -125,6 +126,8 @@ QPlatformNativeInterface::NativeResourceForIntegrationFunction QCocoaNativeInter
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setEmbeddedInForeignView);
if (resource.toLower() == "setcontentborderthickness")
return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setContentBorderThickness);
+ if (resource.toLower() == "setnstoolbar")
+ return NativeResourceForIntegrationFunction(QCocoaNativeInterface::setNSToolbar);
return 0;
}
@@ -285,4 +288,16 @@ void QCocoaNativeInterface::setContentBorderThickness(QWindow *window, int topTh
cocoaWindow->setContentBorderThickness(topThickness, bottomThickness);
}
+void QCocoaNativeInterface::setNSToolbar(QWindow *window, void *nsToolbar)
+{
+ if (!window)
+ return;
+
+ QCocoaIntegration::instance()->setToolbar(window, static_cast<NSToolbar *>(nsToolbar));
+
+ QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle());
+ if (cocoaWindow)
+ cocoaWindow->updateNSToolbar();
+}
+
QT_END_NAMESPACE
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h
index d1de38c997..76baa4ecfc 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.h
+++ b/src/plugins/platforms/cocoa/qcocoawindow.h
@@ -164,6 +164,7 @@ public:
void registerTouch(bool enable);
void setContentBorderThickness(int topThickness, int bottomThickness);
void applyContentBorderThickness(NSWindow *window);
+ void updateNSToolbar();
qreal devicePixelRatio() const;
bool isWindowExposable();
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index ce1e856bfc..5524e12061 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -45,6 +45,7 @@
#include "qcocoaeventdispatcher.h"
#include "qcocoaglcontext.h"
#include "qcocoahelpers.h"
+#include "qcocoanativeinterface.h"
#include "qnsview.h"
#include <QtCore/qfileinfo.h>
#include <QtCore/private/qcore_mac_p.h>
@@ -1124,6 +1125,11 @@ void QCocoaWindow::recreateWindow(const QPlatformWindow *parentWindow)
const qreal opacity = qt_window_private(window())->opacity;
if (!qFuzzyCompare(opacity, qreal(1.0)))
setOpacity(opacity);
+
+ // top-level QWindows may have an attached NSToolBar, call
+ // update function which will attach to the NSWindow.
+ if (!parentWindow)
+ updateNSToolbar();
}
void QCocoaWindow::reinsertChildWindow(QCocoaWindow *child)
@@ -1387,6 +1393,19 @@ void QCocoaWindow::applyContentBorderThickness(NSWindow *window)
}
}
+void QCocoaWindow::updateNSToolbar()
+{
+ if (!m_nsWindow)
+ return;
+
+ NSToolbar *toolbar = QCocoaIntegration::instance()->toolbar(window());
+
+ if ([m_nsWindow toolbar] == toolbar)
+ return;
+
+ [m_nsWindow setToolbar: toolbar];
+ [m_nsWindow setShowsToolbarButton:YES];
+}
qreal QCocoaWindow::devicePixelRatio() const
{