diff --git a/include/wx/msw/private/keyboard.h b/include/wx/msw/private/keyboard.h new file mode 100644 index 0000000000..5bc8cc7445 --- /dev/null +++ b/include/wx/msw/private/keyboard.h @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////////// +// Name: wx/msw/private/keyboard.h +// Purpose: Helper keyboard-related functions. +// Author: Vadim Zeitlin +// Created: 2010-09-09 +// RCS-ID: $Id: wxhead.h,v 1.12 2010-04-22 12:44:51 zeitlin Exp $ +// Copyright: (c) 2010 Vadim Zeitlin +// Licence: wxWindows licence +/////////////////////////////////////////////////////////////////////////////// + +#ifndef _WX_MSW_PRIVATE_KEYBOARD_H_ +#define _WX_MSW_PRIVATE_KEYBOARD_H_ + +#include "wx/defs.h" + +namespace wxMSWKeyboard +{ + +// ---------------------------------------------------------------------------- +// Functions for translating between MSW virtual keys codes and wx key codes +// +// These functions are currently implemented in src/msw/window.cpp. +// ---------------------------------------------------------------------------- + +// 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 VKToWX(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 WXToVK(int id, bool *isExtended = NULL); + +} // namespace wxMSWKeyboard + +#endif // _WX_MSW_PRIVATE_KEYBOARD_H_ diff --git a/include/wx/msw/window.h b/include/wx/msw/window.h index fe5dc28d9e..64b95f9cd5 100644 --- a/include/wx/msw/window.h +++ b/include/wx/msw/window.h @@ -648,26 +648,6 @@ private: DECLARE_EVENT_TABLE() }; -// ---------------------------------------------------------------------------- -// inline functions -// ---------------------------------------------------------------------------- - -// --------------------------------------------------------------------------- -// global functions -// --------------------------------------------------------------------------- - -// key codes translation between wx and MSW - -// 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 // object of this class on stack - this allows to process the messages sent to // the window even before CreateWindow() returns diff --git a/src/msw/accel.cpp b/src/msw/accel.cpp index f3e2f10c7f..cce31919c2 100644 --- a/src/msw/accel.cpp +++ b/src/msw/accel.cpp @@ -33,6 +33,7 @@ #include "wx/accel.h" #include "wx/msw/private.h" +#include "wx/msw/private/keyboard.h" IMPLEMENT_DYNAMIC_CLASS(wxAcceleratorTable, wxObject) @@ -111,7 +112,7 @@ wxAcceleratorTable::wxAcceleratorTable(int n, const wxAcceleratorEntry entries[] if ( flags & wxACCEL_CTRL ) fVirt |= FCONTROL; - WORD key = wxCharCodeWXToMSW(entries[i].GetKeyCode()); + WORD key = wxMSWKeyboard::WXToVK(entries[i].GetKeyCode()); arr[i].fVirt = fVirt; arr[i].key = key; diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index f5a7a6a75f..6e526f3784 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -42,6 +42,7 @@ #include "wx/vector.h" #include "wx/msw/private.h" +#include "wx/msw/private/keyboard.h" #if defined(__WXWINCE__) && !defined(__HANDHELDPC__) #include @@ -2340,7 +2341,7 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) { eventType = wxEVT_COMMAND_LIST_KEY_DOWN; - event.m_code = wxCharCodeMSWToWX(wVKey); + event.m_code = wxMSWKeyboard::VKToWX(wVKey); } event.m_itemIndex = diff --git a/src/msw/uiaction.cpp b/src/msw/uiaction.cpp index ee59fd0603..eb5bfd1e34 100644 --- a/src/msw/uiaction.cpp +++ b/src/msw/uiaction.cpp @@ -16,9 +16,10 @@ #if wxUSE_UIACTIONSIMULATOR #include "wx/uiaction.h" -#include "wx/window.h" //for wxCharCodeWXToMSW #include "wx/msw/wrapwin.h" +#include "wx/msw/private/keyboard.h" + namespace { @@ -75,7 +76,7 @@ bool wxUIActionSimulator::DoKey(int keycode, int WXUNUSED(modifiers), bool isDown) { bool isExtended; - DWORD vkkeycode = wxCharCodeWXToMSW(keycode, &isExtended); + DWORD vkkeycode = wxMSWKeyboard::WXToVK(keycode, &isExtended); DWORD flags = 0; if ( isExtended ) diff --git a/src/msw/window.cpp b/src/msw/window.cpp index 4bcb4b22a6..d389407b70 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -79,6 +79,7 @@ #endif #include "wx/msw/private.h" +#include "wx/msw/private/keyboard.h" #include "wx/msw/dcclient.h" #if wxUSE_TOOLTIPS @@ -3223,7 +3224,7 @@ WXLRESULT wxWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM l // generate CHAR events with WXK_HOME and not // WXK_NUMPAD_HOME even if the "Home" key on numpad was // pressed. - event.m_keyCode = wxCharCodeMSWToWX + event.m_keyCode = wxMSWKeyboard::VKToWX ( wParam, lParam | (KF_EXTENDED << 16) @@ -5664,7 +5665,7 @@ wxWindowMSW::CreateKeyEvent(wxEventType evType, wxKeyEvent event(evType); InitAnyKeyEvent(event, wParam, lParam); - event.m_keyCode = wxCharCodeMSWToWX(wParam, lParam); + event.m_keyCode = wxMSWKeyboard::VKToWX(wParam, lParam); #if wxUSE_UNICODE if ( event.m_keyCode < WXK_START ) { @@ -6054,6 +6055,13 @@ void wxGetCharSize(WXHWND wnd, int *x, int *y, const wxFont& the_font) // the_font.ReleaseResource(); } +// ---------------------------------------------------------------------------- +// keyboard codes +// ---------------------------------------------------------------------------- + +namespace wxMSWKeyboard +{ + namespace { @@ -6070,7 +6078,7 @@ int ChooseNormalOrExtended(int lParam, int keyNormal, int keyExtended) } // this array contains the Windows virtual key codes which map one to one to -// WXK_xxx constants and is used in wxCharCodeMSWToWX/WXToMSW() below +// WXK_xxx constants and is used in wxMSWKeyboard::VKToWX/WXToVK() below // // note that keys having a normal and numpad version (e.g. WXK_HOME and // WXK_NUMPAD_HOME) are not included in this table as the mapping is not 1-to-1 @@ -6150,7 +6158,7 @@ const struct wxKeyMapping } // anonymous namespace -int wxCharCodeMSWToWX(WXWORD vk, WXLPARAM lParam) +int VKToWX(WXWORD vk, WXLPARAM lParam) { // check the table first for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ ) @@ -6233,7 +6241,7 @@ int wxCharCodeMSWToWX(WXWORD vk, WXLPARAM lParam) return wxk; } -WXWORD wxCharCodeWXToMSW(int wxk, bool *isExtended) +WXWORD WXToVK(int wxk, bool *isExtended) { // check the table first for ( size_t n = 0; n < WXSIZEOF(gs_specialKeys); n++ ) @@ -6338,6 +6346,8 @@ WXWORD wxCharCodeWXToMSW(int wxk, bool *isExtended) return vk; } +} // namespace wxMSWKeyboard + // small helper for wxGetKeyState() and wxGetMouseState() static inline bool wxIsKeyDown(WXWORD vk) { @@ -6370,7 +6380,7 @@ bool wxGetKeyState(wxKeyCode key) key != VK_MBUTTON, wxT("can't use wxGetKeyState() for mouse buttons") ); - const WXWORD vk = wxCharCodeWXToMSW(key); + const WXWORD vk = wxMSWKeyboard::WXToVK(key); // if the requested key is a LED key, return true if the led is pressed if ( key == WXK_NUMLOCK || key == WXK_CAPITAL || key == WXK_SCROLL ) @@ -6495,7 +6505,7 @@ wxKeyboardHook(int nCode, WORD wParam, DWORD lParam) DWORD hiWord = HIWORD(lParam); if ( nCode != HC_NOREMOVE && ((hiWord & KF_UP) == 0) ) { - int id = wxCharCodeMSWToWX(wParam, lParam); + int id = wxMSWKeyboard::VKToWX(wParam, lParam); if ( id >= WXK_START ) { wxKeyEvent event(wxEVT_CHAR_HOOK);