-
Notifications
You must be signed in to change notification settings - Fork 30
/
edit.go
111 lines (91 loc) · 2.51 KB
/
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
109
110
111
/*
* Copyright (C) 2019 The Winc Authors. All Rights Reserved.
* Copyright (C) 2010-2013 Allen Dang. All Rights Reserved.
*/
package winc
import "github.com/tadvi/winc/w32"
type Edit struct {
ControlBase
onChange EventManager
}
const passwordChar = '*'
const nopasswordChar = ' '
func NewEdit(parent Controller) *Edit {
edt := new(Edit)
edt.InitControl("EDIT", parent, w32.WS_EX_CLIENTEDGE, w32.WS_CHILD|w32.WS_VISIBLE|w32.WS_TABSTOP|w32.ES_LEFT|
w32.ES_AUTOHSCROLL)
RegMsgHandler(edt)
edt.SetFont(DefaultFont)
edt.SetSize(200, 22)
return edt
}
// Events.
func (ed *Edit) OnChange() *EventManager {
return &ed.onChange
}
// Public methods.
func (ed *Edit) SetReadOnly(isReadOnly bool) {
w32.SendMessage(ed.hwnd, w32.EM_SETREADONLY, uintptr(w32.BoolToBOOL(isReadOnly)), 0)
}
//Public methods
func (ed *Edit) SetPassword(isPassword bool) {
if isPassword {
w32.SendMessage(ed.hwnd, w32.EM_SETPASSWORDCHAR, uintptr(passwordChar), 0)
} else {
w32.SendMessage(ed.hwnd, w32.EM_SETPASSWORDCHAR, 0, 0)
}
}
func (ed *Edit) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_COMMAND:
switch w32.HIWORD(uint32(wparam)) {
case w32.EN_CHANGE:
ed.onChange.Fire(NewEvent(ed, nil))
}
/*case w32.WM_GETDLGCODE:
println("Edit")
if wparam == w32.VK_RETURN {
return w32.DLGC_WANTALLKEYS
}*/
}
return w32.DefWindowProc(ed.hwnd, msg, wparam, lparam)
}
// MultiEdit is multiline text edit.
type MultiEdit struct {
ControlBase
onChange EventManager
}
func NewMultiEdit(parent Controller) *MultiEdit {
med := new(MultiEdit)
med.InitControl("EDIT", parent, w32.WS_EX_CLIENTEDGE, w32.WS_CHILD|w32.WS_VISIBLE|w32.WS_TABSTOP|w32.ES_LEFT|
w32.WS_VSCROLL|w32.WS_HSCROLL|w32.ES_MULTILINE|w32.ES_WANTRETURN|w32.ES_AUTOHSCROLL|w32.ES_AUTOVSCROLL)
RegMsgHandler(med)
med.SetFont(DefaultFont)
med.SetSize(200, 400)
return med
}
// Events
func (med *MultiEdit) OnChange() *EventManager {
return &med.onChange
}
// Public methods
func (med *MultiEdit) SetReadOnly(isReadOnly bool) {
w32.SendMessage(med.hwnd, w32.EM_SETREADONLY, uintptr(w32.BoolToBOOL(isReadOnly)), 0)
}
func (med *MultiEdit) AddLine(text string) {
if len(med.Text()) == 0 {
med.SetText(text)
} else {
med.SetText(med.Text() + "\r\n" + text)
}
}
func (med *MultiEdit) WndProc(msg uint32, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_COMMAND:
switch w32.HIWORD(uint32(wparam)) {
case w32.EN_CHANGE:
med.onChange.Fire(NewEvent(med, nil))
}
}
return w32.DefWindowProc(med.hwnd, msg, wparam, lparam)
}