diff options
| author | Pietro Gagliardi <[email protected]> | 2014-07-17 15:10:26 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2014-07-17 15:10:26 -0400 |
| commit | 19f7b2946a6198862f860b1f7c5798c0d66b8fc1 (patch) | |
| tree | dcad78ffbde01eb9d4b952e15a33f6308eea8559 /redo/controls_windows.go | |
| parent | 1a712d4064a646f366612139269d075db78d56cd (diff) | |
Laid down the framework for control events on Windows. The only problem left is that we need to use functions from comctl32.dll, so it's time to bring that blob of code back.
Diffstat (limited to 'redo/controls_windows.go')
| -rw-r--r-- | redo/controls_windows.go | 45 |
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)) +} |
