[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.
This commit is contained in:
Katayama Hirofumi MZ 2024-02-26 21:54:51 +09:00 committed by GitHub
parent a08b83a90b
commit 8209aa528b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)