Better checks for wxMSWKeyboard::VKToWX() return value.

Don't generate key events without any valid key code (this shouldn't normally
happen but might on exotic keyboards with keys that we don't know about).

Also ensure that we can distinguish between VKToWX() returning dead keys and
non-Latin-1 keys by setting wchar_t output parameter to WXK_NONE too in the
former case but not the latter.

Generate wxEVT_CHAR_HOOK events for non-Latin-1 keys too in Unicode build.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65590 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-09-22 13:31:41 +00:00
parent 246117d444
commit 033428a32c
2 changed files with 32 additions and 26 deletions

View File

@@ -27,8 +27,9 @@ namespace wxMSWKeyboard
// default if lParam == 0. // default if lParam == 0.
// //
// Returns WXK_NONE if translation couldn't be done at all (this happens e.g. // Returns WXK_NONE if translation couldn't be done at all (this happens e.g.
// for dead keys) or if the key corresponds to a non-ASCII character in which // for dead keys and in this case uc will be WXK_NONE too) or if the key
// case uc is filled with its Unicode value. // corresponds to a non-Latin-1 character in which case uc is filled with its
// Unicode value.
WXDLLIMPEXP_CORE int VKToWX(WXWORD vk, WXLPARAM lParam = 0, wchar_t *uc = NULL); WXDLLIMPEXP_CORE int VKToWX(WXWORD vk, WXLPARAM lParam = 0, wchar_t *uc = NULL);
// Translate wxKeyCode enum element (passed as int for compatibility reasons) // Translate wxKeyCode enum element (passed as int for compatibility reasons)

View File

@@ -3233,6 +3233,10 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l
wParam, wParam,
lParam | (KF_EXTENDED << 16) lParam | (KF_EXTENDED << 16)
); );
// Don't produce events without any valid character
// code (even if this shouldn't normally happen...).
if ( event.m_keyCode != WXK_NONE )
processed = HandleWindowEvent(event); processed = HandleWindowEvent(event);
} }
} }
@@ -6244,8 +6248,7 @@ int VKToWX(WXWORD vk, WXLPARAM lParam, wchar_t *uc)
// good idea. // good idea.
wxk = WXK_NONE; wxk = WXK_NONE;
} }
else // Not a dead key.
{
// In any case return this as a Unicode character value. // In any case return this as a Unicode character value.
if ( uc ) if ( uc )
*uc = wxk; *uc = wxk;
@@ -6263,8 +6266,6 @@ int VKToWX(WXWORD vk, WXLPARAM lParam, wchar_t *uc)
// "LATIN CAPITAL LETTER I WITH BREVE"). // "LATIN CAPITAL LETTER I WITH BREVE").
wxk = WXK_NONE; wxk = WXK_NONE;
} }
//
}
break; break;
// handle extended keys // handle extended keys
@@ -6320,14 +6321,14 @@ int VKToWX(WXWORD vk, WXLPARAM lParam, wchar_t *uc)
// A simple alphanumeric key and the values of them coincide in // A simple alphanumeric key and the values of them coincide in
// Windows and wx for both ASCII and Unicode codes. // Windows and wx for both ASCII and Unicode codes.
wxk = vk; wxk = vk;
if ( uc )
*uc = vk;
} }
else // Something we simply don't know about at all. else // Something we simply don't know about at all.
{ {
wxk = WXK_NONE; wxk = WXK_NONE;
} }
if ( uc )
*uc = vk;
} }
return wxk; return wxk;
@@ -6599,7 +6600,11 @@ wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
{ {
wchar_t uc; wchar_t uc;
int id = wxMSWKeyboard::VKToWX(wParam, lParam, &uc); int id = wxMSWKeyboard::VKToWX(wParam, lParam, &uc);
if ( id != WXK_NONE ) if ( id != WXK_NONE
#if wxUSE_UNICODE
|| uc != WXK_NONE
#endif // wxUSE_UNICODE
)
{ {
const wxWindow * const win = wxGetActiveWindow(); const wxWindow * const win = wxGetActiveWindow();