From 4856790299cf531b874a4e1b835017b0ca9abd03 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 6 Jun 2014 01:49:23 -0400 Subject: [PATCH] Fixed the standard window class focus behavior on Windows from the previous commit to work. Also updated the SetFocus() call in area_windows.go to boot and removed the relevant TODO after checking both wine and Windows XP work fine. --- area_windows.go | 8 +++----- stdwndclass_windows.go | 13 +++++-------- todo.md | 4 ---- zconstants_windows_386.go | 1 - zconstants_windows_amd64.go | 1 - 5 files changed, 8 insertions(+), 19 deletions(-) diff --git a/area_windows.go b/area_windows.go index 492595c..344f43f 100644 --- a/area_windows.go +++ b/area_windows.go @@ -625,11 +625,9 @@ func areaWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESU // this happens on every mouse click (apparently), so DON'T reset the click counter, otherwise it will always be reset (not an issue, as MSDN says WM_ACTIVATE is sent alongside WM_MOUSEACTIVATE when necessary) // transfer keyboard focus to our Area on an activating click // (see http://www.catch22.net/tuts/custom-controls) - r1, _, err := _setFocus.Call(uintptr(s.hwnd)) - if r1 == 0 { // failure - panic(fmt.Errorf("error giving Area keyboard focus: %v", err)) - return _MA_ACTIVATE // TODO eat the click? - } + // don't bother checking SetFocus()'s error; see http://stackoverflow.com/questions/24073695/winapi-can-setfocus-return-null-without-an-error-because-thats-what-im-see/24074912#24074912 + _setFocus.Call(uintptr(s.hwnd)) +// return _MA_ACTIVATE // TODO eat the click? return defWindowProc(hwnd, uMsg, wParam, lParam) case _WM_MOUSEMOVE: areaMouseEvent(s, 0, false, wParam, lParam) diff --git a/stdwndclass_windows.go b/stdwndclass_windows.go index d32bd8c..df7aef8 100644 --- a/stdwndclass_windows.go +++ b/stdwndclass_windows.go @@ -92,15 +92,12 @@ func (s *sysData) handleFocus(wParam _WPARAM) { old) if r1 != 0 { s.lastfocus = _HWND(old) -println("s",s.lastfocus) } } } else { // focusing in if s.lastfocus != _HWND(_NULL) { // if we have one - r1, _, err := _setFocus.Call(uintptr(s.lastfocus)) - if _HWND(r1) == _HWND(_NULL) { - panic(fmt.Errorf("error setting focus to previously focused window on reactivating Window: %v", err)) - } + // don't bother checking SetFocus()'s error; see http://stackoverflow.com/questions/24073695/winapi-can-setfocus-return-null-without-an-error-because-thats-what-im-see/24074912#24074912 + _setFocus.Call(uintptr(s.lastfocus)) } } } @@ -142,9 +139,9 @@ func stdWndProc(hwnd _HWND, uMsg uint32, wParam _WPARAM, lParam _LPARAM) _LRESUL } } return 0 -// case _WM_ACTIVATE: -// s.handleFocus(wParam) -// return 0 + case _WM_ACTIVATE: + s.handleFocus(wParam) + return 0 case _WM_GETMINMAXINFO: mm := lParam.MINMAXINFO() // ... minimum size diff --git a/todo.md b/todo.md index 385474c..259a035 100644 --- a/todo.md +++ b/todo.md @@ -30,10 +30,6 @@ super ultra important things: - on Windows, Shift+(num pad key) triggers the shifted key code when num lock is off; will need to reorder key code tests on all platforms to fix this - http://blogs.msdn.com/b/oldnewthing/archive/2004/09/06/226045.aspx - related: make sure all keyboard checks are in the same order on all platforms -- pressing global keycodes (including kwin's zoom in/out) when running the keyboard test in wine causes the Area to lose keyboard focus; this doesn't happen on the GTK+ version (fix the Windows version to behave like the GTK+ version) - - this also happens in real windows (press the windows key to open the start menu); there's something I'm not handling and I'm not sure what it is - - oh hey would you look at that http://blogs.msdn.com/b/oldnewthing/archive/2014/05/21/10527168.aspx how timely - - part 2 http://blogs.msdn.com/b/oldnewthing/archive/2014/05/22/10527522.aspx - Message boxes that belong to agiven parent are still application-modal on all platforms except Mac OS X because the whole system waits... we'll need to use a channel for this, I guess :S - [12:55] pietro10: I meant to mention: 1073): Gtk-WARNING **: Theme parsing error: gtk.css:72:20: Not using units is deprecated. Assuming 'px'. twice. diff --git a/zconstants_windows_386.go b/zconstants_windows_386.go index 31a92fb..304b175 100644 --- a/zconstants_windows_386.go +++ b/zconstants_windows_386.go @@ -49,7 +49,6 @@ const _LB_GETTEXT = 393 const _LB_GETTEXTLEN = 394 const _LB_INSERTSTRING = 385 const _LF_FACESIZE = 32 -const _MA_ACTIVATE = 1 const _MB_APPLMODAL = 0 const _MB_ICONERROR = 16 const _MB_OK = 0 diff --git a/zconstants_windows_amd64.go b/zconstants_windows_amd64.go index 4d8e4c4..ab3cba2 100644 --- a/zconstants_windows_amd64.go +++ b/zconstants_windows_amd64.go @@ -49,7 +49,6 @@ const _LB_GETTEXT = 393 const _LB_GETTEXTLEN = 394 const _LB_INSERTSTRING = 385 const _LF_FACESIZE = 32 -const _MA_ACTIVATE = 1 const _MB_APPLMODAL = 0 const _MB_ICONERROR = 16 const _MB_OK = 0