-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathedit_line.go
113 lines (94 loc) · 2.18 KB
/
edit_line.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
package wui
import "github.com/gonutz/w32/v2"
func NewEditLine() *EditLine {
return &EditLine{limit: 0x7FFFFFFE}
}
type EditLine struct {
textEditControl
isPassword bool
passwordChar uintptr
limit int
readOnly bool
onTextChange func()
}
var _ Control = (*EditLine)(nil)
func (e *EditLine) closing() {
e.Text()
}
func (*EditLine) canFocus() bool {
return true
}
func (e *EditLine) OnTabFocus() func() {
return e.onTabFocus
}
func (e *EditLine) SetOnTabFocus(f func()) {
e.onTabFocus = f
}
func (*EditLine) eatsTabs() bool {
return false
}
func (e *EditLine) create(id int) {
e.textEditControl.create(
id,
w32.WS_EX_CLIENTEDGE,
"EDIT",
w32.WS_TABSTOP|w32.ES_AUTOHSCROLL|w32.ES_PASSWORD,
)
e.passwordChar = w32.SendMessage(e.handle, w32.EM_GETPASSWORDCHAR, 0, 0)
e.SetIsPassword(e.isPassword)
e.SetCharacterLimit(e.limit)
e.SetReadOnly(e.readOnly)
}
func (e *EditLine) SetIsPassword(isPassword bool) {
e.isPassword = isPassword
if e.handle != 0 {
if e.isPassword {
w32.SendMessage(e.handle, w32.EM_SETPASSWORDCHAR, e.passwordChar, 0)
} else {
w32.SendMessage(e.handle, w32.EM_SETPASSWORDCHAR, 0, 0)
}
w32.InvalidateRect(e.parent.getHandle(), nil, true)
}
}
func (e *EditLine) IsPassword() bool {
return e.isPassword
}
func (e *EditLine) SetCharacterLimit(count int) {
if count <= 0 || count > 0x7FFFFFFE {
count = 0x7FFFFFFE
}
e.limit = count
if e.handle != 0 {
w32.SendMessage(e.handle, w32.EM_SETLIMITTEXT, uintptr(e.limit), 0)
}
}
func (e *EditLine) CharacterLimit() int {
if e.handle != 0 {
e.limit = int(w32.SendMessage(e.handle, w32.EM_GETLIMITTEXT, 0, 0))
}
return e.limit
}
func (e *EditLine) SetReadOnly(readOnly bool) {
e.readOnly = readOnly
if e.handle != 0 {
if readOnly {
w32.SendMessage(e.handle, w32.EM_SETREADONLY, 1, 0)
} else {
w32.SendMessage(e.handle, w32.EM_SETREADONLY, 0, 0)
}
}
}
func (e *EditLine) ReadOnly() bool {
return e.readOnly
}
func (e *EditLine) SetOnTextChange(f func()) {
e.onTextChange = f
}
func (e *EditLine) OnTextChange() func() {
return e.onTextChange
}
func (e *EditLine) handleNotification(cmd uintptr) {
if cmd == w32.EN_CHANGE && e.onTextChange != nil {
e.onTextChange()
}
}