summaryrefslogtreecommitdiff
path: root/redo/button_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/button_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/button_windows.go')
-rw-r--r--redo/button_windows.go77
1 files changed, 77 insertions, 0 deletions
diff --git a/redo/button_windows.go b/redo/button_windows.go
new file mode 100644
index 0000000..aa7a60a
--- /dev/null
+++ b/redo/button_windows.go
@@ -0,0 +1,77 @@
+// 15 july 2014
+
+package ui
+
+import (
+ "unsafe"
+)
+
+// #include "winapi_windows.h"
+import "C"
+
+type button struct {
+ *controlbase
+ clicked *event
+}
+
+var buttonclass = toUTF16("BUTTON")
+
+func startNewButton(text string, style C.DWORD) *button {
+ c := newControl(buttonclass,
+ style | C.WS_TABSTOP,
+ 0)
+ c.setText(text)
+ C.controlSetControlFont(c.hwnd)
+ b := &button{
+ controlbase: c,
+ clicked: newEvent(),
+ }
+ return b
+}
+
+func newButton(text string) *button {
+ b := startNewButton(text, C.BS_PUSHBUTTON)
+ C.setButtonSubclass(b.hwnd, unsafe.Pointer(b))
+ b.fpreferredSize = b.buttonpreferredSize
+ return b
+}
+
+func (b *button) OnClicked(e func()) {
+ b.clicked.set(e)
+}
+
+func (b *button) Text() string {
+ return b.text()
+}
+
+func (b *button) SetText(text string) {
+ b.setText(text)
+}
+
+//export buttonClicked
+func buttonClicked(data unsafe.Pointer) {
+ b := (*button)(data)
+ b.clicked.fire()
+ println("button clicked")
+}
+
+const (
+ // from http://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
+ buttonHeight = 14
+)
+
+func (b *button) buttonpreferredSize(d *sizing) (width, height int) {
+ // common controls 6 thankfully provides a method to grab this...
+ var size C.SIZE
+
+ size.cx = 0 // explicitly ask for ideal size
+ size.cy = 0
+ if C.SendMessageW(b.hwnd, C.BCM_GETIDEALSIZE, 0, C.LPARAM(uintptr(unsafe.Pointer(&size)))) != C.FALSE {
+ return int(size.cx), int(size.cy)
+ }
+ // that failed, fall back
+println("message failed; falling back")
+ // don't worry about the error return from GetSystemMetrics(); there's no way to tell (explicitly documented as such)
+ xmargins := 2 * int(C.GetSystemMetrics(C.SM_CXEDGE))
+ return xmargins + int(b.textlen), fromdlgunitsY(buttonHeight, d)
+}