Cocoa: Establish pattern for accessing globals
Use a static QCocoaIntegration pointer instead of QGuiApplication. This removes the need to call out of the platform plugin as well as the casting from "platform" to "cocoa" types. Change-Id: If432b3567811223b73a67548e475e07d63635b73 Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
This commit is contained in:
parent
b0e6bc42eb
commit
d01f0213b8
@ -114,7 +114,7 @@ static void cleanupCocoaApplicationDelegate()
|
||||
- (void)updateScreens:(NSNotification *)notification
|
||||
{
|
||||
Q_UNUSED(notification);
|
||||
if (QCocoaIntegration *ci = dynamic_cast<QCocoaIntegration *>(QGuiApplicationPrivate::platformIntegration()))
|
||||
if (QCocoaIntegration *ci = QCocoaIntegration::instance())
|
||||
ci->updateScreens();
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,10 @@
|
||||
|
||||
#include "qcocoaautoreleasepool.h"
|
||||
#include "qcocoacursor.h"
|
||||
#include "qcocoawindow.h"
|
||||
#include "qcocoanativeinterface.h"
|
||||
#include "qcocoainputcontext.h"
|
||||
#include "qcocoaaccessibility.h"
|
||||
#include "qcocoaclipboard.h"
|
||||
#include "qcocoadrag.h"
|
||||
#include "qcocoaservices.h"
|
||||
@ -53,6 +57,7 @@
|
||||
|
||||
#include <QtCore/QScopedPointer>
|
||||
#include <qpa/qplatformintegration.h>
|
||||
#include <QtPlatformSupport/private/qcoretextfontdatabase_p.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@ -103,23 +108,25 @@ public:
|
||||
QCocoaIntegration();
|
||||
~QCocoaIntegration();
|
||||
|
||||
static QCocoaIntegration *instance();
|
||||
|
||||
bool hasCapability(QPlatformIntegration::Capability cap) const;
|
||||
QPlatformWindow *createPlatformWindow(QWindow *window) const;
|
||||
QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;
|
||||
QPlatformBackingStore *createPlatformBackingStore(QWindow *widget) const;
|
||||
|
||||
QAbstractEventDispatcher *createEventDispatcher() const;
|
||||
QPlatformFontDatabase *fontDatabase() const;
|
||||
|
||||
QPlatformNativeInterface *nativeInterface() const;
|
||||
QPlatformInputContext *inputContext() const;
|
||||
QPlatformAccessibility *accessibility() const;
|
||||
QPlatformClipboard *clipboard() const;
|
||||
QPlatformDrag *drag() const;
|
||||
QCoreTextFontDatabase *fontDatabase() const;
|
||||
QCocoaNativeInterface *nativeInterface() const;
|
||||
QCocoaInputContext *inputContext() const;
|
||||
QCocoaAccessibility *accessibility() const;
|
||||
QCocoaClipboard *clipboard() const;
|
||||
QCocoaDrag *drag() const;
|
||||
|
||||
QStringList themeNames() const;
|
||||
QPlatformTheme *createPlatformTheme(const QString &name) const;
|
||||
QPlatformServices *services() const;
|
||||
QCocoaServices *services() const;
|
||||
QVariant styleHint(StyleHint hint) const;
|
||||
|
||||
QList<int> possibleKeys(const QKeyEvent *event) const;
|
||||
@ -128,18 +135,19 @@ public:
|
||||
QCocoaScreen *screenAtIndex(int index);
|
||||
|
||||
private:
|
||||
static QCocoaIntegration *mInstance;
|
||||
|
||||
QScopedPointer<QPlatformFontDatabase> mFontDb;
|
||||
QScopedPointer<QCoreTextFontDatabase> mFontDb;
|
||||
|
||||
QScopedPointer<QPlatformInputContext> mInputContext;
|
||||
QScopedPointer<QCocoaInputContext> mInputContext;
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
QScopedPointer<QPlatformAccessibility> mAccessibility;
|
||||
QScopedPointer<QCocoaAccessibility> mAccessibility;
|
||||
#endif
|
||||
QScopedPointer<QPlatformTheme> mPlatformTheme;
|
||||
QList<QCocoaScreen *> mScreens;
|
||||
QCocoaClipboard *mCocoaClipboard;
|
||||
QScopedPointer<QCocoaDrag> mCocoaDrag;
|
||||
QScopedPointer<QPlatformNativeInterface> mNativeInterface;
|
||||
QScopedPointer<QCocoaNativeInterface> mNativeInterface;
|
||||
QScopedPointer<QCocoaServices> mServices;
|
||||
QScopedPointer<QCocoaKeyMapper> mKeyboardMapper;
|
||||
};
|
||||
|
@ -58,7 +58,6 @@
|
||||
#include <qpa/qplatformaccessibility.h>
|
||||
#include <QtCore/qcoreapplication.h>
|
||||
|
||||
#include <QtPlatformSupport/private/qcoretextfontdatabase_p.h>
|
||||
#include <IOKit/graphics/IOGraphicsLib.h>
|
||||
|
||||
static void initResources()
|
||||
@ -214,6 +213,8 @@ QPixmap QCocoaScreen::grabWindow(WId window, int x, int y, int width, int height
|
||||
return windowPixmap;
|
||||
}
|
||||
|
||||
QCocoaIntegration *QCocoaIntegration::mInstance = 0;
|
||||
|
||||
QCocoaIntegration::QCocoaIntegration()
|
||||
: mFontDb(new QCoreTextFontDatabase())
|
||||
, mInputContext(new QCocoaInputContext)
|
||||
@ -226,6 +227,10 @@ QCocoaIntegration::QCocoaIntegration()
|
||||
, mServices(new QCocoaServices)
|
||||
, mKeyboardMapper(new QCocoaKeyMapper)
|
||||
{
|
||||
if (mInstance != 0)
|
||||
qWarning("Creating multiple Cocoa platform integrations is not supported");
|
||||
mInstance = this;
|
||||
|
||||
initResources();
|
||||
QCocoaAutoReleasePool pool;
|
||||
|
||||
@ -273,6 +278,8 @@ QCocoaIntegration::QCocoaIntegration()
|
||||
|
||||
QCocoaIntegration::~QCocoaIntegration()
|
||||
{
|
||||
mInstance = 0;
|
||||
|
||||
qt_resetNSApplicationSendEvent();
|
||||
|
||||
QCocoaAutoReleasePool pool;
|
||||
@ -296,6 +303,11 @@ QCocoaIntegration::~QCocoaIntegration()
|
||||
}
|
||||
}
|
||||
|
||||
QCocoaIntegration *QCocoaIntegration::instance()
|
||||
{
|
||||
return mInstance;
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Synchronizes the screen list, adds new screens, removes deleted ones
|
||||
*/
|
||||
@ -388,22 +400,22 @@ QAbstractEventDispatcher *QCocoaIntegration::createEventDispatcher() const
|
||||
return new QCocoaEventDispatcher;
|
||||
}
|
||||
|
||||
QPlatformFontDatabase *QCocoaIntegration::fontDatabase() const
|
||||
QCoreTextFontDatabase *QCocoaIntegration::fontDatabase() const
|
||||
{
|
||||
return mFontDb.data();
|
||||
}
|
||||
|
||||
QPlatformNativeInterface *QCocoaIntegration::nativeInterface() const
|
||||
QCocoaNativeInterface *QCocoaIntegration::nativeInterface() const
|
||||
{
|
||||
return mNativeInterface.data();
|
||||
}
|
||||
|
||||
QPlatformInputContext *QCocoaIntegration::inputContext() const
|
||||
QCocoaInputContext *QCocoaIntegration::inputContext() const
|
||||
{
|
||||
return mInputContext.data();
|
||||
}
|
||||
|
||||
QPlatformAccessibility *QCocoaIntegration::accessibility() const
|
||||
QCocoaAccessibility *QCocoaIntegration::accessibility() const
|
||||
{
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
return mAccessibility.data();
|
||||
@ -412,12 +424,12 @@ QPlatformAccessibility *QCocoaIntegration::accessibility() const
|
||||
#endif
|
||||
}
|
||||
|
||||
QPlatformClipboard *QCocoaIntegration::clipboard() const
|
||||
QCocoaClipboard *QCocoaIntegration::clipboard() const
|
||||
{
|
||||
return mCocoaClipboard;
|
||||
}
|
||||
|
||||
QPlatformDrag *QCocoaIntegration::drag() const
|
||||
QCocoaDrag *QCocoaIntegration::drag() const
|
||||
{
|
||||
return mCocoaDrag.data();
|
||||
}
|
||||
@ -434,7 +446,7 @@ QPlatformTheme *QCocoaIntegration::createPlatformTheme(const QString &name) cons
|
||||
return QPlatformIntegration::createPlatformTheme(name);
|
||||
}
|
||||
|
||||
QPlatformServices *QCocoaIntegration::services() const
|
||||
QCocoaServices *QCocoaIntegration::services() const
|
||||
{
|
||||
return mServices.data();
|
||||
}
|
||||
|
@ -137,6 +137,7 @@ private:
|
||||
static void setContentBorderThickness(QWindow *window, int topThickness, int bottomThickness);
|
||||
};
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
||||
#endif // QCOCOANATIVEINTERFACE_H
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -308,10 +308,9 @@ static QTouchDevice *touchDevice = 0;
|
||||
m_platformWindow->exposeWindow();
|
||||
} else if (notificationName == NSWindowDidChangeScreenNotification) {
|
||||
if (m_window) {
|
||||
QCocoaIntegration *ci = static_cast<QCocoaIntegration *>(QGuiApplicationPrivate::platformIntegration());
|
||||
NSUInteger screenIndex = [[NSScreen screens] indexOfObject:self.window.screen];
|
||||
if (screenIndex != NSNotFound) {
|
||||
QCocoaScreen *cocoaScreen = ci->screenAtIndex(screenIndex);
|
||||
QCocoaScreen *cocoaScreen = QCocoaIntegration::instance()->screenAtIndex(screenIndex);
|
||||
QWindowSystemInterface::handleWindowScreenChanged(m_window, cocoaScreen->screen());
|
||||
}
|
||||
}
|
||||
@ -552,7 +551,7 @@ static QTouchDevice *touchDevice = 0;
|
||||
[self convertFromScreen:[NSEvent mouseLocation] toWindowPoint:&qtWindowPoint andScreenPoint:&qtScreenPoint];
|
||||
ulong timestamp = [theEvent timestamp] * 1000;
|
||||
|
||||
QCocoaDrag* nativeDrag = static_cast<QCocoaDrag *>(QGuiApplicationPrivate::platformIntegration()->drag());
|
||||
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
|
||||
nativeDrag->setLastMouseEvent(theEvent, self);
|
||||
|
||||
Qt::KeyboardModifiers keyboardModifiers = [QNSView convertKeyModifiers:[theEvent modifierFlags]];
|
||||
@ -1602,7 +1601,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
|
||||
- (NSDragOperation) draggingSourceOperationMaskForLocal:(BOOL)isLocal
|
||||
{
|
||||
Q_UNUSED(isLocal);
|
||||
QCocoaDrag* nativeDrag = static_cast<QCocoaDrag *>(QGuiApplicationPrivate::platformIntegration()->drag());
|
||||
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
|
||||
return qt_mac_mapDropActions(nativeDrag->currentDrag()->supportedActions());
|
||||
}
|
||||
|
||||
@ -1633,7 +1632,7 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
|
||||
|
||||
QPlatformDragQtResponse response(false, Qt::IgnoreAction, QRect());
|
||||
if ([sender draggingSource] != nil) {
|
||||
QCocoaDrag* nativeDrag = static_cast<QCocoaDrag *>(QGuiApplicationPrivate::platformIntegration()->drag());
|
||||
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
|
||||
response = QWindowSystemInterface::handleDrag(m_window, nativeDrag->platformDropData(), qt_windowPoint, qtAllowed);
|
||||
} else {
|
||||
QCocoaDropData mimeData([sender draggingPasteboard]);
|
||||
@ -1661,14 +1660,14 @@ static QTabletEvent::TabletDevice wacomTabletDevice(NSEvent *theEvent)
|
||||
|
||||
QPlatformDropQtResponse response(false, Qt::IgnoreAction);
|
||||
if ([sender draggingSource] != nil) {
|
||||
QCocoaDrag* nativeDrag = static_cast<QCocoaDrag *>(QGuiApplicationPrivate::platformIntegration()->drag());
|
||||
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
|
||||
response = QWindowSystemInterface::handleDrop(m_window, nativeDrag->platformDropData(), qt_windowPoint, qtAllowed);
|
||||
} else {
|
||||
QCocoaDropData mimeData([sender draggingPasteboard]);
|
||||
response = QWindowSystemInterface::handleDrop(m_window, &mimeData, qt_windowPoint, qtAllowed);
|
||||
}
|
||||
if (response.isAccepted()) {
|
||||
QCocoaDrag* nativeDrag = static_cast<QCocoaDrag *>(QGuiApplicationPrivate::platformIntegration()->drag());
|
||||
QCocoaDrag* nativeDrag = QCocoaIntegration::instance()->drag();
|
||||
nativeDrag->setAcceptedAction(response.acceptedAction());
|
||||
}
|
||||
return response.isAccepted();
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "qcocoahelpers.h"
|
||||
#include "qcocoaaccessibility.h"
|
||||
#include "qcocoaaccessibilityelement.h"
|
||||
#include <qpa/qplatformintegration.h>
|
||||
#include "qcocoaintegration.h"
|
||||
|
||||
#include <QtGui/qaccessible.h>
|
||||
#include <QtCore/QDebug>
|
||||
@ -63,7 +63,7 @@
|
||||
- (id)accessibilityAttributeValue:(NSString *)attribute {
|
||||
|
||||
// activate accessibility updates
|
||||
QGuiApplicationPrivate::platformIntegration()->accessibility()->setActive(true);
|
||||
QCocoaIntegration::instance()->accessibility()->setActive(true);
|
||||
|
||||
if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
|
||||
if (m_window->accessibleRoot())
|
||||
|
Loading…
Reference in New Issue
Block a user