summaryrefslogtreecommitdiff
path: root/darwintest/delegate.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-02-28 21:30:32 -0500
committerPietro Gagliardi <[email protected]>2014-02-28 21:30:32 -0500
commit1c6d4e915177caa65c542619763d73ca704b52bb (patch)
tree452e9621493d9f159703ce072db4531b57e05dfa /darwintest/delegate.go
parent4e1b0b12724581d416325a2ca5ca7a91e2703cd3 (diff)
Split the actual delegate into a separate file; this simplifies even more things. I think we're as clean as we can go... should probably start writing the real backend now :D
Diffstat (limited to 'darwintest/delegate.go')
-rw-r--r--darwintest/delegate.go43
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)
+}