-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistbox.go
110 lines (89 loc) · 2.71 KB
/
listbox.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
package newt
/*
#cgo pkg-config: libnewt
#cgo LDFLAGS: -lnewt
#include <stdio.h>
#include <stdlib.h>
#include <newt.h>
*/
import "C"
import (
"unsafe"
"reflect"
)
func Listbox(left, top, height, flags int) Component {
var c Component
c.c = C.newtListbox(C.int(left), C.int(top), C.int(height), C.int(flags))
c.t = GRID_COMPONENT
return c
}
func ListboxGetCurrent(c Component) uintptr {
data := uintptr(C.newtListboxGetCurrent(c.c))
return data
}
func ListboxSetCurrent(c Component, num int) {
C.newtListboxSetCurrent(c.c, C.int(num))
}
func ListboxSetCurrentByKey(c Component, key uintptr) {
C.newtListboxSetCurrentByKey(c.c, unsafe.Pointer(key))
}
func ListboxSetEntry(c Component, num int, text string) {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
C.newtListboxSetEntry(c.c, C.int(num), t)
}
func ListboxSetWidth(c Component, width int) {
C.newtListboxSetWidth(c.c, C.int(width))
}
func ListboxSetData(c Component, num int, data uintptr) {
C.newtListboxSetData(c.c, C.int(num), unsafe.Pointer(data))
}
func ListboxAppendEntry(c Component, text string, data uintptr) int {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
return int(C.newtListboxAppendEntry(c.c, t, unsafe.Pointer(data)))
}
func ListboxAddEntry(c Component, text string, data uintptr) int {
return ListboxAppendEntry(c, text, data)
}
func ListboxInsertEntry(c Component, text string, data, key uintptr) int {
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
return int(C.newtListboxInsertEntry(c.c, t, unsafe.Pointer(data), unsafe.Pointer(key)))
}
func ListboxDeleteEntry(c Component, data uintptr) int {
return int(C.newtListboxDeleteEntry(c.c, unsafe.Pointer(data)))
}
func ListboxClear(c Component) {
C.newtListboxClear(c.c)
}
func ListboxGetEntry(c Component, num int) (string, uintptr) {
var text *C.char
var data unsafe.Pointer
C.newtListboxGetEntry(c.c, C.int(num), &text, &data)
return C.GoString(text), uintptr(data)
}
func ListboxGetSelection(c Component) (int, []uintptr) {
var numitems C.int
var i []uintptr
items := C.newtListboxGetSelection(c.c, &numitems)
if items != nil {
hdr := reflect.SliceHeader{
Data: uintptr(unsafe.Pointer(items)),
Len: int(numitems),
Cap: int(numitems),
}
i = *(*[]uintptr)(unsafe.Pointer(&hdr))
}
return int(numitems), i
}
func ListboxClearSelection(c Component) {
C.newtListboxClearSelection(c.c)
}
func ListboxSelectItem(c Component, key uintptr, sense uint32) {
C.newtListboxSelectItem(c.c, unsafe.Pointer(key), sense)
}
func ListboxItemCount(c Component) int {
n := C.newtListboxItemCount(c.c)
return int(n)
}