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