summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--newctrl/checkbox_windows.go76
-rw-r--r--newctrl/label_windows.go63
-rw-r--r--newctrl/textfield_windows.go75
3 files changed, 214 insertions, 0 deletions
diff --git a/newctrl/checkbox_windows.go b/newctrl/checkbox_windows.go
new file mode 100644
index 0000000..b1f2e8a
--- /dev/null
+++ b/newctrl/checkbox_windows.go
@@ -0,0 +1,76 @@
+// 15 july 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "winapi_windows.h"
+import "C"
+
+type checkbox struct {
+ *controlSingleHWNDWithText
+ toggled *event
+}
+
+func newCheckbox(text string) *checkbox {
+ // don't use BS_AUTOCHECKBOX here because it creates problems when refocusing (see http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx)
+ // we'll handle actually toggling the check state ourselves (see controls_windows.c)
+ hwnd := C.newControl(buttonclass,
+ C.BS_CHECKBOX|C.WS_TABSTOP,
+ 0)
+ c := &checkbox{
+ controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
+ toggled: newEvent(),
+ }
+ c.fpreferredSize = c.preferredSize
+ c.SetText(text)
+ C.controlSetControlFont(c.hwnd)
+ C.setCheckboxSubclass(c.hwnd, unsafe.Pointer(c))
+ return c
+}
+
+func (c *checkbox) OnToggled(e func()) {
+ c.toggled.set(e)
+}
+
+func (c *checkbox) Text() string {
+ return c.text()
+}
+
+func (c *checkbox) SetText(text string) {
+ c.setText(text)
+}
+
+func (c *checkbox) Checked() bool {
+ return C.checkboxChecked(c.hwnd) != C.FALSE
+}
+
+func (c *checkbox) SetChecked(checked bool) {
+ if checked {
+ C.checkboxSetChecked(c.hwnd, C.TRUE)
+ return
+ }
+ C.checkboxSetChecked(c.hwnd, C.FALSE)
+}
+
+//export checkboxToggled
+func checkboxToggled(data unsafe.Pointer) {
+ c := (*checkbox)(data)
+ c.toggled.fire()
+}
+
+const (
+ // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
+ checkboxHeight = 10
+ // from http://msdn.microsoft.com/en-us/library/windows/desktop/bb226818%28v=vs.85%29.aspx
+ checkboxXFromLeftOfBoxToLeftOfLabel = 12
+)
+
+func (c *checkbox) preferredSize(d *sizing) (width, height int) {
+return 0,0/*TODO
+ return fromdlgunitsX(checkboxXFromLeftOfBoxToLeftOfLabel, d) + int(c._textlen),
+ fromdlgunitsY(checkboxHeight, d)
+*/
+}
diff --git a/newctrl/label_windows.go b/newctrl/label_windows.go
new file mode 100644
index 0000000..3a9e3b7
--- /dev/null
+++ b/newctrl/label_windows.go
@@ -0,0 +1,63 @@
+// 15 july 2014
+
+package ui
+
+// #include "winapi_windows.h"
+import "C"
+
+type label struct {
+ *controlSingleHWNDWithText
+ standalone bool
+}
+
+var labelclass = toUTF16("STATIC")
+
+func newLabel(text string) {
+ hwnd := C.newControl(labelclass,
+ // SS_NOPREFIX avoids accelerator translation; SS_LEFTNOWORDWRAP clips text past the end
+ // controls are vertically aligned to the top by default (thanks Xeek in irc.freenode.net/#winapi)
+ C.SS_NOPREFIX|C.SS_LEFTNOWORDWRAP,
+ C.WS_EX_TRANSPARENT)
+ l := &label{
+ controlSingleHWNDWithText: newControlSingleHWNDWithText(hwnd),
+ }
+ l.fpreferredSize = l.preferredSize
+ l.SetText(text)
+ C.controlSetControlFont(l.hwnd)
+ return l
+}
+
+func (l *label) Text() string {
+ return l.text()
+}
+
+func (l *label) SetText(text string) {
+ l.setText(text)
+}
+
+const (
+ // via http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
+ labelHeight = 8
+ labelYOffset = 3
+)
+
+func (l *label) preferredSize(d *sizing) (width, height int) {
+return 0,0//TODO return int(l._textlen), fromdlgunitsY(labelHeight, d)
+}
+
+/*TODO
+func (l *label) commitResize(c *allocation, d *sizing) {
+ if !l.standalone {
+ yoff := fromdlgunitsY(labelYOffset, d)
+ c.y += yoff
+ c.height -= yoff
+ // by default, labels are drawn offset by the internal leading (the space reserved for accents on uppercase letters)
+ // the above calculation assumes otherwise, so account for the difference
+ // there will be enough space left over for the internal leading anyway (at least on the standard fonts)
+ // don't do this to standalone labels, otherwise those accents get cut off!
+ c.y -= int(d.internalLeading)
+ c.height += int(d.internalLeading)
+ }
+ basecommitResize(l, c, d)
+}
+*/
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)
+}