-
Notifications
You must be signed in to change notification settings - Fork 0
/
winentry.go
55 lines (45 loc) · 1.07 KB
/
winentry.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
package newt
/*
#cgo pkg-config: libnewt
#cgo LDFLAGS: -lnewt
#include <newt.h>
#include <stdlib.h>
#include <string.h>
*/
import "C"
import "unsafe"
type WinEntry struct {
we C.struct_newtWinEntry
dv ResultStr
}
func NewWinEntry(text string, flags int) WinEntry {
var we WinEntry
t := C.CString(text)
defer C.free(unsafe.Pointer(t))
we.we.text = (*C.char)(C.calloc(C.size_t(len(text) + 2), 1))
C.strncpy(we.we.text, t, C.size_t(len(text)))
we.we.value = nil
we.we.flags = C.int(flags)
we.dv = NewResultStr()
return we
}
func NewWinEntryDef(text, defaultValue string, flags int) WinEntry {
we := NewWinEntry(text, flags)
we.dv.Set(defaultValue)
we.we.value = &we.dv.value
return we
}
func (we WinEntry) Text() string {
return C.GoString(we.we.text)
}
func (we WinEntry) Value() string {
return we.dv.String()
//return uintptr(unsafe.Pointer(we.we.value))
}
func (we WinEntry) Flags() int {
return int(we.we.flags)
}
func (we WinEntry) Destroy() {
we.dv.Destroy()
C.free(unsafe.Pointer(we.we.text))
}