-
Notifications
You must be signed in to change notification settings - Fork 3
/
TableView.go
85 lines (63 loc) · 2.7 KB
/
TableView.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
/*
#cgo LDFLAGS: -framework AppKit
#include <objc/objc-runtime.h>
*/
import "C"
import (
"fmt"
. "gocoa"
"unsafe"
)
/*
* main()
* a simple application with a datagrid in a scrollview
*/
func main() {
appctrl := ClassForName("NSObject").Subclass("ApplicationController")
appctrl.AddMethod("applicationWillFinishLaunching:", BApplicationWillFinishLaunching)
appctrl.AddIvar("scrollTable1", ClassForName("NSScrollView"))
appctrl.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("TableView"), dict, app.Call("zone"))
app.Call("run")
}
//export BApplicationWillFinishLaunching
func BApplicationWillFinishLaunching(self C.id, op C.SEL, notification C.id) {
fmt.Println("applicationWillFinishLaunching:")
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))
scrollTable1 := me.InstanceVariable("scrollTable1")
fmt.Println("scrollTable1 class:", scrollTable1.Class().Name())
tableView := scrollTable1.Call("documentView")
// add some stuff to the TableView
// XXX, tableview discovering only the first column
arrayController := ClassForName("NSArrayController").Instance("alloc").Call("init")
dict := ClassForName("NSMutableDictionary").Instance("alloc").Call("init")
objects := ClassForName("NSMutableArray").Instance("alloc").Call("init")
objects.Call("addObject:", NSString("Joe"))
objects.Call("addObject:", NSString("(444) 444-4444"))
keys := ClassForName("NSMutableArray").Instance("alloc").Call("init")
keys.Call("addObject:", NSString("column1"))
keys.Call("addObject:", NSString("column2"))
dict.Call("addObjects:forKeys:", objects, keys)
arrayController.Call("addObject:", dict)
column1 := tableView.Call("tableColumnWithIdentifier:", NSString("column1"))
column1.Call("bind:toObject:withKeyPath:options:", NSString("value"), arrayController, NSString("arrangedObjects.column1"), (Object)(0))
column2 := tableView.Call("tableColumnWithIdentifier:", NSString("column2"))
column2.Call("bind:toObject:withKeyPath:options:", NSString("value"), arrayController, NSString("arrangedObjects.column2"), (Object)(0))
// headerView := tableView.Call("headerView")
// headerView.Class().ListMethods()
}