From f1ff15d2f7822fb45ba170e5954b5d5c22843bf1 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Tue, 27 Apr 2010 18:44:19 +0000 Subject: [PATCH] Fix crash when using the services menu on mac. --- src/mac_startup.mm | 45 +++++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/src/mac_startup.mm b/src/mac_startup.mm index 717d83cff..fb890f697 100644 --- a/src/mac_startup.mm +++ b/src/mac_startup.mm @@ -1,6 +1,8 @@ #import #import +#import + #import #import #import @@ -14,12 +16,11 @@ #include #include #include -#import // Capture global media keys on Mac (Cocoa only!) // See: http://www.rogueamoeba.com/utm/2007/09/29/apple-keyboard-media-key-event-handling/ -@interface MacApplication :NSApplication { // { //, SUUpdaterDelegateInformalProtocol> { +@interface MacApplication :NSApplication { GlobalShortcuts* shortcut_handler_; QObject* application_handler_; } @@ -31,18 +32,45 @@ - (void) SetApplicationHandler: (QObject*)handler; - (void) mediaKeyEvent: (int)key state: (BOOL)state repeat: (BOOL)repeat; +@end +@interface AppDelegate :NSObject { + QObject* application_handler_; +} + +- (id) initWithHandler: (QObject*)handler; // NSApplicationDelegate - (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag; @end +@implementation AppDelegate + +- (id) init { + if ((self = [super init])) { + application_handler_ = nil; + } + return self; +} + +- (id) initWithHandler: (QObject*)handler { + application_handler_ = handler; + return self; +} + +- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag { + if (application_handler_) { + qApp->postEvent(application_handler_, new QEvent(QEvent::ApplicationActivate)); + } + return YES; +} +@end + @implementation MacApplication - (id) init { if ((self = [super init])) { [self SetShortcutHandler:nil]; [self SetApplicationHandler:nil]; - [self setDelegate:self]; } return self; } @@ -60,17 +88,10 @@ } - (void) SetApplicationHandler: (QObject*)handler { - application_handler_ = handler; + AppDelegate* delegate = [[AppDelegate alloc] initWithHandler:handler]; + [self setDelegate:delegate]; } -- (BOOL) applicationShouldHandleReopen: (NSApplication*)app hasVisibleWindows:(BOOL)flag { - if (application_handler_) { - qApp->postEvent(application_handler_, new QEvent(QEvent::ApplicationActivate)); - } - return YES; -} - - -(void) sendEvent: (NSEvent*)event { if ([event type] == NSSystemDefined && [event subtype] == 8) { int keycode = (([event data1] & 0xFFFF0000) >> 16);