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