sl@0: /******************************* sl@0: Mac support for HID Test GUI sl@0: sl@0: Alan Ott sl@0: Signal 11 Software sl@0: *******************************/ sl@0: sl@0: #include sl@0: #import sl@0: sl@0: extern FXMainWindow *g_main_window; sl@0: sl@0: sl@0: @interface MyAppDelegate : NSObject sl@0: { sl@0: } sl@0: @end sl@0: sl@0: @implementation MyAppDelegate sl@0: - (void) applicationWillBecomeActive:(NSNotification*)notif sl@0: { sl@0: printf("WillBecomeActive\n"); sl@0: g_main_window->show(); sl@0: sl@0: } sl@0: sl@0: - (void) applicationWillTerminate:(NSNotification*)notif sl@0: { sl@0: /* Doesn't get called. Not sure why */ sl@0: printf("WillTerminate\n"); sl@0: FXApp::instance()->exit(); sl@0: } sl@0: sl@0: - (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender sl@0: { sl@0: /* Doesn't get called. Not sure why */ sl@0: printf("ShouldTerminate\n"); sl@0: return YES; sl@0: } sl@0: sl@0: - (void) applicationWillHide:(NSNotification*)notif sl@0: { sl@0: printf("WillHide\n"); sl@0: g_main_window->hide(); sl@0: } sl@0: sl@0: - (void) handleQuitEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent sl@0: { sl@0: printf("QuitEvent\n"); sl@0: FXApp::instance()->exit(); sl@0: } sl@0: sl@0: @end sl@0: sl@0: extern "C" { sl@0: sl@0: void sl@0: init_apple_message_system() sl@0: { sl@0: static MyAppDelegate *d = [MyAppDelegate new]; sl@0: sl@0: [[NSApplication sharedApplication] setDelegate:d]; sl@0: sl@0: /* Register for Apple Events. */ sl@0: /* This is from sl@0: http://stackoverflow.com/questions/1768497/application-exit-event */ sl@0: NSAppleEventManager *aem = [NSAppleEventManager sharedAppleEventManager]; sl@0: [aem setEventHandler:d sl@0: andSelector:@selector(handleQuitEvent:withReplyEvent:) sl@0: forEventClass:kCoreEventClass andEventID:kAEQuitApplication]; sl@0: } sl@0: sl@0: void sl@0: check_apple_events() sl@0: { sl@0: NSApplication *app = [NSApplication sharedApplication]; sl@0: sl@0: NSAutoreleasePool *pool = [NSAutoreleasePool new]; sl@0: while (1) { sl@0: NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask sl@0: untilDate:nil sl@0: inMode:NSDefaultRunLoopMode sl@0: dequeue:YES]; sl@0: if (event == NULL) sl@0: break; sl@0: else { sl@0: //printf("Event happened: Type: %d\n", event->_type); sl@0: [app sendEvent: event]; sl@0: } sl@0: } sl@0: [pool release]; sl@0: } sl@0: sl@0: } /* extern "C" */