-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.go
151 lines (130 loc) · 3.01 KB
/
form.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
139
140
141
142
143
144
145
146
147
148
149
150
151
package newt
/*
#cgo pkg-config: libnewt
#cgo LDFLAGS: -lnewt
#include <stdio.h>
#include <stdlib.h>
#include <newt.h>
*/
import "C"
import (
"unsafe"
)
func Form(vertBar *Component, helpTag string, flags int) Component {
var c Component
t := C.CString(helpTag)
defer C.free(unsafe.Pointer(t))
if vertBar != nil {
c.c = C.newtForm(vertBar.c, unsafe.Pointer(t), C.int(flags))
} else {
c.c = C.newtForm(nil, unsafe.Pointer(t), C.int(flags))
}
c.t = GRID_COMPONENT
c.ct = CMP_FORM
return c
}
func FormSetTimer(form Component, millisecs int) {
if form.ct == CMP_FORM {
C.newtFormSetTimer(form.c, C.int(millisecs))
}
}
func FormWatchFd(form Component, fd, fdFlags int) {
if form.ct == CMP_FORM {
C.newtFormWatchFd(form.c, C.int(fd), C.int(fdFlags))
}
}
func FormSetSize(c Component) {
if c.ct == CMP_FORM {
C.newtFormSetSize(c.c)
}
}
func FormGetCurrent(form Component) Component {
if form.ct == CMP_FORM {
var c Component
c.c = C.newtFormGetCurrent(form.c)
c.t = GRID_COMPONENT
// c.ct == ?????
return c
} else {
var c Component
return c
}
}
func FormSetBackground(c Component, color int) {
if c.ct == CMP_FORM {
C.newtFormSetBackground(c.c, C.int(color))
}
}
func FormSetCurrent(form, c Component) {
if form.ct == CMP_FORM {
C.newtFormSetCurrent(form.c, c.c)
}
}
func FormAddComponent(form, c Component) {
if form.ct == CMP_FORM {
C.newtFormAddComponent(form.c, c.c)
}
}
func FormAddComponents(form Component, args ...Component) {
if form.ct == CMP_FORM {
for _, v := range args {
FormAddComponent(form, v)
}
}
}
func FormSetHeight(c Component, height int) {
if c.ct == CMP_FORM {
C.newtFormSetHeight(c.c, C.int(height))
}
}
func FormSetWidth(c Component, width int) {
if c.ct == CMP_FORM {
C.newtFormSetWidth(c.c, C.int(width))
}
}
func RunForm(form Component) Component {
if form.ct == CMP_FORM {
var c Component
c.c = C.newtRunForm(form.c)
c.t = GRID_COMPONENT
// c.ct == ????
return c
} else {
var c Component
return c
}
}
func FormRun(form Component) ExitStruct {
var es ExitStruct
if form.ct == CMP_FORM {
C.newtFormRun(form.c, &es.es)
}
return es
}
func DrawForm(form Component) {
if form.ct == CMP_FORM {
C.newtDrawForm(form.c)
}
}
func FormAddHotKey(c Component, key int) {
if c.ct == CMP_FORM {
C.newtFormAddHotKey(c.c, C.int(key))
}
}
func FormGetScrollPosition(c Component) int {
if c.ct == CMP_FORM {
return int(C.newtFormGetScrollPosition(c.c))
} else {
return -1
}
}
func FormSetScrollPosition(c Component, position int) {
if c.ct == CMP_FORM {
C.newtFormSetScrollPosition(c.c, C.int(position))
}
}
func FormDestroy(c Component) {
if c.ct == CMP_FORM {
C.newtFormDestroy(c.c)
}
}