summaryrefslogtreecommitdiff
path: root/redo/textfield_windows.go
blob: 8410432b653aebaf957b2fdca6d5a3b566785249 (plain)
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
// 15 july 2014

package ui

// #include "winapi_windows.h"
import "C"

type textField struct {
	_hwnd	C.HWND
	_textlen	C.LONG
}

var editclass = toUTF16("EDIT")

func startNewTextField(style C.DWORD) *textField {
	hwnd := C.newControl(editclass,
		style | C.ES_AUTOHSCROLL | C.ES_LEFT | C.ES_NOHIDESEL | C.WS_TABSTOP,
		C.WS_EX_CLIENTEDGE)		// WS_EX_CLIENTEDGE without WS_BORDER will show the canonical visual styles border (thanks to MindChild in irc.efnet.net/#winprog)
	t := &textField{
		_hwnd:	hwnd,
	}
	C.controlSetControlFont(t._hwnd)
	return t
}

func newTextField() *textField {
	return startNewTextField(0)
}

func newPasswordField() *textField {
	return startNewTextField(C.ES_PASSWORD)
}

func (t *textField) Text() string {
	return baseText(t)
}

func (t *textField) SetText(text string) {
	baseSetText(t, text)
}

func (t *textField) hwnd() C.HWND {
	return t._hwnd
}

func (t *textField) textlen() C.LONG {
	return t._textlen
}

func (t *textField) settextlen(len C.LONG) {
	t._textlen = len
}

func (t *textField) setParent(p *controlParent) {
	basesetParent(t, p)
}

func (t *textField) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
	return baseallocate(t, x, y, width, height, d)
}

const (
	// from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
	textfieldWidth = 107		// this is actually the shorter progress bar width, but Microsoft only indicates as wide as necessary
	textfieldHeight = 14
)

func (t *textField) preferredSize(d *sizing) (width, height int) {
	return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d)
}

func (t *textField) commitResize(a *allocation, d *sizing) {
	basecommitResize(t, a, d)
}

func (t *textField) getAuxResizeInfo(d *sizing) {
	basegetAuxResizeInfo(t, d)
}