summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qcocoaapplication_mac.mm
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-02-10 08:04:50 (GMT)
committerRichard Moe Gustavsen <richard.gustavsen@nokia.com>2010-02-10 09:15:03 (GMT)
commit5be0f78985f73515645762b2895b6969be69a6e4 (patch)
treef6823851470d4de322c71b1e1f09cf7c29ddd097 /src/gui/kernel/qcocoaapplication_mac.mm
parent8b112609b7d86572fbb41dc59354da1f958d1910 (diff)
downloadQt-5be0f78985f73515645762b2895b6969be69a6e4.zip
Qt-5be0f78985f73515645762b2895b6969be69a6e4.tar.gz
Qt-5be0f78985f73515645762b2895b6969be69a6e4.tar.bz2
Cocoa: Implement our own NSApplication subclass
We have avoided doing so up till now, since we cannot always know if we will be able to use it. If some 3rd-party application creates NSApplication before Qt, our subclass will never be used (because of the singleton pattern that NSApplication follows). However, in most cases, Qt will be used in standalone applications, or the 3rd-party application will not subclass NSApplication. And in those cases, we can make certain functionallity more robust. Rev-By:msorvig
Diffstat (limited to 'src/gui/kernel/qcocoaapplication_mac.mm')
-rw-r--r--src/gui/kernel/qcocoaapplication_mac.mm45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/gui/kernel/qcocoaapplication_mac.mm b/src/gui/kernel/qcocoaapplication_mac.mm
index 5b98420..5629940 100644
--- a/src/gui/kernel/qcocoaapplication_mac.mm
+++ b/src/gui/kernel/qcocoaapplication_mac.mm
@@ -107,5 +107,50 @@
| NSFontPanelStrikethroughEffectModeMask;
}
+
+- (void)qt_sendPostedMessage:(NSEvent *)event
+{
+ // WARNING: data1 and data2 is truncated to from 64-bit to 32-bit on OS 10.5!
+ // That is why we need to split the address in two parts:
+ quint64 lower = [event data1];
+ quint64 upper = [event data2];
+ QCocoaPostMessageArgs *args = reinterpret_cast<QCocoaPostMessageArgs *>(lower | (upper << 32));
+ [args->target performSelector:args->selector];
+ delete args;
+}
+
+- (BOOL)qt_sendEvent:(NSEvent *)event
+{
+ if ([event type] == NSApplicationDefined) {
+ switch ([event subtype]) {
+ case QtCocoaEventSubTypePostMessage:
+ [NSApp qt_sendPostedMessage:event];
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
@end
+
+@implementation QNSApplication
+
+// WARNING: If Qt did not create NSApplication (this can e.g.
+// happend if Qt is used as a plugin from a 3rd-party cocoa
+// application), QNSApplication::sendEvent will never be called.
+// SO DO NOT RELY ON THIS FUNCTION BEING AVAILABLE.
+// Plugin developers that _do_ control the NSApplication sub-class
+// implementation of the 3rd-party application can call qt_sendEvent
+// from the sub-class event handler (like we do here) to work around
+// any issues.
+- (void)sendEvent:(NSEvent *)event
+{
+ if (![self qt_sendEvent:event])
+ [super sendEvent:event];
+}
+
+@end
+
#endif