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
This commit is contained in:
@@ -338,13 +338,15 @@ void wxGridCellEditor::HandleReturn(wxKeyEvent& event)
|
|||||||
bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
|
bool wxGridCellEditor::IsAcceptedKey(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
bool ctrl = event.ControlDown();
|
bool ctrl = event.ControlDown();
|
||||||
bool alt = event.AltDown();
|
bool alt;
|
||||||
|
|
||||||
#ifdef __WXMAC__
|
#ifdef __WXMAC__
|
||||||
// On the Mac the Alt key is more like shift and is used for entry of
|
// 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.
|
// valid characters, so check for Ctrl and Meta instead.
|
||||||
alt = event.MetaDown();
|
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
|
// 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
|
// 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;
|
return false;
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
// if the unicode key code is not really a unicode character (it may
|
if ( event.GetUnicodeKey() == WXK_NONE )
|
||||||
// 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 )
|
|
||||||
return false;
|
return false;
|
||||||
#else
|
#else
|
||||||
if ( event.GetKeyCode() > 255 )
|
if ( event.GetKeyCode() > WXK_START )
|
||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -530,8 +528,16 @@ void wxGridCellTextEditor::DoReset(const wxString& startValue)
|
|||||||
|
|
||||||
bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event)
|
bool wxGridCellTextEditor::IsAcceptedKey(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
|
switch ( event.GetKeyCode() )
|
||||||
|
{
|
||||||
|
case WXK_DELETE:
|
||||||
|
case WXK_BACK:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
return wxGridCellEditor::IsAcceptedKey(event);
|
return wxGridCellEditor::IsAcceptedKey(event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
|
void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
|
||||||
{
|
{
|
||||||
@@ -544,13 +550,18 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
|
|||||||
wxChar ch;
|
wxChar ch;
|
||||||
long pos;
|
long pos;
|
||||||
|
|
||||||
|
bool isPrintable;
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
ch = event.GetUnicodeKey();
|
ch = event.GetUnicodeKey();
|
||||||
if (ch <= 127)
|
if ( ch != WXK_NONE )
|
||||||
|
isPrintable = true;
|
||||||
|
else
|
||||||
|
#endif // wxUSE_UNICODE
|
||||||
|
{
|
||||||
ch = (wxChar)event.GetKeyCode();
|
ch = (wxChar)event.GetKeyCode();
|
||||||
#else
|
isPrintable = ch >= WXK_SPACE && ch < WXK_START;
|
||||||
ch = (wxChar)event.GetKeyCode();
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (ch)
|
switch (ch)
|
||||||
{
|
{
|
||||||
@@ -569,6 +580,7 @@ void wxGridCellTextEditor::StartingKey(wxKeyEvent& event)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
if ( isPrintable )
|
||||||
tc->WriteText(ch);
|
tc->WriteText(ch);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user