comctl32/listview: Properly update selection mark on item state change.

This commit is contained in:
Nikolay Sivov 2012-06-09 12:15:16 +04:00 committed by Alexandre Julliard
parent 7f57141078
commit 6560d88151
2 changed files with 130 additions and 2 deletions

View File

@ -6,7 +6,7 @@
* Copyright 2000 Jason Mawdsley
* Copyright 2001 CodeWeavers Inc.
* Copyright 2002 Dimitrie O. Paun
* Copyright 2009-2011 Nikolay Sivov
* Copyright 2009-2012 Nikolay Sivov
* Copyright 2009 Owen Rudge for CodeWeavers
*
* This library is free software; you can redistribute it and/or
@ -4276,6 +4276,10 @@ static BOOL set_main_item(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem, BOOL
{
if (lpLVItem->state & LVIS_FOCUSED)
{
/* update selection mark */
if (infoPtr->nFocusedItem == -1 && infoPtr->nSelectionMark == -1)
infoPtr->nSelectionMark = lpLVItem->iItem;
if (infoPtr->nFocusedItem != -1)
{
/* remove current focus */

View File

@ -2090,7 +2090,6 @@ static void test_multiselect(void)
{ "using VK_HOME", -1, VK_HOME, 1, -1 }
};
hwnd = create_listview_control(LVS_REPORT);
for (i=0;i<items;i++) {
@ -2237,6 +2236,131 @@ static void test_multiselect(void)
r = ListView_GetSelectedCount(hwnd);
expect(0, r);
/* 1. selection mark is update when new focused item is set */
style = GetWindowLongPtrA(hwnd, GWL_STYLE);
SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
expect(-1, r);
item.stateMask = LVIS_FOCUSED;
item.state = LVIS_FOCUSED;
r = SendMessage(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(0, r);
/* it's not updated if already set */
item.stateMask = LVIS_FOCUSED;
item.state = LVIS_FOCUSED;
r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(0, r);
r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
expect(0, r);
item.stateMask = LVIS_FOCUSED;
item.state = LVIS_FOCUSED;
r = SendMessage(hwnd, LVM_SETITEMSTATE, 1, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(-1, r);
/* need to reset focused item first */
item.stateMask = LVIS_FOCUSED;
item.state = 0;
r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
expect(TRUE, r);
item.stateMask = LVIS_FOCUSED;
item.state = LVIS_FOCUSED;
r = SendMessage(hwnd, LVM_SETITEMSTATE, 2, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(2, r);
item.stateMask = LVIS_FOCUSED;
item.state = 0;
r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(2, r);
/* 2. same tests, with LVM_SETITEM */
style = GetWindowLongPtrA(hwnd, GWL_STYLE);
SetWindowLongPtrA(hwnd, GWL_STYLE, style & ~LVS_SINGLESEL);
r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
expect(2, r);
item.stateMask = LVIS_FOCUSED;
item.state = LVIS_FOCUSED;
item.mask = LVIF_STATE;
item.iItem = item.iSubItem = 0;
r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(0, r);
/* it's not updated if already set */
item.stateMask = LVIS_FOCUSED;
item.state = LVIS_FOCUSED;
item.mask = LVIF_STATE;
item.iItem = 1;
item.iSubItem = 0;
r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(0, r);
r = SendMessage(hwnd, LVM_SETSELECTIONMARK, 0, -1);
expect(0, r);
item.stateMask = LVIS_FOCUSED;
item.state = LVIS_FOCUSED;
item.mask = LVIF_STATE;
item.iItem = 1;
item.iSubItem = 0;
r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(-1, r);
/* need to reset focused item first */
item.stateMask = LVIS_FOCUSED;
item.state = 0;
r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
expect(TRUE, r);
item.stateMask = LVIS_FOCUSED;
item.state = LVIS_FOCUSED;
item.mask = LVIF_STATE;
item.iItem = 2;
item.iSubItem = 0;
r = SendMessage(hwnd, LVM_SETITEMA, 0, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(2, r);
item.stateMask = LVIS_FOCUSED;
item.state = 0;
r = SendMessage(hwnd, LVM_SETITEMSTATE, -1, (LPARAM)&item);
expect(TRUE, r);
r = SendMessage(hwnd, LVM_GETSELECTIONMARK, 0, 0);
expect(2, r);
DestroyWindow(hwnd);
}