diff options
Diffstat (limited to 'src/plugins/platforms/cocoa')
52 files changed, 586 insertions, 820 deletions
diff --git a/src/plugins/platforms/cocoa/cocoa.pro b/src/plugins/platforms/cocoa/cocoa.pro index 6645b6c90a..6b93b1acf0 100644 --- a/src/plugins/platforms/cocoa/cocoa.pro +++ b/src/plugins/platforms/cocoa/cocoa.pro @@ -31,8 +31,7 @@ SOURCES += main.mm \ qcocoaintrospection.mm \ qcocoakeymapper.mm \ qcocoamimetypes.mm \ - qiosurfacegraphicsbuffer.mm \ - messages.cpp + qiosurfacegraphicsbuffer.mm HEADERS += qcocoaintegration.h \ qcocoascreen.h \ @@ -63,7 +62,6 @@ HEADERS += qcocoaintegration.h \ qcocoasystemtrayicon.h \ qcocoaintrospection.h \ qcocoakeymapper.h \ - messages.h \ qiosurfacegraphicsbuffer.h \ qcocoamimetypes.h @@ -85,10 +83,17 @@ qtConfig(accessibility) { qcocoaaccessibility.h } +qtConfig(sessionmanager) { + SOURCES += qcocoasessionmanager.cpp + HEADERS += qcocoasessionmanager.h +} + RESOURCES += qcocoaresources.qrc LIBS += -framework AppKit -framework CoreServices -framework Carbon -framework IOKit -framework QuartzCore -framework CoreVideo -framework Metal -framework IOSurface -lcups +DEFINES += QT_NO_FOREACH + QT += \ core-private gui-private \ clipboard_support-private theme_support-private \ diff --git a/src/plugins/platforms/cocoa/messages.cpp b/src/plugins/platforms/cocoa/messages.cpp deleted file mode 100644 index 06e3dd454e..0000000000 --- a/src/plugins/platforms/cocoa/messages.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "messages.h" - -#include <QtCore/qcoreapplication.h> -#include <QtCore/qregularexpression.h> - -// Translatable messages should go into this .cpp file for them to be picked up by lupdate. - -QT_BEGIN_NAMESPACE - -QString msgAboutQt() -{ - return QCoreApplication::translate("QCocoaMenuItem", "About Qt"); -} - -static const char *application_menu_strings[] = -{ - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","About %1"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Preferences..."), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Services"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide %1"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide Others"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Show All"), - QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Quit %1") -}; - -QString qt_mac_applicationmenu_string(int type) -{ - QString menuString = QString::fromLatin1(application_menu_strings[type]); - const QString translated = QCoreApplication::translate("QMenuBar", application_menu_strings[type]); - if (translated != menuString) { - return translated; - } else { - return QCoreApplication::translate("MAC_APPLICATION_MENU", application_menu_strings[type]); - } -} - -QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption) -{ - QString captionNoAmpersand(caption); - captionNoAmpersand.remove(QLatin1Char('&')); - const QString aboutString = QCoreApplication::translate("QCocoaMenuItem", "About"); - if (captionNoAmpersand.startsWith(aboutString, Qt::CaseInsensitive) - || captionNoAmpersand.endsWith(aboutString, Qt::CaseInsensitive)) { - static const QRegularExpression qtRegExp(QLatin1String("qt$"), QRegularExpression::CaseInsensitiveOption); - if (captionNoAmpersand.contains(qtRegExp)) - return QPlatformMenuItem::AboutQtRole; - return QPlatformMenuItem::AboutRole; - } - if (captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Config"), Qt::CaseInsensitive) - || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Preference"), Qt::CaseInsensitive) - || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Options"), Qt::CaseInsensitive) - || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Setting"), Qt::CaseInsensitive) - || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Setup"), Qt::CaseInsensitive)) { - return QPlatformMenuItem::PreferencesRole; - } - if (captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Quit"), Qt::CaseInsensitive) - || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Exit"), Qt::CaseInsensitive)) { - return QPlatformMenuItem::QuitRole; - } - if (!captionNoAmpersand.compare(QCoreApplication::translate("QCocoaMenuItem", "Cut"), Qt::CaseInsensitive)) - return QPlatformMenuItem::CutRole; - if (!captionNoAmpersand.compare(QCoreApplication::translate("QCocoaMenuItem", "Copy"), Qt::CaseInsensitive)) - return QPlatformMenuItem::CopyRole; - if (!captionNoAmpersand.compare(QCoreApplication::translate("QCocoaMenuItem", "Paste"), Qt::CaseInsensitive)) - return QPlatformMenuItem::PasteRole; - if (!captionNoAmpersand.compare(QCoreApplication::translate("QCocoaMenuItem", "Select All"), Qt::CaseInsensitive)) - return QPlatformMenuItem::SelectAllRole; - return QPlatformMenuItem::NoRole; -} - -QString msgDialogButtonDiscard() -{ - return QCoreApplication::translate("QCocoaTheme", "Don't Save"); -} - -QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h index 141ce6bf1a..f74afb8440 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.h @@ -41,7 +41,7 @@ #include <QtCore/qglobal.h> -#include "qt_mac_p.h" +#include <QtCore/private/qcore_mac_p.h> #ifndef QT_NO_ACCESSIBILITY diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index 3560c9d9b5..ad40c6b0cb 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -41,7 +41,8 @@ #include "qcocoahelpers.h" #include "qcocoawindow.h" #include "qcocoascreen.h" -#include "private/qaccessiblecache_p.h" + +#include <QtGui/private/qaccessiblecache_p.h> #include <QtAccessibilitySupport/private/qaccessiblebridgeutils_p.h> #include <QtGui/qaccessible.h> @@ -547,7 +548,7 @@ static void convertLineOffset(QAccessibleTextInterface *text, int *line, int *of return nsActions; const QStringList &supportedActionNames = QAccessibleBridgeUtils::effectiveActionNames(iface); - foreach (const QString &qtAction, supportedActionNames) { + for (const QString &qtAction : supportedActionNames) { NSString *nsAction = QCocoaAccessible::getTranslatedAction(qtAction); if (nsAction) [nsActions addObject : nsAction]; diff --git a/src/plugins/platforms/cocoa/qcocoaapplication.h b/src/plugins/platforms/cocoa/qcocoaapplication.h index 15530d8281..4314a01ca1 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplication.h +++ b/src/plugins/platforms/cocoa/qcocoaapplication.h @@ -83,8 +83,8 @@ // We mean it. // -#include "qglobal.h" -#include "private/qcore_mac_p.h" +#include <qglobal.h> +#include <QtCore/private/qcore_mac_p.h> #import <AppKit/AppKit.h> diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 9b0a6b1b86..e8d789275c 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -79,12 +79,14 @@ #include "qcocoamenuitem.h" #include "qcocoansmenu.h" +#if QT_CONFIG(sessionmanager) +# include "qcocoasessionmanager.h" +#endif + #include <qevent.h> #include <qurl.h> #include <qdebug.h> #include <qguiapplication.h> -#include <private/qguiapplication_p.h> -#include "qt_mac_p.h" #include <qpa/qwindowsysteminterface.h> #include <qwindowdefs.h> @@ -149,7 +151,7 @@ QT_USE_NAMESPACE if ([reflectionDelegate respondsToSelector:_cmd]) return [reflectionDelegate applicationShouldTerminate:sender]; - if (QGuiApplicationPrivate::instance()->threadData->eventLoops.isEmpty()) { + if (QGuiApplicationPrivate::instance()->threadData.loadRelaxed()->eventLoops.isEmpty()) { // No event loop is executing. This probably means that Qt is used as a plugin, // or as a part of a native Cocoa application. In any case it should be fine to // terminate now. @@ -157,6 +159,17 @@ QT_USE_NAMESPACE return NSTerminateNow; } +#if QT_CONFIG(sessionmanager) + QCocoaSessionManager *cocoaSessionManager = QCocoaSessionManager::instance(); + cocoaSessionManager->resetCancellation(); + cocoaSessionManager->appCommitData(); + + if (cocoaSessionManager->wasCanceled()) { + qCDebug(lcQpaApplication) << "Session management canceled application termination"; + return NSTerminateCancel; + } +#endif + if (!QWindowSystemInterface::handleApplicationTermination<QWindowSystemInterface::SynchronousDelivery>()) { qCDebug(lcQpaApplication) << "Application termination canceled"; return NSTerminateCancel; @@ -359,7 +372,7 @@ QT_USE_NAMESPACE if (!platformItem || platformItem->menu()) return; - QScopedScopeLevelCounter scopeLevelCounter(QGuiApplicationPrivate::instance()->threadData); + QScopedScopeLevelCounter scopeLevelCounter(QGuiApplicationPrivate::instance()->threadData.loadRelaxed()); QGuiApplicationPrivate::modifier_buttons = [QNSView convertKeyModifiers:[NSEvent modifierFlags]]; static QMetaMethod activatedSignal = QMetaMethod::fromSignal(&QCocoaMenuItem::activated); diff --git a/src/plugins/platforms/cocoa/qcocoabackingstore.mm b/src/plugins/platforms/cocoa/qcocoabackingstore.mm index 2b4c71f279..3b9df8da3a 100644 --- a/src/plugins/platforms/cocoa/qcocoabackingstore.mm +++ b/src/plugins/platforms/cocoa/qcocoabackingstore.mm @@ -43,6 +43,7 @@ #include "qcocoahelpers.h" #include <QtCore/qmath.h> +#include <QtGui/qpainter.h> #include <QuartzCore/CATransaction.h> diff --git a/src/plugins/platforms/cocoa/qcocoaclipboard.mm b/src/plugins/platforms/cocoa/qcocoaclipboard.mm index a35c153084..141940cc50 100644 --- a/src/plugins/platforms/cocoa/qcocoaclipboard.mm +++ b/src/plugins/platforms/cocoa/qcocoaclipboard.mm @@ -67,7 +67,7 @@ void QCocoaClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode) } pasteBoard->sync(); - pasteBoard->setMimeData(data); + pasteBoard->setMimeData(data, QMacPasteboard::LazyRequest); emitChanged(mode); } } diff --git a/src/plugins/platforms/cocoa/qcocoacursor.h b/src/plugins/platforms/cocoa/qcocoacursor.h index 5b008eff35..6589891ef2 100644 --- a/src/plugins/platforms/cocoa/qcocoacursor.h +++ b/src/plugins/platforms/cocoa/qcocoacursor.h @@ -63,8 +63,8 @@ private: QHash<Qt::CursorShape, NSCursor *> m_cursors; NSCursor *convertCursor(QCursor *cursor); NSCursor *createCursorData(QCursor * cursor); - NSCursor *createCursorFromBitmap(const QBitmap *bitmap, const QBitmap *mask, const QPoint hotspot = QPoint()); - NSCursor *createCursorFromPixmap(const QPixmap pixmap, const QPoint hotspot = QPoint()); + NSCursor *createCursorFromBitmap(const QBitmap &bitmap, const QBitmap &mask, const QPoint hotspot = QPoint()); + NSCursor *createCursorFromPixmap(const QPixmap &pixmap, const QPoint hotspot = QPoint()); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoacursor.mm b/src/plugins/platforms/cocoa/qcocoacursor.mm index e0d623fc4c..8ca72ec619 100644 --- a/src/plugins/platforms/cocoa/qcocoacursor.mm +++ b/src/plugins/platforms/cocoa/qcocoacursor.mm @@ -243,7 +243,7 @@ NSCursor *QCocoaCursor::createCursorData(QCursor *cursor) switch (cursor->shape()) { case Qt::BitmapCursor: { if (cursor->pixmap().isNull()) - return createCursorFromBitmap(cursor->bitmap(), cursor->mask(), hotspot); + return createCursorFromBitmap(cursor->bitmap(Qt::ReturnByValue), cursor->mask(Qt::ReturnByValue), hotspot); else return createCursorFromPixmap(cursor->pixmap(), hotspot); break; } @@ -301,17 +301,17 @@ NSCursor *QCocoaCursor::createCursorData(QCursor *cursor) if (cursorData) { QBitmap bitmap(QBitmap::fromData(QSize(16, 16), cursorData, QImage::Format_Mono)); QBitmap mask(QBitmap::fromData(QSize(16, 16), cursorMaskData, QImage::Format_Mono)); - return (createCursorFromBitmap(&bitmap, &mask, hotspot)); + return (createCursorFromBitmap(bitmap, mask, hotspot)); } return nil; // should not happen, all cases covered above } -NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap *bitmap, const QBitmap *mask, const QPoint hotspot) +NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap &bitmap, const QBitmap &mask, const QPoint hotspot) { - QImage finalCursor(bitmap->size(), QImage::Format_ARGB32); - QImage bmi = bitmap->toImage().convertToFormat(QImage::Format_RGB32); - QImage bmmi = mask->toImage().convertToFormat(QImage::Format_RGB32); + QImage finalCursor(bitmap.size(), QImage::Format_ARGB32); + QImage bmi = bitmap.toImage().convertToFormat(QImage::Format_RGB32); + QImage bmmi = mask.toImage().convertToFormat(QImage::Format_RGB32); for (int row = 0; row < finalCursor.height(); ++row) { QRgb *bmData = reinterpret_cast<QRgb *>(bmi.scanLine(row)); QRgb *bmmData = reinterpret_cast<QRgb *>(bmmi.scanLine(row)); @@ -332,27 +332,11 @@ NSCursor *QCocoaCursor::createCursorFromBitmap(const QBitmap *bitmap, const QBit return createCursorFromPixmap(QPixmap::fromImage(finalCursor), hotspot); } -NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap pixmap, const QPoint hotspot) +NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap &pixmap, const QPoint hotspot) { NSPoint hotSpot = NSMakePoint(hotspot.x(), hotspot.y()); - NSImage *nsimage; - if (pixmap.devicePixelRatio() > 1.0) { - QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio(); - QPixmap scaledPixmap = pixmap.scaled(layoutSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - scaledPixmap.setDevicePixelRatio(1.0); - nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(scaledPixmap)); - CGImageRef cgImage = qt_mac_toCGImage(pixmap.toImage()); - NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; - [nsimage addRepresentation:imageRep]; - [imageRep release]; - CGImageRelease(cgImage); - } else { - nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap)); - } - - NSCursor *nsCursor = [[NSCursor alloc] initWithImage:nsimage hotSpot: hotSpot]; - [nsimage release]; - return nsCursor; + auto *image = [NSImage imageFromQImage:pixmap.toImage()]; + return [[NSCursor alloc] initWithImage:image hotSpot:hotSpot]; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoadrag.mm b/src/plugins/platforms/cocoa/qcocoadrag.mm index 95808b8a11..b4a16ab912 100644 --- a/src/plugins/platforms/cocoa/qcocoadrag.mm +++ b/src/plugins/platforms/cocoa/qcocoadrag.mm @@ -130,9 +130,8 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o) QPoint hotSpot = m_drag->hotSpot(); QPixmap pm = dragPixmap(m_drag, hotSpot); - QSize pmDeviceIndependentSize = pm.size() / pm.devicePixelRatio(); - NSImage *nsimage = qt_mac_create_nsimage(pm); - [nsimage setSize:NSSizeFromCGSize(pmDeviceIndependentSize.toCGSize())]; + NSImage *dragImage = [NSImage imageFromQImage:pm.toImage()]; + Q_ASSERT(dragImage); QMacPasteboard dragBoard(CFStringRef(NSPasteboardNameDrag), QMacInternalPasteboardMime::MIME_DND); m_drag->mimeData()->setData(QLatin1String("application/x-qt-mime-type-name"), QByteArray("dummy")); @@ -142,12 +141,12 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o) NSWindow *theWindow = [m_lastEvent window]; Q_ASSERT(theWindow); event_location.x -= hotSpot.x(); - CGFloat flippedY = pmDeviceIndependentSize.height() - hotSpot.y(); + CGFloat flippedY = dragImage.size.height - hotSpot.y(); event_location.y -= flippedY; NSSize mouseOffset_unused = NSMakeSize(0.0, 0.0); NSPasteboard *pboard = [NSPasteboard pasteboardWithName:NSPasteboardNameDrag]; - [theWindow dragImage:nsimage + [theWindow dragImage:dragImage at:event_location offset:mouseOffset_unused event:m_lastEvent @@ -155,8 +154,6 @@ Qt::DropAction QCocoaDrag::drag(QDrag *o) source:m_lastView slideBack:YES]; - [nsimage release]; - m_drag = nullptr; return m_executed_drop_action; } diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h index 69587a24be..b8d2532b8e 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h @@ -186,6 +186,7 @@ public: QAtomicInt serialNumber; int lastSerial; bool interrupt; + bool propagateInterrupt = false; static void postedEventsSourceCallback(void *info); static void waitingObserverCallback(CFRunLoopObserverRef observer, diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index e87fc39c42..338a5516d9 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -73,24 +73,26 @@ #include "qcocoaeventdispatcher.h" #include "qcocoawindow.h" - #include "qcocoahelpers.h" -#include "qguiapplication.h" -#include "qevent.h" -#include "qmutex.h" -#include "qsocketnotifier.h" + +#include <QtGui/qevent.h> +#include <QtGui/qguiapplication.h> +#include <QtGui/private/qguiapplication_p.h> + +#include <QtCore/qmutex.h> +#include <QtCore/qscopeguard.h> +#include <QtCore/qsocketnotifier.h> +#include <QtCore/private/qthread_p.h> + #include <qpa/qplatformwindow.h> #include <qpa/qplatformnativeinterface.h> -#include "private/qthread_p.h" -#include "private/qguiapplication_p.h" -#include <qdebug.h> + +#include <QtCore/qdebug.h> #include <AppKit/AppKit.h> QT_BEGIN_NAMESPACE -QT_USE_NAMESPACE - static inline CFRunLoopRef mainRunLoop() { return CFRunLoopGetMain(); @@ -293,46 +295,42 @@ bool QCocoaEventDispatcher::hasPendingEvents() return qGlobalPostedEventsCount() || (qt_is_gui_used && !CFRunLoopIsWaiting(CFRunLoopGetMain())); } -static bool IsMouseOrKeyEvent( NSEvent* event ) +static bool isUserInputEvent(NSEvent* event) { - bool result = false; - - switch( [event type] ) - { - case NSEventTypeLeftMouseDown: - case NSEventTypeLeftMouseUp: - case NSEventTypeRightMouseDown: - case NSEventTypeRightMouseUp: - case NSEventTypeMouseMoved: // ?? - case NSEventTypeLeftMouseDragged: - case NSEventTypeRightMouseDragged: - case NSEventTypeMouseEntered: - case NSEventTypeMouseExited: - case NSEventTypeKeyDown: - case NSEventTypeKeyUp: - case NSEventTypeFlagsChanged: // key modifiers changed? - case NSEventTypeCursorUpdate: // ?? - case NSEventTypeScrollWheel: - case NSEventTypeTabletPoint: - case NSEventTypeTabletProximity: - case NSEventTypeOtherMouseDown: - case NSEventTypeOtherMouseUp: - case NSEventTypeOtherMouseDragged: + switch ([event type]) { + case NSEventTypeLeftMouseDown: + case NSEventTypeLeftMouseUp: + case NSEventTypeRightMouseDown: + case NSEventTypeRightMouseUp: + case NSEventTypeMouseMoved: // ?? + case NSEventTypeLeftMouseDragged: + case NSEventTypeRightMouseDragged: + case NSEventTypeMouseEntered: + case NSEventTypeMouseExited: + case NSEventTypeKeyDown: + case NSEventTypeKeyUp: + case NSEventTypeFlagsChanged: // key modifiers changed? + case NSEventTypeCursorUpdate: // ?? + case NSEventTypeScrollWheel: + case NSEventTypeTabletPoint: + case NSEventTypeTabletProximity: + case NSEventTypeOtherMouseDown: + case NSEventTypeOtherMouseUp: + case NSEventTypeOtherMouseDragged: #ifndef QT_NO_GESTURES - case NSEventTypeGesture: // touch events - case NSEventTypeMagnify: - case NSEventTypeSwipe: - case NSEventTypeRotate: - case NSEventTypeBeginGesture: - case NSEventTypeEndGesture: + case NSEventTypeGesture: // touch events + case NSEventTypeMagnify: + case NSEventTypeSwipe: + case NSEventTypeRotate: + case NSEventTypeBeginGesture: + case NSEventTypeEndGesture: #endif // QT_NO_GESTURES - result = true; + return true; break; - - default: + default: break; } - return result; + return false; } static inline void qt_mac_waitForMoreEvents(NSString *runLoopMode = NSDefaultRunLoopMode) @@ -352,6 +350,16 @@ static inline void qt_mac_waitForMoreEvents(NSString *runLoopMode = NSDefaultRun bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_D(QCocoaEventDispatcher); + + // In rare rather corner cases a user's application messes with + // QEventLoop::exec()/exit() and QCoreApplication::processEvents(), + // we have to undo what bool blocker normally does. + d->propagateInterrupt = false; + const auto boolBlockerUndo = qScopeGuard([d](){ + if (d->propagateInterrupt) + d->interrupt = true; + d->propagateInterrupt = false; + }); QBoolBlocker interruptBlocker(d->interrupt, false); bool interruptLater = false; @@ -465,7 +473,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) dequeue: YES]; if (event) { - if (IsMouseOrKeyEvent(event)) { + if (isUserInputEvent(event)) { [event retain]; d->queuedUserInputEvents.append(event); continue; @@ -485,7 +493,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) if (event) { if (flags & QEventLoop::ExcludeUserInputEvents) { - if (IsMouseOrKeyEvent(event)) { + if (isUserInputEvent(event)) { [event retain]; d->queuedUserInputEvents.append(event); continue; @@ -500,7 +508,16 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) if ((d->processEventsFlags & QEventLoop::EventLoopExec) == 0) { // When called "manually", always process posted events and timers + bool oldInterrupt = d->interrupt; d->processPostedEvents(); + if (!oldInterrupt && d->interrupt && !d->currentModalSession()) { + // We had direct processEvent call, coming not from QEventLoop::exec(). + // One of the posted events triggered an application to interrupt the loop. + // But bool blocker will reset d->interrupt to false, so the real event + // loop will never notice it was interrupted. Now we'll have to fix it by + // enforcing the value of d->interrupt. + d->propagateInterrupt = true; + } retVal = d->processTimers() || retVal; } @@ -515,7 +532,7 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) if (hadModalSession && !d->currentModalSessionCached) interruptLater = true; } - bool canWait = (d->threadData->canWait + bool canWait = (d->threadData.loadRelaxed()->canWait && !retVal && !d->interrupt && (d->processEventsFlags & QEventLoop::WaitForMoreEvents)); @@ -882,7 +899,7 @@ void QCocoaEventDispatcherPrivate::processPostedEvents() } int serial = serialNumber.loadRelaxed(); - if (!threadData->canWait || (serial != lastSerial)) { + if (!threadData.loadRelaxed()->canWait || (serial != lastSerial)) { lastSerial = serial; QCoreApplication::sendPostedEvents(); QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents); diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 6aa21d78d1..15e83db48f 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -48,7 +48,6 @@ #include <qguiapplication.h> #include <private/qguiapplication_p.h> -#include "qt_mac_p.h" #include "qcocoahelpers.h" #include "qcocoaeventdispatcher.h" #include <qbuffer.h> @@ -419,8 +418,7 @@ static QString strippedText(QString s) [mPopUpButton setHidden:chooseDirsOnly]; // TODO hide the whole sunken pane instead? if (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) { - const QStringList ext = [self acceptableExtensionsForSave]; - [mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : qt_mac_QStringListToNSMutableArray(ext)]; + [self recomputeAcceptableExtensionsForSave]; } else { [mOpenPanel setAllowedFileTypes:nil]; // delegate panel:shouldEnableURL: does the file filtering for NSOpenPanel } @@ -457,25 +455,49 @@ static QString strippedText(QString s) } /* - Returns a list of extensions (e.g. "png", "jpg", "gif") - for the current name filter. If a filter do not conform - to the format *.xyz or * or *.*, an empty list - is returned meaning accept everything. + Computes a list of extensions (e.g. "png", "jpg", "gif") + for the current name filter, and updates the save panel. + + If a filter do not conform to the format *.xyz or * or *.*, + all files types are allowed. + + Extensions with more than one part (e.g. "tar.gz") are + reduced to their final part, as NSSavePanel does not deal + well with multi-part extensions. */ -- (QStringList)acceptableExtensionsForSave -{ - QStringList result; - for (int i=0; i<mSelectedNameFilter->count(); ++i) { - const QString &filter = mSelectedNameFilter->at(i); - if (filter.startsWith(QLatin1String("*.")) - && !filter.contains(QLatin1Char('?')) - && filter.count(QLatin1Char('*')) == 1) { - result += filter.mid(2); - } else { - return QStringList(); // Accept everything - } +- (void)recomputeAcceptableExtensionsForSave +{ + QStringList fileTypes; + for (const QString &filter : *mSelectedNameFilter) { + if (!filter.startsWith(QLatin1String("*."))) + continue; + + if (filter.contains(QLatin1Char('?'))) + continue; + + if (filter.count(QLatin1Char('*')) != 1) + continue; + + auto extensions = filter.split('.', Qt::SkipEmptyParts); + fileTypes += extensions.last(); + + // Explicitly show extensions if we detect a filter + // that has a multi-part extension. This prevents + // confusing situations where the user clicks e.g. + // 'foo.tar.gz' and 'foo.tar' is populated in the + // file name box, but when then clicking save macOS + // will warn that the file needs to end in .gz, + // due to thinking the user tried to save the file + // as a 'tar' file instead. Unfortunately this + // property can only be set before the panel is + // shown, so it will not have any effect when + // swithcing filters in an already opened dialog. + if (extensions.size() > 2) + mSavePanel.extensionHidden = NO; } - return result; + + mSavePanel.allowedFileTypes = fileTypes.isEmpty() ? nil + : qt_mac_QStringListToNSMutableArray(fileTypes); } - (QString)removeExtensions:(const QString &)filter diff --git a/src/plugins/platforms/cocoa/qcocoaglcontext.mm b/src/plugins/platforms/cocoa/qcocoaglcontext.mm index 6db4bdb9fd..ccb6e20071 100644 --- a/src/plugins/platforms/cocoa/qcocoaglcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoaglcontext.mm @@ -554,7 +554,7 @@ NSOpenGLContext *QCocoaGLContext::nativeContext() const QFunctionPointer QCocoaGLContext::getProcAddress(const char *procName) { - return (QFunctionPointer)dlsym(RTLD_DEFAULT, procName); + return (QFunctionPointer)dlsym(RTLD_NEXT, procName); } #ifndef QT_NO_DEBUG_STREAM diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.h b/src/plugins/platforms/cocoa/qcocoahelpers.h index 69a1854598..71e72dca4f 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.h +++ b/src/plugins/platforms/cocoa/qcocoahelpers.h @@ -45,14 +45,17 @@ // ------------- // // This file is not part of the Qt API. It provides helper functions -// for the Cocoa lighthouse plugin. This header file may +// for the Cocoa plugin. This header file may // change from version to version without notice, or even be removed. // // We mean it. // -#include "qt_mac_p.h" + +#include <AppKit/AppKit.h> + #include <private/qguiapplication_p.h> #include <QtCore/qoperatingsystemversion.h> +#include <QtCore/qloggingcategory.h> #include <QtGui/qpalette.h> #include <QtGui/qscreen.h> diff --git a/src/plugins/platforms/cocoa/qcocoainputcontext.mm b/src/plugins/platforms/cocoa/qcocoainputcontext.mm index d0baea5b36..000bcd708b 100644 --- a/src/plugins/platforms/cocoa/qcocoainputcontext.mm +++ b/src/plugins/platforms/cocoa/qcocoainputcontext.mm @@ -74,8 +74,6 @@ QT_BEGIN_NAMESPACE Input method support in Cocoa uses NSTextInput protorol. Therefore almost all functionality is implemented in QNSView. - - \ingroup qt-lighthouse-cocoa */ diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index bfc3bfe9de..0c14e07551 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -92,6 +92,10 @@ public: QCocoaVulkanInstance *getCocoaVulkanInstance() const; #endif +#if QT_CONFIG(sessionmanager) + QPlatformSessionManager *createPlatformSessionManager(const QString &id, const QString &key) const override; +#endif + QCoreTextFontDatabase *fontDatabase() const override; QCocoaNativeInterface *nativeInterface() const override; QPlatformInputContext *inputContext() const override; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index b7f15a2bf1..245db429c5 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -52,6 +52,9 @@ #include "qcocoamimetypes.h" #include "qcocoaaccessibility.h" #include "qcocoascreen.h" +#if QT_CONFIG(sessionmanager) +# include "qcocoasessionmanager.h" +#endif #include <qpa/qplatforminputcontextfactory_p.h> #include <qpa/qplatformaccessibility.h> @@ -113,7 +116,7 @@ class QFontEngineFT; static QCocoaIntegration::Options parseOptions(const QStringList ¶mList) { QCocoaIntegration::Options options; - foreach (const QString ¶m, paramList) { + for (const QString ¶m : paramList) { #ifndef QT_NO_FREETYPE if (param == QLatin1String("fontengine=freetype")) options |= QCocoaIntegration::UseFreeTypeFontEngine; @@ -245,6 +248,13 @@ QCocoaIntegration::Options QCocoaIntegration::options() const return mOptions; } +#if QT_CONFIG(sessionmanager) +QPlatformSessionManager *QCocoaIntegration::createPlatformSessionManager(const QString &id, const QString &key) const +{ + return new QCocoaSessionManager(id, key); +} +#endif + bool QCocoaIntegration::hasCapability(QPlatformIntegration::Capability cap) const { switch (cap) { @@ -462,14 +472,7 @@ QList<QCocoaWindow *> *QCocoaIntegration::popupWindowStack() void QCocoaIntegration::setApplicationIcon(const QIcon &icon) const { - NSImage *image = nil; - if (!icon.isNull()) { - NSSize size = [[[NSApplication sharedApplication] dockTile] size]; - QPixmap pixmap = icon.pixmap(size.width, size.height); - image = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap)); - } - [[NSApplication sharedApplication] setApplicationIconImage:image]; - [image release]; + NSApp.applicationIconImage = [NSImage imageFromQIcon:icon]; } void QCocoaIntegration::beep() const diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index 8c4fca0d29..90d5180fed 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -334,7 +334,7 @@ void QCocoaMenu::setEnabled(bool enabled) bool QCocoaMenu::isEnabled() const { - return m_attachedItem ? m_attachedItem.enabled : m_enabled && m_parentEnabled; + return m_enabled && m_parentEnabled; } void QCocoaMenu::setVisible(bool visible) diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index 363defdd28..a2a8535547 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -191,7 +191,7 @@ void QCocoaMenuBar::syncMenu_helper(QPlatformMenu *menu, bool menubarUpdate) QMacAutoReleasePool pool; QCocoaMenu *cocoaMenu = static_cast<QCocoaMenu *>(menu); - Q_FOREACH (QCocoaMenuItem *item, cocoaMenu->items()) + for (QCocoaMenuItem *item : cocoaMenu->items()) cocoaMenu->syncMenuItem_helper(item, menubarUpdate); BOOL shouldHide = YES; diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.h b/src/plugins/platforms/cocoa/qcocoamenuitem.h index c842b08d52..029d29be9d 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.h +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.h @@ -53,6 +53,18 @@ Q_FORWARD_DECLARE_OBJC_CLASS(NSView); QT_BEGIN_NAMESPACE +enum { + AboutAppMenuItem = 0, + PreferencesAppMenuItem, + ServicesAppMenuItem, + HideAppMenuItem, + HideOthersAppMenuItem, + ShowAllAppMenuItem, + QuitAppMenuItem +}; + +QString qt_mac_applicationmenu_string(int type); + class QCocoaMenu; class QCocoaMenuObject diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index c35cf6d799..3b37e7c9c1 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -45,18 +45,39 @@ #include "qcocoansmenu.h" #include "qcocoamenu.h" #include "qcocoamenubar.h" -#include "messages.h" #include "qcocoahelpers.h" -#include "qt_mac_p.h" #include "qcocoaapplication.h" // for custom application category #include "qcocoamenuloader.h" #include <QtGui/private/qcoregraphics_p.h> +#include <QtCore/qregularexpression.h> #include <QtCore/QDebug> #include <QtCore/QRegExp> QT_BEGIN_NAMESPACE +static const char *application_menu_strings[] = +{ + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","About %1"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Preferences..."), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Services"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide %1"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Hide Others"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Show All"), + QT_TRANSLATE_NOOP("MAC_APPLICATION_MENU","Quit %1") +}; + +QString qt_mac_applicationmenu_string(int type) +{ + QString menuString = QString::fromLatin1(application_menu_strings[type]); + const QString translated = QCoreApplication::translate("QMenuBar", application_menu_strings[type]); + if (translated != menuString) { + return translated; + } else { + return QCoreApplication::translate("MAC_APPLICATION_MENU", application_menu_strings[type]); + } +} + static quint32 constructModifierMask(quint32 accel_key) { quint32 ret = 0; @@ -226,6 +247,40 @@ void QCocoaMenuItem::setNativeContents(WId item) m_itemView.needsDisplay = YES; } +static QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption) +{ + QString captionNoAmpersand(caption); + captionNoAmpersand.remove(QLatin1Char('&')); + const QString aboutString = QCoreApplication::translate("QCocoaMenuItem", "About"); + if (captionNoAmpersand.startsWith(aboutString, Qt::CaseInsensitive) + || captionNoAmpersand.endsWith(aboutString, Qt::CaseInsensitive)) { + static const QRegularExpression qtRegExp(QLatin1String("qt$"), QRegularExpression::CaseInsensitiveOption); + if (captionNoAmpersand.contains(qtRegExp)) + return QPlatformMenuItem::AboutQtRole; + return QPlatformMenuItem::AboutRole; + } + if (captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Config"), Qt::CaseInsensitive) + || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Preference"), Qt::CaseInsensitive) + || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Options"), Qt::CaseInsensitive) + || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Setting"), Qt::CaseInsensitive) + || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Setup"), Qt::CaseInsensitive)) { + return QPlatformMenuItem::PreferencesRole; + } + if (captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Quit"), Qt::CaseInsensitive) + || captionNoAmpersand.startsWith(QCoreApplication::translate("QCocoaMenuItem", "Exit"), Qt::CaseInsensitive)) { + return QPlatformMenuItem::QuitRole; + } + if (!captionNoAmpersand.compare(QCoreApplication::translate("QCocoaMenuItem", "Cut"), Qt::CaseInsensitive)) + return QPlatformMenuItem::CutRole; + if (!captionNoAmpersand.compare(QCoreApplication::translate("QCocoaMenuItem", "Copy"), Qt::CaseInsensitive)) + return QPlatformMenuItem::CopyRole; + if (!captionNoAmpersand.compare(QCoreApplication::translate("QCocoaMenuItem", "Paste"), Qt::CaseInsensitive)) + return QPlatformMenuItem::PasteRole; + if (!captionNoAmpersand.compare(QCoreApplication::translate("QCocoaMenuItem", "Select All"), Qt::CaseInsensitive)) + return QPlatformMenuItem::SelectAllRole; + return QPlatformMenuItem::NoRole; +} + NSMenuItem *QCocoaMenuItem::sync() { if (m_isSeparator != m_native.separatorItem) { @@ -341,13 +396,7 @@ NSMenuItem *QCocoaMenuItem::sync() m_native.keyEquivalentModifierMask = NSEventModifierFlagCommand; } - NSImage *img = nil; - if (!m_icon.isNull()) { - img = qt_mac_create_nsimage(m_icon, m_iconSize); - img.size = CGSizeMake(m_iconSize, m_iconSize); - } - m_native.image = img; - [img release]; + m_native.image = [NSImage imageFromQIcon:m_icon withSize:m_iconSize]; m_native.state = m_checked ? NSOnState : NSOffState; return m_native; @@ -360,7 +409,7 @@ QString QCocoaMenuItem::mergeText() return qt_mac_applicationmenu_string(AboutAppMenuItem).arg(qt_mac_applicationName()); } else if (m_native== [loader aboutQtMenuItem]) { if (m_text == QString("About Qt")) - return msgAboutQt(); + return QCoreApplication::translate("QCocoaMenuItem", "About Qt"); else return m_text; } else if (m_native == [loader preferencesMenuItem]) { diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm index d384078e91..a7c17fc177 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm @@ -39,7 +39,6 @@ #include "qcocoamenuloader.h" -#include "messages.h" #include "qcocoahelpers.h" #include "qcocoansmenu.h" #include "qcocoamenubar.h" diff --git a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm index d0e69bdca5..90e124b790 100644 --- a/src/plugins/platforms/cocoa/qcocoanativeinterface.mm +++ b/src/plugins/platforms/cocoa/qcocoanativeinterface.mm @@ -50,13 +50,13 @@ #include <qwindow.h> #include <qpixmap.h> #include <qpa/qplatformwindow.h> -#include "qsurfaceformat.h" +#include <QtGui/qsurfaceformat.h> #ifndef QT_NO_OPENGL #include <qpa/qplatformopenglcontext.h> -#include "qopenglcontext.h" +#include <QtGui/qopenglcontext.h> #include "qcocoaglcontext.h" #endif -#include "qguiapplication.h" +#include <QtGui/qguiapplication.h> #include <qdebug.h> #if !defined(QT_NO_WIDGETS) && defined(QT_PRINTSUPPORT_LIB) @@ -107,7 +107,7 @@ void *QCocoaNativeInterface::nativeResourceForWindow(const QByteArray &resourceS #if QT_CONFIG(vulkan) } else if (resourceString == "vkSurface") { if (QVulkanInstance *instance = window->vulkanInstance()) - return static_cast<QCocoaVulkanInstance *>(instance->handle())->createSurface(window); + return static_cast<QCocoaVulkanInstance *>(instance->handle())->surface(window); #endif } return nullptr; diff --git a/src/plugins/platforms/cocoa/qcocoansmenu.h b/src/plugins/platforms/cocoa/qcocoansmenu.h index 0c77e2f1aa..bd0334e061 100644 --- a/src/plugins/platforms/cocoa/qcocoansmenu.h +++ b/src/plugins/platforms/cocoa/qcocoansmenu.h @@ -53,7 +53,7 @@ #import <AppKit/AppKit.h> -#include <qcocoahelpers.h> +#include "qcocoahelpers.h" QT_FORWARD_DECLARE_CLASS(QCocoaMenu); QT_FORWARD_DECLARE_CLASS(QCocoaMenuItem); diff --git a/src/plugins/platforms/cocoa/qcocoaprintdevice.h b/src/plugins/platforms/cocoa/qcocoaprintdevice.h index d267343b0e..59a521e0b5 100644 --- a/src/plugins/platforms/cocoa/qcocoaprintdevice.h +++ b/src/plugins/platforms/cocoa/qcocoaprintdevice.h @@ -55,8 +55,6 @@ #ifndef QT_NO_PRINTER -#include "qt_mac_p.h" - #include <cups/ppd.h> QT_BEGIN_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoaprintdevice.mm b/src/plugins/platforms/cocoa/qcocoaprintdevice.mm index 7605dc9d1a..ab304d9c04 100644 --- a/src/plugins/platforms/cocoa/qcocoaprintdevice.mm +++ b/src/plugins/platforms/cocoa/qcocoaprintdevice.mm @@ -37,6 +37,8 @@ ** ****************************************************************************/ +#include <ApplicationServices/ApplicationServices.h> + #include "qcocoaprintdevice.h" #if QT_CONFIG(mimetype) @@ -44,6 +46,8 @@ #endif #include <qdebug.h> +#include <QtCore/private/qcore_mac_p.h> + QT_BEGIN_NAMESPACE #ifndef QT_NO_PRINTER @@ -117,7 +121,7 @@ QCocoaPrintDevice::~QCocoaPrintDevice() { if (m_ppd) ppdClose(m_ppd); - foreach (PMPaper paper, m_macPapers) + for (PMPaper paper : m_macPapers) PMRelease(paper); // Releasing the session appears to also release the printer if (m_session) @@ -171,7 +175,7 @@ QPageSize QCocoaPrintDevice::createPageSize(const PMPaper &paper) const void QCocoaPrintDevice::loadPageSizes() const { m_pageSizes.clear(); - foreach (PMPaper paper, m_macPapers) + for (PMPaper paper : m_macPapers) PMRelease(paper); m_macPapers.clear(); m_printableMargins.clear(); diff --git a/src/plugins/platforms/cocoa/qcocoaprintersupport.h b/src/plugins/platforms/cocoa/qcocoaprintersupport.h index 40a638207a..b1a9541c03 100644 --- a/src/plugins/platforms/cocoa/qcocoaprintersupport.h +++ b/src/plugins/platforms/cocoa/qcocoaprintersupport.h @@ -43,8 +43,6 @@ #include <qpa/qplatformprintersupport.h> #ifndef QT_NO_PRINTER -#include "qt_mac_p.h" - QT_BEGIN_NAMESPACE class QCocoaPrinterSupport : public QPlatformPrinterSupport diff --git a/src/plugins/platforms/cocoa/qcocoaprintersupport.mm b/src/plugins/platforms/cocoa/qcocoaprintersupport.mm index d7eaa469fb..4c5c7aef88 100644 --- a/src/plugins/platforms/cocoa/qcocoaprintersupport.mm +++ b/src/plugins/platforms/cocoa/qcocoaprintersupport.mm @@ -41,6 +41,10 @@ #ifndef QT_NO_PRINTER +#include <AppKit/AppKit.h> + +#include <QtCore/private/qcore_mac_p.h> + #include "qcocoaprintdevice.h" #include "qprintengine_mac_p.h" diff --git a/src/plugins/platforms/cocoa/qcocoasessionmanager.cpp b/src/plugins/platforms/cocoa/qcocoasessionmanager.cpp new file mode 100644 index 0000000000..725fc5acc0 --- /dev/null +++ b/src/plugins/platforms/cocoa/qcocoasessionmanager.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Samuel Gaist <samuel.gaist@idiap.ch> +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the plugins of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QT_NO_SESSIONMANAGER +#include <private/qsessionmanager_p.h> +#include <private/qguiapplication_p.h> + +#include "qcocoasessionmanager.h" +#include <qstring.h> + +QT_BEGIN_NAMESPACE + +QCocoaSessionManager::QCocoaSessionManager(const QString &id, const QString &key) + : QPlatformSessionManager(id, key), + m_canceled(false) +{ +} + +QCocoaSessionManager::~QCocoaSessionManager() +{ +} + +bool QCocoaSessionManager::allowsInteraction() +{ + return false; +} + +void QCocoaSessionManager::resetCancellation() +{ + m_canceled = false; +} + +void QCocoaSessionManager::cancel() +{ + m_canceled = true; +} + +bool QCocoaSessionManager::wasCanceled() const +{ + return m_canceled; +} + +QCocoaSessionManager *QCocoaSessionManager::instance() +{ + auto *qGuiAppPriv = QGuiApplicationPrivate::instance(); + auto *managerPrivate = static_cast<QSessionManagerPrivate*>(QObjectPrivate::get(qGuiAppPriv->session_manager)); + return static_cast<QCocoaSessionManager *>(managerPrivate->platformSessionManager); +} + +QT_END_NAMESPACE + +#endif // QT_NO_SESSIONMANAGER diff --git a/src/plugins/platforms/cocoa/messages.h b/src/plugins/platforms/cocoa/qcocoasessionmanager.h index 3a9eaf604e..89ab7bd157 100644 --- a/src/plugins/platforms/cocoa/messages.h +++ b/src/plugins/platforms/cocoa/qcocoasessionmanager.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2018 The Qt Company Ltd. +** Copyright (C) 2019 Samuel Gaist <samuel.gaist@idiap.ch> ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the plugins of the Qt Toolkit. @@ -37,33 +37,45 @@ ** ****************************************************************************/ -#ifndef MESSAGES_H -#define MESSAGES_H +#ifndef QCOCOASESSIONMANAGER_H +#define QCOCOASESSIONMANAGER_H -#include <QString> -#include <qpa/qplatformmenu.h> +// +// W A R N I N G +// ------------- +// +// This file is part of the QPA API and is not meant to be used +// in applications. Usage of this API may make your code +// source and binary incompatible with future versions of Qt. +// -QT_BEGIN_NAMESPACE +#ifndef QT_NO_SESSIONMANAGER -enum { - AboutAppMenuItem = 0, - PreferencesAppMenuItem, - ServicesAppMenuItem, - HideAppMenuItem, - HideOthersAppMenuItem, - ShowAllAppMenuItem, - QuitAppMenuItem -}; +#include <qpa/qplatformsessionmanager.h> + +QT_BEGIN_NAMESPACE +class QCocoaSessionManager : public QPlatformSessionManager +{ +public: + QCocoaSessionManager(const QString &id, const QString &key); + virtual ~QCocoaSessionManager(); -QString msgAboutQt(); + bool allowsInteraction() override; + void cancel() override; + void resetCancellation(); + bool wasCanceled() const; -QString qt_mac_applicationmenu_string(int type); + static QCocoaSessionManager *instance(); -QPlatformMenuItem::MenuRole detectMenuRole(const QString &caption); +private: + bool m_canceled; -QString msgDialogButtonDiscard(); + Q_DISABLE_COPY(QCocoaSessionManager) +}; QT_END_NAMESPACE -#endif // MESSAGES_H +#endif // QT_NO_SESSIONMANAGER + +#endif // QCOCOASESSIONMANAGER_H diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h index 6779bda491..141995d1b1 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.h @@ -46,17 +46,26 @@ #if QT_CONFIG(systemtrayicon) -#include "QtCore/qstring.h" -#include "QtGui/qpa/qplatformsystemtrayicon.h" +#include <QtCore/qstring.h> +#include <QtGui/qpa/qplatformsystemtrayicon.h> -QT_BEGIN_NAMESPACE +#include "qcocoamenu.h" + +QT_FORWARD_DECLARE_CLASS(QCocoaSystemTrayIcon); + +@interface QT_MANGLE_NAMESPACE(QStatusItemDelegate) : NSObject <NSUserNotificationCenterDelegate> +- (instancetype)initWithSysTray:(QCocoaSystemTrayIcon *)platformSystemTray; +@property (nonatomic, assign) QCocoaSystemTrayIcon *platformSystemTray; +@end -class QSystemTrayIconSys; +QT_NAMESPACE_ALIAS_OBJC_CLASS(QStatusItemDelegate); + +QT_BEGIN_NAMESPACE class Q_GUI_EXPORT QCocoaSystemTrayIcon : public QPlatformSystemTrayIcon { public: - QCocoaSystemTrayIcon() : m_sys(nullptr) {} + QCocoaSystemTrayIcon() {} void init() override; void cleanup() override; @@ -65,13 +74,17 @@ public: void updateMenu(QPlatformMenu *menu) override; QRect geometry() const override; void showMessage(const QString &title, const QString &msg, - const QIcon& icon, MessageIcon iconType, int secs) override; + const QIcon& icon, MessageIcon iconType, int msecs) override; bool isSystemTrayAvailable() const override; bool supportsMessages() const override; + void statusItemClicked(); + private: - QSystemTrayIconSys *m_sys; + NSStatusItem *m_statusItem = nullptr; + QStatusItemDelegate *m_delegate = nullptr; + QCocoaMenu *m_menu = nullptr; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index a5b42ac4e3..704498acb1 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -84,7 +84,6 @@ #include "qcocoamenu.h" -#include "qt_mac_p.h" #include "qcocoahelpers.h" #include "qcocoaintegration.h" #include "qcocoascreen.h" @@ -92,67 +91,46 @@ #import <AppKit/AppKit.h> -QT_USE_NAMESPACE - -@interface QT_MANGLE_NAMESPACE(QNSStatusItem) : NSObject <NSUserNotificationCenterDelegate> -@property (nonatomic, assign) QCocoaMenu *menu; -@property (nonatomic, assign) QIcon icon; -@property (nonatomic, readonly) NSStatusItem *item; -@property (nonatomic, readonly) QRectF geometry; -- (instancetype)initWithSysTray:(QCocoaSystemTrayIcon *)systray; -- (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton; -- (void)doubleClickSelector:(id)sender; -@end +QT_BEGIN_NAMESPACE -QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSStatusItem); +void QCocoaSystemTrayIcon::init() +{ + m_statusItem = [[NSStatusBar.systemStatusBar statusItemWithLength:NSSquareStatusItemLength] retain]; -@interface QT_MANGLE_NAMESPACE(QNSImageView) : NSImageView -@property (nonatomic, assign) BOOL down; -@property (nonatomic, assign) QNSStatusItem *parent; -@end + m_delegate = [[QStatusItemDelegate alloc] initWithSysTray:this]; -QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSImageView); + m_statusItem.button.target = m_delegate; + m_statusItem.button.action = @selector(statusItemClicked); + [m_statusItem.button sendActionOn:NSEventMaskLeftMouseUp | NSEventMaskRightMouseUp | NSEventMaskOtherMouseUp]; +} -QT_BEGIN_NAMESPACE -class QSystemTrayIconSys +void QCocoaSystemTrayIcon::cleanup() { -public: - QSystemTrayIconSys(QCocoaSystemTrayIcon *sys) { - item = [[QNSStatusItem alloc] initWithSysTray:sys]; - NSUserNotificationCenter.defaultUserNotificationCenter.delegate = item; - } - ~QSystemTrayIconSys() { - [[[item item] view] setHidden: YES]; - NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter; - if (center.delegate == item) - center.delegate = nil; - [item release]; - } - QNSStatusItem *item; -}; + NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter; + if (center.delegate == m_delegate) + center.delegate = nil; -void QCocoaSystemTrayIcon::init() -{ - if (!m_sys) - m_sys = new QSystemTrayIconSys(this); + [NSStatusBar.systemStatusBar removeStatusItem:m_statusItem]; + [m_statusItem release]; + m_statusItem = nil; + + [m_delegate release]; + m_delegate = nil; + + m_menu = nullptr; } QRect QCocoaSystemTrayIcon::geometry() const { - if (!m_sys) + if (!m_statusItem) return QRect(); - const QRectF geom = [m_sys->item geometry]; - if (!geom.isNull()) - return geom.toRect(); - else - return QRect(); -} + if (NSWindow *window = m_statusItem.button.window) { + if (QCocoaScreen *screen = QCocoaScreen::get(window.screen)) + return screen->mapFromNative(window.frame).toRect(); + } -void QCocoaSystemTrayIcon::cleanup() -{ - delete m_sys; - m_sys = nullptr; + return QRect(); } static bool heightCompareFunction (QSize a, QSize b) { return (a.height() < b.height()); } @@ -165,17 +143,15 @@ static QList<QSize> sortByHeight(const QList<QSize> &sizes) void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon) { - if (!m_sys) + if (!m_statusItem) return; - m_sys->item.icon = icon; - - // The reccomended maximum title bar icon height is 18 points + // The recommended maximum title bar icon height is 18 points // (device independent pixels). The menu height on past and // current OS X versions is 22 points. Provide some future-proofing // by deriving the icon height from the menu height. const int padding = 4; - const int menuHeight = [[NSStatusBar systemStatusBar] thickness]; + const int menuHeight = NSStatusBar.systemStatusBar.thickness; const int maxImageHeight = menuHeight - padding; // Select pixmap based on the device pixel height. Ideally we would use @@ -185,7 +161,7 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon) qreal devicePixelRatio = qApp->devicePixelRatio(); const int maxPixmapHeight = maxImageHeight * devicePixelRatio; QSize selectedSize; - Q_FOREACH (const QSize& size, sortByHeight(icon.availableSizes())) { + for (const QSize& size : sortByHeight(icon.availableSizes())) { // Select a pixmap based on the height. We want the largest pixmap // with a height smaller or equal to maxPixmapHeight. The pixmap // may rectangular; assume it has a reasonable size. If there is @@ -228,30 +204,28 @@ void QCocoaSystemTrayIcon::updateIcon(const QIcon &icon) p.drawPixmap(r, pixmap); } - NSImage *nsimage = static_cast<NSImage *>(qt_mac_create_nsimage(fullHeightPixmap)); + auto *nsimage = [NSImage imageFromQImage:fullHeightPixmap.toImage()]; [nsimage setTemplate:icon.isMask()]; - [(NSImageView*)[[m_sys->item item] view] setImage: nsimage]; - [nsimage release]; + m_statusItem.button.image = nsimage; + m_statusItem.button.imageScaling = NSImageScaleProportionallyDown; } void QCocoaSystemTrayIcon::updateMenu(QPlatformMenu *menu) { - if (!m_sys) - return; - - m_sys->item.menu = static_cast<QCocoaMenu *>(menu); - if (menu && [m_sys->item.menu->nsMenu() numberOfItems] > 0) { - [[m_sys->item item] setHighlightMode:YES]; - } else { - [[m_sys->item item] setHighlightMode:NO]; - } + // We don't set the menu property of the NSStatusItem here, + // as that would prevent us from receiving the action for the + // click, and we wouldn't be able to emit the activated signal. + // Instead we show the menu manually when the status item is + // clicked. + m_menu = static_cast<QCocoaMenu *>(menu); } void QCocoaSystemTrayIcon::updateToolTip(const QString &toolTip) { - if (!m_sys) + if (!m_statusItem) return; - [[[m_sys->item item] view] setToolTip:toolTip.toNSString()]; + + m_statusItem.button.toolTip = toolTip.toNSString(); } bool QCocoaSystemTrayIcon::isSystemTrayAvailable() const @@ -265,179 +239,85 @@ bool QCocoaSystemTrayIcon::supportsMessages() const } void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &message, - const QIcon& icon, MessageIcon, int) + const QIcon& icon, MessageIcon, int msecs) { - if (!m_sys) + if (!m_statusItem) return; - NSUserNotification *notification = [[NSUserNotification alloc] init]; - notification.title = [NSString stringWithUTF8String:title.toUtf8().data()]; - notification.informativeText = [NSString stringWithUTF8String:message.toUtf8().data()]; - - if (!icon.isNull()) { - auto *nsimage = qt_mac_create_nsimage(icon); - [nsimage setTemplate:icon.isMask()]; - notification.contentImage = [nsimage autorelease]; - } + auto *notification = [[NSUserNotification alloc] init]; + notification.title = title.toNSString(); + notification.informativeText = message.toNSString(); + notification.contentImage = [NSImage imageFromQIcon:icon]; NSUserNotificationCenter *center = NSUserNotificationCenter.defaultUserNotificationCenter; - center.delegate = m_sys->item; - [center deliverNotification:notification]; - [notification release]; -} -QT_END_NAMESPACE + center.delegate = m_delegate; -@implementation NSStatusItem (Qt) -@end + [center deliverNotification:[notification autorelease]]; -@implementation QNSImageView -- (instancetype)initWithParent:(QNSStatusItem *)myParent { - self = [super init]; - self.parent = myParent; - self.down = NO; - return self; + if (msecs) { + NSTimeInterval timeout = msecs / 1000.0; + [center performSelector:@selector(removeDeliveredNotification:) withObject:notification afterDelay:timeout]; + } } -- (void)menuTrackingDone:(NSNotification *)__unused notification +void QCocoaSystemTrayIcon::statusItemClicked() { - self.down = NO; + auto *mouseEvent = NSApp.currentEvent; - [self setNeedsDisplay:YES]; -} - -- (void)mousePressed:(NSEvent *)mouseEvent -{ - self.down = YES; - int clickCount = [mouseEvent clickCount]; - [self setNeedsDisplay:YES]; + auto activationReason = QPlatformSystemTrayIcon::Unknown; - if (clickCount == 2) { - [self menuTrackingDone:nil]; - [self.parent doubleClickSelector:self]; + if (mouseEvent.clickCount == 2) { + activationReason = QPlatformSystemTrayIcon::DoubleClick; } else { - [self.parent triggerSelector:self button:cocoaButton2QtButton(mouseEvent)]; + auto mouseButton = cocoaButton2QtButton(mouseEvent); + if (mouseButton == Qt::MidButton) + activationReason = QPlatformSystemTrayIcon::MiddleClick; + else if (mouseButton == Qt::RightButton) + activationReason = QPlatformSystemTrayIcon::Context; + else + activationReason = QPlatformSystemTrayIcon::Trigger; } -} -- (void)mouseDown:(NSEvent *)mouseEvent -{ - [self mousePressed:mouseEvent]; -} + emit activated(activationReason); -- (void)mouseUp:(NSEvent *)mouseEvent -{ - Q_UNUSED(mouseEvent); - [self menuTrackingDone:nil]; + if (NSMenu *menu = m_menu ? m_menu->nsMenu() : nil) + [m_statusItem popUpStatusItemMenu:menu]; } -- (void)rightMouseDown:(NSEvent *)mouseEvent -{ - [self mousePressed:mouseEvent]; -} +QT_END_NAMESPACE -- (void)rightMouseUp:(NSEvent *)mouseEvent -{ - Q_UNUSED(mouseEvent); - [self menuTrackingDone:nil]; -} +@implementation QStatusItemDelegate -- (void)otherMouseDown:(NSEvent *)mouseEvent +- (instancetype)initWithSysTray:(QCocoaSystemTrayIcon *)platformSystemTray { - [self mousePressed:mouseEvent]; -} + if ((self = [super init])) + self.platformSystemTray = platformSystemTray; -- (void)otherMouseUp:(NSEvent *)mouseEvent -{ - Q_UNUSED(mouseEvent); - [self menuTrackingDone:nil]; -} - -- (void)drawRect:(NSRect)rect { - [[self.parent item] drawStatusBarBackgroundInRect:rect withHighlight:self.down]; - [super drawRect:rect]; -} -@end - -@implementation QNSStatusItem { - QCocoaSystemTrayIcon *systray; - NSStatusItem *item; - QNSImageView *imageCell; -} - -@synthesize menu = menu; -@synthesize icon = icon; - -- (instancetype)initWithSysTray:(QCocoaSystemTrayIcon *)sys -{ - self = [super init]; - if (self) { - item = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength] retain]; - menu = nullptr; - systray = sys; - imageCell = [[QNSImageView alloc] initWithParent:self]; - [item setView: imageCell]; - } return self; } -- (void)dealloc { - [[NSStatusBar systemStatusBar] removeStatusItem:item]; - [[NSNotificationCenter defaultCenter] removeObserver:imageCell]; - imageCell.parent = nil; - [imageCell release]; - [item release]; +- (void)dealloc +{ + self.platformSystemTray = nullptr; [super dealloc]; } -- (NSStatusItem *)item { - return item; -} - -- (QRectF)geometry { - if (NSWindow *window = item.view.window) { - if (QCocoaScreen *screen = QCocoaScreen::get(window.screen)) - return screen->mapFromNative(window.frame); - } - return QRectF(); -} - -- (void)triggerSelector:(id)sender button:(Qt::MouseButton)mouseButton { - Q_UNUSED(sender); - if (!systray) - return; - - if (mouseButton == Qt::MidButton) - emit systray->activated(QPlatformSystemTrayIcon::MiddleClick); - else - emit systray->activated(QPlatformSystemTrayIcon::Trigger); - - if (menu) { - NSMenu *m = menu->nsMenu(); - [[NSNotificationCenter defaultCenter] addObserver:imageCell - selector:@selector(menuTrackingDone:) - name:NSMenuDidEndTrackingNotification - object:m]; - [item popUpStatusItemMenu: m]; - } -} - -- (void)doubleClickSelector:(id)sender { - Q_UNUSED(sender); - if (!systray) - return; - emit systray->activated(QPlatformSystemTrayIcon::DoubleClick); +- (void)statusItemClicked +{ + self.platformSystemTray->statusItemClicked(); } -- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification { +- (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center shouldPresentNotification:(NSUserNotification *)notification +{ Q_UNUSED(center); Q_UNUSED(notification); return YES; } -- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification { - Q_UNUSED(center); - Q_UNUSED(notification); - emit systray->messageClicked(); +- (void)userNotificationCenter:(NSUserNotificationCenter *)center didActivateNotification:(NSUserNotification *)notification +{ + [center removeDeliveredNotification:notification]; + emit self.platformSystemTray->messageClicked(); } @end diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h index a00cbdfea3..50e56ef1bf 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.h +++ b/src/plugins/platforms/cocoa/qcocoatheme.h @@ -70,7 +70,7 @@ public: const QPalette *palette(Palette type = SystemPalette) const override; const QFont *font(Font type = SystemFont) const override; QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const override; - QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions options = 0) const override; + QIcon fileIcon(const QFileInfo &fileInfo, QPlatformTheme::IconOptions options = {}) const override; QVariant themeHint(ThemeHint hint) const override; QString standardButtonText(int button) const override; diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index a76ba300e9..d73b028afb 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -40,7 +40,6 @@ #import <AppKit/AppKit.h> #include "qcocoatheme.h" -#include "messages.h" #include <QtCore/QOperatingSystemVersion> #include <QtCore/QVariant> @@ -547,7 +546,9 @@ QVariant QCocoaTheme::themeHint(ThemeHint hint) const QString QCocoaTheme::standardButtonText(int button) const { - return button == QPlatformDialogHelper::Discard ? msgDialogButtonDiscard() : QPlatformTheme::standardButtonText(button); + return button == QPlatformDialogHelper::Discard ? + QCoreApplication::translate("QCocoaTheme", "Don't Save") + : QPlatformTheme::standardButtonText(button); } QKeySequence QCocoaTheme::standardButtonShortcut(int button) const diff --git a/src/plugins/platforms/cocoa/qcocoavulkaninstance.h b/src/plugins/platforms/cocoa/qcocoavulkaninstance.h index 5fe6a612af..2a8d04757e 100644 --- a/src/plugins/platforms/cocoa/qcocoavulkaninstance.h +++ b/src/plugins/platforms/cocoa/qcocoavulkaninstance.h @@ -61,9 +61,11 @@ public: void createOrAdoptInstance() override; - VkSurfaceKHR *createSurface(QWindow *window); - VkSurfaceKHR createSurface(NSView *view); + VkSurfaceKHR *surface(QWindow *window); + private: + VkSurfaceKHR createSurface(NSView *view); + QVulkanInstance *m_instance = nullptr; QLibrary m_lib; VkSurfaceKHR m_nullSurface = nullptr; diff --git a/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm b/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm index 7ce78ee738..9e714859f2 100644 --- a/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm +++ b/src/plugins/platforms/cocoa/qcocoavulkaninstance.mm @@ -57,12 +57,11 @@ void QCocoaVulkanInstance::createOrAdoptInstance() initInstance(m_instance, QByteArrayList() << QByteArrayLiteral("VK_MVK_macos_surface")); } -VkSurfaceKHR *QCocoaVulkanInstance::createSurface(QWindow *window) +VkSurfaceKHR *QCocoaVulkanInstance::surface(QWindow *window) { QCocoaWindow *cocoaWindow = static_cast<QCocoaWindow *>(window->handle()); - if (cocoaWindow->m_vulkanSurface) - destroySurface(cocoaWindow->m_vulkanSurface); - cocoaWindow->m_vulkanSurface = createSurface(cocoaWindow->m_view); + if (!cocoaWindow->m_vulkanSurface) + cocoaWindow->m_vulkanSurface = createSurface(cocoaWindow->m_view); return &cocoaWindow->m_vulkanSurface; } @@ -81,7 +80,7 @@ VkSurfaceKHR QCocoaVulkanInstance::createSurface(NSView *view) surfaceInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK; surfaceInfo.pNext = nullptr; surfaceInfo.flags = 0; - surfaceInfo.pView = view; + surfaceInfo.pView = view.layer; VkSurfaceKHR surface = nullptr; VkResult err = m_createSurface(m_vkInst, &surfaceInfo, nullptr, &surface); diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index fef72bc496..291a27b15e 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -51,7 +51,6 @@ #endif #include "qnsview.h" #include "qnswindow.h" -#include "qt_mac_p.h" #if QT_CONFIG(vulkan) #include <MoltenVK/mvk_vulkan.h> @@ -218,6 +217,8 @@ protected: void toggleFullScreen(); bool isTransitioningToFullScreen() const; + bool startSystemMove() override; + // private: public: // for QNSView friend class QCocoaBackingStore; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 69d192b4f5..79dfe58a4e 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -299,6 +299,22 @@ void QCocoaWindow::setCocoaGeometry(const QRect &rect) // will call QPlatformWindow::setGeometry(rect) during resize confirmation (see qnsview.mm) } +bool QCocoaWindow::startSystemMove() +{ + switch (NSApp.currentEvent.type) { + case NSEventTypeLeftMouseDown: + case NSEventTypeRightMouseDown: + case NSEventTypeOtherMouseDown: + case NSEventTypeMouseMoved: + // The documentation only describes starting a system move + // based on mouse down events, but move events also work. + [m_view.window performWindowDragWithEvent:NSApp.currentEvent]; + return true; + default: + return false; + } +} + void QCocoaWindow::setVisible(bool visible) { qCDebug(lcQpaWindow) << "QCocoaWindow::setVisible" << window() << visible; @@ -878,14 +894,10 @@ void QCocoaWindow::setWindowIcon(const QIcon &icon) QMacAutoReleasePool pool; - if (icon.isNull()) { - NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; - [iconButton setImage:[workspace iconForFile:m_view.window.representedFilename]]; - } else { - QPixmap pixmap = icon.pixmap(QSize(22, 22)); - NSImage *image = static_cast<NSImage *>(qt_mac_create_nsimage(pixmap)); - [iconButton setImage:[image autorelease]]; - } + if (icon.isNull()) + iconButton.image = [NSWorkspace.sharedWorkspace iconForFile:m_view.window.representedFilename]; + else + iconButton.image = [NSImage imageFromQIcon:icon]; } void QCocoaWindow::setAlertState(bool enabled) @@ -1224,7 +1236,9 @@ void QCocoaWindow::windowDidOrderOffScreen() void QCocoaWindow::windowDidChangeOcclusionState() { - if (m_view.window.occlusionState & NSWindowOcclusionStateVisible) + bool visible = m_view.window.occlusionState & NSWindowOcclusionStateVisible; + qCDebug(lcQpaWindow) << "QCocoaWindow::windowDidChangeOcclusionState" << window() << "is now" << (visible ? "visible" : "occluded"); + if (visible) [m_view setNeedsDisplay:YES]; else handleExposeEvent(QRegion()); @@ -1619,6 +1633,7 @@ QCocoaNSWindow *QCocoaWindow::createNSWindow(bool shouldBePanel) nsWindow.restorable = NO; nsWindow.level = windowLevel(flags); + nsWindow.tabbingMode = NSWindowTabbingModeDisallowed; if (shouldBePanel) { // Qt::Tool windows hide on app deactivation, unless Qt::WA_MacAlwaysShowToolWindow is set @@ -1818,7 +1833,7 @@ qreal QCocoaWindow::devicePixelRatio() const QWindow *QCocoaWindow::childWindowAt(QPoint windowPoint) { QWindow *targetWindow = window(); - foreach (QObject *child, targetWindow->children()) + for (QObject *child : targetWindow->children()) if (QWindow *childWindow = qobject_cast<QWindow *>(child)) if (QPlatformWindow *handle = childWindow->handle()) if (handle->isExposed() && childWindow->geometry().contains(windowPoint)) diff --git a/src/plugins/platforms/cocoa/qmacclipboard.mm b/src/plugins/platforms/cocoa/qmacclipboard.mm index 358a6b49fd..99b378be68 100644 --- a/src/plugins/platforms/cocoa/qmacclipboard.mm +++ b/src/plugins/platforms/cocoa/qmacclipboard.mm @@ -38,14 +38,14 @@ ****************************************************************************/ #include "qmacclipboard.h" -#include "qclipboard.h" -#include "qguiapplication.h" -#include "qbitmap.h" -#include "qdatetime.h" -#include "qdebug.h" -#include "qguiapplication.h" -#include "qevent.h" -#include "qurl.h" +#include <QtGui/qclipboard.h> +#include <QtGui/qguiapplication.h> +#include <QtGui/qbitmap.h> +#include <QtCore/qdatetime.h> +#include <QtCore/qdebug.h> +#include <QtGui/qguiapplication.h> +#include <QtGui/qevent.h> +#include <QtCore/qurl.h> #include <stdlib.h> #include <string.h> #include "qcocoahelpers.h" @@ -138,8 +138,12 @@ QMacPasteboard::QMacPasteboard(CFStringRef name, uchar mt) QMacPasteboard::~QMacPasteboard() { - // commit all promises for paste after exit close - resolvingBeforeDestruction = true; + /* + Commit all promises for paste when shutting down, + unless we are the stack-allocated clipboard used by QCocoaDrag. + */ + if (mime_type == QMacInternalPasteboardMime::MIME_DND) + resolvingBeforeDestruction = true; PasteboardResolvePromises(paste); if (paste) CFRelease(paste); diff --git a/src/plugins/platforms/cocoa/qmacdefines_mac.h b/src/plugins/platforms/cocoa/qmacdefines_mac.h deleted file mode 100644 index 9e229b8dcb..0000000000 --- a/src/plugins/platforms/cocoa/qmacdefines_mac.h +++ /dev/null @@ -1,129 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/**************************************************************************** -** -** Copyright (c) 2007-2008, Apple, Inc. -** -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are met: -** -** * Redistributions of source code must retain the above copyright notice, -** this list of conditions and the following disclaimer. -** -** * Redistributions in binary form must reproduce the above copyright notice, -** this list of conditions and the following disclaimer in the documentation -** and/or other materials provided with the distribution. -** -** * Neither the name of Apple, Inc. nor the names of its contributors -** may be used to endorse or promote products derived from this software -** without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -** LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -** -****************************************************************************/ - -/* - * qmacdefines_mac_p.h - * All the defines you'll ever need for Qt/Mac :-) - */ - -/* This is just many defines. Therefore it doesn't need things like: -QT_BEGIN_NAMESPACE - - -QT_END_NAMESPACE - -Yes, it is an informative comment ;-) -*/ - -#include <QtCore/qglobal.h> - -#ifdef __LP64__ -typedef signed int OSStatus; -#else -typedef signed long OSStatus; -#endif - -typedef struct OpaqueEventHandlerCallRef * EventHandlerCallRef; -typedef struct OpaqueEventRef * EventRef; -typedef struct OpaqueMenuRef * MenuRef; -typedef struct OpaquePasteboardRef* PasteboardRef; -typedef struct OpaqueRgnHandle * RgnHandle; -typedef const struct __HIShape *HIShapeRef; -typedef struct __HIShape *HIMutableShapeRef; -typedef struct CGRect CGRect; -typedef struct CGImage *CGImageRef; -typedef struct CGContext *CGContextRef; -typedef struct GDevice * GDPtr; -typedef GDPtr * GDHandle; -typedef struct OpaqueIconRef * IconRef; - -#ifdef __OBJC__ -typedef NSWindow* OSWindowRef; -typedef NSView *OSViewRef; -typedef NSMenu *OSMenuRef; -typedef NSEvent *OSEventRef; -#else -typedef void *OSWindowRef; -typedef void *OSViewRef; -typedef void *OSMenuRef; -typedef void *OSEventRef; -#endif - -typedef PasteboardRef OSPasteboardRef; -typedef struct AEDesc AEDescList; -typedef AEDescList AERecord; -typedef AERecord AppleEvent; - -#ifdef check -#undef check -#endif diff --git a/src/plugins/platforms/cocoa/qmultitouch_mac.mm b/src/plugins/platforms/cocoa/qmultitouch_mac.mm index 10652dc6a1..95256657fe 100644 --- a/src/plugins/platforms/cocoa/qmultitouch_mac.mm +++ b/src/plugins/platforms/cocoa/qmultitouch_mac.mm @@ -184,7 +184,7 @@ QCocoaTouch::getCurrentTouchPointList(NSEvent *event, bool acceptSingleTouch) if (_touchCount != _currentTouches.size()) { // Remove all instances, and basically start from scratch: touchPoints.clear(); - foreach (QCocoaTouch *qcocoaTouch, _currentTouches) { + for (QCocoaTouch *qcocoaTouch : _currentTouches) { if (!_updateInternalStateOnly) { qcocoaTouch->_touchPoint.state = Qt::TouchPointReleased; touchPoints.insert(qcocoaTouch->_touchPoint.id, qcocoaTouch->_touchPoint); diff --git a/src/plugins/platforms/cocoa/qnsview.h b/src/plugins/platforms/cocoa/qnsview.h index 74d0735b4c..0a18afe3a6 100644 --- a/src/plugins/platforms/cocoa/qnsview.h +++ b/src/plugins/platforms/cocoa/qnsview.h @@ -43,7 +43,7 @@ #include <AppKit/AppKit.h> #include <MetalKit/MetalKit.h> -#include "private/qcore_mac_p.h" +#include <QtCore/private/qcore_mac_p.h> QT_BEGIN_NAMESPACE class QCocoaWindow; diff --git a/src/plugins/platforms/cocoa/qnsview_dragging.mm b/src/plugins/platforms/cocoa/qnsview_dragging.mm index 650612e7ff..463e3c5579 100644 --- a/src/plugins/platforms/cocoa/qnsview_dragging.mm +++ b/src/plugins/platforms/cocoa/qnsview_dragging.mm @@ -150,10 +150,8 @@ static QPoint mapWindowCoordinates(QWindow *source, QWindow *target, QPoint poin break; } } else { - NSImage *nsimage = qt_mac_create_nsimage(pixmapCursor); - nsimage.size = NSSizeFromCGSize((pixmapCursor.size() / pixmapCursor.devicePixelRatioF()).toCGSize()); + auto *nsimage = [NSImage imageFromQImage:pixmapCursor.toImage()]; nativeCursor = [[NSCursor alloc] initWithImage:nsimage hotSpot:NSZeroPoint]; - [nsimage release]; } // Change the cursor diff --git a/src/plugins/platforms/cocoa/qnsview_menus.mm b/src/plugins/platforms/cocoa/qnsview_menus.mm index a55fd97eb7..7ae274ab04 100644 --- a/src/plugins/platforms/cocoa/qnsview_menus.mm +++ b/src/plugins/platforms/cocoa/qnsview_menus.mm @@ -39,11 +39,11 @@ // This file is included from qnsview.mm, and only used to organize the code -#include <qcocoaapplicationdelegate.h> -#include <qcocoansmenu.h> -#include <qcocoamenuitem.h> -#include <qcocoamenu.h> -#include <qcocoamenubar.h> +#include "qcocoaapplicationdelegate.h" +#include "qcocoansmenu.h" +#include "qcocoamenuitem.h" +#include "qcocoamenu.h" +#include "qcocoamenubar.h" static bool selectorIsCutCopyPaste(SEL selector) { @@ -84,7 +84,8 @@ static bool selectorIsCutCopyPaste(SEL selector) menuParent = menuObject->menuParent(); } - if (menubar && menubar->cocoaWindow() != self.platformWindow) + // we have no menubar parent for the application menu items, e.g About and Preferences + if (!menubar || menubar->cocoaWindow() != self.platformWindow) return NO; } diff --git a/src/plugins/platforms/cocoa/qnswindow.h b/src/plugins/platforms/cocoa/qnswindow.h index 5fc48d826f..3263df3862 100644 --- a/src/plugins/platforms/cocoa/qnswindow.h +++ b/src/plugins/platforms/cocoa/qnswindow.h @@ -42,7 +42,7 @@ #include <qglobal.h> #include <QPointer> -#include "qt_mac_p.h" +#include <QtCore/private/qcore_mac_p.h> #include <AppKit/AppKit.h> diff --git a/src/plugins/platforms/cocoa/qpaintengine_mac.mm b/src/plugins/platforms/cocoa/qpaintengine_mac.mm index 00b2267f0d..5ced962cb1 100644 --- a/src/plugins/platforms/cocoa/qpaintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qpaintengine_mac.mm @@ -37,6 +37,9 @@ ** ****************************************************************************/ +#include <AppKit/AppKit.h> +#include <CoreGraphics/CoreGraphics.h> + #include "qpaintengine_mac_p.h" #if defined(QT_PRINTSUPPORT_LIB) #include "qprintengine_mac_p.h" @@ -394,16 +397,19 @@ QCoreGraphicsPaintEngine::begin(QPaintDevice *pdev) d->cosmeticPenSize = 1; d->current.clipEnabled = false; d->pixelSize = QPoint(1,1); - QMacCGContext ctx(pdev); - d->hd = CGContextRetain(ctx); - if (d->hd) { - d->saveGraphicsState(); - d->orig_xform = CGContextGetCTM(d->hd); - if (d->shading) { - CGShadingRelease(d->shading); - d->shading = nullptr; + + if (pdev->devType() != QInternal::Printer) { + QMacCGContext ctx(pdev); + d->hd = CGContextRetain(ctx); + if (d->hd) { + d->saveGraphicsState(); + d->orig_xform = CGContextGetCTM(d->hd); + if (d->shading) { + CGShadingRelease(d->shading); + d->shading = nullptr; + } + d->setClip(nullptr); //clear the context's clipping } - d->setClip(nullptr); //clear the context's clipping } setActive(true); diff --git a/src/plugins/platforms/cocoa/qpaintengine_mac_p.h b/src/plugins/platforms/cocoa/qpaintengine_mac_p.h index 1416386745..a52e9cbe1c 100644 --- a/src/plugins/platforms/cocoa/qpaintengine_mac_p.h +++ b/src/plugins/platforms/cocoa/qpaintengine_mac_p.h @@ -51,15 +51,15 @@ // We mean it. // -#include "QtGui/qpaintengine.h" -#include "private/qpaintengine_p.h" -#include "private/qpolygonclipper_p.h" -#include "private/qfont_p.h" -#include "QtCore/qhash.h" - -#include "qt_mac_p.h" +#include <QtGui/qpaintengine.h> +#include <QtGui/private/qpaintengine_p.h> +#include <QtGui/private/qpolygonclipper_p.h> +#include <QtGui/private/qfont_p.h> +#include <QtCore/qhash.h> typedef struct CGColorSpace *CGColorSpaceRef; +typedef struct CGContext *CGContextRef; + QT_BEGIN_NAMESPACE class QCoreGraphicsPaintEnginePrivate; diff --git a/src/plugins/platforms/cocoa/qprintengine_mac.mm b/src/plugins/platforms/cocoa/qprintengine_mac.mm index dcb9a85a3c..9391f921ec 100644 --- a/src/plugins/platforms/cocoa/qprintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qprintengine_mac.mm @@ -37,6 +37,9 @@ ** ****************************************************************************/ +#include <AppKit/AppKit.h> +#include <ApplicationServices/ApplicationServices.h> + #include "qprintengine_mac_p.h" #include "qcocoaprintersupport.h" #include <quuid.h> @@ -44,6 +47,7 @@ #include <QtCore/qcoreapplication.h> #include <QtCore/qdebug.h> +#include <QtCore/private/qcore_mac_p.h> #ifndef QT_NO_PRINTER @@ -485,7 +489,7 @@ void QMacPrintEngine::setProperty(PrintEnginePropertyKey key, const QVariant &va int bestResolution = 0; int dpi = value.toInt(); int bestDistance = INT_MAX; - foreach (int resolution, d->m_printDevice->supportedResolutions()) { + for (int resolution : d->m_printDevice->supportedResolutions()) { if (dpi == resolution) { bestResolution = resolution; break; @@ -758,7 +762,7 @@ QVariant QMacPrintEngine::property(PrintEnginePropertyKey key) const } case PPK_SupportedResolutions: { QList<QVariant> list; - foreach (int resolution, d->m_printDevice->supportedResolutions()) + for (int resolution : d->m_printDevice->supportedResolutions()) list << resolution; ret = list; break; diff --git a/src/plugins/platforms/cocoa/qt_attribution.json b/src/plugins/platforms/cocoa/qt_attribution.json index 37c0937f29..1da0d7e370 100644 --- a/src/plugins/platforms/cocoa/qt_attribution.json +++ b/src/plugins/platforms/cocoa/qt_attribution.json @@ -3,7 +3,7 @@ "Name": "Cocoa Platform Plugin", "QDocModule": "qtgui", "QtUsage": "Code used in the Qt Platform Abstraction (QPA) for macOS.", - "Files": "qcocoaapplication.h qcocoaapplication.mm qcocoaapplicationdelegate.h qcocoaapplicationdelegate.mm qcocoaeventdispatcher.h qcocoaeventdispatcher.mm qcocoaintrospection.h qcocoaintrospection.mm qcocoasystemtrayicon.mm qmacdefines_mac.h", + "Files": "qcocoaapplication.h qcocoaapplication.mm qcocoaapplicationdelegate.h qcocoaapplicationdelegate.mm qcocoaeventdispatcher.h qcocoaeventdispatcher.mm qcocoaintrospection.h qcocoaintrospection.mm qcocoasystemtrayicon.mm", "Description": "Allows Qt to integrate into Apple's Cocoa API.", "LicenseId": "BSD-3-Clause", diff --git a/src/plugins/platforms/cocoa/qt_mac_p.h b/src/plugins/platforms/cocoa/qt_mac_p.h deleted file mode 100644 index fdcf3bcdd3..0000000000 --- a/src/plugins/platforms/cocoa/qt_mac_p.h +++ /dev/null @@ -1,127 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QT_MAC_P_H -#define QT_MAC_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#ifdef __OBJC__ -#include <AppKit/AppKit.h> -#include <objc/runtime.h> -#endif - -#include "qmacdefines_mac.h" - -#include <CoreServices/CoreServices.h> - -#include "QtCore/qglobal.h" -#include "QtCore/qvariant.h" -#include "QtCore/qmimedata.h" -#include "QtCore/qpointer.h" -#include "QtCore/qloggingcategory.h" -#include "private/qcore_mac_p.h" - - -#include "QtGui/qpainter.h" - -QT_BEGIN_NAMESPACE -class QWidget; -class QDragMoveEvent; - -// Simple class to manage short-lived regions -class QMacSmartQuickDrawRegion -{ - RgnHandle qdRgn; - Q_DISABLE_COPY(QMacSmartQuickDrawRegion) -public: - explicit QMacSmartQuickDrawRegion(RgnHandle rgn) : qdRgn(rgn) {} - ~QMacSmartQuickDrawRegion() { - extern void qt_mac_dispose_rgn(RgnHandle); // qregion_mac.cpp - qt_mac_dispose_rgn(qdRgn); - } - operator RgnHandle() { - return qdRgn; - } -}; - -class QMacInternalPasteboardMime; -class QMimeData; - - -extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp - -extern OSWindowRef qt_mac_window_for(const QWidget*); //qwidget_mac.mm -extern OSViewRef qt_mac_nativeview_for(const QWidget *); //qwidget_mac.mm -extern QPoint qt_mac_nativeMapFromParent(const QWidget *child, const QPoint &pt); //qwidget_mac.mm - -#ifdef check -# undef check -#endif - -struct QMacDndAnswerRecord { - QRect rect; - Qt::KeyboardModifiers modifiers; - Qt::MouseButtons buttons; - Qt::DropAction lastAction; - unsigned int lastOperation; - void clear() { - rect = QRect(); - modifiers = Qt::NoModifier; - buttons = Qt::NoButton; - lastAction = Qt::IgnoreAction; - lastOperation = 0; - } -}; -extern QMacDndAnswerRecord qt_mac_dnd_answer_rec; -void qt_mac_copy_answer_rect(const QDragMoveEvent &event); -bool qt_mac_mouse_inside_answer_rect(QPoint mouse); - -QT_END_NAMESPACE - -#endif // QT_MAC_P_H |