From c543f5639b121bcdae11f681466c030394902f65 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi <pietro10@mac.com> Date: Fri, 30 May 2014 14:13:47 -0400 Subject: [PATCH] Normalized DefWindowProc() handling across the Windows files; the syscall.LazyProc now has the normalized name _defWindowProc and defWindowProc() is a convenience function that calls _defWindowProc properly. This will also be important for the switch to a single window class per Window/Area. --- area_windows.go | 21 ++++++--------------- stdwndclass_windows.go | 18 +++++++++++------- uitask_windows.go | 7 +------ 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/area_windows.go b/area_windows.go index 6269002..6708a27 100644 --- a/area_windows.go +++ b/area_windows.go @@ -606,15 +606,6 @@ var ( func areaWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT { return func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT { - defwndproc := func() _LRESULT { - r1, _, _ := defWindowProc.Call( - uintptr(hwnd), - uintptr(uMsg), - uintptr(wParam), - uintptr(lParam)) - return _LRESULT(r1) - } - switch uMsg { case _WM_PAINT: paintArea(s) @@ -635,14 +626,14 @@ func areaWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lPara scrollArea(s, wParam, _SB_VERT) return 0 } - return defwndproc() + return defWindowProc(hwnd, uMsg, wParam, lParam) case _WM_SIZE: // TODO make this unnecessary if s != nil && s.hwnd != 0 { // this message can be sent before s is assigned properly adjustAreaScrollbars(s) return 0 } - return defwndproc() + return defWindowProc(hwnd, uMsg, wParam, lParam) case _WM_ACTIVATE: // don't keep the double-click timer running if the user switched programs in between clicks s.clickCounter.reset() @@ -656,7 +647,7 @@ func areaWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lPara panic(fmt.Errorf("error giving Area keyboard focus: %v", err)) return _MA_ACTIVATE // TODO eat the click? } - return defwndproc() + return defWindowProc(hwnd, uMsg, wParam, lParam) case _WM_MOUSEMOVE: areaMouseEvent(s, 0, false, wParam, lParam) return 0 @@ -698,13 +689,13 @@ func areaWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lPara if handled { return 0 } - return defwndproc() + return defWindowProc(hwnd, uMsg, wParam, lParam) case _WM_SYSKEYUP: handled := areaKeyEvent(s, true, wParam, lParam) if handled { return 0 } - return defwndproc() + return defWindowProc(hwnd, uMsg, wParam, lParam) case msgSetAreaSize: s.areawidth = int(wParam) // see setAreaSize() in sysdata_windows.go s.areaheight = int(lParam) @@ -712,7 +703,7 @@ func areaWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lPara repaintArea(s) // this calls for an update return 0 default: - return defwndproc() + return defWindowProc(hwnd, uMsg, wParam, lParam) } panic(fmt.Sprintf("areaWndProc message %d did not return: internal bug in ui library", uMsg)) } diff --git a/stdwndclass_windows.go b/stdwndclass_windows.go index 276e698..d57cc20 100644 --- a/stdwndclass_windows.go +++ b/stdwndclass_windows.go @@ -19,9 +19,18 @@ var ( ) var ( - defWindowProc = user32.NewProc("DefWindowProcW") + _defWindowProc = user32.NewProc("DefWindowProcW") ) +func defWindowProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT { + r1, _, _ := _defWindowProc.Call( + uintptr(hwnd), + uintptr(uMsg), + uintptr(wParam), + uintptr(lParam)) + return _LRESULT(r1) +} + func stdWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT { return func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESULT { switch uMsg { @@ -62,12 +71,7 @@ func stdWndProc(s *sysData) func(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam s.signal() return 0 default: - r1, _, _ := defWindowProc.Call( - uintptr(hwnd), - uintptr(uMsg), - uintptr(wParam), - uintptr(lParam)) - return _LRESULT(r1) + return defWindowProc(hwnd, uMsg, wParam, lParam) } panic(fmt.Sprintf("stdWndProc message %d did not return: internal bug in ui library", uMsg)) } diff --git a/uitask_windows.go b/uitask_windows.go index 2002e7c..563cca9 100644 --- a/uitask_windows.go +++ b/uitask_windows.go @@ -178,10 +178,5 @@ func messageHandlerWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPAR _postQuitMessage.Call(0) return 0 } - r1, _, _ := defWindowProc.Call( - uintptr(hwnd), - uintptr(uMsg), - uintptr(wParam), - uintptr(lParam)) - return _LRESULT(r1) + return defWindowProc(hwnd, uMsg, wParam, lParam) }