summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNorwegian Rock Cat <qt-info@nokia.com>2009-05-04 11:54:47 (GMT)
committerNorwegian Rock Cat <qt-info@nokia.com>2009-05-04 12:02:04 (GMT)
commitea91eb38d81e37bd12d6abc2604f025ac1d254ce (patch)
tree4254cffab872294a7e00338c5a61c70bc26cff6b
parent237b4b8c8e9b5184578b4776c5f1f554c0d8efb5 (diff)
downloadQt-ea91eb38d81e37bd12d6abc2604f025ac1d254ce.zip
Qt-ea91eb38d81e37bd12d6abc2604f025ac1d254ce.tar.gz
Qt-ea91eb38d81e37bd12d6abc2604f025ac1d254ce.tar.bz2
Ensure that we send the Apple Events even when Cocoa isn't ready.
In general, Cocoa handles the the Apple Events for us. However, this is time between creating the NSApplication and Cocoa has set everything up, usually after the event loop is running. This means that until that time, the events are dropped on the floor :-/. The workaround is to use the same handler that we use for Carbon, but to only have it enabled for until Cocoa is ready to handle things. This will result in not stepping on the toes when used in a plugin (if it does, we can conditionalize it). Task-number: 252795 Reviewed-by: Richard Moe Gustavsen
-rw-r--r--src/gui/kernel/qapplication_mac.mm32
-rw-r--r--src/gui/kernel/qcocoaapplicationdelegate_mac.mm2
2 files changed, 23 insertions, 11 deletions
diff --git a/src/gui/kernel/qapplication_mac.mm b/src/gui/kernel/qapplication_mac.mm
index 5f8c572..69302ec 100644
--- a/src/gui/kernel/qapplication_mac.mm
+++ b/src/gui/kernel/qapplication_mac.mm
@@ -194,8 +194,8 @@ static bool appNoGrab = false; // mouse/keyboard grabbing
#ifndef QT_MAC_USE_COCOA
static EventHandlerRef app_proc_handler = 0;
static EventHandlerUPP app_proc_handlerUPP = 0;
-static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL;
#endif
+static AEEventHandlerUPP app_proc_ae_handlerUPP = NULL;
static EventHandlerRef tablet_proximity_handler = 0;
static EventHandlerUPP tablet_proximity_UPP = 0;
bool QApplicationPrivate::native_modal_dialog_active;
@@ -951,7 +951,6 @@ void qt_mac_event_release(QWidget *w)
}
}
-#ifndef QT_MAC_USE_COCOA
struct QMacAppleEventTypeSpec {
AEEventClass mac_class;
AEEventID mac_id;
@@ -959,6 +958,7 @@ struct QMacAppleEventTypeSpec {
{ kCoreEventClass, kAEQuitApplication },
{ kCoreEventClass, kAEOpenDocuments }
};
+#ifndef QT_MAC_USE_COCOA
/* watched events */
static EventTypeSpec app_events[] = {
{ kEventClassQt, kEventQtRequestWindowChange },
@@ -1156,13 +1156,13 @@ void qt_init(QApplicationPrivate *priv, int)
qt_init_app_proc_handler();
}
+#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), true);
}
-#endif
if (QApplicationPrivate::app_style) {
QEvent ev(QEvent::Style);
@@ -1210,6 +1210,17 @@ void qt_init(QApplicationPrivate *priv, int)
}
+void qt_release_apple_event_handler()
+{
+ if(app_proc_ae_handlerUPP) {
+ for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i)
+ AERemoveEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id,
+ app_proc_ae_handlerUPP, true);
+ DisposeAEEventHandlerUPP(app_proc_ae_handlerUPP);
+ app_proc_ae_handlerUPP = 0;
+ }
+}
+
/*****************************************************************************
qt_cleanup() - cleans up when the application is finished
*****************************************************************************/
@@ -1223,15 +1234,8 @@ void qt_cleanup()
DisposeEventHandlerUPP(app_proc_handlerUPP);
app_proc_handlerUPP = 0;
}
- if(app_proc_ae_handlerUPP) {
- for(uint i = 0; i < sizeof(app_apple_events) / sizeof(QMacAppleEventTypeSpec); ++i)
- AERemoveEventHandler(app_apple_events[i].mac_class, app_apple_events[i].mac_id,
- app_proc_ae_handlerUPP, true);
- DisposeAEEventHandlerUPP(app_proc_ae_handlerUPP);
- app_proc_ae_handlerUPP = NULL;
- }
#endif
-
+ qt_release_apple_event_handler();
qt_release_tablet_proximity_handler();
if (tablet_proximity_UPP)
DisposeEventHandlerUPP(tablet_proximity_UPP);
@@ -2367,6 +2371,12 @@ QApplicationPrivate::globalEventProcessor(EventHandlerCallRef er, EventRef event
#endif
}
+// In Carbon this is your one stop for apple events.
+// In Cocoa, it ISN'T. This is the catch-all Apple Event handler that exists
+// for the time between instantiating the NSApplication, but before the
+// NSApplication has installed it's OWN Apple Event handler. When Cocoa has
+// that set up, we remove this. So, if you are debugging problems, you likely
+// want to check out QCocoaApplicationDelegate instead.
OSStatus QApplicationPrivate::globalAppleEventProcessor(const AppleEvent *ae, AppleEvent *, long handlerRefcon)
{
QApplication *app = (QApplication *)handlerRefcon;
diff --git a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm
index 6571068..dad15d9 100644
--- a/src/gui/kernel/qcocoaapplicationdelegate_mac.mm
+++ b/src/gui/kernel/qcocoaapplicationdelegate_mac.mm
@@ -204,6 +204,8 @@ static void cleanupCocoaApplicationDelegate()
{
Q_UNUSED(aNotification);
inLaunch = false;
+ extern void qt_release_apple_event_handler(); //qapplication_mac.mm
+ qt_release_apple_event_handler();
}
- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames