diff options
author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-06-19 12:27:51 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-08-29 12:44:07 +0200 |
commit | 1e14762b8d79118540bd09a84dd3e48f4f5e113e (patch) | |
tree | f06cb1b7ccb161f3495d2c1abb941c2911a50314 /src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | |
parent | ee9b9d9fd9a714f97ed8f7e26404c2f113588e9c (diff) |
Make QGuiApplication::exec() run within NSApplicationMain()
We follow the same pattern as for iOS and Windows ports, making
sure the user's main() runs in a platform friendly environment. In
this particular case, it means calling the user's main() during the
call of NSApplicationMain(), and calling the user's main() function
(renamed to qMain() as in Windows) after receiving
NSApplicationDidFinishLaunchingNotification. In practice, this means
that NSApp is running when qMain() is called, and therefore when
QCoreApplication::exec() is called.
For those command-line utilities running on QGuiApplication, or any
deriving class, and that do not provide a bundle, we override the main
bundle's dictionary and get NSApplicationMain() to run as usual.
Added cocoa/cocoamain "subdir" to build libqtcocoamain.a (together with
cocoa/cocoaplugin -- plugins/platforms/cocoa is made a subdirs project).
This library is linked against all GUI Qt apps and provides the actual
main() function. It also catches the launching NSApplication notifications,
and calls the user's qMain() function. Note that this will happen in the
same cases when the user's application will run with the Cocoa QPA plugin.
Launch related code in QCocoaApplicationDelegate is moved to libqtcocoamain,
QNSApplication is removed (but sendEvent: redirection still there), and
code in QCocoaEventDispatcher dealing with calling [NSApp run] and related
has been removed since it's become unreachable.
ChangeLog: [Qt for Mac] Make QGuiApplication::exec() run within NSApplicationMain()
Change-Id: I790e5138c29aac2e0215a9147d0148fece40ca22
Reviewed-by: Morten Johan Sørvig <morten.sorvig@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 77 |
1 files changed, 5 insertions, 72 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index 423d552627..7e0fb62dcf 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -101,7 +101,6 @@ static void cleanupCocoaApplicationDelegate() { self = [super init]; if (self) { - inLaunch = true; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateScreens:) @@ -241,55 +240,6 @@ static void cleanupCocoaApplicationDelegate() return NSTerminateCancel; } -- (void) applicationWillFinishLaunching:(NSNotification *)notification -{ - Q_UNUSED(notification); - - /* - From the Cocoa documentation: "A good place to install event handlers - is in the applicationWillFinishLaunching: method of the application - delegate. At that point, the Application Kit has installed its default - event handlers, so if you install a handler for one of the same events, - it will replace the Application Kit version." - */ - - /* - If Qt is used as a plugin, we let the 3rd party application handle - events like quit and open file events. Otherwise, if we install our own - handlers, we easily end up breaking functionality the 3rd party - application depends on. - */ - NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; - [eventManager setEventHandler:self - andSelector:@selector(appleEventQuit:withReplyEvent:) - forEventClass:kCoreEventClass - andEventID:kAEQuitApplication]; - [eventManager setEventHandler:self - andSelector:@selector(getUrl:withReplyEvent:) - forEventClass:kInternetEventClass - andEventID:kAEGetURL]; -} - -// called by QCocoaIntegration's destructor before resetting the application delegate to nil -- (void) removeAppleEventHandlers -{ - NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; - [eventManager removeEventHandlerForEventClass:kCoreEventClass andEventID:kAEQuitApplication]; - [eventManager removeEventHandlerForEventClass:kInternetEventClass andEventID:kAEGetURL]; -} - -- (void)applicationDidFinishLaunching:(NSNotification *)aNotification -{ - Q_UNUSED(aNotification); - inLaunch = false; - // qt_release_apple_event_handler(); - - - // Insert code here to initialize your application -} - - - - (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames { Q_UNUSED(filenames); @@ -297,14 +247,6 @@ static void cleanupCocoaApplicationDelegate() for (NSString *fileName in filenames) { QString qtFileName = QCFString::toQString(fileName); - if (inLaunch) { - // We need to be careful because Cocoa will be nice enough to take - // command line arguments and send them to us as events. Given the history - // of Qt Applications, this will result in behavior people don't want, as - // they might be doing the opening themselves with the command line parsing. - if (qApp->arguments().contains(qtFileName)) - continue; - } QWindowSystemInterface::handleFileOpenEvent(qtFileName); } @@ -367,6 +309,11 @@ static void cleanupCocoaApplicationDelegate() */ } +- (NSObject<NSApplicationDelegate> *)reflectionDelegate +{ + return reflectionDelegate; +} + - (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate { [oldDelegate retain]; @@ -400,20 +347,6 @@ static void cleanupCocoaApplicationDelegate() [self doesNotRecognizeSelector:invocationSelector]; } -- (void)getUrl:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent -{ - Q_UNUSED(replyEvent); - NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue]; - QWindowSystemInterface::handleFileOpenEvent(QCFString::toQString(urlString)); -} - -- (void)appleEventQuit:(NSAppleEventDescriptor *)event withReplyEvent:(NSAppleEventDescriptor *)replyEvent -{ - Q_UNUSED(event); - Q_UNUSED(replyEvent); - [NSApp terminate:self]; -} - - (void)qtDispatcherToQAction:(id)sender { Q_UNUSED(sender); |