From 91cc74fbd7cb70da6ec05652ddc4891d9ddd377c Mon Sep 17 00:00:00 2001 From: Craig Watson Date: Mon, 16 Nov 2015 14:56:57 +0100 Subject: [PATCH] First pass at OS X port (Qt4->5; Carbon->Cocoa) Application compiles and runs, with some caveats. Full list of changes: - minor changes related to Qt4->Qt5 API differences - Replaced calls to Carbon framework by Cocoa - Removed registering of AE event handler. Seems to be done automatically in Qt5. - temporarily removed Podcast functionality, pending (presumably) complete re-write due to Quicktime being obsolete in newer OS X versions. - Created OBCocoa namespace, and associated files src/core/OBCocoa.h/.mm, to handle OS X - specific system calls. Currently used only by UBApplication, but can in the future provide a useful interface between the cocoa framework and OB, to avoid having too much OSX-specific code in various files --- OpenBoard.pro | 34 +++++++++-------- src/adaptors/UBThumbnailAdaptor.cpp | 2 +- src/board/UBBoardView.cpp | 3 +- src/core/OBCocoa.h | 11 ++++++ src/core/OBCocoa.mm | 24 ++++++++++++ src/core/UBApplication.cpp | 38 ++----------------- src/core/UBApplication.h | 9 +++-- src/core/UBApplicationController.cpp | 3 -- src/core/core.pri | 4 ++ src/desktop/UBWindowCapture_mac.mm | 3 +- src/frameworks/UBPlatformUtils_mac.mm | 12 +++--- src/gui/UBFloatingPalette.cpp | 2 +- ...lette_mac.cpp => UBKeyboardPalette_mac.mm} | 6 ++- src/gui/UBMagnifer.cpp | 2 +- src/gui/UBRubberBand.cpp | 10 ++--- src/gui/gui.pri | 3 +- src/podcast/UBPodcastController.cpp | 14 +++---- src/podcast/podcast.pri | 16 ++++---- 18 files changed, 104 insertions(+), 92 deletions(-) create mode 100644 src/core/OBCocoa.h create mode 100644 src/core/OBCocoa.mm rename src/gui/{UBKeyboardPalette_mac.cpp => UBKeyboardPalette_mac.mm} (97%) diff --git a/OpenBoard.pro b/OpenBoard.pro index 5f073bea..4ba4b151 100644 --- a/OpenBoard.pro +++ b/OpenBoard.pro @@ -128,32 +128,34 @@ win32 { macx { LIBS += -framework Foundation + LIBS += -framework Cocoa + LIBS += -framework Carbon LIBS += -lcrypto - CONFIG(release, debug|release):CONFIG += x86 + CONFIG(release, debug|release):CONFIG += x86_64 + CONFIG(debug, debug|release):CONFIG += x86_64 - # [03-02-2011] We must use the 32bit version for the moment - # because the Quicktime components used by this application - # are not yet available in 64bits. - CONFIG(debug, debug|release):CONFIG += x86 + # TODO Craig: switch to 64bit - QMAKE_MAC_SDK = "/Developer/SDKs/MacOSX10.6.sdk" - QMAKE_MACOSX_DEPLOYMENT_TARGET = "10.5" + QMAKE_MAC_SDK = macosx + QMAKE_MACOSX_DEPLOYMENT_TARGET = "10.10" - VERSION_RC_PATH = "$$BUILD_DIR/version_rc" + QMAKE_CXXFLAGS += -Wno-overloaded-virtual + #VERSION_RC_PATH = "$$BUILD_DIR/version_rc" + # No references to breakpad in the code =>is this still used? # Embed version into executable for breakpad - QMAKE_LFLAGS += -sectcreate \ - __DATA \ - __version \ - $$VERSION_RC_PATH + #QMAKE_LFLAGS += -sectcreate \ + # __DATA \ + # __version \ + # $$VERSION_RC_PATH QMAKE_CXXFLAGS_RELEASE += -gdwarf-2 \ -mdynamic-no-pic - QMAKE_CFLAGS += -fopenmp - QMAKE_CXXFLAGS += -fopenmp - QMAKE_LFLAGS += -fopenmp +# QMAKE_CFLAGS += -fopenmp + # QMAKE_CXXFLAGS += -fopenmp + # QMAKE_LFLAGS += -fopenmp CONTENTS_DIR = "Contents" RESOURCES_DIR = "Contents/Resources" @@ -364,7 +366,7 @@ macx { system(mkdir -p $$BUILD_DIR) system(printf \""$$OSX_VERSION"\" > $$BUILD_DIR/osx_version) system(printf \""$$VERSION"\" > $$BUILD_DIR/version) - system(printf "%02x%02x%02x%02x" `printf $$VERSION_RC | cut -d ',' -f 1` `printf $$VERSION_RC | cut -d ',' -f 2` `printf $$VERSION_RC | cut -d ',' -f 3` `printf $$VERSION_RC | cut -d ',' -f 4` | xxd -r -p > "$$VERSION_RC_PATH") + # system(printf "%02x%02x%02x%02x" `printf $$VERSION_RC | cut -d ',' -f 1` `printf $$VERSION_RC | cut -d ',' -f 2` `printf $$VERSION_RC | cut -d ',' -f 3` `printf $$VERSION_RC | cut -d ',' -f 4` | xxd -r -p > "$$VERSION_RC_PATH") } linux-g++* { diff --git a/src/adaptors/UBThumbnailAdaptor.cpp b/src/adaptors/UBThumbnailAdaptor.cpp index 96545d0f..660e3a7f 100644 --- a/src/adaptors/UBThumbnailAdaptor.cpp +++ b/src/adaptors/UBThumbnailAdaptor.cpp @@ -98,7 +98,7 @@ const QPixmap* UBThumbnailAdaptor::get(UBDocumentProxy* proxy, int pageIndex) #ifdef Q_OS_LINUX pix->load(fileName, 0, Qt::AutoColor); #else - pix->load(fileName, 0, Qt::AutoColor, false); + pix->load(fileName, 0, Qt::AutoColor); #endif } return pix; diff --git a/src/board/UBBoardView.cpp b/src/board/UBBoardView.cpp index 6024b07a..57b61d6f 100644 --- a/src/board/UBBoardView.cpp +++ b/src/board/UBBoardView.cpp @@ -872,7 +872,6 @@ bool UBBoardView::directTabletEvent(QEvent *event) tEvent = new QTabletEvent(tEvent->type() , mapFromGlobal(tEvent->pos()) , tEvent->globalPos() - , tEvent->hiResGlobalPos() , tEvent->device() , tEvent->pointerType() , tEvent->pressure() @@ -905,7 +904,7 @@ QWidget *UBBoardView::widgetForTabletEvent(QWidget *w, const QPoint &pos) QWidget *childAtPos = NULL; - QList childs = w->childItems(); + QList childs = w->children(); foreach(QObject *child, childs) { QWidget *childWidget = qobject_cast(child); diff --git a/src/core/OBCocoa.h b/src/core/OBCocoa.h new file mode 100644 index 00000000..f646d434 --- /dev/null +++ b/src/core/OBCocoa.h @@ -0,0 +1,11 @@ +/* + OBCocoa.h + + Header file permitting access to Mac OSX / Cocoa specific functions + +*/ + + +namespace OBCocoa { + void setFrontProcess(); +} diff --git a/src/core/OBCocoa.mm b/src/core/OBCocoa.mm new file mode 100644 index 00000000..53c01e2f --- /dev/null +++ b/src/core/OBCocoa.mm @@ -0,0 +1,24 @@ +#include "OBCocoa.h" +#include "UBApplicationController.h" + +#include +#import + +namespace OBCocoa { + +/** + * @brief Activate the current application + */ +void setFrontProcess() +{ + NSRunningApplication* app = [NSRunningApplication currentApplication]; + + // activate the application, forcing focus on it + [app activateWithOptions: NSApplicationActivateIgnoringOtherApps]; + + // other option:NSApplicationActivateAllWindows. This won't steal focus from another app, e.g + // if the user is doing something else while waiting for OpenBoard to load +} + + +} // namespace OBCocoa diff --git a/src/core/UBApplication.cpp b/src/core/UBApplication.cpp index 5225655b..c24ffbbb 100644 --- a/src/core/UBApplication.cpp +++ b/src/core/UBApplication.cpp @@ -34,7 +34,7 @@ #include #if defined(Q_OS_OSX) -#include + #include "OBCocoa.h" #endif #include "frameworks/UBPlatformUtils.h" @@ -91,27 +91,6 @@ bool bIsMinimized = false; QObject* UBApplication::staticMemoryCleaner = 0; -#if defined(Q_OS_OSX) -static OSStatus ub_appleEventProcessor(const AppleEvent *ae, AppleEvent *event, long handlerRefCon) -{ - Q_UNUSED(event); - OSType aeID = typeWildCard; - OSType aeClass = typeWildCard; - - AEGetAttributePtr(ae, keyEventClassAttr, typeType, 0, &aeClass, sizeof(aeClass), 0); - AEGetAttributePtr(ae, keyEventIDAttr, typeType, 0, &aeID, sizeof(aeID), 0); - - if (aeClass == kCoreEventClass && aeID == kAEReopenApplication) - { - // User clicked on Uniboard in the Dock - ((UBApplicationController*)handlerRefCon)->hideDesktop(); - return noErr; - } - - return eventNotHandledErr; -} -#endif - UBApplication::UBApplication(const QString &id, int &argc, char **argv) : QtSingleApplication(id, argc, argv) , mPreferencesController(NULL) @@ -368,11 +347,6 @@ int UBApplication::exec(const QString& pFileToImport) if (pFileToImport.length() > 0) UBApplication::applicationController->importFile(pFileToImport); -#if defined(Q_OS_OSX) - static AEEventHandlerUPP ub_proc_ae_handlerUPP = AEEventHandlerUPP(ub_appleEventProcessor); - AEInstallEventHandler(kCoreEventClass, kAEReopenApplication, ub_proc_ae_handlerUPP, SRefCon(UBApplication::applicationController), true); -#endif - if (UBSettings::settings()->appStartMode->get().toInt()) applicationController->showDesktop(); else @@ -390,14 +364,14 @@ void UBApplication::onScreenCountChanged(int newCount) mainWindow->actionMultiScreen->setEnabled(displayManager.numScreens() > 1); } -#ifdef Q_OS_OSX void UBApplication::showMinimized() { +#ifdef Q_OS_OSX mainWindow->hide(); bIsMinimized = true; +#endif } -#endif void UBApplication::startScript() { @@ -590,11 +564,7 @@ bool UBApplication::eventFilter(QObject *obj, QEvent *event) { QFileOpenEvent *fileToOpenEvent = static_cast(event); -#if defined(Q_OS_OSX) - ProcessSerialNumber psn; - GetCurrentProcess(&psn); - SetFrontProcess(&psn); -#endif + OBCocoa::setFrontProcess(); applicationController->importFile(fileToOpenEvent->file()); } diff --git a/src/core/UBApplication.h b/src/core/UBApplication.h index 2ab2c65a..ccb8f605 100644 --- a/src/core/UBApplication.h +++ b/src/core/UBApplication.h @@ -124,9 +124,9 @@ class UBApplication : public QtSingleApplication private slots: void closing(); -#ifdef Q_OS_OSX +//#ifdef Q_OS_OSX // for some reason this is not compiled if the ifdef is uncommented void showMinimized(); -#endif +//#endif void onScreenCountChanged(int newCount); private: @@ -136,10 +136,11 @@ class UBApplication : public QtSingleApplication bool mIsVerbose; QString checkLanguageAvailabilityForSankore(QString& language); protected: - -#if defined(Q_OS_OSX) && !defined(QT_MAC_USE_COCOA) +/* +#if defined(Q_OS_MAC) && !defined(QT_MAC_USE_COCOA) bool macEventFilter(EventHandlerCallRef caller, EventRef event); #endif + */ UBPreferencesController* mPreferencesController; QTranslator* mApplicationTranslator; diff --git a/src/core/UBApplicationController.cpp b/src/core/UBApplicationController.cpp index b4ae6a28..203aad85 100644 --- a/src/core/UBApplicationController.cpp +++ b/src/core/UBApplicationController.cpp @@ -67,9 +67,6 @@ #include "ui_mainWindow.h" -#ifdef Q_OS_OSX -#include -#endif #include "core/memcheck.h" diff --git a/src/core/core.pri b/src/core/core.pri index fedfde3f..92825ee3 100644 --- a/src/core/core.pri +++ b/src/core/core.pri @@ -36,3 +36,7 @@ SOURCES += src/core/main.cpp \ src/core/UBPersistenceWorker.cpp +macx { + HEADERS += src/core/OBCocoa.h + OBJECTIVE_SOURCES += src/core/OBCocoa.mm +} diff --git a/src/desktop/UBWindowCapture_mac.mm b/src/desktop/UBWindowCapture_mac.mm index 9e39b3b6..1de369fe 100644 --- a/src/desktop/UBWindowCapture_mac.mm +++ b/src/desktop/UBWindowCapture_mac.mm @@ -26,9 +26,10 @@ #include "UBWindowCapture.h" #include "UBDesktopAnnotationController.h" +#include #import -#import +#import UBWindowCapture::UBWindowCapture(UBDesktopAnnotationController *parent) diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index 9b73b850..70619205 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -33,6 +33,7 @@ #include #import +#import #import #import @@ -51,7 +52,7 @@ OSStatus emptySetSystemUIMode ( return noErr; } -void *originalSetSystemUIMode = 0; +//void *originalSetSystemUIMode = 0; void UBPlatformUtils::init() { @@ -62,7 +63,7 @@ void UBPlatformUtils::init() // http://developer.apple.com/mac/library/documentation/Carbon/Reference/Dock_Manager/Reference/reference.html#//apple_ref/c/func/SetSystemUIMode // - originalSetSystemUIMode = APEPatchCreate((const void *)SetSystemUIMode, (const void *)emptySetSystemUIMode); + //originalSetSystemUIMode = APEPatchCreate((const void *)SetSystemUIMode, (const void *)emptySetSystemUIMode); setDesktopMode(false); @@ -92,9 +93,9 @@ void UBPlatformUtils::init() void UBPlatformUtils::setDesktopMode(bool desktop) -{ +{ /* #ifndef OS_NEWER_THAN_OR_EQUAL_TO_1010 - OSStatus (*functor)(SystemUIMode, SystemUIOptions) = (OSStatus (*)(SystemUIMode, SystemUIOptions))originalSetSystemUIMode; + //OSStatus (*functor)(SystemUIMode, SystemUIOptions) = (OSStatus (*)(SystemUIMode, SystemUIOptions))originalSetSystemUIMode; if (desktop) { @@ -105,6 +106,7 @@ void UBPlatformUtils::setDesktopMode(bool desktop) functor(kUIModeAllHidden, 0); } #endif +*/ } @@ -533,7 +535,7 @@ void UBPlatformUtils::SetMacLocaleByIdentifier(const QString& id) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - const char * strName = id.toAscii().data(); + const char * strName = id.toLatin1().data(); CFStringRef iName = CFStringCreateWithCString(NULL, strName, kCFStringEncodingMacRoman ); diff --git a/src/gui/UBFloatingPalette.cpp b/src/gui/UBFloatingPalette.cpp index 749320c2..0aa19233 100644 --- a/src/gui/UBFloatingPalette.cpp +++ b/src/gui/UBFloatingPalette.cpp @@ -60,7 +60,7 @@ UBFloatingPalette::UBFloatingPalette(Qt::Corner position, QWidget *parent) #endif #ifdef Q_OS_OSX setAttribute(Qt::WA_MacAlwaysShowToolWindow); - setAttribute(Qt::WA_MacNonActivatingToolWindow); + //setAttribute(Qt::WA_MacNonActivatingToolWindow); // no longer exists setAttribute(Qt::WA_MacNoShadow); #endif } diff --git a/src/gui/UBKeyboardPalette_mac.cpp b/src/gui/UBKeyboardPalette_mac.mm similarity index 97% rename from src/gui/UBKeyboardPalette_mac.cpp rename to src/gui/UBKeyboardPalette_mac.mm index 401242bb..8fa984fd 100644 --- a/src/gui/UBKeyboardPalette_mac.cpp +++ b/src/gui/UBKeyboardPalette_mac.mm @@ -30,7 +30,8 @@ #include #include #include -#include + +#import #include #include @@ -74,6 +75,8 @@ void UBKeyboardPalette::createCtrlButtons() void UBKeyboardPalette::checkLayout() { + /* + * REMOVED FOR NOW -- check if is still needed in 10.9/10.10 TISInputSourceRef selectedLocale = TISCopyCurrentKeyboardInputSource(); CFStringRef sr = (CFStringRef) TISGetInputSourceProperty(selectedLocale, @@ -96,6 +99,7 @@ void UBKeyboardPalette::checkLayout() } } } + */ } void UBKeyboardPalette::onActivated(bool) diff --git a/src/gui/UBMagnifer.cpp b/src/gui/UBMagnifer.cpp index b6ce41cf..0d492655 100644 --- a/src/gui/UBMagnifer.cpp +++ b/src/gui/UBMagnifer.cpp @@ -85,7 +85,7 @@ UBMagnifier::UBMagnifier(QWidget *parent, bool isInteractive) #endif #ifdef Q_OS_OSX setAttribute(Qt::WA_MacAlwaysShowToolWindow); - setAttribute(Qt::WA_MacNonActivatingToolWindow); + //setAttribute(Qt::WA_MacNonActivatingToolWindow); setAttribute(Qt::WA_MacNoShadow); #endif } diff --git a/src/gui/UBRubberBand.cpp b/src/gui/UBRubberBand.cpp index a6c36e98..8fdd3117 100644 --- a/src/gui/UBRubberBand.cpp +++ b/src/gui/UBRubberBand.cpp @@ -31,15 +31,11 @@ #include #include -#ifdef Q_OS_OSX -#include -#endif - -#include "core/UBApplication.h" -#include "board/UBBoardController.h" #include "board/UBBoardView.h" #include "core/memcheck.h" +#include "core/UBApplication.h" +#include "board/UBBoardController.h" UBRubberBand::UBRubberBand(Shape s, QWidget * p) : QRubberBand(s, p) @@ -53,7 +49,7 @@ UBRubberBand::UBRubberBand(Shape s, QWidget * p) #ifdef Q_OS_WIN customStyle = new QWindowsXPStyle(); #elif defined(Q_OS_OSX) - customStyle = new QMacStyle(); + customStyle = QStyleFactory::create("macintosh"); #elif defined(Q_OS_LINUX) customStyle = QStyleFactory::create("oxygen"); #endif diff --git a/src/gui/gui.pri b/src/gui/gui.pri index dd1fd260..38f5f654 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -85,7 +85,8 @@ SOURCES += src/gui/UBThumbnailView.cpp \ src/gui/UBOpenSankoreImporterWidget.cpp \ src/gui/UBStartupHintsPalette.cpp win32:SOURCES += src/gui/UBKeyboardPalette_win.cpp -macx:SOURCES += src/gui/UBKeyboardPalette_mac.cpp +macx:OBJECTIVE_SOURCES += src/gui/UBKeyboardPalette_mac.mm linux-g++:SOURCES += src/gui/UBKeyboardPalette_linux.cpp linux-g++-32:SOURCES += src/gui/UBKeyboardPalette_linux.cpp linux-g++-64:SOURCES += src/gui/UBKeyboardPalette_linux.cpp + diff --git a/src/podcast/UBPodcastController.cpp b/src/podcast/UBPodcastController.cpp index 12641434..45a5e435 100644 --- a/src/podcast/UBPodcastController.cpp +++ b/src/podcast/UBPodcastController.cpp @@ -59,9 +59,9 @@ #ifdef Q_OS_WIN #include "windowsmedia/UBWindowsMediaVideoEncoder.h" #include "windowsmedia/UBWaveRecorder.h" -#elif defined(Q_OS_OSX) - #include "quicktime/UBQuickTimeVideoEncoder.h" - #include "quicktime/UBAudioQueueRecorder.h" +//#elif defined(Q_OS_OSX) +// #include "quicktime/UBQuickTimeVideoEncoder.h" +// #include "quicktime/UBAudioQueueRecorder.h" #endif #include "core/memcheck.h" @@ -305,8 +305,8 @@ void UBPodcastController::start() #ifdef Q_OS_WIN mVideoEncoder = new UBWindowsMediaVideoEncoder(this); //deleted on stop -#elif defined(Q_OS_OSX) - mVideoEncoder = new UBQuickTimeVideoEncoder(this); //deleted on stop +//#elif defined(Q_OS_OSX) +// mVideoEncoder = new UBQuickTimeVideoEncoder(this); //deleted on stop #endif if (mVideoEncoder) @@ -795,8 +795,8 @@ QStringList UBPodcastController::audioRecordingDevices() #ifdef Q_OS_WIN devices = UBWaveRecorder::waveInDevices(); -#elif defined(Q_OS_OSX) - devices = UBAudioQueueRecorder::waveInDevices(); +//#elif defined(Q_OS_OSX) +// devices = UBAudioQueueRecorder::waveInDevices(); #endif return devices; diff --git a/src/podcast/podcast.pri b/src/podcast/podcast.pri index 88943d78..d6d5aa94 100644 --- a/src/podcast/podcast.pri +++ b/src/podcast/podcast.pri @@ -22,13 +22,13 @@ win32 { src/podcast/windowsmedia/UBWaveRecorder.h } -macx { +#macx { - SOURCES += src/podcast/quicktime/UBQuickTimeVideoEncoder.cpp \ - src/podcast/quicktime/UBQuickTimeFile.cpp \ - src/podcast/quicktime/UBAudioQueueRecorder.cpp +# SOURCES += src/podcast/quicktime/UBQuickTimeVideoEncoder.cpp \ +# src/podcast/quicktime/UBQuickTimeFile.cpp \ +# src/podcast/quicktime/UBAudioQueueRecorder.cpp - HEADERS += src/podcast/quicktime/UBQuickTimeVideoEncoder.h \ - src/podcast/quicktime/UBQuickTimeFile.h \ - src/podcast/quicktime/UBAudioQueueRecorder.h -} \ No newline at end of file +# HEADERS += src/podcast/quicktime/UBQuickTimeVideoEncoder.h \ +# src/podcast/quicktime/UBQuickTimeFile.h \ +# src/podcast/quicktime/UBAudioQueueRecorder.h +#}