Improve code in gtk_window_key_press_callback()

Don't use isalpha() in it as this was potentially incorrect, both
because the key code could be not in the supported range and because
isalpha() might return unexpected result in non C locale, and also
inconsistent with AdjustCharEventKeyCodes().

Just check that the code is in a..z or A..Z range explicitly instead.

See #23379.
This commit is contained in:
Vadim Zeitlin 2023-04-08 16:26:53 +02:00
parent 435efa8b5a
commit 4799785b6d

View file

@ -1413,9 +1413,12 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget),
{
wxKeyEvent eventChar(wxEVT_CHAR, event);
if ( event.ControlDown() && isalpha(event.m_keyCode) )
// Check for the special case of Ctrl+letter, see comment before
// AdjustCharEventKeyCodes().
if ( event.ControlDown() &&
((event.m_keyCode >= 'a' && event.m_keyCode <= 'z') ||
(event.m_keyCode >= 'A' && event.m_keyCode <= 'Z')) )
{
// Ctrl+letter is handled specially by AdjustCharEventKeyCodes().
eventChar.m_keyCode = event.m_keyCode;
eventChar.m_uniChar = event.m_uniChar;
}