Fix truncating CJK mnemonics in control labels

13068d3603 introduced code for stripping
CJK mnemonics (i.e. trailing " (&X)") from the menu items, but due to
the use of wxStripMenuCodes() in wxControl::GetLabelText(), it also
applied to the control labels, resulting in wrongly measuring their size
(because the text used for measurement didn't include the "(&X)" part)
and truncating them in display.

Fix this by adding an explicit wxStrip_CJKMnemonics and using it only in
the code dealing with the menu item labels. This requires more changes
than just modifying GetLabelText() to use some wxStrip_NoCJKMnemonics
flag, but is more compatible as it's not impossible that some existing
code using wxStripMenuCodes() could be broken by this change too, while
now the existing behaviour is preserved.

Also improve wxStrip_XXX documentation.

Closes https://github.com/wxWidgets/wxWidgets/pull/1439

See #16736.

Closes #18452.
This commit is contained in:
Vadim Zeitlin
2019-07-24 11:19:29 +02:00
parent 8ea46e70c5
commit 9d92ba185c
12 changed files with 80 additions and 30 deletions

View File

@@ -365,8 +365,8 @@ void MenuTestCase::TranslatedMnemonics()
wxString filemenu = m_frame->GetMenuBar()->GetMenuLabel(0);
CPPUNIT_ASSERT_EQUAL
(
wxStripMenuCodes(GetTranslatedString(trans, "&File")),
wxStripMenuCodes(GetTranslatedString(trans, filemenu))
wxStripMenuCodes(GetTranslatedString(trans, "&File"), wxStrip_Menu),
wxStripMenuCodes(GetTranslatedString(trans, filemenu), wxStrip_Menu)
);
// Test strings that have shortcuts. Duplicate non-mnemonic translations
@@ -374,21 +374,21 @@ void MenuTestCase::TranslatedMnemonics()
CPPUNIT_ASSERT_EQUAL
(
GetTranslatedString(trans, "Edit"),
wxStripMenuCodes(GetTranslatedString(trans, "E&dit\tCtrl+E"))
wxStripMenuCodes(GetTranslatedString(trans, "E&dit\tCtrl+E"), wxStrip_Menu)
);
// "Vie&w" also has a space before the (&W)
CPPUNIT_ASSERT_EQUAL
(
GetTranslatedString(trans, "View"),
wxStripMenuCodes(GetTranslatedString(trans, "Vie&w\tCtrl+V"))
wxStripMenuCodes(GetTranslatedString(trans, "Vie&w\tCtrl+V"), wxStrip_Menu)
);
// Test a 'normal' mnemonic too: the translation is "Preten&d"
CPPUNIT_ASSERT_EQUAL
(
"Pretend",
wxStripMenuCodes(GetTranslatedString(trans, "B&ogus"))
wxStripMenuCodes(GetTranslatedString(trans, "B&ogus"), wxStrip_Menu)
);
}
#endif // wxUSE_INTL