https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8209aa528b683ccad227a2ec14951702dd6cdb42
commit 8209aa528b683ccad227a2ec14951702dd6cdb42 Author: Katayama Hirofumi MZ <katayama.hirofumi...@gmail.com> AuthorDate: Mon Feb 26 21:54:51 2024 +0900 Commit: GitHub <nore...@github.com> CommitDate: Mon Feb 26 21:54:51 2024 +0900 [BROWSEUI] Enable Address bar access key (Alt+D) (#6534) Retrial of #5052. Improve keyboard interface usability. JIRA issue: CORE-18823 - Add GetAddressBarAccessKey helper function to get the accelerator of Address bar from resource string IDS_ADDRESSBANDLABEL. - Implement Alt+D (or something) accelerator in CAddressBand:: TranslateAcceleratorIO method by handling WM_SYSKEYDOWN and WM_SYSCHAR messages. --- dll/win32/browseui/addressband.cpp | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/dll/win32/browseui/addressband.cpp b/dll/win32/browseui/addressband.cpp index 2f0dfe36619..25b038655e0 100644 --- a/dll/win32/browseui/addressband.cpp +++ b/dll/win32/browseui/addressband.cpp @@ -259,8 +259,66 @@ HRESULT STDMETHODCALLTYPE CAddressBand::HasFocusIO() return S_FALSE; } +static WCHAR GetAccessKeyFromText(WCHAR chAccess, LPCWSTR pszText) +{ + for (const WCHAR *pch = pszText; *pch != UNICODE_NULL; ++pch) + { + if (*pch == L'&' && pch[1] == L'&') + { + /* Skip the first '&', the second is skipped by the for-loop */ + ++pch; + continue; + } + if (*pch == L'&') + { + ++pch; + chAccess = *pch; + break; + } + } + + ::CharUpperBuffW(&chAccess, 1); + return chAccess; +} + +static WCHAR GetAddressBarAccessKey(WCHAR chAccess) +{ + static WCHAR s_chCache = 0; + static LANGID s_ThreadLocale = 0; + if (s_chCache && s_ThreadLocale == ::GetThreadLocale()) + return s_chCache; + + WCHAR szText[80]; + if (!LoadStringW(_AtlBaseModule.GetResourceInstance(), IDS_ADDRESSBANDLABEL, + szText, _countof(szText))) + { + return chAccess; + } + + s_chCache = GetAccessKeyFromText(chAccess, szText); + s_ThreadLocale = ::GetThreadLocale(); + return s_chCache; +} + HRESULT STDMETHODCALLTYPE CAddressBand::TranslateAcceleratorIO(LPMSG lpMsg) { + // Enable Address bar access key (Alt+D) + switch (lpMsg->message) + { + case WM_SYSKEYDOWN: + case WM_SYSCHAR: + { + WCHAR chAccess = GetAddressBarAccessKey(L'D'); + if (lpMsg->wParam == chAccess) + { + ::PostMessageW(fEditControl, EM_SETSEL, 0, -1); + ::SetFocus(fEditControl); + return S_FALSE; + } + break; + } + } + if (lpMsg->hwnd == fEditControl) { switch (lpMsg->message)