-
Notifications
You must be signed in to change notification settings - Fork 24
/
text_edit.go
108 lines (88 loc) · 1.92 KB
/
text_edit.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
//+build windows
package wui
import "github.com/gonutz/w32/v2"
func NewTextEdit() *TextEdit {
return &TextEdit{
autoHScroll: true,
limit: 0x7FFFFFFE,
}
}
type TextEdit struct {
textEditControl
limit int
autoHScroll bool
writesTabs bool
onTextChange func()
}
var _ Control = (*TextEdit)(nil)
func (e *TextEdit) closing() {
e.Text()
}
func (*TextEdit) canFocus() bool {
return true
}
func (e *TextEdit) OnTabFocus() func() {
return e.onTabFocus
}
func (e *TextEdit) SetOnTabFocus(f func()) {
e.onTabFocus = f
}
func (e *TextEdit) eatsTabs() bool {
return e.writesTabs
}
func (e *TextEdit) create(id int) {
var hScroll uint
if e.autoHScroll {
hScroll = w32.ES_AUTOHSCROLL | w32.WS_HSCROLL
}
e.textEditControl.create(
id, w32.WS_EX_CLIENTEDGE, "EDIT",
w32.WS_TABSTOP|w32.WS_VSCROLL|
w32.ES_LEFT|w32.ES_MULTILINE|w32.ES_AUTOVSCROLL|hScroll|
w32.ES_WANTRETURN,
)
if e.limit != 0 {
e.SetCharacterLimit(e.limit)
}
}
func (e *TextEdit) 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 *TextEdit) CharacterLimit() int {
if e.handle != 0 {
e.limit = int(w32.SendMessage(e.handle, w32.EM_GETLIMITTEXT, 0, 0))
}
return e.limit
}
func (e *TextEdit) SetWordWrap(wrap bool) {
if e.handle == 0 {
// the ES_AUTOHSCROLL style cannot be changed at runtime
e.autoHScroll = !wrap
}
}
func (e *TextEdit) WordWrap() bool {
return !e.autoHScroll
}
func (e *TextEdit) WritesTabs() bool {
return e.writesTabs
}
func (e *TextEdit) SetWritesTabs(tabs bool) {
e.writesTabs = tabs
}
func (e *TextEdit) SetOnTextChange(f func()) {
e.onTextChange = f
}
func (e *TextEdit) OnTextChange() func() {
return e.onTextChange
}
func (e *TextEdit) handleNotification(cmd uintptr) {
if cmd == w32.EN_CHANGE && e.onTextChange != nil {
e.onTextChange()
}
}