Fixes to key codes in keyboard events generated by wxMSW.

Only set Unicode key code if the event corresponds to a character key and set
it to (newly added) WXK_NONE for the other ones to avoid nonsensical values in
it for e.g. "Home" key presses.

Also set non-Unicode key to WXK_NONE for the characters that can't be
represented in the current locale. This is consistent with wxGTK and avoids
conflicts between special key values and Unicode keys.

Clearly document the above behaviour.

Notice that implementing the correct behaviour in wxMSW involved untangling
previously interwoven WM_KEY{DOWN,UP} and WM_CHAR messages handlers. Clearly
separate them now as they get different input (key codes for the former,
characters for the latter) and especially don't try to convert from both kinds
of input using a single wxCharCodeMSWToWX() function. As this function doesn't
need to distinguish between keys and characters any more it can simply return
the converted value in all cases instead of returning 0 sometimes to indicate
a character value instead of a key. Simplify the code using this function
accordingly.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65522 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-09-11 10:18:47 +00:00
parent 86408a0374
commit b6885972ee
8 changed files with 184 additions and 110 deletions

View File

@@ -347,7 +347,7 @@ public:
bool HandleMouseMove(int x, int y, WXUINT flags);
bool HandleMouseWheel(WXWPARAM wParam, WXLPARAM lParam);
bool HandleChar(WXWPARAM wParam, WXLPARAM lParam, bool isASCII = false);
bool HandleChar(WXWPARAM wParam, WXLPARAM lParam);
bool HandleKeyDown(WXWPARAM wParam, WXLPARAM lParam);
bool HandleKeyUp(WXWPARAM wParam, WXLPARAM lParam);
#if wxUSE_ACCEL
@@ -571,9 +571,21 @@ protected:
const wxString& ttip);
#endif // wxUSE_TOOLTIPS
// the helper functions used by HandleChar/KeyXXX methods
wxKeyEvent CreateKeyEvent(wxEventType evType, int id,
WXLPARAM lParam = 0, WXWPARAM wParam = 0) const;
// This is used by CreateKeyEvent() and also for wxEVT_CHAR[_HOOK] event
// creation. Notice that this method doesn't initialize wxKeyEvent
// m_keyCode and m_uniChar fields.
void InitAnyKeyEvent(wxKeyEvent& event,
WXWPARAM wParam,
WXLPARAM lParam) const;
// Helper functions used by HandleKeyXXX() methods and some derived
// classes, wParam and lParam have the same meaning as in WM_KEY{DOWN,UP}.
//
// NB: evType here must be wxEVT_KEY_{DOWN,UP} as wParam here contains the
// virtual key code, not character!
wxKeyEvent CreateKeyEvent(wxEventType evType,
WXWPARAM wParam,
WXLPARAM lParam = 0) const;
// default OnEraseBackground() implementation, return true if we did erase
@@ -645,7 +657,15 @@ private:
// ---------------------------------------------------------------------------
// key codes translation between wx and MSW
WXDLLIMPEXP_CORE int wxCharCodeMSWToWX(int keySym, WXLPARAM lParam = 0);
// Translate MSW virtual key code to wx key code. lParam is used to distinguish
// between numpad and extended version of the keys, extended is assumed by
// default if lParam == 0.
WXDLLIMPEXP_CORE int wxCharCodeMSWToWX(WXWORD vk, WXLPARAM lParam = 0);
// Translate wxKeyCode enum element (passed as int for compatibility reasons)
// to MSW virtual key code. isExtended is set to true if the key corresponds to
// a non-numpad version of a key that exists both on numpad and outside it.
WXDLLIMPEXP_CORE WXWORD wxCharCodeWXToMSW(int id, bool *isExtended = NULL);
// window creation helper class: before creating a new HWND, instantiate an