diff options
| author | Pietro Gagliardi <[email protected]> | 2014-02-27 21:53:44 -0500 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-02-27 21:53:44 -0500 |
| commit | 134afc60a64620d9f67b087c8f494b053d00efea (patch) | |
| tree | 5ece8c0969f18deeda4b477cd8f336c5519f897a | |
| parent | 3347d7fa4825d6eaab9d6af8e8cb7fa471922f18 (diff) | |
And we now have a window in the darwin test! You can't really do much with it since the Cocoa event loop isn't running, but it can be moved around!
| -rw-r--r-- | darwintest/runtimetest.go | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/darwintest/runtimetest.go b/darwintest/runtimetest.go index 04a10c1..be6357f 100644 --- a/darwintest/runtimetest.go +++ b/darwintest/runtimetest.go @@ -6,14 +6,21 @@ import ( "unsafe" ) -// #cgo LDFLAGS: -lobjc -framework Foundation +// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit // #include <stdlib.h> // #include <objc/message.h> // #include <objc/objc.h> // #include <objc/runtime.h> +// /* TODO <objc/NSObjCRuntime.h not found?!?! */ +// /* TODO this HAS to be unsafe */ +// typedef unsigned long NSUInteger; +// /* avoid depending on Objective-C */ +// #include <CoreGraphics/CGGeometry.h> // /* cgo doesn't handle ... */ // id objc_msgSend_noargs(id obj, SEL sel) { return objc_msgSend(obj, sel); } // id objc_msgSend_strarg(id obj, SEL sel, char *a) { return objc_msgSend(obj, sel, a); } +// id objc_msgSend_NSRect_uint_uint_bool(id obj, SEL sel, CGRect a, NSUInteger b, NSUInteger c, BOOL d) { return objc_msgSend(obj, sel, a, b, c, d); } +// id objc_msgSend_id(id obj, SEL sel, id a) { return objc_msgSend(obj, sel, a); } import "C" func objc_getClass(class string) C.id { @@ -30,7 +37,48 @@ func sel_getUid(sel string) C.SEL { return C.sel_getUid(csel) } +const ( + NSBorderlessWindowMask = 0 + NSTitledWindowMask = 1 << 0 + NSClosableWindowMask = 1 << 1 + NSMiniaturizableWindowMask = 1 << 2 + NSResizableWindowMask = 1 << 3 + NSTexturedBackgroundWindowMask = 1 << 8 +) + +const ( +// NSBackingStoreRetained = 0 // "You should not use this mode." +// NSBackingStoreNonretained = 1 // "You should not use this mode." + NSBackingStoreBuffered = 2 +) + +var alloc = sel_getUid("alloc") + func main() { + NSWindow := objc_getClass("NSWindow") + NSWindowinit := + sel_getUid("initWithContentRect:styleMask:backing:defer:") + makeKeyAndOrderFront := sel_getUid("makeKeyAndOrderFront:") + + // need an NSApplication first - see https://github.com/TooTallNate/NodObjC/issues/21 + NSApplication := objc_getClass("NSApplication") + sharedApplication := sel_getUid("sharedApplication") + C.objc_msgSend_noargs(NSApplication, sharedApplication) + + rect := C.CGRect{ + origin: C.CGPoint{100, 100}, + size: C.CGSize{320, 240}, + } + style := C.NSUInteger(NSTitledWindowMask | NSClosableWindowMask) + backing := C.NSUInteger(NSBackingStoreBuffered) + deferx := C.BOOL(C.YES) + window := C.objc_msgSend_noargs(NSWindow, alloc) + window = C.objc_msgSend_NSRect_uint_uint_bool(window, NSWindowinit, rect, style, backing, deferx) + C.objc_msgSend_id(window, makeKeyAndOrderFront, window) + select{} +} + +func helloworld() { _hello := C.CString("hello, world\n") defer C.free(unsafe.Pointer(_hello)) |
