Importing SDLPerl 2.2
[sdlgit/SDL_perl.git] / src / support / darwin_support.m
1 #include <Foundation/Foundation.h>
2 #include <AppKit/AppKit.h>
3 #include <setjmp.h>
4
5 @interface perl_SDLMain : NSObject
6 @end
7
8 @interface SDLApplication : NSApplication
9 @end
10
11 static jmp_buf jmpbuf;
12
13 @implementation perl_SDLMain
14
15 - (void) applicationDidFinishLaunching: (NSNotification *) note
16 {
17         fprintf(stderr,"Finished launching\n");
18 //      longjmp(jmpbuf,1);
19 }
20
21 @end
22
23 extern void setApplicationMenu(void);
24 extern void setupWindowMenu(void);
25
26 static NSAutoreleasePool* pool = NULL;
27 static perl_SDLMain* perl_sdlMain = NULL;
28
29
30 void
31 init_ns_application()
32 {
33         // Allocate pool so Cocoa can refcount
34         pool = [[NSAutoreleasePool alloc] init];
35
36         // Create the application
37         [SDLApplication sharedApplication];
38
39         [NSApp setMainMenu: [[NSMenu alloc] init]];
40 //      setApplicationMenu();
41 //      setupWindowMenu();
42
43         perl_sdlMain = [[perl_SDLMain alloc] init];
44         [NSApp setDelegate: perl_sdlMain];
45
46 //      fprintf(stderr,"Calling [NSapp run]\n");
47 //      if (0 == setjmp(jmpbuf)) {
48                 [NSApp run];
49 //      } else {
50 //              fprintf(stderr, "Returned from that nasty [NSApp run]");
51 //      }
52 }
53
54 void
55 quit_ns_application()
56 {
57         [perl_sdlMain release];
58         [pool release];
59 }
60