diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-03-01 12:09:11 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2010-03-01 12:51:50 (GMT) |
commit | dd4079c6c465c80104ff0ea1cda681ed7cc18310 (patch) | |
tree | 0a44a50d1ec65b124e7c27a1c113e1b4e8a004fe /src/gui/kernel/qapplication_mac.mm | |
parent | c14e9bb7d8bb86129983df96dc5f8926190f5b06 (diff) | |
download | Qt-dd4079c6c465c80104ff0ea1cda681ed7cc18310.zip Qt-dd4079c6c465c80104ff0ea1cda681ed7cc18310.tar.gz Qt-dd4079c6c465c80104ff0ea1cda681ed7cc18310.tar.bz2 |
Mac: using Qt to write plugins disables quit for 3rd party application
The reason is that qt_init always installs/overwrites apple event
handlers. So if the 3rd party app had already installed an event
handler for kAEQuit, then it will be removed when the Qt plugin is
loaded. This patch checks (in the carbon case) if event handlers
already exists before installing new ones, or, in the cocoa case,
avoids installing apple event handlers if the AA_MacPluginApplication
is set. In other words, handling quit etc is seen as the responsibility
of the app, and not the plugin.
Task-number: QTBUG-8087
Reviewed-by: prasanth
Diffstat (limited to 'src/gui/kernel/qapplication_mac.mm')
-rw-r--r-- | src/gui/kernel/qapplication_mac.mm | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm index e511c3a..babfc72 100644 --- a/src/gui/kernel/qapplication_mac.mm +++ b/src/gui/kernel/qapplication_mac.mm @@ -1222,9 +1222,16 @@ void qt_init(QApplicationPrivate *priv, int) #endif if (!app_proc_ae_handlerUPP) { app_proc_ae_handlerUPP = AEEventHandlerUPP(QApplicationPrivate::globalAppleEventProcessor); - for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) - AEInstallEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, - app_proc_ae_handlerUPP, SRefCon(qApp), false); + for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i) { + // Install apple event handler, but avoid overwriting an already + // existing handler (it means a 3rd party application has installed one): + SRefCon refCon = 0; + AEEventHandlerUPP current_handler = NULL; + AEGetEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, ¤t_handler, &refCon, false); + if (!current_handler) + AEInstallEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id, + app_proc_ae_handlerUPP, SRefCon(qApp), false); + } } if (QApplicationPrivate::app_style) { @@ -2495,6 +2502,13 @@ void QApplicationPrivate::setupAppleEvents() // finished initialization, which appears to be just after [NSApplication run] has // started to execute. By setting up our apple events handlers this late, we override // the ones set up by NSApplication. + + // 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 functionallity the 3rd party application depend on: + if (QApplication::testAttribute(Qt::AA_MacPluginApplication)) + return; + QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) *newDelegate = [QT_MANGLE_NAMESPACE(QCocoaApplicationDelegate) sharedDelegate]; NSAppleEventManager *eventManager = [NSAppleEventManager sharedAppleEventManager]; [eventManager setEventHandler:newDelegate andSelector:@selector(appleEventQuit:withReplyEvent:) |