-
Notifications
You must be signed in to change notification settings - Fork 0
/
textedit.go
93 lines (70 loc) · 2.05 KB
/
textedit.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
// Copyright 2010 The Walk Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package walk
import "unsafe"
import . "github.com/lxn/go-winapi"
var textEditOrigWndProcPtr uintptr
var _ subclassedWidget = &TextEdit{}
type TextEdit struct {
WidgetBase
}
func NewTextEdit(parent Container) (*TextEdit, error) {
te := &TextEdit{}
if err := initChildWidget(
te,
parent,
"EDIT",
WS_TABSTOP|WS_VISIBLE|WS_VSCROLL|ES_MULTILINE|ES_WANTRETURN,
WS_EX_CLIENTEDGE); err != nil {
return nil, err
}
return te, nil
}
func (*TextEdit) origWndProcPtr() uintptr {
return textEditOrigWndProcPtr
}
func (*TextEdit) setOrigWndProcPtr(ptr uintptr) {
textEditOrigWndProcPtr = ptr
}
func (*TextEdit) LayoutFlags() LayoutFlags {
return ShrinkableHorz | ShrinkableVert | GrowableHorz | GrowableVert | GreedyHorz | GreedyVert
}
func (te *TextEdit) MinSizeHint() Size {
return te.dialogBaseUnitsToPixels(Size{20, 12})
}
func (te *TextEdit) SizeHint() Size {
return Size{100, 100}
}
func (te *TextEdit) Text() string {
return widgetText(te.hWnd)
}
func (te *TextEdit) SetText(value string) error {
return setWidgetText(te.hWnd, value)
}
func (te *TextEdit) TextSelection() (start, end int) {
SendMessage(te.hWnd, EM_GETSEL, uintptr(unsafe.Pointer(&start)), uintptr(unsafe.Pointer(&end)))
return
}
func (te *TextEdit) SetTextSelection(start, end int) {
SendMessage(te.hWnd, EM_SETSEL, uintptr(start), uintptr(end))
}
func (te *TextEdit) ReadOnly() bool {
return te.hasStyleBits(ES_READONLY)
}
func (te *TextEdit) SetReadOnly(readOnly bool) error {
if 0 == SendMessage(te.hWnd, EM_SETREADONLY, uintptr(BoolToBOOL(readOnly)), 0) {
return newError("SendMessage(EM_SETREADONLY)")
}
return nil
}
func (te *TextEdit) wndProc(hwnd HWND, msg uint32, wParam, lParam uintptr) uintptr {
switch msg {
case WM_GETDLGCODE:
if wParam == VK_RETURN {
return DLGC_WANTALLKEYS
}
return DLGC_HASSETSEL | DLGC_WANTARROWS | DLGC_WANTCHARS
}
return te.WidgetBase.wndProc(hwnd, msg, wParam, lParam)
}