From 93c580ccaf4dfde77b797f3669b83ae22c72fa6b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 22 Aug 2020 18:49:25 +0200 Subject: [PATCH] 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. --- src/msw/toolbar.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/msw/toolbar.cpp b/src/msw/toolbar.cpp index dd354dc95d..1f5a9df9fa 100644 --- a/src/msw/toolbar.cpp +++ b/src/msw/toolbar.cpp @@ -452,6 +452,20 @@ bool wxToolBar::MSWCreateToolbar(const wxPoint& pos, const wxSize& size) 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; }