Skip to content

Commit 8501523

Browse files
authored
[COMCTL32][WINESYNC] Fix keyboard-driven item selection (reactos#8437)
CORE-20210 comctl32/listview: Do not consider key state when navigating with alphanumeric keys. For example holding down Shift and using letter keys shouldn't produce a selection range. Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=58275 Signed-off-by: Nikolay Sivov <[email protected]> wine commit id 3b06cc75849240a6ba4f6d0435710f152e2188e5 by Nikolay Sivov <[email protected]>
1 parent 9ab2b1b commit 8501523

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

dll/win32/comctl32/listview.c

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ typedef struct tagLISTVIEW_INFO
426426

427427
static const WCHAR themeClass[] = {'L','i','s','t','V','i','e','w',0};
428428

429+
enum key_state
430+
{
431+
SHIFT_KEY = 0x1,
432+
CTRL_KEY = 0x2,
433+
SPACE_KEY = 0x4,
434+
};
435+
429436
/*
430437
* forward declarations
431438
*/
@@ -439,7 +446,7 @@ static BOOL LISTVIEW_GetViewRect(const LISTVIEW_INFO *, LPRECT);
439446
static void LISTVIEW_UpdateSize(LISTVIEW_INFO *);
440447
static LRESULT LISTVIEW_Command(LISTVIEW_INFO *, WPARAM, LPARAM);
441448
static INT LISTVIEW_GetStringWidthT(const LISTVIEW_INFO *, LPCWSTR, BOOL);
442-
static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *, INT, BOOL);
449+
static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *, INT, DWORD);
443450
static UINT LISTVIEW_GetItemState(const LISTVIEW_INFO *, INT, UINT);
444451
static BOOL LISTVIEW_SetItemState(LISTVIEW_INFO *, INT, const LVITEMW *);
445452
static LRESULT LISTVIEW_VScroll(LISTVIEW_INFO *, INT, INT);
@@ -1989,7 +1996,7 @@ static INT LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO *infoPtr, WPARAM charCode, L
19891996
}
19901997

19911998
if (nItem != -1)
1992-
LISTVIEW_KeySelection(infoPtr, nItem, FALSE);
1999+
LISTVIEW_KeySelection(infoPtr, nItem, 0);
19932000

19942001
return 0;
19952002
}
@@ -3815,24 +3822,11 @@ static void LISTVIEW_SetSelection(LISTVIEW_INFO *infoPtr, INT nItem)
38153822
infoPtr->nSelectionMark = nItem;
38163823
}
38173824

3818-
/***
3819-
* DESCRIPTION:
3820-
* Set selection(s) with keyboard.
3821-
*
3822-
* PARAMETER(S):
3823-
* [I] infoPtr : valid pointer to the listview structure
3824-
* [I] nItem : item index
3825-
* [I] space : VK_SPACE code sent
3826-
*
3827-
* RETURN:
3828-
* SUCCESS : TRUE (needs to be repainted)
3829-
* FAILURE : FALSE (nothing has changed)
3830-
*/
3831-
static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *infoPtr, INT nItem, BOOL space)
3825+
/* Change item selection with key input. */
3826+
static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *infoPtr, INT nItem, DWORD keys)
38323827
{
3833-
/* FIXME: pass in the state */
3834-
WORD wShift = GetKeyState(VK_SHIFT) & 0x8000;
3835-
WORD wCtrl = GetKeyState(VK_CONTROL) & 0x8000;
3828+
WORD wShift = !!(keys & SHIFT_KEY);
3829+
WORD wCtrl = !!(keys & CTRL_KEY);
38363830
BOOL bResult = FALSE;
38373831

38383832
TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem, wShift, wCtrl);
@@ -3851,7 +3845,7 @@ static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *infoPtr, INT nItem, BOOL space)
38513845
LVITEMW lvItem;
38523846
lvItem.state = ~LISTVIEW_GetItemState(infoPtr, nItem, LVIS_SELECTED);
38533847
lvItem.stateMask = LVIS_SELECTED;
3854-
if (space)
3848+
if (keys & SPACE_KEY)
38553849
{
38563850
LISTVIEW_SetItemState(infoPtr, nItem, &lvItem);
38573851
if (lvItem.state & LVIS_SELECTED)
@@ -10223,7 +10217,18 @@ static LRESULT LISTVIEW_KeyDown(LISTVIEW_INFO *infoPtr, INT nVirtualKey, LONG lK
1022310217
}
1022410218

1022510219
if ((nItem != -1) && (nItem != infoPtr->nFocusedItem || nVirtualKey == VK_SPACE))
10226-
LISTVIEW_KeySelection(infoPtr, nItem, nVirtualKey == VK_SPACE);
10220+
{
10221+
DWORD keys = 0;
10222+
10223+
if (GetKeyState(VK_SHIFT) & 0x8000)
10224+
keys |= SHIFT_KEY;
10225+
if (GetKeyState(VK_CONTROL) & 0x8000)
10226+
keys |= CTRL_KEY;
10227+
if (nVirtualKey == VK_SPACE)
10228+
keys |= SPACE_KEY;
10229+
10230+
LISTVIEW_KeySelection(infoPtr, nItem, keys);
10231+
}
1022710232

1022810233
return 0;
1022910234
}

0 commit comments

Comments
 (0)