-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathHelloWorld.go
60 lines (48 loc) · 1.74 KB
/
HelloWorld.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
/*
#cgo LDFLAGS: -framework AppKit
#include <objc/objc-runtime.h>
*/
import "C"
import (
. "gocoa"
"unsafe"
)
func main() {
hellow := ClassForName("NSObject").Subclass("ApplicationController")
hellow.AddMethod("applicationWillFinishLaunching:", BApplicationWillFinishLaunching)
hellow.AddMethod("buttonClick:", IButtonClick)
hellow.AddIvar("textBox1", ClassForName("NSTextField"))
hellow.Register()
app := ClassForName("NSApplication").Instance("sharedApplication")
bundle := ClassForName("NSBundle").Instance("alloc")
path := NSString(".")
dict := NSDictionary("NSOwner", app)
bundle = bundle.Call("initWithPath:", path)
bundle.Call("loadNibFile:externalNameTable:withZone:", NSString("HelloWorld"), dict, app.Call("zone"))
icon := ClassForName("NSImage").Instance("alloc")
icon = icon.Call("initByReferencingFile:", NSString("go.icns"))
app.Call("setApplicationIconImage:", icon)
app.Call("run")
}
//export BApplicationWillFinishLaunching
func BApplicationWillFinishLaunching(self C.id, op C.SEL, notification C.id) {
notify := (Object)(unsafe.Pointer(notification))
application := notify.Call("object")
windowsArray := application.Call("windows")
windowsCount := (NSUInteger)(windowsArray.Call("count"))
var ix NSUInteger
for ix = 0; ix < windowsCount; ix++ {
window := windowsArray.Call("objectAtIndex:", ix)
window.Call("setTitle:", NSString("Form Loaded"))
}
me := (Object)(unsafe.Pointer(self))
textBox1 := me.InstanceVariable("textBox1")
textBox1.Call("setStringValue:", NSString("Form Loaded"))
}
//export IButtonClick
func IButtonClick(self C.id, op C.SEL, sender C.id) {
me := (Object)(unsafe.Pointer(self))
textBox1 := me.InstanceVariable("textBox1")
textBox1.Call("setStringValue:", NSString("Button Pushed"))
}