no real changes, just some cleanup: add wxIsAltDown() in addition to the existing wxIsShift/CtrlDown() and wxIsAnyModifiedDown() to test for all of them at once (slightly modified patch 1833235)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50013 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2007-11-17 00:24:07 +00:00
parent d04a9fdfe2
commit 6719c06a97
4 changed files with 33 additions and 28 deletions

View File

@@ -311,21 +311,32 @@ HCURSOR wxBitmapToHCURSOR(const wxBitmap& bmp, int hotSpotX, int hotSpotY);
#define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp)) #define GET_Y_LPARAM(lp) ((int)(short)HIWORD(lp))
#endif // GET_X_LPARAM #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() inline bool wxIsShiftDown()
{ {
// return (::GetKeyState(VK_SHIFT) & 0x100) != 0; return wxIsModifierDown(VK_SHIFT);
// Returns different negative values on WinME and WinNT,
// so simply test for negative value.
return ::GetKeyState(VK_SHIFT) < 0;
} }
inline bool wxIsCtrlDown() inline bool wxIsCtrlDown()
{ {
// return (::GetKeyState(VK_CONTROL) & 0x100) != 0; return wxIsModifierDown(VK_CONTROL);
// Returns different negative values on WinME and WinNT, }
// so simply test for negative value.
return ::GetKeyState(VK_CONTROL) < 0; inline bool wxIsAltDown()
{
return wxIsModifierDown(VK_MENU);
}
inline bool wxIsAnyModifierDown()
{
return wxIsShiftDown() || wxIsCtrlDown() || wxIsAltDown();
} }
// wrapper around GetWindowRect() and GetClientRect() APIs doing error checking // wrapper around GetWindowRect() and GetClientRect() APIs doing error checking

View File

@@ -1806,17 +1806,14 @@ bool wxListCtrl::MSWShouldPreProcessMessage(WXMSG* msg)
{ {
if ( msg->message == WM_KEYDOWN ) 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, // 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))
return false; return false;
} }
} }
return wxControl::MSWShouldPreProcessMessage(msg); return wxControl::MSWShouldPreProcessMessage(msg);
} }

View File

@@ -1948,11 +1948,9 @@ bool wxTreeCtrl::MSWShouldPreProcessMessage(WXMSG* msg)
{ {
if ( msg->message == WM_KEYDOWN ) 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
// Only eat VK_RETURN if not being used by the application in conjunction with if ( (msg->wParam == VK_RETURN) && !wxIsAnyModifierDown() )
// modifiers
if ( msg->wParam == VK_RETURN && !wxIsCtrlDown() && !wxIsShiftDown() && !isAltDown)
{ {
// we need VK_RETURN to generate wxEVT_COMMAND_TREE_ITEM_ACTIVATED // we need VK_RETURN to generate wxEVT_COMMAND_TREE_ITEM_ACTIVATED
return false; return false;
@@ -2607,8 +2605,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
// fabricate the lParam and wParam parameters sufficiently // fabricate the lParam and wParam parameters sufficiently
// similar to the ones from a "real" WM_KEYDOWN so that // similar to the ones from a "real" WM_KEYDOWN so that
// CreateKeyEvent() works correctly // CreateKeyEvent() works correctly
const bool isAltDown = ::GetKeyState(VK_MENU) < 0; WXLPARAM lParam = (wxIsAltDown() ? KF_ALTDOWN : 0) << 16;
WXLPARAM lParam = (isAltDown ? KF_ALTDOWN : 0) << 16;
WXWPARAM wParam = info->wVKey; WXWPARAM wParam = info->wVKey;
@@ -2626,7 +2623,7 @@ bool wxTreeCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result)
wParam); wParam);
// a separate event for Space/Return // a separate event for Space/Return
if ( !wxIsCtrlDown() && !wxIsShiftDown() && !isAltDown && if ( !wxIsAnyModifierDown() &&
((info->wVKey == VK_SPACE) || (info->wVKey == VK_RETURN)) ) ((info->wVKey == VK_SPACE) || (info->wVKey == VK_RETURN)) )
{ {
wxTreeItemId item; wxTreeItemId item;

View File

@@ -5020,7 +5020,7 @@ void wxWindowMSW::InitMouseEvent(wxMouseEvent& event,
event.m_aux1Down = (flags & MK_XBUTTON1) != 0; event.m_aux1Down = (flags & MK_XBUTTON1) != 0;
event.m_aux2Down = (flags & MK_XBUTTON2) != 0; event.m_aux2Down = (flags & MK_XBUTTON2) != 0;
#endif // wxHAS_XBUTTON #endif // wxHAS_XBUTTON
event.m_altDown = ::GetKeyState(VK_MENU) < 0; event.m_altDown = ::wxIsAltDown();
#ifndef __WXWINCE__ #ifndef __WXWINCE__
event.SetTimestamp(::GetMessageTime()); event.SetTimestamp(::GetMessageTime());
@@ -6061,9 +6061,9 @@ wxMouseState wxGetMouseState()
ms.SetAux2Down(wxIsKeyDown(VK_XBUTTON2)); ms.SetAux2Down(wxIsKeyDown(VK_XBUTTON2));
#endif // wxHAS_XBUTTON #endif // wxHAS_XBUTTON
ms.SetControlDown(wxIsKeyDown(VK_CONTROL)); ms.SetControlDown(wxIsCtrlDown ());
ms.SetShiftDown(wxIsKeyDown(VK_SHIFT)); ms.SetShiftDown (wxIsShiftDown());
ms.SetAltDown(wxIsKeyDown(VK_MENU)); ms.SetAltDown (wxIsAltDown ());
// ms.SetMetaDown(); // ms.SetMetaDown();
return ms; return ms;