-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkboxtree.go
139 lines (121 loc) · 3.66 KB
/
checkboxtree.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
package newt
/*
#cgo pkg-config: libnewt
#cgo LDFLAGS: -lnewt
#include <stdio.h>
#include <stdlib.h>
#include <newt.h>
int nNewtCheckboxTreeAddItem(newtComponent co, const char *text, const void *data, int flags, int index) {
return newtCheckboxTreeAddItem(co, text, data, flags, index);
}
*/
import "C"
import (
"unsafe"
)
func CheckboxTree(left, top, height, flags int) Component {
var c Component
c.c = C.newtCheckboxTree(C.int(left), C.int(top), C.int(height), C.int(flags))
c.t = GRID_COMPONENT
c.ct = CMP_CHECKBOXTREE
return c
}
func CheckboxTreeMulti(left, top, height int, seq string, flags int) Component {
var c Component
s := C.CString(seq)
defer C.free(unsafe.Pointer(s))
c.c = C.newtCheckboxTreeMulti(C.int(left), C.int(top), C.int(height), s, C.int(flags))
c.t = GRID_COMPONENT
c.ct = CMP_CHECKBOXTREE
return c
}
func CheckboxTreeGetSelection(c Component) (int, *uintptr) {
if c.ct == CMP_CHECKBOXTREE {
var numitems C.int
items := C.newtCheckboxTreeGetSelection(c.c, &numitems)
i := uintptr(*items)
return int(numitems), &i
} else {
return -1, nil
}
}
func CheckboxTreeGetCurrent(c Component) uintptr {
if c.ct == CMP_CHECKBOXTREE {
return uintptr(C.newtCheckboxTreeGetCurrent(c.c))
} else {
var i uintptr
return i
}
}
func CheckboxTreeSetCurrent(c Component, item uintptr) {
if c.ct == CMP_CHECKBOXTREE {
C.newtCheckboxTreeSetCurrent(c.c, unsafe.Pointer(item))
}
}
func CheckboxTreeGetMultiSelection(c Component, seqnum int) (int, *uintptr) {
if c.ct == CMP_CHECKBOXTREE {
var numitems C.int
items := C.newtCheckboxTreeGetMultiSelection(c.c, &numitems, C.char(seqnum))
i := uintptr(*items)
return int(numitems), &i
} else {
return -1, nil
}
}
func CheckboxTreeAddItem(c Component, text string, data uintptr, flags int, index int) int {
if c.ct == CMP_CHECKBOXTREE {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
return int(C.nNewtCheckboxTreeAddItem(c.c, t, unsafe.Pointer(data), C.int(flags), C.int(index)))
} else {
return -1
}
}
func CheckboxTreeAddArray(c Component, text string, data uintptr, flags int, indexes []int) int {
if c.ct == CMP_CHECKBOXTREE {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
var i []C.int
for a := range indexes {
i = append(i, C.int(a))
}
return int(C.newtCheckboxTreeAddArray(c.c, t, unsafe.Pointer(data), C.int(flags), &i[0]))
} else {
return -1
}
}
func CheckboxTreeFindItem(c Component, data uintptr) int {
if c.ct == CMP_CHECKBOXTREE {
r := C.newtCheckboxTreeFindItem(c.c, unsafe.Pointer(data))
return int(*r)
} else {
return -1
}
}
func CheckboxTreeSetEntry(c Component, data uintptr, text string) {
if c.ct == CMP_CHECKBOXTREE {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
C.newtCheckboxTreeSetEntry(c.c, unsafe.Pointer(data), t)
}
}
func CheckboxTreeSetWidth(c Component, width int) {
if c.ct == CMP_CHECKBOXTREE {
C.newtCheckboxTreeSetWidth(c.c, C.int(width))
}
}
func CheckboxTreeGetEntryValue(c Component) (int, uintptr) {
if c.ct == CMP_CHECKBOXTREE {
var p unsafe.Pointer
r := C.newtCheckboxTreeGetEntryValue(c.c, p)
return int(r), uintptr(p)
} else {
var i uintptr
return -1, i
}
}
func CheckboxTreeSetEntryValue(c Component, data uintptr, value int) {
if c.ct == CMP_CHECKBOXTREE {
C.newtCheckboxTreeSetEntryValue(c.c, unsafe.Pointer(data), C.char(value))
}
}