aboutsummaryrefslogtreecommitdiff
path: root/testgui/mac_support_cocoa.m
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:55:39 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2017-12-22 16:55:39 +0100
commitc41cb82ea7499c132546c1ab6f798deda6a9d7af (patch)
tree5ccc1ad6bd60620ae2ec3a7d341af8864e3b100d /testgui/mac_support_cocoa.m
downloadlibnitrokey-c41cb82ea7499c132546c1ab6f798deda6a9d7af.tar.gz
libnitrokey-c41cb82ea7499c132546c1ab6f798deda6a9d7af.tar.bz2
Squashed 'hidapi/' content from commit b767b43f
git-subtree-dir: hidapi git-subtree-split: b767b43f3e6f9c5b92ea7d738331deb8e03c4baf
Diffstat (limited to 'testgui/mac_support_cocoa.m')
-rw-r--r--testgui/mac_support_cocoa.m94
1 files changed, 94 insertions, 0 deletions
diff --git a/testgui/mac_support_cocoa.m b/testgui/mac_support_cocoa.m
new file mode 100644
index 0000000..75de7e9
--- /dev/null
+++ b/testgui/mac_support_cocoa.m
@@ -0,0 +1,94 @@
+/*******************************
+ Mac support for HID Test GUI
+
+ Alan Ott
+ Signal 11 Software
+*******************************/
+
+#include <fx.h>
+#import <Cocoa/Cocoa.h>
+
+extern FXMainWindow *g_main_window;
+
+
+@interface MyAppDelegate : NSObject
+{
+}
+@end
+
+@implementation MyAppDelegate
+- (void) applicationWillBecomeActive:(NSNotification*)notif
+{
+ printf("WillBecomeActive\n");
+ g_main_window->show();
+
+}
+
+- (void) applicationWillTerminate:(NSNotification*)notif
+{
+ /* Doesn't get called. Not sure why */
+ printf("WillTerminate\n");
+ FXApp::instance()->exit();
+}
+
+- (NSApplicationTerminateReply) applicationShouldTerminate:(NSApplication*)sender
+{
+ /* Doesn't get called. Not sure why */
+ printf("ShouldTerminate\n");
+ return YES;
+}
+
+- (void) applicationWillHide:(NSNotification*)notif
+{
+ printf("WillHide\n");
+ g_main_window->hide();
+}
+
+- (void) handleQuitEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
+{
+ printf("QuitEvent\n");
+ FXApp::instance()->exit();
+}
+
+@end
+
+extern "C" {
+
+void
+init_apple_message_system()
+{
+ static MyAppDelegate *d = [MyAppDelegate new];
+
+ [[NSApplication sharedApplication] setDelegate:d];
+
+ /* Register for Apple Events. */
+ /* This is from
+ http://stackoverflow.com/questions/1768497/application-exit-event */
+ NSAppleEventManager *aem = [NSAppleEventManager sharedAppleEventManager];
+ [aem setEventHandler:d
+ andSelector:@selector(handleQuitEvent:withReplyEvent:)
+ forEventClass:kCoreEventClass andEventID:kAEQuitApplication];
+}
+
+void
+check_apple_events()
+{
+ NSApplication *app = [NSApplication sharedApplication];
+
+ NSAutoreleasePool *pool = [NSAutoreleasePool new];
+ while (1) {
+ NSEvent* event = [NSApp nextEventMatchingMask:NSAnyEventMask
+ untilDate:nil
+ inMode:NSDefaultRunLoopMode
+ dequeue:YES];
+ if (event == NULL)
+ break;
+ else {
+ //printf("Event happened: Type: %d\n", event->_type);
+ [app sendEvent: event];
+ }
+ }
+ [pool release];
+}
+
+} /* extern "C" */