diff --git a/include/wx/msw/private.h b/include/wx/msw/private.h index 262fc9ff80..da4b7e83ca 100644 --- a/include/wx/msw/private.h +++ b/include/wx/msw/private.h @@ -311,21 +311,32 @@ HCURSOR wxBitmapToHCURSOR(const wxBitmap& bmp, int hotSpotX, int hotSpotY); #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) #endif // GET_X_LPARAM -// get the current state of SHIFT/CTRL keys +// get the current state of SHIFT/CTRL/ALT keys +inline bool wxIsModifierDown(int vk) +{ + // GetKeyState() returns different negative values on WinME and WinNT, + // so simply test for negative value. + return ::GetKeyState(vk) < 0; +} + inline bool wxIsShiftDown() { -// return (::GetKeyState(VK_SHIFT) & 0x100) != 0; - // Returns different negative values on WinME and WinNT, - // so simply test for negative value. - return ::GetKeyState(VK_SHIFT) < 0; + return wxIsModifierDown(VK_SHIFT); } inline bool wxIsCtrlDown() { -// return (::GetKeyState(VK_CONTROL) & 0x100) != 0; - // Returns different negative values on WinME and WinNT, - // so simply test for negative value. - return ::GetKeyState(VK_CONTROL) < 0; + return wxIsModifierDown(VK_CONTROL); +} + +inline bool wxIsAltDown() +{ + return wxIsModifierDown(VK_MENU); +} + +inline bool wxIsAnyModifierDown() +{ + return wxIsShiftDown() || wxIsCtrlDown() || wxIsAltDown(); } // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 1f67a95bbc..281d6c9efb 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -1806,17 +1806,14 @@ bool wxListCtrl::MSWShouldPreProcessMessage(WXMSG* msg) { if ( msg->message == WM_KEYDOWN ) { - if ( msg->wParam == VK_RETURN ) + // Only eat VK_RETURN if not being used by the application in + // conjunction with modifiers + if ( msg->wParam == VK_RETURN && !wxIsAnyModifierDown() ) { - // We need VK_RETURN to generate wxEVT_COMMAND_LIST_ITEM_ACTIVATED, - // but only if none of the modifiers is down. We'll let normal - // accelerators handle those. - if ( !wxIsCtrlDown() && !wxIsCtrlDown() && - !((HIWORD(msg->lParam) & KF_ALTDOWN) == KF_ALTDOWN)) + // we need VK_RETURN to generate wxEVT_COMMAND_LIST_ITEM_ACTIVATED return false; } } - return wxControl::MSWShouldPreProcessMessage(msg); } diff --git a/src/msw/treectrl.cpp b/src/msw/treectrl.cpp index 20d027fbcd..63019b5e22 100644 --- a/src/msw/treectrl.cpp +++ b/src/msw/treectrl.cpp @@ -1948,11 +1948,9 @@ bool wxTreeCtrl::MSWShouldPreProcessMessage(WXMSG* msg) { if ( msg->message == WM_KEYDOWN ) { - const bool isAltDown = ::GetKeyState(VK_MENU) < 0; - - // Only eat VK_RETURN if not being used by the application in conjunction with - // modifiers - if ( msg->wParam == VK_RETURN && !wxIsCtrlDown() && !wxIsShiftDown() && !isAltDown) + // Only eat VK_RETURN if not being used by the application in + // conjunction with modifiers + if ( (msg->wParam == VK_RETURN) && !wxIsAnyModifierDown() ) { // we need VK_RETURN to generate wxEVT_COMMAND_TREE_ITEM_ACTIVATED return false; @@ -2607,8 +2605,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) // fabricate the lParam and wParam parameters sufficiently // similar to the ones from a "real" WM_KEYDOWN so that // CreateKeyEvent() works correctly - const bool isAltDown = ::GetKeyState(VK_MENU) < 0; - WXLPARAM lParam = (isAltDown ? KF_ALTDOWN : 0) << 16; + WXLPARAM lParam = (wxIsAltDown() ? KF_ALTDOWN : 0) << 16; WXWPARAM wParam = info->wVKey; @@ -2626,7 +2623,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) wParam); // a separate event for Space/Return - if ( !wxIsCtrlDown() && !wxIsShiftDown() && !isAltDown && + if ( !wxIsAnyModifierDown() && ((info->wVKey == VK_SPACE) || (info->wVKey == VK_RETURN)) ) { wxTreeItemId item; diff --git a/src/msw/window.cpp b/src/msw/window.cpp index dbf35ef999..d8be1a890b 100644 --- a/src/msw/window.cpp +++ b/src/msw/window.cpp @@ -5020,7 +5020,7 @@ void wxWindowMSW::InitMouseEvent(wxMouseEvent& event, event.m_aux1Down = (flags & MK_XBUTTON1) != 0; event.m_aux2Down = (flags & MK_XBUTTON2) != 0; #endif // wxHAS_XBUTTON - event.m_altDown = ::GetKeyState(VK_MENU) < 0; + event.m_altDown = ::wxIsAltDown(); #ifndef __WXWINCE__ event.SetTimestamp(::GetMessageTime()); @@ -6061,9 +6061,9 @@ wxMouseState wxGetMouseState() ms.SetAux2Down(wxIsKeyDown(VK_XBUTTON2)); #endif // wxHAS_XBUTTON - ms.SetControlDown(wxIsKeyDown(VK_CONTROL)); - ms.SetShiftDown(wxIsKeyDown(VK_SHIFT)); - ms.SetAltDown(wxIsKeyDown(VK_MENU)); + ms.SetControlDown(wxIsCtrlDown ()); + ms.SetShiftDown (wxIsShiftDown()); + ms.SetAltDown (wxIsAltDown ()); // ms.SetMetaDown(); return ms;