/src/support/darwin_support.m

http://github.com/PerlGameDev/SDL · Objective C · 60 lines · 34 code · 16 blank · 10 comment · 0 complexity · bb08ef88bf6d2a3ae31b6989a35c0b1b MD5 · raw file

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