summaryrefslogtreecommitdiff
path: root/spinbox_windows.go
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2014-10-28 15:46:13 -0400
committerPietro Gagliardi <[email protected]>2014-10-28 15:46:13 -0400
commit667745dd8c79ea358b66456ea7afcc751429da88 (patch)
tree7fd057c74e34a50282221cf0699569b00e90dc97 /spinbox_windows.go
parent649b52b6ef273c2ea5a4cf881835a7fd61bd4df1 (diff)
Added the initial Windows Spinbox code.
Diffstat (limited to 'spinbox_windows.go')
-rw-r--r--spinbox_windows.go62
1 files changed, 62 insertions, 0 deletions
diff --git a/spinbox_windows.go b/spinbox_windows.go
new file mode 100644
index 0000000..6d6cb5e
--- /dev/null
+++ b/spinbox_windows.go
@@ -0,0 +1,62 @@
+// 28 october 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "winapi_windows.h"
+import "C"
+
+// TODO do we have to manually monitor user changes to the edit control?
+
+type spinbox struct {
+ hwndEdit C.HWND
+ hwndUpDown C.HWND
+}
+
+func newSpinbox() Spinbox {
+ s := new(spinbox)
+ s.hwndEdit = C.newControl(editclass,
+ C.textfieldStyle | C.ES_NUMBER,
+ C.textfieldExtStyle)
+ s.hwndUpDown = C.newControl(C.xUPDOWN_CLASSW,
+ C.UDS_ALIGNRIGHT | C.UDS_ARROWKEYS | C.UDS_HOTTRACK | C.UDS_NOTHOUSANDS | C.UDS_SETBUDDYINT,
+ 0)
+ C.SendMessageW(s.hwndUpDown, C.UDM_SETBUDDY, C.WPARAM(uintptr(unsafe.Pointer(s.hwndEdit))), 0)
+ C.SendMessageW(s.hwndUpDown, C.UDM_SETRANGE32, 0, 100)
+ C.SendMessageW(s.hwndUpDown, C.UDM_SETPOS32, 0, 0)
+ return s
+}
+
+func (s *spinbox) setParent(p *controlParent) {
+ C.controlSetParent(s.hwndEdit, p.hwnd)
+ C.controlSetParent(s.hwndUpDown, p.hwnd)
+}
+
+func (s *spinbox) preferredSize(d *sizing) (width, height int) {
+ // TODO
+ return 20, 20
+}
+
+func (s *spinbox) resize(x int, y int, width int, height int, d *sizing) {
+ C.moveWindow(s.hwndEdit, C.int(x), C.int(y), C.int(width), C.int(height))
+}
+
+func (s *spinbox) nTabStops() int {
+ // TODO does the up-down control count?
+ return 1
+}
+
+// TODO be sure to modify this when we add Show()/Hide()
+func (s *spinbox) containerShow() {
+ C.ShowWindow(s.hwndEdit, C.SW_SHOW)
+ C.ShowWindow(s.hwndUpDown, C.SW_SHOW)
+}
+
+// TODO be sure to modify this when we add Show()/Hide()
+func (s *spinbox) containerHide() {
+ C.ShowWindow(s.hwndEdit, C.SW_HIDE)
+ C.ShowWindow(s.hwndUpDown, C.SW_HIDE)
+}