🛠️🐜 Antkeeper superbuild with dependencies included https://antkeeper.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

  1. #include "testnative.h"
  2. #ifdef TEST_NATIVE_COCOA
  3. #include <AvailabilityMacros.h>
  4. #include <Cocoa/Cocoa.h>
  5. #ifndef MAC_OS_X_VERSION_10_12
  6. static const unsigned int NSWindowStyleMaskTitled = NSTitledWindowMask;
  7. static const unsigned int NSWindowStyleMaskMiniaturizable = NSMiniaturizableWindowMask;
  8. static const unsigned int NSWindowStyleMaskClosable = NSClosableWindowMask;
  9. #endif
  10. static void *CreateWindowCocoa(int w, int h);
  11. static void DestroyWindowCocoa(void *window);
  12. NativeWindowFactory CocoaWindowFactory = {
  13. "cocoa",
  14. CreateWindowCocoa,
  15. DestroyWindowCocoa
  16. };
  17. static void *CreateWindowCocoa(int w, int h)
  18. {
  19. NSAutoreleasePool *pool;
  20. NSWindow *nswindow;
  21. NSRect rect;
  22. unsigned int style;
  23. pool = [[NSAutoreleasePool alloc] init];
  24. rect.origin.x = 0;
  25. rect.origin.y = 0;
  26. rect.size.width = w;
  27. rect.size.height = h;
  28. rect.origin.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - rect.origin.y - rect.size.height;
  29. style = (NSWindowStyleMaskTitled|NSWindowStyleMaskClosable|NSWindowStyleMaskMiniaturizable);
  30. nswindow = [[NSWindow alloc] initWithContentRect:rect styleMask:style backing:NSBackingStoreBuffered defer:FALSE];
  31. [nswindow makeKeyAndOrderFront:nil];
  32. [pool release];
  33. return nswindow;
  34. }
  35. static void DestroyWindowCocoa(void *window)
  36. {
  37. NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
  38. NSWindow *nswindow = (NSWindow *)window;
  39. [nswindow close];
  40. [pool release];
  41. }
  42. #endif