diff options
| author | Pietro Gagliardi <[email protected]> | 2014-10-14 15:29:59 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-10-14 15:29:59 -0400 |
| commit | abdbec2449d8d362e7a440bec5b85eb615541cf0 (patch) | |
| tree | a3000c06cc5a968fc79e81d178000a940edbcdd7 /newctrl/textfield_windows.go | |
| parent | eef3e1136b51112c23620b150ffcf03caddc0ff9 (diff) | |
Moved more of the basic controls over. Also an important change: all Labels are now Standalone. A separate Form layout container will be used for the purpose instead.
Diffstat (limited to 'newctrl/textfield_windows.go')
| -rw-r--r-- | newctrl/textfield_windows.go | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/newctrl/textfield_windows.go b/newctrl/textfield_windows.go new file mode 100644 index 0000000..416cc2f --- /dev/null +++ b/newctrl/textfield_windows.go @@ -0,0 +1,75 @@ +// 15 july 2014 + +package ui + +import ( + "unsafe" +) + +// #include "winapi_windows.h" +import "C" + +type textfield struct { + *controlSingleHWNDWithText + changed *event +} + +var editclass = toUTF16("EDIT") + +func startNewTextField(style C.DWORD) *textfield { + hwnd := C.newControl(editclass, + 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) + t := &textfield{ + controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd), + changed: newEvent(), + } + t.fpreferredSize = t.preferredSize + C.controlSetControlFont(t.hwnd) + C.setTextFieldSubclass(t.hwnd, unsafe.Pointer(t)) + return t +} + +func newTextField() *textfield { + return startNewTextField(0) +} + +func newPasswordField() *textfield { + return startNewTextField(C.ES_PASSWORD) +} + +func (t *textfield) Text() string { + return t.text() +} + +func (t *textfield) SetText(text string) { + t.setText(text) +} + +func (t *textfield) OnChanged(f func()) { + t.changed.set(f) +} + +func (t *textfield) Invalid(reason string) { + if reason == "" { + C.textfieldHideInvalidBalloonTip(t.hwnd) + return + } + C.textfieldSetAndShowInvalidBalloonTip(t.hwnd, toUTF16(reason)) +} + +//export textfieldChanged +func textfieldChanged(data unsafe.Pointer) { + t := (*textfield)(data) + t.changed.fire() +} + +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 0,0//TODO return fromdlgunitsX(textfieldWidth, d), fromdlgunitsY(textfieldHeight, d) +} |
