Simplify wxKeyEvent generation in wxGTK a bit
Try to make the code generating key events a bit more clear and also avoid duplicating the checks in AdjustCharEventKeyCodes() by returning true from this function if the key code passed them. This shouldn't result in any real changes in behaviour. Closes #23452.
This commit is contained in:
parent
83773cec9a
commit
1506d46a1d
1 changed files with 15 additions and 14 deletions
|
|
@ -1267,9 +1267,13 @@ bool SendCharHookEvent(const wxKeyEvent& event, wxWindow *win)
|
|||
// Adjust wxEVT_CHAR event key code fields. This function takes care of two
|
||||
// conventions:
|
||||
// (a) Ctrl-letter key presses generate key codes in range 1..26
|
||||
// (b) Unicode key codes are same as key codes for the codes in 1..255 range
|
||||
void AdjustCharEventKeyCodes(wxKeyEvent& event)
|
||||
// (b) Unicode key codes are same as key codes for the codes in ASCII range
|
||||
//
|
||||
// Return true if the key code was modified.
|
||||
bool AdjustCharEventKeyCodes(wxKeyEvent& event)
|
||||
{
|
||||
bool modified = false;
|
||||
|
||||
const int code = event.m_keyCode;
|
||||
|
||||
// Check for (a) above.
|
||||
|
|
@ -1285,14 +1289,22 @@ void AdjustCharEventKeyCodes(wxKeyEvent& event)
|
|||
|
||||
// Adjust the Unicode equivalent in the same way too.
|
||||
if ( event.m_keyCode != code )
|
||||
{
|
||||
event.m_uniChar = event.m_keyCode;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for (b) from above.
|
||||
//
|
||||
// FIXME: Should we do it for key codes up to 255?
|
||||
if ( !event.m_uniChar && code < WXK_DELETE )
|
||||
{
|
||||
event.m_uniChar = code;
|
||||
modified = true;
|
||||
}
|
||||
|
||||
return modified;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
|
|
@ -1412,16 +1424,7 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget),
|
|||
{
|
||||
wxKeyEvent eventChar(wxEVT_CHAR, event);
|
||||
|
||||
// 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')) )
|
||||
{
|
||||
eventChar.m_keyCode = event.m_keyCode;
|
||||
eventChar.m_uniChar = event.m_uniChar;
|
||||
}
|
||||
else
|
||||
if ( !AdjustCharEventKeyCodes(eventChar) )
|
||||
{
|
||||
// use Unicode values
|
||||
eventChar.m_keyCode = key_code;
|
||||
|
|
@ -1430,8 +1433,6 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget),
|
|||
|
||||
wxLogTrace(TRACE_KEYS, wxT("Char event: %ld"), eventChar.m_keyCode);
|
||||
|
||||
AdjustCharEventKeyCodes(eventChar);
|
||||
|
||||
ret = win->HandleWindowEvent(eventChar);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue