From: Akihiro Sagawa Subject: [2/2] comctl32: Don't update the status if the item is no longer valid. Message-Id: <20160119234212.A8E5.375B48EC@gmail.com> Date: Tue, 19 Jan 2016 23:45:07 +0900 This fixes https://bugs.winehq.org/show_bug.cgi?id=39677 Signed-off-by: Akihiro Sagawa --- dlls/comctl32/listview.c | 2 +- dlls/comctl32/tests/listview.c | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/dlls/comctl32/listview.c b/dlls/comctl32/listview.c index 68a5515..419a823 100644 --- a/dlls/comctl32/listview.c +++ b/dlls/comctl32/listview.c @@ -8808,6 +8808,7 @@ static BOOL LISTVIEW_SetItemCount(LISTVIEW_INFO *infoPtr, INT nItems, DWORD dwFl if (infoPtr->dwStyle & LVS_OWNERDATA) { INT nOldCount = infoPtr->nItemCount; + infoPtr->nItemCount = nItems; if (nItems < nOldCount) { @@ -8820,7 +8821,6 @@ static BOOL LISTVIEW_SetItemCount(LISTVIEW_INFO *infoPtr, INT nItems, DWORD dwFl } } - infoPtr->nItemCount = nItems; LISTVIEW_UpdateScroll(infoPtr); /* the flags are valid only in ownerdata report and list modes */ diff --git a/dlls/comctl32/tests/listview.c b/dlls/comctl32/tests/listview.c index 2afa44d..7f686d8 100644 --- a/dlls/comctl32/tests/listview.c +++ b/dlls/comctl32/tests/listview.c @@ -3418,6 +3418,28 @@ static void test_ownerdata(void) style = GetWindowLongPtrA(hwnd, GWL_STYLE); ok(style & LVS_SORTDESCENDING, "Expected LVS_SORTDESCENDING to be set\n"); DestroyWindow(hwnd); + + /* The focused item isn't updated after the invalidation */ + hwnd = create_listview_control(LVS_OWNERDATA | LVS_REPORT); + ok(hwnd != NULL, "failed to create a listview window\n"); + res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 3, 0); + expect(TRUE, res); + + memset(&item, 0, sizeof(item)); + item.stateMask = LVIS_FOCUSED; + item.state = LVIS_FOCUSED; + res = SendMessageA(hwnd, LVM_SETITEMSTATE, 0, (LPARAM)&item); + expect(TRUE, res); + + flush_sequences(sequences, NUM_MSG_SEQUENCES); + res = SendMessageA(hwnd, LVM_SETITEMCOUNT, 0, 0); + expect(TRUE, res); + ok_sequence(sequences, PARENT_SEQ_INDEX, empty_seq, + "ownerdata setitemcount", FALSE); + + res = SendMessageA(hwnd, LVM_GETNEXTITEM, -1, LVNI_FOCUSED); + expect(-1, res); + DestroyWindow(hwnd); } static void test_norecompute(void)