summaryrefslogtreecommitdiff
path: root/redo/controls_windows.go
diff options
context:
space:
mode:
Diffstat (limited to 'redo/controls_windows.go')
-rw-r--r--redo/controls_windows.go45
1 files changed, 43 insertions, 2 deletions
diff --git a/redo/controls_windows.go b/redo/controls_windows.go
index 3b73b48..dd4b8c9 100644
--- a/redo/controls_windows.go
+++ b/redo/controls_windows.go
@@ -5,6 +5,7 @@ package ui
import (
"fmt"
"syscall"
+ "unsafe"
)
type widgetbase struct {
@@ -73,8 +74,20 @@ func (w *widgetbase) settext(text string, results ...t_LRESULT) *Request {
}
}
+// all controls that have events receive the events themselves through subclasses
+// to do this, all windows (including the message-only window; see http://support.microsoft.com/default.aspx?scid=KB;EN-US;Q104069) forward WM_COMMAND to each control with this function
+func forwardCommand(hwnd uintptr, uMsg t_UINT, wParam t_WPARAM, lParam t_LPARAM) t_LRESULT {
+ control := uintptr(lParam)
+ // don't generate an event if the control (if there is one) is unparented (a child of the message-only window)
+ if control != hNULL && f_IsChild(msgwin, control) == 0 {
+ return f_SendMessageW(control, msgCOMMAND, wParam, lParam)
+ }
+ return f_DefWindowProcW(hwnd, uMsg, wParam, lParam)
+}
+
type button struct {
*widgetbase
+ clicked *event
}
var buttonclass = syscall.StringToUTF16Ptr("BUTTON")
@@ -89,6 +102,7 @@ func newButton(text string) *Request {
setWindowText(w.hwnd, text, []t_LRESULT{c_FALSE})
c <- &button{
widgetbase: w,
+ clicked: newEvent(),
}
},
resp: c,
@@ -96,8 +110,14 @@ func newButton(text string) *Request {
}
func (b *button) OnClicked(e func(c Doer)) *Request {
- // TODO
- return nil
+ c := make(chan interface{})
+ return &Request{
+ op: func() {
+ b.clicked.set(e)
+ c <- struct{}{}
+ },
+ resp: c,
+ }
}
func (b *button) Text() *Request {
@@ -107,3 +127,24 @@ func (b *button) Text() *Request {
func (b *button) SetText(text string) *Request {
return b.settext(text)
}
+
+var buttonsubprocptr = syscall.NewCallback(buttonSubProc)
+
+func buttonSubProc(hwnd uintptr, uMsg t_UINT, wParam t_WPARAM, lParam t_LPARAM, id t_UINT_PTR, data t_DWORD_PTR) t_LRESULT {
+ b := (*button)(unsafe.Pointer(uintptr(data)))
+ switch uMsg {
+ case msgCOMMAND:
+ if wParam.HIWORD() == c_BN_CLICKED {
+ b.clicked.fire()
+ println("button clicked")
+ return 0
+ }
+ // TODO return
+ case c_WM_NCDESTROY:
+ // TODO remove
+ // TODO return
+ default:
+ // TODO return
+ }
+ panic(fmt.Errorf("Button message %d does not return a value (bug in buttonSubProc())", uMsg))
+}