2014-08-02 21:35:58 -05:00
|
|
|
// 15 july 2014
|
|
|
|
|
|
|
|
package ui
|
|
|
|
|
2014-08-20 11:04:36 -05:00
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2014-08-02 21:35:58 -05:00
|
|
|
// #include "winapi_windows.h"
|
|
|
|
import "C"
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
type textfield struct {
|
2014-08-03 20:52:21 -05:00
|
|
|
_hwnd C.HWND
|
|
|
|
_textlen C.LONG
|
2014-08-20 11:04:36 -05:00
|
|
|
changed *event
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
var editclass = toUTF16("EDIT")
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func startNewTextField(style C.DWORD) *textfield {
|
2014-08-03 20:52:21 -05:00
|
|
|
hwnd := C.newControl(editclass,
|
2014-08-22 12:57:32 -05:00
|
|
|
style | C.textfieldStyle,
|
|
|
|
C.textfieldExtStyle) // WS_EX_CLIENTEDGE without WS_BORDER will show the canonical visual styles border (thanks to MindChild in irc.efnet.net/#winprog)
|
2014-08-05 16:46:42 -05:00
|
|
|
t := &textfield{
|
2014-08-20 11:04:36 -05:00
|
|
|
_hwnd: hwnd,
|
|
|
|
changed: newEvent(),
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
2014-08-03 20:52:21 -05:00
|
|
|
C.controlSetControlFont(t._hwnd)
|
2014-08-20 11:04:36 -05:00
|
|
|
C.setTextFieldSubclass(t._hwnd, unsafe.Pointer(t))
|
2014-08-02 21:35:58 -05:00
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func newTextField() *textfield {
|
2014-08-02 21:35:58 -05:00
|
|
|
return startNewTextField(0)
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func newPasswordField() *textfield {
|
2014-08-02 21:35:58 -05:00
|
|
|
return startNewTextField(C.ES_PASSWORD)
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) Text() string {
|
2014-08-03 20:52:21 -05:00
|
|
|
return baseText(t)
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) SetText(text string) {
|
2014-08-03 20:52:21 -05:00
|
|
|
baseSetText(t, text)
|
|
|
|
}
|
|
|
|
|
2014-08-20 11:04:36 -05:00
|
|
|
func (t *textfield) OnChanged(f func()) {
|
|
|
|
t.changed.set(f)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *textfield) Invalid(reason string) {
|
2014-08-20 13:17:00 -05:00
|
|
|
if reason == "" {
|
|
|
|
C.textfieldHideInvalidBalloonTip(t._hwnd)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
C.textfieldSetAndShowInvalidBalloonTip(t._hwnd, toUTF16(reason))
|
2014-08-20 11:04:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//export textfieldChanged
|
|
|
|
func textfieldChanged(data unsafe.Pointer) {
|
|
|
|
t := (*textfield)(data)
|
|
|
|
println("changed")
|
|
|
|
t.changed.fire()
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) hwnd() C.HWND {
|
2014-08-03 20:52:21 -05:00
|
|
|
return t._hwnd
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) textlen() C.LONG {
|
2014-08-03 20:52:21 -05:00
|
|
|
return t._textlen
|
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) settextlen(len C.LONG) {
|
2014-08-03 20:52:21 -05:00
|
|
|
t._textlen = len
|
2014-08-02 21:35:58 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) setParent(p *controlParent) {
|
2014-08-03 20:52:21 -05:00
|
|
|
basesetParent(t, p)
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) allocate(x int, y int, width int, height int, d *sizing) []*allocation {
|
2014-08-03 08:18:35 -05:00
|
|
|
return baseallocate(t, x, y, width, height, d)
|
|
|
|
}
|
|
|
|
|
2014-08-02 21:35:58 -05:00
|
|
|
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
|
|
|
|
)
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) preferredSize(d *sizing) (width, height int) {
|
2014-08-02 21:35:58 -05:00
|
|
|
return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d)
|
|
|
|
}
|
2014-08-03 08:18:35 -05:00
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) commitResize(a *allocation, d *sizing) {
|
2014-08-03 20:52:21 -05:00
|
|
|
basecommitResize(t, a, d)
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|
|
|
|
|
2014-08-05 16:46:42 -05:00
|
|
|
func (t *textfield) getAuxResizeInfo(d *sizing) {
|
2014-08-03 19:42:45 -05:00
|
|
|
basegetAuxResizeInfo(t, d)
|
2014-08-03 08:18:35 -05:00
|
|
|
}
|