summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-09-02 09:30:26 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-02 13:07:35 +0200
commit8fc97fdfc76fc62e1faa23f8b768d1ec303329d4 (patch)
tree3991bf746691a6c33615718dd05f6e23b9795ec6 /src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
parent585758389c64e556ef4808308dee27e19241581e (diff)
Revert Mac event loop changes.
"Make QGuiApplication::exec() run within NSApplicationMain()" "Make Qt process native and timer events on Cocoa applications" "Cocoa: Fix QFontDialog, QColorDialog auto-tests" This reverts commits 1e14762b8d79118540bd09a84dd3e48f4f5e113e e4b2a0b4bab2a17a65fedafe9bae50af1fe019f6 df7944e7d7dd8b2bbccbd639eff0ab09745d6cc3 Change-Id: I80b65b5ee0297b090f807bd420664233dfc44f7b Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm')
-rw-r--r--src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm77
1 files changed, 72 insertions, 5 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
index 7e0fb62dcf..423d552627 100644
--- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
+++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm
@@ -101,6 +101,7 @@ static void cleanupCocoaApplicationDelegate()
{
self = [super init];
if (self) {
+ inLaunch = true;
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(updateScreens:)
@@ -240,6 +241,55 @@ 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);
@@ -247,6 +297,14 @@ 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);
}
@@ -309,11 +367,6 @@ static void cleanupCocoaApplicationDelegate()
*/
}
-- (NSObject<NSApplicationDelegate> *)reflectionDelegate
-{
- return reflectionDelegate;
-}
-
- (void)setReflectionDelegate:(NSObject <NSApplicationDelegate> *)oldDelegate
{
[oldDelegate retain];
@@ -347,6 +400,20 @@ 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);