diff options
Diffstat (limited to 'darwintest/delegate.go')
| -rw-r--r-- | darwintest/delegate.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/darwintest/delegate.go b/darwintest/delegate.go new file mode 100644 index 0000000..d0cd3e7 --- /dev/null +++ b/darwintest/delegate.go @@ -0,0 +1,43 @@ +// 28 february 2014 +package main + +import ( + "fmt" +) + +// #cgo LDFLAGS: -lobjc -framework Foundation -framework AppKit +// #include "objc_darwin.h" +// extern void windowShouldClose(id, SEL, id); +// extern void buttonClicked(id, SEL, id); +// extern void gotNotification(id, SEL, id); +import "C" + +// TODO move these around later +var ( + _stop = sel_getUid("stop:") +) + +//export windowShouldClose +func windowShouldClose(self C.id, sel C.SEL, sender C.id) { + fmt.Println("-[hello windowShouldClose:]") + C.objc_msgSend_id(NSApp, _stop, sender) +} + +//export buttonClicked +func buttonClicked(self C.id, sel C.SEL, sender C.id) { + fmt.Println("button clicked; sending notification...") + notify("button") +} + +//export gotNotification +func gotNotification(self C.id, sel C.SEL, object C.id) { + fmt.Printf("got notification from %s\n", fromNSString(object)) +} + +func mk(name string, selW C.SEL, selB C.SEL, selN C.SEL) C.id { + class := newClass(name) + addDelegateMethod(class, selW, C.windowShouldClose) + addDelegateMethod(class, selB, C.buttonClicked) + addDelegateMethod(class, selN, C.gotNotification) + return objc_getClass(name) +} |
