summaryrefslogtreecommitdiff
path: root/newctrl/checkbox_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-14 15:29:59 -0400
committerPietro Gagliardi <[email protected]>2014-10-14 15:29:59 -0400
commitabdbec2449d8d362e7a440bec5b85eb615541cf0 (patch)
treea3000c06cc5a968fc79e81d178000a940edbcdd7 /newctrl/checkbox_windows.go
parenteef3e1136b51112c23620b150ffcf03caddc0ff9 (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/checkbox_windows.go')
-rw-r--r--newctrl/checkbox_windows.go76
1 files changed, 76 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)
+*/
+}