diff options
Diffstat (limited to 'src/plugins/platforms/cocoa')
26 files changed, 317 insertions, 273 deletions
diff --git a/src/plugins/platforms/cocoa/main.mm b/src/plugins/platforms/cocoa/main.mm index 6adcb27817..b730514b12 100644 --- a/src/plugins/platforms/cocoa/main.mm +++ b/src/plugins/platforms/cocoa/main.mm @@ -51,7 +51,7 @@ QT_BEGIN_NAMESPACE class QCocoaIntegrationPlugin : public QPlatformIntegrationPlugin { Q_OBJECT - Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.1" FILE "cocoa.json") + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QPA.QPlatformIntegrationFactoryInterface.5.2" FILE "cocoa.json") public: QPlatformIntegration *create(const QString&, const QStringList&); }; diff --git a/src/plugins/platforms/cocoa/qcocoaapplication.h b/src/plugins/platforms/cocoa/qcocoaapplication.h index 2376b35501..ffb12ea846 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplication.h +++ b/src/plugins/platforms/cocoa/qcocoaapplication.h @@ -89,8 +89,10 @@ Cocoa Application Categories */ #include "qglobal.h" +#include "private/qcore_mac_p.h" #import <AppKit/AppKit.h> + @class QT_MANGLE_NAMESPACE(QCocoaMenuLoader); @interface NSApplication (QT_MANGLE_NAMESPACE(QApplicationIntegration)) @@ -106,6 +108,8 @@ } @end +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSApplication); + QT_BEGIN_NAMESPACE void qt_redirectNSApplicationSendEvent(); diff --git a/src/plugins/platforms/cocoa/qcocoaapplication.mm b/src/plugins/platforms/cocoa/qcocoaapplication.mm index d962ef8f75..c293f4cd52 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplication.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplication.mm @@ -87,12 +87,12 @@ QT_USE_NAMESPACE - (void)QT_MANGLE_NAMESPACE(qt_setDockMenu):(NSMenu *)newMenu { - [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] setDockMenu:newMenu]; + [[QCocoaApplicationDelegate sharedDelegate] setDockMenu:newMenu]; } - (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader) { - return [[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] menuLoader]; + return [[QCocoaApplicationDelegate sharedDelegate] menuLoader]; } - (int)QT_MANGLE_NAMESPACE(qt_validModesForFontPanel):(NSFontPanel *)fontPanel @@ -155,7 +155,7 @@ static const QByteArray q_macLocalEventType = QByteArrayLiteral("mac_generic_NSE @end -@implementation QT_MANGLE_NAMESPACE(QNSApplication) +@implementation QNSApplication - (void)qt_sendEvent_original:(NSEvent *)event { @@ -189,7 +189,7 @@ QT_BEGIN_NAMESPACE void qt_redirectNSApplicationSendEvent() { - if ([NSApp isMemberOfClass:[QT_MANGLE_NAMESPACE(QNSApplication) class]]) { + if ([NSApp isMemberOfClass:[QNSApplication class]]) { // No need to change implementation since Qt // already controls a subclass of NSApplication return; @@ -202,7 +202,7 @@ void qt_redirectNSApplicationSendEvent() qt_cocoa_change_implementation( [NSApplication class], @selector(sendEvent:), - [QT_MANGLE_NAMESPACE(QNSApplication) class], + [QNSApplication class], @selector(qt_sendEvent_replacement:), @selector(qt_sendEvent_original:)); } diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h index e44b2d1b6d..7f6c4224df 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.h @@ -90,6 +90,7 @@ #import <Cocoa/Cocoa.h> #include <qglobal.h> +#include <private/qcore_mac_p.h> @class QT_MANGLE_NAMESPACE(QCocoaMenuLoader); @@ -108,3 +109,5 @@ - (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent; - (void) removeAppleEventHandlers; @end + +QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaApplicationDelegate); diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 3ec6ad7a20..423d552627 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -88,14 +88,14 @@ QT_USE_NAMESPACE -static QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *sharedCocoaApplicationDelegate = nil; +static QCocoaApplicationDelegate *sharedCocoaApplicationDelegate = nil; static void cleanupCocoaApplicationDelegate() { [sharedCocoaApplicationDelegate release]; } -@implementation QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) +@implementation QCocoaApplicationDelegate - (id)init { @@ -144,7 +144,7 @@ static void cleanupCocoaApplicationDelegate() return nil; } -+ (QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate)*)sharedDelegate ++ (QCocoaApplicationDelegate *)sharedDelegate { @synchronized(self) { if (sharedCocoaApplicationDelegate == nil) @@ -166,14 +166,14 @@ static void cleanupCocoaApplicationDelegate() return [[dockMenu retain] autorelease]; } -- (void)setMenuLoader:(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader +- (void)setMenuLoader:(QCocoaMenuLoader *)menuLoader { [menuLoader retain]; [qtMenuLoader release]; qtMenuLoader = menuLoader; } -- (QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *)menuLoader +- (QCocoaMenuLoader *)menuLoader { return [[qtMenuLoader retain] autorelease]; } @@ -183,7 +183,7 @@ static void cleanupCocoaApplicationDelegate() [[NSApp mainMenu] cancelTracking]; bool handle_quit = true; - NSMenuItem *quitMenuItem = [[[QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate] menuLoader] quitMenuItem]; + NSMenuItem *quitMenuItem = [[[QCocoaApplicationDelegate sharedDelegate] menuLoader] quitMenuItem]; if (!QGuiApplicationPrivate::instance()->modalWindowList.isEmpty() && [quitMenuItem isEnabled]) { int visible = 0; diff --git a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm index 3379a26650..d90d77ec1d 100644 --- a/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoacolordialoghelper.mm @@ -87,7 +87,9 @@ static NSButton *macCreateButton(const char *text, NSView *superview) - (void)finishOffWithCode:(NSInteger)code; @end -@implementation QT_MANGLE_NAMESPACE(QNSColorPanelDelegate) +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSColorPanelDelegate); + +@implementation QNSColorPanelDelegate - (id)init { @@ -308,12 +310,13 @@ static NSButton *macCreateButton(const char *text, NSView *superview) // close down during the cleanup. qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); [NSApp runModalForWindow:mColorPanel]; + mDialogIsExecuting = false; return (mResultCode == NSOKButton); } -- (QT_PREPEND_NAMESPACE(QPlatformDialogHelper::DialogCode))dialogResultCode +- (QPlatformDialogHelper::DialogCode)dialogResultCode { - return (mResultCode == NSOKButton) ? QT_PREPEND_NAMESPACE(QPlatformDialogHelper::Accepted) : QT_PREPEND_NAMESPACE(QPlatformDialogHelper::Rejected); + return (mResultCode == NSOKButton) ? QPlatformDialogHelper::Accepted : QPlatformDialogHelper::Rejected; } - (BOOL)windowShouldClose:(id)window diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h index 701e8e2dbf..8a8b1d946c 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.h @@ -62,10 +62,10 @@ public: bool show(Qt::WindowFlags windowFlags, Qt::WindowModality windowModality, QWindow *parent); void hide(); - void setDirectory(const QString &directory); - QString directory() const; - void selectFile(const QString &filename); - QStringList selectedFiles() const; + void setDirectory(const QUrl &directory) Q_DECL_OVERRIDE; + QUrl directory() const Q_DECL_OVERRIDE; + void selectFile(const QUrl &filename) Q_DECL_OVERRIDE; + QList<QUrl> selectedFiles() const Q_DECL_OVERRIDE; void setFilter(); void selectNameFilter(const QString &filter); QString selectedNameFilter() const; diff --git a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm index 76cd235514..b3bc4a8ebf 100644 --- a/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafiledialoghelper.mm @@ -139,7 +139,9 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions; @end -@implementation QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSOpenSavePanelDelegate); + +@implementation QNSOpenSavePanelDelegate - (id)initWithAcceptMode: (const QString &)selectFile @@ -148,7 +150,7 @@ typedef QSharedPointer<QFileDialogOptions> SharedPointerFileDialogOptions; { self = [super init]; mOptions = options; - if (mOptions->acceptMode() == QT_PREPEND_NAMESPACE(QFileDialogOptions::AcceptOpen)){ + if (mOptions->acceptMode() == QFileDialogOptions::AcceptOpen){ mOpenPanel = [NSOpenPanel openPanel]; mSavePanel = mOpenPanel; } else { @@ -234,7 +236,7 @@ static QString strippedText(QString s) - (void)closePanel { - *mCurrentSelection = QT_PREPEND_NAMESPACE(QCFString::toQString)([[mSavePanel URL] path]).normalized(QString::NormalizationForm_C); + *mCurrentSelection = QCFString::toQString([[mSavePanel URL] path]).normalized(QString::NormalizationForm_C); if ([mSavePanel respondsToSelector:@selector(close)]) [mSavePanel close]; if ([mSavePanel isSheet]) @@ -245,7 +247,7 @@ static QString strippedText(QString s) { if (mOpenPanel){ QFileInfo info(*mCurrentSelection); - NSString *filepath = QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.filePath()); + NSString *filepath = QCFString::toNSString(info.filePath()); bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) || [self panel:nil shouldShowFilename:filepath]; @@ -264,12 +266,12 @@ static QString strippedText(QString s) - (BOOL)runApplicationModalPanel { QFileInfo info(*mCurrentSelection); - NSString *filepath = QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.filePath()); + NSString *filepath = QCFString::toNSString(info.filePath()); bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) || [self panel:nil shouldShowFilename:filepath]; [mSavePanel setDirectoryURL: [NSURL fileURLWithPath:mCurrentDir]]; - [mSavePanel setNameFieldStringValue:selectable ? QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.fileName()) : @""]; + [mSavePanel setNameFieldStringValue:selectable ? QCFString::toNSString(info.fileName()) : @""]; // Call processEvents in case the event dispatcher has been interrupted, and needs to do // cleanup of modal sessions. Do this before showing the native dialog, otherwise it will @@ -281,22 +283,22 @@ static QString strippedText(QString s) return (mReturnCode == NSOKButton); } -- (QT_PREPEND_NAMESPACE(QPlatformDialogHelper::DialogCode))dialogResultCode +- (QPlatformDialogHelper::DialogCode)dialogResultCode { - return (mReturnCode == NSOKButton) ? QT_PREPEND_NAMESPACE(QPlatformDialogHelper::Accepted) : QT_PREPEND_NAMESPACE(QPlatformDialogHelper::Rejected); + return (mReturnCode == NSOKButton) ? QPlatformDialogHelper::Accepted : QPlatformDialogHelper::Rejected; } - (void)showWindowModalSheet:(QWindow *)parent { QFileInfo info(*mCurrentSelection); - NSString *filepath = QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.filePath()); + NSString *filepath = QCFString::toNSString(info.filePath()); bool selectable = (mOptions->acceptMode() == QFileDialogOptions::AcceptSave) || [self panel:nil shouldShowFilename:filepath]; [self updateProperties]; [mSavePanel setDirectoryURL: [NSURL fileURLWithPath:mCurrentDir]]; - [mSavePanel setNameFieldStringValue:selectable ? QT_PREPEND_NAMESPACE(QCFString::toNSString)(info.fileName()) : @""]; + [mSavePanel setNameFieldStringValue:selectable ? QCFString::toNSString(info.fileName()) : @""]; NSWindow *nsparent = static_cast<NSWindow *>(qGuiApp->platformNativeInterface()->nativeResourceForWindow("nswindow", parent)); [mSavePanel beginSheetModalForWindow:nsparent completionHandler:^(NSInteger result){ @@ -322,8 +324,8 @@ static QString strippedText(QString s) } } - QString qtFileName = QT_PREPEND_NAMESPACE(QCFString::toQString)(filename); - QFileInfo info(qtFileName.normalized(QT_PREPEND_NAMESPACE(QString::NormalizationForm_C))); + QString qtFileName = QCFString::toQString(filename); + QFileInfo info(qtFileName.normalized(QString::NormalizationForm_C)); QString path = info.absolutePath(); if (mCachedEntries->directory() != path) { mCachedEntries->updateDirCache(path); @@ -363,7 +365,7 @@ static QString strippedText(QString s) if (filters.size() > 0){ for (int i=0; i<filters.size(); ++i) { QString filter = hideDetails ? [self removeExtensions:filters.at(i)] : filters.at(i); - [mPopUpButton addItemWithTitle:QT_PREPEND_NAMESPACE(QCFString::toNSString)(filter)]; + [mPopUpButton addItemWithTitle:QCFString::toNSString(filter)]; } [mPopUpButton selectItemAtIndex:0]; [mSavePanel setAccessoryView:mAccessoryView]; @@ -391,18 +393,20 @@ static QString strippedText(QString s) return mNameFilterDropDownList->value([mPopUpButton indexOfSelectedItem]); } -- (QStringList)selectedFiles +- (QList<QUrl>)selectedFiles { if (mOpenPanel) { - QStringList result; + QList<QUrl> result; NSArray* array = [mOpenPanel URLs]; - for (NSUInteger i=0; i<[array count]; ++i) - result << QCFString::toQString([[array objectAtIndex:i] path]).normalized(QString::NormalizationForm_C); + for (NSUInteger i=0; i<[array count]; ++i) { + QString path = QCFString::toQString([[array objectAtIndex:i] path]).normalized(QString::NormalizationForm_C); + result << QUrl::fromLocalFile(path); + } return result; } else { - QStringList result; - QString filename = QT_PREPEND_NAMESPACE(QCFString::toQString)([[mSavePanel URL] path]).normalized(QString::NormalizationForm_C); - result << filename.remove(QLatin1String("___qt_very_unlikely_prefix_")); + QList<QUrl> result; + QString filename = QCFString::toQString([[mSavePanel URL] path]).normalized(QString::NormalizationForm_C); + result << QUrl::fromLocalFile(filename.remove(QLatin1String("___qt_very_unlikely_prefix_"))); return result; } } @@ -412,18 +416,18 @@ static QString strippedText(QString s) // Call this functions if mFileMode, mFileOptions, // mNameFilterDropDownList or mQDirFilter changes. // The savepanel does not contain the neccessary functions for this. - const QT_PREPEND_NAMESPACE(QFileDialogOptions::FileMode) fileMode = mOptions->fileMode(); - bool chooseFilesOnly = fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::ExistingFile) - || fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::ExistingFiles); - bool chooseDirsOnly = fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::Directory) - || fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::DirectoryOnly) - || mOptions->testOption(QT_PREPEND_NAMESPACE(QFileDialogOptions::ShowDirsOnly)); + const QFileDialogOptions::FileMode fileMode = mOptions->fileMode(); + bool chooseFilesOnly = fileMode == QFileDialogOptions::ExistingFile + || fileMode == QFileDialogOptions::ExistingFiles; + bool chooseDirsOnly = fileMode == QFileDialogOptions::Directory + || fileMode == QFileDialogOptions::DirectoryOnly + || mOptions->testOption(QFileDialogOptions::ShowDirsOnly); [mOpenPanel setCanChooseFiles:!chooseDirsOnly]; [mOpenPanel setCanChooseDirectories:!chooseFilesOnly]; - [mSavePanel setCanCreateDirectories:!(mOptions->testOption(QT_PREPEND_NAMESPACE(QFileDialogOptions::ReadOnly)))]; - [mOpenPanel setAllowsMultipleSelection:(fileMode == QT_PREPEND_NAMESPACE(QFileDialogOptions::ExistingFiles))]; - [mOpenPanel setResolvesAliases:!(mOptions->testOption(QT_PREPEND_NAMESPACE(QFileDialogOptions::DontResolveSymlinks)))]; + [mSavePanel setCanCreateDirectories:!(mOptions->testOption(QFileDialogOptions::ReadOnly))]; + [mOpenPanel setAllowsMultipleSelection:(fileMode == QFileDialogOptions::ExistingFiles)]; + [mOpenPanel setResolvesAliases:!(mOptions->testOption(QFileDialogOptions::DontResolveSymlinks))]; [mOpenPanel setTitle:QCFString::toNSString(mOptions->windowTitle())]; [mSavePanel setTitle:QCFString::toNSString(mOptions->windowTitle())]; [mPopUpButton setHidden:chooseDirsOnly]; // TODO hide the whole sunken pane instead? @@ -432,7 +436,7 @@ static QString strippedText(QString s) const QString defaultSuffix = mOptions->defaultSuffix(); if (!ext.isEmpty() && !defaultSuffix.isEmpty()) ext.prepend(defaultSuffix); - [mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : QT_PREPEND_NAMESPACE(qt_mac_QStringListToNSMutableArray(ext))]; + [mSavePanel setAllowedFileTypes:ext.isEmpty() ? nil : qt_mac_QStringListToNSMutableArray(ext)]; if ([mSavePanel respondsToSelector:@selector(isVisible)] && [mSavePanel isVisible]) { if ([mSavePanel respondsToSelector:@selector(validateVisibleColumns)]) @@ -444,7 +448,7 @@ static QString strippedText(QString s) { Q_UNUSED(sender); if (mHelper) { - QString selection = QT_PREPEND_NAMESPACE(QCFString::toQString([[mSavePanel URL] path])); + QString selection = QCFString::toQString([[mSavePanel URL] path]); if (selection != mCurrentSelection) { *mCurrentSelection = selection; mHelper->QNSOpenSavePanelDelegate_selectionChanged(selection); @@ -462,7 +466,7 @@ static QString strippedText(QString s) [mCurrentDir release]; mCurrentDir = [path retain]; - mHelper->QNSOpenSavePanelDelegate_directoryEntered(QT_PREPEND_NAMESPACE(QCFString::toQString(mCurrentDir))); + mHelper->QNSOpenSavePanelDelegate_directoryEntered(QCFString::toQString(mCurrentDir)); } /* @@ -489,7 +493,7 @@ static QString strippedText(QString s) - (QString)removeExtensions:(const QString &)filter { - QRegExp regExp(QT_PREPEND_NAMESPACE(QString::fromLatin1)(QT_PREPEND_NAMESPACE(QPlatformFileDialogHelper::filterRegExp))); + QRegExp regExp(QString::fromLatin1(QPlatformFileDialogHelper::filterRegExp)); if (regExp.indexIn(filter) != -1) return regExp.cap(1).trimmed(); return filter; @@ -525,7 +529,7 @@ static QString strippedText(QString s) (filterToUse == -1 && currentFilter.startsWith(selectedFilter))) filterToUse = i; QString filter = hideDetails ? [self removeExtensions:currentFilter] : currentFilter; - [mPopUpButton addItemWithTitle:QT_PREPEND_NAMESPACE(QCFString::toNSString)(filter)]; + [mPopUpButton addItemWithTitle:QCFString::toNSString(filter)]; } if (filterToUse != -1) [mPopUpButton selectItemAtIndex:filterToUse]; @@ -563,13 +567,13 @@ QCocoaFileDialogHelper::~QCocoaFileDialogHelper() if (!mDelegate) return; QCocoaAutoReleasePool pool; - [reinterpret_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate) release]; + [reinterpret_cast<QNSOpenSavePanelDelegate *>(mDelegate) release]; mDelegate = 0; } void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_selectionChanged(const QString &newPath) { - emit currentChanged(newPath); + emit currentChanged(QUrl::fromLocalFile(newPath)); } void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_panelClosed(bool accepted) @@ -584,7 +588,7 @@ void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_panelClosed(bool accepted) void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_directoryEntered(const QString &newDir) { // ### fixme: priv->setLastVisitedDirectory(newDir); - emit directoryEntered(newDir); + emit directoryEntered(QUrl::fromLocalFile(newDir)); } void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_filterSelected(int menuIndex) @@ -596,43 +600,45 @@ void QCocoaFileDialogHelper::QNSOpenSavePanelDelegate_filterSelected(int menuInd extern OSErr qt_mac_create_fsref(const QString &, FSRef *); // qglobal.cpp extern void qt_mac_to_pascal_string(QString s, Str255 str, TextEncoding encoding=0, int len=-1); // qglobal.cpp -void QCocoaFileDialogHelper::setDirectory(const QString &directory) +void QCocoaFileDialogHelper::setDirectory(const QUrl &directory) { - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); if (delegate) - [delegate->mSavePanel setDirectoryURL:[NSURL fileURLWithPath:QCFString::toNSString(directory)]]; + [delegate->mSavePanel setDirectoryURL:[NSURL fileURLWithPath:QCFString::toNSString(directory.toLocalFile())]]; } -QString QCocoaFileDialogHelper::directory() const +QUrl QCocoaFileDialogHelper::directory() const { - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); - if (delegate) - return QCFString::toQString([[delegate->mSavePanel directoryURL] path]).normalized(QString::NormalizationForm_C); - return QString(); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); + if (delegate) { + QString path = QCFString::toQString([[delegate->mSavePanel directoryURL] path]).normalized(QString::NormalizationForm_C); + return QUrl::fromLocalFile(path); + } + return QUrl(); } -void QCocoaFileDialogHelper::selectFile(const QString &filename) +void QCocoaFileDialogHelper::selectFile(const QUrl &filename) { - QString filePath = filename; + QString filePath = filename.toLocalFile(); if (QDir::isRelativePath(filePath)) - filePath = QFileInfo(directory(), filePath).filePath(); + filePath = QFileInfo(directory().toLocalFile(), filePath).filePath(); // There seems to no way to select a file once the dialog is running. // So do the next best thing, set the file's directory: setDirectory(QFileInfo(filePath).absolutePath()); } -QStringList QCocoaFileDialogHelper::selectedFiles() const +QList<QUrl> QCocoaFileDialogHelper::selectedFiles() const { - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); if (delegate) return [delegate selectedFiles]; - return QStringList(); + return QList<QUrl>(); } void QCocoaFileDialogHelper::setFilter() { - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); if (!delegate) return; const SharedPointerFileDialogOptions &opts = options(); @@ -651,7 +657,7 @@ void QCocoaFileDialogHelper::selectNameFilter(const QString &filter) return; const int index = options()->nameFilters().indexOf(filter); if (index != -1) { - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); if (!delegate) return; [delegate->mPopUpButton selectItemAtIndex:index]; @@ -661,7 +667,7 @@ void QCocoaFileDialogHelper::selectNameFilter(const QString &filter) QString QCocoaFileDialogHelper::selectedNameFilter() const { - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); if (!delegate) return QString(); int index = [delegate->mPopUpButton indexOfSelectedItem]; @@ -695,11 +701,11 @@ void QCocoaFileDialogHelper::createNSOpenSavePanelDelegate() return; QCocoaAutoReleasePool pool; const SharedPointerFileDialogOptions &opts = options(); - const QStringList selectedFiles = opts->initiallySelectedFiles(); - const QString directory = opts->initialDirectory(); + const QList<QUrl> selectedFiles = opts->initiallySelectedFiles(); + const QUrl directory = opts->initialDirectory(); const bool selectDir = selectedFiles.isEmpty(); - QString selection(selectDir ? directory : selectedFiles.front()); - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) alloc] + QString selection(selectDir ? directory.toLocalFile() : selectedFiles.front().toLocalFile()); + QNSOpenSavePanelDelegate *delegate = [[QNSOpenSavePanelDelegate alloc] initWithAcceptMode: selection options:opts @@ -711,7 +717,7 @@ void QCocoaFileDialogHelper::createNSOpenSavePanelDelegate() bool QCocoaFileDialogHelper::showCocoaFilePanel(Qt::WindowModality windowModality, QWindow *parent) { createNSOpenSavePanelDelegate(); - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); if (!delegate) return false; if (windowModality == Qt::NonModal) @@ -729,7 +735,7 @@ bool QCocoaFileDialogHelper::hideCocoaFilePanel() // open regarding whether or not to go native: return false; } else { - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); [delegate closePanel]; // Even when we hide it, we are still using a // native dialog, so return true: @@ -744,7 +750,7 @@ void QCocoaFileDialogHelper::exec() // yet been reactivated (regardless if [NSApp run] is still on the stack)), // showing a native modal dialog will fail. QCocoaAutoReleasePool pool; - QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSOpenSavePanelDelegate) *>(mDelegate); + QNSOpenSavePanelDelegate *delegate = static_cast<QNSOpenSavePanelDelegate *>(mDelegate); if ([delegate runApplicationModalPanel]) emit accept(); else diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.h b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.h index c1fef68f42..83aebba6d3 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.h +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.h @@ -47,9 +47,6 @@ QT_BEGIN_NAMESPACE -class QFontDialog; -class QFontDialogPrivate; - class QCocoaFontDialogHelper : public QPlatformFontDialogHelper { public: @@ -63,14 +60,6 @@ public: void setCurrentFont(const QFont &); QFont currentFont() const; - -protected: - void createNSFontPanelDelegate(); - bool showCocoaFontPanel(Qt::WindowModality windowModality, QWindow *parent); - bool hideCocoaFontPanel(); - -private: - void *mDelegate; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm index a70ba3749f..91fb52eb6d 100644 --- a/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm +++ b/src/plugins/platforms/cocoa/qcocoafontdialoghelper.mm @@ -128,14 +128,18 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) - (void)finishOffWithCode:(NSInteger)code; @end -@implementation QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSFontPanelDelegate); -- (id)initWithDialogHelper: - (QCocoaFontDialogHelper *)helper +@implementation QNSFontPanelDelegate + +- (id)init { self = [super init]; mFontPanel = [NSFontPanel sharedFontPanel]; - mHelper = helper; + mHelper = 0; + mStolenContentView = 0; + mOkButton = 0; + mCancelButton = 0; mResultCode = NSCancelButton; mDialogIsExecuting = false; mResultSet = false; @@ -145,13 +149,32 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) [mFontPanel setRestorable:NO]; #endif + [mFontPanel setDelegate:self]; + [[NSFontManager sharedFontManager] setDelegate:self]; + + [mFontPanel retain]; + return self; +} + +- (void)dealloc +{ + [self restoreOriginalContentView]; + [mFontPanel setDelegate:nil]; + [[NSFontManager sharedFontManager] setDelegate:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; + + [super dealloc]; +} + +- (void)setDialogHelper:(QCocoaFontDialogHelper *)helper +{ + mHelper = helper; + [mFontPanel setTitle:QCFString::toNSString(helper->options()->windowTitle())]; if (mHelper->options()->testOption(QFontDialogOptions::NoButtons)) { - mStolenContentView = 0; - mOkButton = 0; - mCancelButton = 0; - } else { + [self restoreOriginalContentView]; + } else if (!mStolenContentView) { // steal the font panel's contents view mStolenContentView = [mFontPanel contentView]; [mStolenContentView retain]; @@ -176,14 +199,22 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) [mCancelButton setAction:@selector(onCancelClicked)]; [mCancelButton setTarget:self]; } +} - [mFontPanel retain]; - return self; +- (void)closePanel +{ + [mFontPanel close]; } -- (void)dealloc +- (void)windowDidResize:(NSNotification *)notification { - if (mOkButton) { + Q_UNUSED(notification); + [self relayout]; +} + +- (void)restoreOriginalContentView +{ + if (mStolenContentView) { NSView *ourContentView = [mFontPanel contentView]; // return stolen stuff to its rightful owner @@ -192,28 +223,17 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) [mOkButton release]; [mCancelButton release]; [ourContentView release]; + mOkButton = 0; + mCancelButton = 0; + mStolenContentView = 0; } - - [mFontPanel setDelegate:nil]; - [[NSNotificationCenter defaultCenter] removeObserver:self]; - - [super dealloc]; -} - -- (void)closePanel -{ - [mFontPanel close]; -} - -- (void)windowDidResize:(NSNotification *)notification -{ - Q_UNUSED(notification); - if (mOkButton) - [self relayout]; } - (void)relayout { + if (!mOkButton) + return; + [self relayoutToContentSize:[[mStolenContentView superview] frame].size]; } @@ -289,30 +309,32 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) NSFont *panelFont = [fontManager convertFont:selectedFont]; mQtFont = qfontForCocoaFont(panelFont, mQtFont); - emit mHelper->currentFontChanged(mQtFont); + if (mHelper) + emit mHelper->currentFontChanged(mQtFont); } - (void)showModelessPanel { mDialogIsExecuting = false; + mResultSet = false; [mFontPanel makeKeyAndOrderFront:mFontPanel]; } - (BOOL)runApplicationModalPanel { mDialogIsExecuting = true; - [mFontPanel setDelegate:self]; // Call processEvents in case the event dispatcher has been interrupted, and needs to do // cleanup of modal sessions. Do this before showing the native dialog, otherwise it will // close down during the cleanup. qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); [NSApp runModalForWindow:mFontPanel]; + mDialogIsExecuting = false; return (mResultCode == NSOKButton); } -- (QT_PREPEND_NAMESPACE(QPlatformDialogHelper::DialogCode))dialogResultCode +- (QPlatformDialogHelper::DialogCode)dialogResultCode { - return (mResultCode == NSOKButton) ? QT_PREPEND_NAMESPACE(QPlatformDialogHelper::Accepted) : QT_PREPEND_NAMESPACE(QPlatformDialogHelper::Rejected); + return (mResultCode == NSOKButton) ? QPlatformDialogHelper::Accepted : QPlatformDialogHelper::Rejected; } - (BOOL)windowShouldClose:(id)window @@ -324,7 +346,8 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) [self finishOffWithCode:NSCancelButton]; } else { mResultSet = true; - emit mHelper->reject(); + if (mHelper) + emit mHelper->reject(); } return true; } @@ -359,27 +382,101 @@ static QFont qfontForCocoaFont(NSFont *cocoaFont, const QFont &resolveFont) QT_BEGIN_NAMESPACE -QCocoaFontDialogHelper::QCocoaFontDialogHelper() : - mDelegate(0) +class QCocoaFontPanel +{ +public: + QCocoaFontPanel() + { + mDelegate = [[QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) alloc] init]; + } + + ~QCocoaFontPanel() + { + [mDelegate release]; + } + + void init(QCocoaFontDialogHelper *helper) + { + [mDelegate setDialogHelper:helper]; + } + + void cleanup(QCocoaFontDialogHelper *helper) + { + if (mDelegate->mHelper == helper) + mDelegate->mHelper = 0; + } + + bool exec() + { + // Note: If NSApp is not running (which is the case if e.g a top-most + // QEventLoop has been interrupted, and the second-most event loop has not + // yet been reactivated (regardless if [NSApp run] is still on the stack)), + // showing a native modal dialog will fail. + return [mDelegate runApplicationModalPanel]; + } + + bool show(Qt::WindowModality windowModality, QWindow *parent) + { + Q_UNUSED(parent); + if (windowModality != Qt::WindowModal) + [mDelegate showModelessPanel]; + // no need to show a Qt::WindowModal dialog here, because it's necessary to call exec() in that case + return true; + } + + void hide() + { + [mDelegate closePanel]; + } + + QFont currentFont() const + { + return mDelegate->mQtFont; + } + + void setCurrentFont(const QFont &font) + { + NSFontManager *mgr = [NSFontManager sharedFontManager]; + const NSFont *nsFont = 0; + + int weight = 5; + NSFontTraitMask mask = 0; + if (font.style() == QFont::StyleItalic) { + mask |= NSItalicFontMask; + } + if (font.weight() == QFont::Bold) { + weight = 9; + mask |= NSBoldFontMask; + } + + QFontInfo fontInfo(font); + nsFont = [mgr fontWithFamily:QCFString::toNSString(fontInfo.family()) + traits:mask + weight:weight + size:fontInfo.pointSize()]; + + [mgr setSelectedFont:const_cast<NSFont *>(nsFont) isMultiple:NO]; + mDelegate->mQtFont = font; + } + +private: + QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *mDelegate; +}; + +Q_GLOBAL_STATIC(QCocoaFontPanel, sharedFontPanel) + +QCocoaFontDialogHelper::QCocoaFontDialogHelper() { } QCocoaFontDialogHelper::~QCocoaFontDialogHelper() { - if (!mDelegate) - return; - [reinterpret_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate) release]; - mDelegate = 0; + sharedFontPanel()->cleanup(this); } void QCocoaFontDialogHelper::exec() { - // Note: If NSApp is not running (which is the case if e.g a top-most - // QEventLoop has been interrupted, and the second-most event loop has not - // yet been reactivated (regardless if [NSApp run] is still on the stack)), - // showing a native modal dialog will fail. - QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate); - if ([delegate runApplicationModalPanel]) + if (sharedFontPanel()->exec()) emit accept(); else emit reject(); @@ -387,86 +484,26 @@ void QCocoaFontDialogHelper::exec() bool QCocoaFontDialogHelper::show(Qt::WindowFlags, Qt::WindowModality windowModality, QWindow *parent) { - if (windowModality == Qt::WindowModal) { - // Cocoa's shared font panel cannot be shown as a sheet - return false; - } - return showCocoaFontPanel(windowModality, parent); + if (windowModality == Qt::WindowModal) + windowModality = Qt::ApplicationModal; + sharedFontPanel()->init(this); + return sharedFontPanel()->show(windowModality, parent); } void QCocoaFontDialogHelper::hide() { - if (!mDelegate) - return; - [reinterpret_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate)->mFontPanel close]; + sharedFontPanel()->hide(); } void QCocoaFontDialogHelper::setCurrentFont(const QFont &font) { - NSFontManager *mgr = [NSFontManager sharedFontManager]; - const NSFont *nsFont = 0; - - int weight = 5; - NSFontTraitMask mask = 0; - if (font.style() == QFont::StyleItalic) { - mask |= NSItalicFontMask; - } - if (font.weight() == QFont::Bold) { - weight = 9; - mask |= NSBoldFontMask; - } - - QFontInfo fontInfo(font); - nsFont = [mgr fontWithFamily:QCFString::toNSString(fontInfo.family()) - traits:mask - weight:weight - size:fontInfo.pointSize()]; - - if (!mDelegate) - createNSFontPanelDelegate(); - - [mgr setSelectedFont:const_cast<NSFont *>(nsFont) isMultiple:NO]; - static_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate)->mQtFont = font; + sharedFontPanel()->init(this); + sharedFontPanel()->setCurrentFont(font); } QFont QCocoaFontDialogHelper::currentFont() const { - if (!mDelegate) - return QFont(); - return reinterpret_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate)->mQtFont; -} - -void QCocoaFontDialogHelper::createNSFontPanelDelegate() -{ - if (mDelegate) - return; - - QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *delegate = [[QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) alloc] - initWithDialogHelper:this]; - - mDelegate = delegate; -} - -bool QCocoaFontDialogHelper::showCocoaFontPanel(Qt::WindowModality windowModality, QWindow *parent) -{ - Q_UNUSED(parent); - createNSFontPanelDelegate(); - QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate); - if (windowModality == Qt::NonModal) - [delegate showModelessPanel]; - // no need to show a Qt::ApplicationModal dialog here, since it will be done in _q_platformRunNativeAppModalPanel() - return true; -} - -bool QCocoaFontDialogHelper::hideCocoaFontPanel() -{ - if (!mDelegate){ - return false; - } else { - QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *delegate = static_cast<QT_MANGLE_NAMESPACE(QNSFontPanelDelegate) *>(mDelegate); - [delegate closePanel]; - return true; - } + return sharedFontPanel()->currentFont(); } QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoahelpers.mm b/src/plugins/platforms/cocoa/qcocoahelpers.mm index 3ade0a2a45..3be294de7e 100644 --- a/src/plugins/platforms/cocoa/qcocoahelpers.mm +++ b/src/plugins/platforms/cocoa/qcocoahelpers.mm @@ -508,7 +508,6 @@ CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget) CGColorSpaceRef colorSpace; CGDirectDisplayID displayID; - CMProfileRef displayProfile = 0; if (widget == 0) { displayID = CGMainDisplayID(); } else { @@ -526,18 +525,11 @@ CGColorSpaceRef qt_mac_displayColorSpace(const QWidget *widget) if ((colorSpace = m_displayColorSpaceHash.value(displayID))) return colorSpace; - CMError err = CMGetProfileByAVID((CMDisplayIDType)displayID, &displayProfile); - if (err == noErr) { - colorSpace = CGColorSpaceCreateWithPlatformColorSpace(displayProfile); - } else if (widget) { - return qt_mac_displayColorSpace(0); // fall back on main display - } - + colorSpace = CGDisplayCopyColorSpace(displayID); if (colorSpace == 0) colorSpace = CGColorSpaceCreateDeviceRGB(); m_displayColorSpaceHash.insert(displayID, colorSpace); - CMCloseProfile(displayProfile); if (!m_postRoutineRegistered) { m_postRoutineRegistered = true; void qt_mac_cleanUpMacColorSpaces(); @@ -810,20 +802,7 @@ CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy) NULL, false); } else { - // Try get a device color space. Using the device color space means - // that the CGImage can be drawn to screen without per-pixel color - // space conversion, at the cost of less color accuracy. - CGColorSpaceRef cgColourSpaceRef = 0; - CMProfileRef sysProfile; - if (CMGetSystemProfile(&sysProfile) == noErr) - { - cgColourSpaceRef = CGColorSpaceCreateWithPlatformColorSpace(sysProfile); - CMCloseProfile(sysProfile); - } - - // Fall back to Generic RGB if a profile was not found. - if (!cgColourSpaceRef) - cgColourSpaceRef = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + CGColorSpaceRef cgColourSpaceRef = qt_mac_displayColorSpace(0); // Create a CGBitmapInfo contiaining the image format. // Support the 8-bit per component (A)RGB formats. @@ -857,7 +836,6 @@ CGImageRef qt_mac_toCGImage(const QImage &qImage, bool isMask, uchar **dataCopy) NULL, false, kCGRenderingIntentDefault); - CGColorSpaceRelease(cgColourSpaceRef); } CGDataProviderRelease(cgDataProviderRef); return cgImage; diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index fad743439e..6d1882f622 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -232,7 +232,7 @@ QCocoaIntegration::QCocoaIntegration() qApp->setAttribute(Qt::AA_DontUseNativeMenuBar, false); - NSApplication *cocoaApplication = [QT_MANGLE_NAMESPACE(QNSApplication) sharedApplication]; + NSApplication *cocoaApplication = [QNSApplication sharedApplication]; qt_redirectNSApplicationSendEvent(); if (qEnvironmentVariableIsEmpty("QT_MAC_DISABLE_FOREGROUND_APPLICATION_TRANSFORM")) { @@ -256,12 +256,12 @@ QCocoaIntegration::QCocoaIntegration() if (!QCoreApplication::testAttribute(Qt::AA_MacPluginApplication)) { // Set app delegate, link to the current delegate (if any) - QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate]; + QCocoaApplicationDelegate *newDelegate = [QCocoaApplicationDelegate sharedDelegate]; [newDelegate setReflectionDelegate:[cocoaApplication delegate]]; [cocoaApplication setDelegate:newDelegate]; // Load the application menu. This menu contains Preferences, Hide, Quit. - QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader = [[QT_MANGLE_NAMESPACE(QCocoaMenuLoader) alloc] init]; + QCocoaMenuLoader *qtMenuLoader = [[QCocoaMenuLoader alloc] init]; qt_mac_loadMenuNib(qtMenuLoader); [cocoaApplication setMenu:[qtMenuLoader menu]]; [newDelegate setMenuLoader:qtMenuLoader]; @@ -279,7 +279,7 @@ QCocoaIntegration::~QCocoaIntegration() QCocoaAutoReleasePool pool; if (!QCoreApplication::testAttribute(Qt::AA_MacPluginApplication)) { // remove the apple event handlers installed by QCocoaApplicationDelegate - QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *delegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate]; + QCocoaApplicationDelegate *delegate = [QCocoaApplicationDelegate sharedDelegate]; [delegate removeAppleEventHandlers]; // reset the application delegate [[NSApplication sharedApplication] setDelegate: 0]; diff --git a/src/plugins/platforms/cocoa/qcocoamenu.mm b/src/plugins/platforms/cocoa/qcocoamenu.mm index f9e033d21b..3ac48df09e 100644 --- a/src/plugins/platforms/cocoa/qcocoamenu.mm +++ b/src/plugins/platforms/cocoa/qcocoamenu.mm @@ -74,7 +74,7 @@ NSString *qt_mac_removePrivateUnicode(NSString* string) return string; } -static inline QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *getMenuLoader() +static inline QCocoaMenuLoader *getMenuLoader() { return [NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)]; } @@ -87,7 +87,9 @@ static inline QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *getMenuLoader() @end -@implementation QT_MANGLE_NAMESPACE(QCocoaMenuDelegate) +QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaMenuDelegate); + +@implementation QCocoaMenuDelegate - (id) initWithMenu:(QCocoaMenu*) m { @@ -220,11 +222,11 @@ QCocoaMenu::QCocoaMenu() : m_tag(0), m_menuBar(0) { - m_delegate = [[QT_MANGLE_NAMESPACE(QCocoaMenuDelegate) alloc] initWithMenu:this]; + m_delegate = [[QCocoaMenuDelegate alloc] initWithMenu:this]; m_nativeItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; m_nativeMenu = [[NSMenu alloc] initWithTitle:@"Untitled"]; [m_nativeMenu setAutoenablesItems:YES]; - m_nativeMenu.delegate = (QT_MANGLE_NAMESPACE(QCocoaMenuDelegate) *) m_delegate; + m_nativeMenu.delegate = (QCocoaMenuDelegate *) m_delegate; [m_nativeItem setSubmenu:m_nativeMenu]; } diff --git a/src/plugins/platforms/cocoa/qcocoamenubar.mm b/src/plugins/platforms/cocoa/qcocoamenubar.mm index ddfa9fff96..0fea55ac68 100644 --- a/src/plugins/platforms/cocoa/qcocoamenubar.mm +++ b/src/plugins/platforms/cocoa/qcocoamenubar.mm @@ -52,7 +52,7 @@ static QList<QCocoaMenuBar*> static_menubars; -static inline QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *getMenuLoader() +static inline QCocoaMenuLoader *getMenuLoader() { return [NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)]; } @@ -240,7 +240,7 @@ void QCocoaMenuBar::updateMenuBarImmediately() } } - QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); + QCocoaMenuLoader *loader = getMenuLoader(); [loader ensureAppMenuInMenu:mb->nsMenu()]; NSMutableSet *mergedItems = [[NSMutableSet setWithCapacity:0] retain]; diff --git a/src/plugins/platforms/cocoa/qcocoamenuitem.mm b/src/plugins/platforms/cocoa/qcocoamenuitem.mm index 6d8174c667..013f9931ff 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuitem.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuitem.mm @@ -52,7 +52,7 @@ #include <QtCore/QDebug> -static inline QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *getMenuLoader() +static inline QCocoaMenuLoader *getMenuLoader() { return [NSApp QT_MANGLE_NAMESPACE(qt_qcocoamenuLoader)]; } @@ -199,7 +199,7 @@ NSMenuItem *QCocoaMenuItem::sync() if ((m_role != NoRole && !m_textSynced) || m_merged) { NSMenuItem *mergeItem = nil; - QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); + QCocoaMenuLoader *loader = getMenuLoader(); switch (m_role) { case ApplicationSpecificRole: mergeItem = [loader appSpecificMenuItem:reinterpret_cast<NSInteger>(this)]; @@ -326,7 +326,7 @@ QT_END_NAMESPACE QString QCocoaMenuItem::mergeText() { - QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); + QCocoaMenuLoader *loader = getMenuLoader(); if (m_native == [loader aboutMenuItem]) { return qt_mac_applicationmenu_string(6).arg(qt_mac_applicationName()); } else if (m_native== [loader aboutQtMenuItem]) { @@ -344,7 +344,7 @@ QString QCocoaMenuItem::mergeText() QKeySequence QCocoaMenuItem::mergeAccel() { - QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *loader = getMenuLoader(); + QCocoaMenuLoader *loader = getMenuLoader(); if (m_native == [loader preferencesMenuItem]) return QKeySequence(QKeySequence::Preferences); else if (m_native == [loader quitMenuItem]) diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.h b/src/plugins/platforms/cocoa/qcocoamenuloader.h index a45ec0fa89..e07da39995 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.h +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.h @@ -92,9 +92,11 @@ - (NSArray *)mergeable; @end +QT_NAMESPACE_ALIAS_OBJC_CLASS(QCocoaMenuLoader); + QT_BEGIN_NAMESPACE -void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader); +void qt_mac_loadMenuNib(QCocoaMenuLoader *qtMenuLoader); QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm index 62b722d2d2..29fc0fb674 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm @@ -69,7 +69,7 @@ QT_BEGIN_NAMESPACE and written to QDir::temp() before loading. (Earlier Qt versions used to require having the nib file in the Qt GUI framework.) */ -void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader) +void qt_mac_loadMenuNib(QCocoaMenuLoader *qtMenuLoader) { // Create qt_menu.nib dir in temp. QDir temp = QDir::temp(); @@ -106,7 +106,7 @@ void qt_mac_loadMenuNib(QT_MANGLE_NAMESPACE(QCocoaMenuLoader) *qtMenuLoader) QT_END_NAMESPACE -@implementation QT_MANGLE_NAMESPACE(QCocoaMenuLoader) +@implementation QCocoaMenuLoader - (void)awakeFromNib { diff --git a/src/plugins/platforms/cocoa/qcocoaservices.mm b/src/plugins/platforms/cocoa/qcocoaservices.mm index e4cec8c5f8..de4c688b71 100644 --- a/src/plugins/platforms/cocoa/qcocoaservices.mm +++ b/src/plugins/platforms/cocoa/qcocoaservices.mm @@ -55,7 +55,7 @@ bool QCocoaServices::openUrl(const QUrl &url) const QString scheme = url.scheme(); if (scheme.isEmpty()) return openDocument(url); - return [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:QT_PREPEND_NAMESPACE(QCFString::toNSString)(url.toString(QUrl::FullyEncoded))]]; + return [[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:QCFString::toNSString(url.toString(QUrl::FullyEncoded))]]; } bool QCocoaServices::openDocument(const QUrl &url) @@ -63,7 +63,7 @@ bool QCocoaServices::openDocument(const QUrl &url) if (!url.isValid()) return false; - return [[NSWorkspace sharedWorkspace] openFile:QT_PREPEND_NAMESPACE(QCFString::toNSString)(url.toLocalFile())]; + return [[NSWorkspace sharedWorkspace] openFile:QCFString::toNSString(url.toLocalFile())]; } QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm index af817bd4c5..194394d11a 100644 --- a/src/plugins/platforms/cocoa/qcocoasystemsettings.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemsettings.mm @@ -264,6 +264,10 @@ QHash<QPlatformTheme::Font, QFont *> qt_mac_createRoleFonts() fonts.insert(QPlatformTheme::SmallFont, qt_mac_qfontForThemeFont(kThemeSmallSystemFont)); fonts.insert(QPlatformTheme::MiniFont, qt_mac_qfontForThemeFont(kThemeMiniSystemFont)); + QFont* fixedFont = new QFont(QStringLiteral("Monaco"), fonts[QPlatformTheme::SystemFont]->pointSize()); + fixedFont->setStyleHint(QFont::TypeWriter); + fonts.insert(QPlatformTheme::FixedFont, fixedFont); + return fonts; } diff --git a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm index 99f533b33a..83c960d931 100755 --- a/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm +++ b/src/plugins/platforms/cocoa/qcocoasystemtrayicon.mm @@ -135,12 +135,16 @@ QT_USE_NAMESPACE -(id)initWithQMenu:(QPlatformMenu*)qmenu; @end +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSStatusItem); +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSImageView); +QT_NAMESPACE_ALIAS_OBJC_CLASS(QNSMenu); + QT_BEGIN_NAMESPACE class QSystemTrayIconSys { public: QSystemTrayIconSys(QCocoaSystemTrayIcon *sys) { - item = [[QT_MANGLE_NAMESPACE(QNSStatusItem) alloc] initWithSysTray:sys]; + item = [[QNSStatusItem alloc] initWithSysTray:sys]; #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { [[NSUserNotificationCenter defaultUserNotificationCenter] setDelegate:item]; @@ -156,7 +160,7 @@ public: #endif [item release]; } - QT_MANGLE_NAMESPACE(QNSStatusItem) *item; + QNSStatusItem *item; }; void QCocoaSystemTrayIcon::init() @@ -310,8 +314,8 @@ QT_END_NAMESPACE @implementation NSStatusItem (Qt) @end -@implementation QT_MANGLE_NAMESPACE(QNSImageView) --(id)initWithParent:(QT_MANGLE_NAMESPACE(QNSStatusItem)*)myParent { +@implementation QNSImageView +-(id)initWithParent:(QNSStatusItem*)myParent { self = [super init]; parent = myParent; down = NO; @@ -406,7 +410,7 @@ QT_END_NAMESPACE } @end -@implementation QT_MANGLE_NAMESPACE(QNSStatusItem) +@implementation QNSStatusItem -(id)initWithSysTray:(QCocoaSystemTrayIcon *)sys { @@ -416,7 +420,7 @@ QT_END_NAMESPACE menu = 0; menuVisible = false; systray = sys; - imageCell = [[QT_MANGLE_NAMESPACE(QNSImageView) alloc] initWithParent:self]; + imageCell = [[QNSImageView alloc] initWithParent:self]; [item setView: imageCell]; } return self; @@ -494,7 +498,7 @@ private: QSystemTrayIconQMenu(); }; -@implementation QT_MANGLE_NAMESPACE(QNSMenu) +@implementation QNSMenu -(id)initWithQMenu:(QPlatformMenu*)qm { self = [super init]; if (self) { diff --git a/src/plugins/platforms/cocoa/qcocoatheme.h b/src/plugins/platforms/cocoa/qcocoatheme.h index cac059763d..e4237c9b3e 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.h +++ b/src/plugins/platforms/cocoa/qcocoatheme.h @@ -68,7 +68,9 @@ public: const QPalette *palette(Palette type = SystemPalette) const; const QFont *font(Font type = SystemFont) const; QPixmap standardPixmap(StandardPixmap sp, const QSizeF &size) const; - QPixmap fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size) const; + QPixmap fileIconPixmap(const QFileInfo &fileInfo, + const QSizeF &size, + QPlatformTheme::IconOptions options = 0) const; QVariant themeHint(ThemeHint hint) const; diff --git a/src/plugins/platforms/cocoa/qcocoatheme.mm b/src/plugins/platforms/cocoa/qcocoatheme.mm index 13a387a0a3..1484ae2ba3 100644 --- a/src/plugins/platforms/cocoa/qcocoatheme.mm +++ b/src/plugins/platforms/cocoa/qcocoatheme.mm @@ -249,8 +249,10 @@ QPixmap QCocoaTheme::standardPixmap(StandardPixmap sp, const QSizeF &size) const return QPlatformTheme::standardPixmap(sp, size); } -QPixmap QCocoaTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size) const +QPixmap QCocoaTheme::fileIconPixmap(const QFileInfo &fileInfo, const QSizeF &size, + QPlatformTheme::IconOptions iconOptions) const { + Q_UNUSED(iconOptions); QCocoaAutoReleasePool pool; NSImage *iconImage = [[NSWorkspace sharedWorkspace] iconForFile:QCFString::toNSString(fileInfo.canonicalFilePath())]; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.h b/src/plugins/platforms/cocoa/qcocoawindow.h index b82d096bb5..8967445f59 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.h +++ b/src/plugins/platforms/cocoa/qcocoawindow.h @@ -61,7 +61,7 @@ QT_FORWARD_DECLARE_CLASS(QCocoaWindow) @end @interface QNSPanel : NSPanel { - @public QT_PREPEND_NAMESPACE(QCocoaWindow) *m_cocoaPlatformWindow; + @public QCocoaWindow *m_cocoaPlatformWindow; } - (void)clearPlatformWindow; - (BOOL)canBecomeKeyWindow; diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 1126315126..fcebb7e0dc 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -155,6 +155,9 @@ static bool isMouseEvent(NSEvent *ev) - (BOOL)canBecomeKeyWindow { + if (!m_cocoaPlatformWindow) + return NO; + // Only tool or dialog windows should become key: if (m_cocoaPlatformWindow && (m_cocoaPlatformWindow->window()->type() == Qt::Tool || m_cocoaPlatformWindow->window()->type() == Qt::Dialog)) diff --git a/src/plugins/platforms/cocoa/qnsview.mm b/src/plugins/platforms/cocoa/qnsview.mm index aff93dd133..b8f0fc3cce 100644 --- a/src/plugins/platforms/cocoa/qnsview.mm +++ b/src/plugins/platforms/cocoa/qnsview.mm @@ -876,7 +876,23 @@ static QTouchDevice *touchDevice = 0; currentWheelModifiers = [QNSView convertKeyModifiers:[theEvent modifierFlags]]; } - QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_screenPoint, pixelDelta, angleDelta, currentWheelModifiers); + QWheelEvent::Phase ph = QWheelEvent::Changed; +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_8 + if (QSysInfo::QSysInfo::MacintoshVersion >= QSysInfo::MV_10_8) { + // On 10.8 and above, MayBegin is likely to happen. We treat it the same as an actual begin. + if (phase == NSEventPhaseMayBegin) + ph = QWheelEvent::Started; + } else +#endif + if (phase == NSEventPhaseBegan) { + // On 10.7, MayBegin will not happen, so Began is the actual beginning. + ph = QWheelEvent::Started; + } + if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled) { + ph = QWheelEvent::Ended; + } + + QWindowSystemInterface::handleWheelEvent(m_window, qt_timestamp, qt_windowPoint, qt_screenPoint, pixelDelta, angleDelta, currentWheelModifiers, ph); if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled) { currentWheelModifiers = Qt::NoModifier; @@ -919,14 +935,11 @@ static QTouchDevice *touchDevice = 0; NSString *charactersIgnoringModifiers = [nsevent charactersIgnoringModifiers]; NSString *characters = [nsevent characters]; - // [from Qt 4 impl] There is no way to get the scan code from carbon. But we cannot + // There is no way to get the scan code from carbon/cocoa. But we cannot // use the value 0, since it indicates that the event originates from somewhere // else than the keyboard. quint32 nativeScanCode = 1; - - UInt32 nativeVirtualKey = 0; - EventRef eventRef = EventRef([nsevent eventRef]); - GetEventParameter(eventRef, kEventParamKeyCode, typeUInt32, 0, sizeof(nativeVirtualKey), 0, &nativeVirtualKey); + quint32 nativeVirtualKey = [nsevent keyCode]; QChar ch = QChar::ReplacementCharacter; int keyCode = Qt::Key_unknown; diff --git a/src/plugins/platforms/cocoa/qpaintengine_mac.mm b/src/plugins/platforms/cocoa/qpaintengine_mac.mm index 301beb11c1..dc3757ce3c 100644 --- a/src/plugins/platforms/cocoa/qpaintengine_mac.mm +++ b/src/plugins/platforms/cocoa/qpaintengine_mac.mm @@ -362,7 +362,6 @@ CGColorSpaceRef QCoreGraphicsPaintEngine::macDisplayColorSpace(const QWidget *wi CGColorSpaceRef colorSpace; CGDirectDisplayID displayID; - CMProfileRef displayProfile = 0; if (widget == 0) { displayID = CGMainDisplayID(); } else { @@ -376,18 +375,11 @@ CGColorSpaceRef QCoreGraphicsPaintEngine::macDisplayColorSpace(const QWidget *wi if ((colorSpace = m_displayColorSpaceHash.value(displayID))) return colorSpace; - CMError err = CMGetProfileByAVID((CMDisplayIDType)displayID, &displayProfile); - if (err == noErr) { - colorSpace = CGColorSpaceCreateWithPlatformColorSpace(displayProfile); - } else if (widget) { - return macDisplayColorSpace(0); // fall back on main display - } - + colorSpace = CGDisplayCopyColorSpace(displayID); if (colorSpace == 0) colorSpace = CGColorSpaceCreateDeviceRGB(); m_displayColorSpaceHash.insert(displayID, colorSpace); - CMCloseProfile(displayProfile); if (!m_postRoutineRegistered) { m_postRoutineRegistered = true; qAddPostRoutine(QCoreGraphicsPaintEngine::cleanUpMacColorSpaces); |