diff options
author | Alexander Neumann <alexander.neumann@picos-software.com> | 2020-08-27 12:27:02 +0200 |
---|---|---|
committer | Alexander Neumann <alexander.neumann@picos-software.com> | 2020-08-27 12:27:02 +0200 |
commit | e918ceb58768422acc50c8eef574e50512cf3d1d (patch) | |
tree | d04d35519abb16e5a0d7d54f46b0d78b062b915c | |
parent | ListBox: Fix weird glitch + some cleanup (diff) | |
download | wireguard-windows-e918ceb58768422acc50c8eef574e50512cf3d1d.tar.xz wireguard-windows-e918ceb58768422acc50c8eef574e50512cf3d1d.zip |
TabWidget: Change automatic focus behavior on current page change
We now only set focus to a descendant if the TabWidget already contains the focus.
-rw-r--r-- | tabwidget.go | 32 | ||||
-rw-r--r-- | window.go | 25 |
2 files changed, 35 insertions, 22 deletions
diff --git a/tabwidget.go b/tabwidget.go index 55412fb5..64958836 100644 --- a/tabwidget.go +++ b/tabwidget.go @@ -295,7 +295,17 @@ func (tw *TabWidget) onSelChange() { page.SetVisible(true) tw.RequestLayout() page.Invalidate() - tw.pages.At(tw.currentIndex).focusFirstCandidateDescendant() + + var containsFocus bool + tw.forEachDescendantRaw(uintptr(win.GetFocus()), func(hwnd win.HWND, lParam uintptr) bool { + if hwnd == win.HWND(lParam) { + containsFocus = true + } + return !containsFocus + }) + if containsFocus { + tw.pages.At(tw.currentIndex).focusFirstCandidateDescendant() + } } tw.Invalidate() @@ -490,26 +500,6 @@ func tabWidgetTabWndProc(hwnd win.HWND, msg uint32, wParam, lParam uintptr) uint } return 0 - - case win.WM_LBUTTONDOWN: - x := win.GET_X_LPARAM(lParam) - y := win.GET_Y_LPARAM(lParam) - - hti := win.TCHITTESTINFO{ - Pt: win.POINT{x, y}, - } - - i := int(win.SendMessage(hwnd, win.TCM_HITTEST, 0, uintptr(unsafe.Pointer(&hti)))) - - if i == -1 { - break - } - - ret := win.CallWindowProc(tw.tabOrigWndProcPtr, hwnd, msg, wParam, lParam) - - tw.pages.At(i).focusFirstCandidateDescendant() - - return ret } return win.CallWindowProc(tw.tabOrigWndProcPtr, hwnd, msg, wParam, lParam) @@ -452,6 +452,7 @@ var ( func init() { AppendToWalkInit(func() { forEachDescendantCallbackPtr = syscall.NewCallback(forEachDescendant) + forEachDescendantRawCallbackPtr = syscall.NewCallback(forEachDescendantRaw) dialogBaseUnitsUTF16StringPtr = syscall.StringToUTF16Ptr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") }) } @@ -1259,7 +1260,7 @@ func (wb *WindowBase) Form() Form { } func forEachDescendant(hwnd win.HWND, lParam uintptr) uintptr { - if window := windowFromHandle(hwnd); window != nil && forEachDescendantCallback(window.(Widget)) { + if window := windowFromHandle(hwnd); window == nil || forEachDescendantCallback(window.(Widget)) { return 1 } @@ -1280,6 +1281,28 @@ func (wb *WindowBase) ForEachDescendant(f func(widget Widget) bool) { win.EnumChildWindows(wb.hWnd, forEachDescendantCallbackPtr, 0) } +func forEachDescendantRaw(hwnd win.HWND, lParam uintptr) uintptr { + if forEachDescendantRawCallback(hwnd, lParam) { + return 1 + } + + return 0 +} + +var ( + forEachDescendantRawCallbackPtr uintptr + forEachDescendantRawCallback func(hwnd win.HWND, lParam uintptr) bool +) + +func (wb *WindowBase) forEachDescendantRaw(lParam uintptr, f func(hwnd win.HWND, lParam uintptr) bool) { + forEachDescendantRawCallback = f + defer func() { + forEachDescendantRawCallback = nil + }() + + win.EnumChildWindows(wb.hWnd, forEachDescendantRawCallbackPtr, lParam) +} + // Visible returns if the *WindowBase is visible. func (wb *WindowBase) Visible() bool { return win.IsWindowVisible(wb.hWnd) |