-
Notifications
You must be signed in to change notification settings - Fork 45
/
edit.go
64 lines (50 loc) · 1.23 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
package gform
import (
"github.com/AllenDang/w32"
)
type Edit struct {
W32Control
onChange EventManager
}
func NewEdit(parent Controller) *Edit {
edt := new(Edit)
edt.init(parent)
edt.SetFont(DefaultFont)
edt.SetSize(200, 20)
return edt
}
func AttachEdit(parent Controller, id int) *Edit {
edt := new(Edit)
edt.attach(parent, id)
RegMsgHandler(edt)
return edt
}
func (this *Edit) init(parent Controller) {
this.W32Control.init("EDIT", parent, w32.WS_EX_CLIENTEDGE, w32.WS_CHILD|w32.WS_VISIBLE|w32.WS_TABSTOP|w32.ES_LEFT|w32.ES_MULTILINE)
RegMsgHandler(this)
}
//Events
func (this *Edit) OnChange() *EventManager {
return &this.onChange
}
//Public methods
func (this *Edit) SetReadOnly(isReadOnly bool) {
w32.SendMessage(this.hwnd, w32.EM_SETREADONLY, uintptr(w32.BoolToBOOL(isReadOnly)), 0)
}
func (this *Edit) AddLine(text string) {
if len(this.Caption()) == 0 {
this.SetCaption(text)
} else {
this.SetCaption(this.Caption() + "\r\n" + text)
}
}
func (this *Edit) WndProc(msg uint, wparam, lparam uintptr) uintptr {
switch msg {
case w32.WM_COMMAND:
switch w32.HIWORD(uint32(wparam)) {
case w32.EN_CHANGE:
this.onChange.Fire(NewEventArg(this, nil))
}
}
return this.W32Control.WndProc(msg, wparam, lparam)
}