From: Vadim Zeitlin Date: Sun, 3 Oct 2010 17:34:15 +0000 (+0000) Subject: Fix non-ASCII key handling in wxGrid editors. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/6a1e8a634a09fa3ff09fe5190429f47e37b1930e?hp=2c5c9c27def1b8fa76fcec01e6c89e719ac13653 Fix non-ASCII key handling in wxGrid editors. Use wxKeyEvent::GetUnicodeKey() correctly, there is no need to guess about what does it return now that its correct behaviour is documented and implemented. Simply check if it returns WXK_NONE to check for non-characters. Also use WXK_START instead of hard-coded 255 when checking GetKeyCode() result. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65748 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/generic/grideditors.cpp b/src/generic/grideditors.cpp index a3cf424363..ef818831bb 100644 --- a/src/generic/grideditors.cpp +++ b/src/generic/grideditors.cpp @@ -338,13 +338,15 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event) bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event) { bool ctrl = event.ControlDown(); - bool alt = event.AltDown(); + bool alt; #ifdef __WXMAC__ // On the Mac the Alt key is more like shift and is used for entry of // valid characters, so check for Ctrl and Meta instead. alt = event.MetaDown(); -#endif +#else // !__WXMAC__ + alt = event.AltDown(); +#endif // __WXMAC__/!__WXMAC__ // Assume it's not a valid char if ctrl or alt is down, but if both are // down then it may be because of an AltGr key combination, so let them @@ -353,14 +355,10 @@ bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event) return false; #if wxUSE_UNICODE - // if the unicode key code is not really a unicode character (it may - // be a function key or etc., the platforms appear to always give us a - // small value in this case) then fallback to the ASCII key code but - // don't do anything for function keys or etc. - if ( event.GetUnicodeKey() > 127 && event.GetKeyCode() > 127 ) + if ( event.GetUnicodeKey() == WXK_NONE ) return false; #else - if ( event.GetKeyCode() > 255 ) + if ( event.GetKeyCode() > WXK_START ) return false; #endif @@ -530,7 +528,15 @@ void wxGridCellTextEditor::DoReset(const wxString& startValue) bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event) { - return wxGridCellEditor::IsAcceptedKey(event); + switch ( event.GetKeyCode() ) + { + case WXK_DELETE: + case WXK_BACK: + return true; + + default: + return wxGridCellEditor::IsAcceptedKey(event); + } } void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) @@ -544,13 +550,18 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) wxChar ch; long pos; + bool isPrintable; + #if wxUSE_UNICODE ch = event.GetUnicodeKey(); - if (ch <= 127) + if ( ch != WXK_NONE ) + isPrintable = true; + else +#endif // wxUSE_UNICODE + { ch = (wxChar)event.GetKeyCode(); -#else - ch = (wxChar)event.GetKeyCode(); -#endif + isPrintable = ch >= WXK_SPACE && ch < WXK_START; + } switch (ch) { @@ -569,7 +580,8 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event) break; default: - tc->WriteText(ch); + if ( isPrintable ) + tc->WriteText(ch); break; } }