summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qt_cocoa_helpers_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/qt_cocoa_helpers_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/qt_cocoa_helpers_mac.mm')
-rw-r--r--src/gui/kernel/qt_cocoa_helpers_mac.mm45
1 files changed, 21 insertions, 24 deletions
diff --git a/src/gui/kernel/qt_cocoa_helpers_mac.mm b/src/gui/kernel/qt_cocoa_helpers_mac.mm
index 74514a0..8c23902 100644
--- a/src/gui/kernel/qt_cocoa_helpers_mac.mm
+++ b/src/gui/kernel/qt_cocoa_helpers_mac.mm
@@ -83,6 +83,7 @@
#include <private/qt_cocoa_helpers_mac_p.h>
#include <private/qt_mac_p.h>
#include <private/qapplication_p.h>
+#include <private/qcocoaapplication_mac_p.h>
#include <private/qcocoawindow_mac_p.h>
#include <private/qcocoaview_mac_p.h>
#include <private/qkeymapper_p.h>
@@ -1279,46 +1280,42 @@ void qt_cocoaChangeOverrideCursor(const QCursor &cursor)
QMacCocoaAutoReleasePool pool;
[static_cast<NSCursor *>(qt_mac_nsCursorForQCursor(cursor)) set];
}
-#endif
+// WARNING: If Qt did not create NSApplication (e.g. in case it is
+// used as a plugin), and at the same time, there is no window on
+// screen (or the window that the event is sendt to becomes hidden etc
+// before the event gets delivered), the message will not be performed.
bool qt_cocoaPostMessage(id target, SEL selector)
{
if (!target)
return false;
- NSWindow *nswin = [NSApp mainWindow];
- if (!nswin) {
- nswin = [NSApp keyWindow];
- if (!nswin)
- return false;
+
+ NSInteger windowNumber = 0;
+ if (![NSApp isMemberOfClass:[QNSApplication class]]) {
+ // INVARIANT: Cocoa is not using our NSApplication subclass. That means
+ // we don't control the main event handler either. So target the event
+ // for one of the windows on screen:
+ NSWindow *nswin = [NSApp mainWindow];
+ if (!nswin) {
+ nswin = [NSApp keyWindow];
+ if (!nswin)
+ return false;
+ }
+ windowNumber = [nswin windowNumber];
}
// 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:
- QCocoaPostCallArgs *args = new QCocoaPostCallArgs(target, selector);
+ QCocoaPostMessageArgs *args = new QCocoaPostMessageArgs(target, selector);
quint32 lower = quintptr(args);
quint32 upper = quintptr(args) >> 32;
NSEvent *e = [NSEvent otherEventWithType:NSApplicationDefined
- location:NSZeroPoint modifierFlags:0 timestamp:0
- windowNumber:[nswin windowNumber]
+ location:NSZeroPoint modifierFlags:0 timestamp:0 windowNumber:windowNumber
context:nil subtype:QtCocoaEventSubTypePostMessage data1:lower data2:upper];
[NSApp postEvent:e atStart:NO];
return true;
}
-
-@implementation DebugNSApplication {
-}
-- (void)sendEvent:(NSEvent *)event
-{
- NSLog(@"NSAppDebug: sendEvent: %@", event);
- return [super sendEvent:event];
-}
-
-- (BOOL)sendAction:(SEL)anAction to:(id)aTarget from:(id)sender
-{
- NSLog(@"NSAppDebug: sendAction: %s to %@ from %@", anAction, aTarget, sender);
- return [super sendAction:anAction to:aTarget from:sender];
-}
-@end
+#endif
QMacCocoaAutoReleasePool::QMacCocoaAutoReleasePool()
{