author | sl |
Mon, 19 May 2014 21:11:52 +0200 | |
changeset 1 | 5c2c48109457 |
permissions | -rw-r--r-- |
sl@0 | 1 |
/******************************* |
sl@0 | 2 |
Mac support for HID Test GUI |
sl@0 | 3 |
|
sl@0 | 4 |
Alan Ott |
sl@0 | 5 |
Signal 11 Software |
sl@0 | 6 |
*******************************/ |
sl@0 | 7 |
|
sl@0 | 8 |
#include <fx.h> |
sl@0 | 9 |
#import <Cocoa/Cocoa.h> |
sl@0 | 10 |
|
sl@0 | 11 |
extern FXMainWindow *g_main_window; |
sl@0 | 12 |
|
sl@0 | 13 |
|
sl@0 | 14 |
@interface MyAppDelegate : NSObject |
sl@0 | 15 |
{ |
sl@0 | 16 |
} |
sl@0 | 17 |
@end |
sl@0 | 18 |
|
sl@0 | 19 |
@implementation MyAppDelegate |
sl@0 | 20 |
- (void) applicationWillBecomeActive:(NSNotification*)notif |
sl@0 | 21 |
{ |
sl@0 | 22 |
printf("WillBecomeActive\n"); |
sl@0 | 23 |
g_main_window->show(); |
sl@0 | 24 |
|
sl@0 | 25 |
} |
sl@0 | 26 |
|
sl@0 | 27 |
- (void) applicationWillTerminate:(NSNotification*)notif |
sl@0 | 28 |
{ |
sl@0 | 29 |
/* Doesn't get called. Not sure why */ |
sl@0 | 30 |
printf("WillTerminate\n"); |
sl@0 | 31 |
FXApp::instance()->exit(); |
sl@0 | 32 |
} |
sl@0 | 33 |
|
sl@0 | 34 |
- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender |
sl@0 | 35 |
{ |
sl@0 | 36 |
/* Doesn't get called. Not sure why */ |
sl@0 | 37 |
printf("ShouldTerminate\n"); |
sl@0 | 38 |
return YES; |
sl@0 | 39 |
} |
sl@0 | 40 |
|
sl@0 | 41 |
- (void) applicationWillHide:(NSNotification*)notif |
sl@0 | 42 |
{ |
sl@0 | 43 |
printf("WillHide\n"); |
sl@0 | 44 |
g_main_window->hide(); |
sl@0 | 45 |
} |
sl@0 | 46 |
|
sl@0 | 47 |
- (void) handleQuitEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent |
sl@0 | 48 |
{ |
sl@0 | 49 |
printf("QuitEvent\n"); |
sl@0 | 50 |
FXApp::instance()->exit(); |
sl@0 | 51 |
} |
sl@0 | 52 |
|
sl@0 | 53 |
@end |
sl@0 | 54 |
|
sl@0 | 55 |
extern "C" { |
sl@0 | 56 |
|
sl@0 | 57 |
void |
sl@0 | 58 |
init_apple_message_system() |
sl@0 | 59 |
{ |
sl@0 | 60 |
static MyAppDelegate *d = [MyAppDelegate new]; |
sl@0 | 61 |
|
sl@0 | 62 |
[[NSApplication sharedApplication] setDelegate:d]; |
sl@0 | 63 |
|
sl@0 | 64 |
/* Register for Apple Events. */ |
sl@0 | 65 |
/* This is from |
sl@0 | 66 |
http://stackoverflow.com/questions/1768497/application-exit-event */ |
sl@0 | 67 |
NSAppleEventManager *aem = [NSAppleEventManager sharedAppleEventManager]; |
sl@0 | 68 |
[aem setEventHandler:d |
sl@0 | 69 |
andSelector:@selector(handleQuitEvent:withReplyEvent:) |
sl@0 | 70 |
forEventClass:kCoreEventClass andEventID:kAEQuitApplication]; |
sl@0 | 71 |
} |
sl@0 | 72 |
|
sl@0 | 73 |
void |
sl@0 | 74 |
check_apple_events() |
sl@0 | 75 |
{ |
sl@0 | 76 |
NSApplication *app = [NSApplication sharedApplication]; |
sl@0 | 77 |
|
sl@0 | 78 |
NSAutoreleasePool *pool = [NSAutoreleasePool new]; |
sl@0 | 79 |
while (1) { |
sl@0 | 80 |
NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask |
sl@0 | 81 |
untilDate:nil |
sl@0 | 82 |
inMode:NSDefaultRunLoopMode |
sl@0 | 83 |
dequeue:YES]; |
sl@0 | 84 |
if (event == NULL) |
sl@0 | 85 |
break; |
sl@0 | 86 |
else { |
sl@0 | 87 |
//printf("Event happened: Type: %d\n", event->_type); |
sl@0 | 88 |
[app sendEvent: event]; |
sl@0 | 89 |
} |
sl@0 | 90 |
} |
sl@0 | 91 |
[pool release]; |
sl@0 | 92 |
} |
sl@0 | 93 |
|
sl@0 | 94 |
} /* extern "C" */ |