Don't mangle ampersands in wxToolBar tooltips under MSW

Preserve the ampersands in the string, which is consistent with wxGTK
behaviour and less surprising than the default behaviour, which creates
mnemonics in the tooltips that are, of course, perfectly useless, as
they can't be activated from keyboard anyhow.

Turn on TTS_NOPREFIX, which is already used by wxToolTip, to fix this.

Closes #18899.
This commit is contained in:
Vadim Zeitlin
2020-08-22 18:49:25 +02:00
parent adb7c8a53d
commit 93c580ccaf

View File

@@ -452,6 +452,20 @@ bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size)
MSWSetPadding(m_toolPacking); MSWSetPadding(m_toolPacking);
} }
#if wxUSE_TOOLTIPS
// MSW "helpfully" handles ampersands as mnemonics in the tooltips
// (officially in order to allow using the same string as the menu item and
// a toolbar item tip), but we don't want this, so force TTS_NOPREFIX to be
// on to preserve all ampersands.
HWND hwndTTip = (HWND)::SendMessage(GetHwnd(), TB_GETTOOLTIPS, 0, 0);
if ( hwndTTip )
{
long styleTTip = ::GetWindowLong(hwndTTip, GWL_STYLE);
styleTTip |= TTS_NOPREFIX;
::SetWindowLong(hwndTTip, GWL_STYLE, styleTTip);
}
#endif // wxUSE_TOOLTIPS
return true; return true;
} }