summaryrefslogtreecommitdiff
path: root/redo/checkbox_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-08-02 22:35:58 -0400
committerPietro Gagliardi <[email protected]>2014-08-02 22:35:58 -0400
commitd018953d7ef1b276cc3229e04ba6fc75018c888a (patch)
tree3f980a017ca498bf499ff9c5e6a53210606b12f9 /redo/checkbox_windows.go
parent1f6bcde3d9ddcab921f2f4347148f6784ca36a14 (diff)
Split all the Control implementations into their own files and renamed the containerctrls implementation files to say tab instead as they only hold Tab. This is the first part of what should hopefully be the final restructuring.
Diffstat (limited to 'redo/checkbox_windows.go')
-rw-r--r--redo/checkbox_windows.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/redo/checkbox_windows.go b/redo/checkbox_windows.go
new file mode 100644
index 0000000..633f8e7
--- /dev/null
+++ b/redo/checkbox_windows.go
@@ -0,0 +1,59 @@
+// 15 july 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "winapi_windows.h"
+import "C"
+
+type checkbox struct {
+ *button
+}
+
+func newCheckbox(text string) *checkbox {
+ c := &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)
+ button: startNewButton(text, C.BS_CHECKBOX),
+ }
+ c.fpreferredSize = c.checkboxpreferredSize
+ C.setCheckboxSubclass(c.hwnd, unsafe.Pointer(c))
+ return c
+}
+
+func (c *checkbox) Checked() bool {
+ if C.checkboxChecked(c.hwnd) == C.FALSE {
+ return false
+ }
+ return true
+}
+
+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.clicked.fire()
+ println("checkbox toggled")
+}
+
+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) checkboxpreferredSize(d *sizing) (width, height int) {
+ return fromdlgunitsX(checkboxXFromLeftOfBoxToLeftOfLabel, d) + int(c.textlen),
+ fromdlgunitsY(checkboxHeight, d)
+}