From 04e5e9cfa0ef77db99c46ecf0f8e63e105d4a38f Mon Sep 17 00:00:00 2001 From: Nikolay Sivov Date: Sat, 23 Oct 2010 20:18:51 +0400 Subject: [PATCH] comctl32/treeview: Accept null item handle as a root for TVM_DELETEITEM. --- dlls/comctl32/tests/treeview.c | 49 ++++++++++++++++++++++++++++++++++ dlls/comctl32/treeview.c | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c index 1de63c61364..7238bd0d46e 100644 --- a/dlls/comctl32/tests/treeview.c +++ b/dlls/comctl32/tests/treeview.c @@ -42,6 +42,7 @@ static const char *TEST_CALLBACK_TEXT = "callback_text"; #define expect(expected, got) ok(got == expected, "Expected %d, got %d\n", expected, got) static struct msg_sequence *sequences[NUM_MSG_SEQUENCES]; +static struct msg_sequence *item_sequence[1]; static const struct message FillRootSeq[] = { { TVM_INSERTITEM, sent }, @@ -958,6 +959,21 @@ static LRESULT CALLBACK parent_wnd_proc(HWND hWnd, UINT message, WPARAM wParam, ok(SendMessage(pHdr->hwndFrom, TVM_GETITEMRECT, TRUE, (LPARAM)&rect), "Failed to get rect for second visible item.\n"); } break; + case TVN_DELETEITEMA: + { + struct message item; + + ok(pTreeView->itemNew.mask == 0, "got wrong mask 0x%x\n", pTreeView->itemNew.mask); + + ok(pTreeView->itemOld.mask == (TVIF_HANDLE | TVIF_PARAM), "got wrong mask 0x%x\n", pTreeView->itemOld.mask); + ok(pTreeView->itemOld.hItem != NULL, "got %p\n", pTreeView->itemOld.hItem); + + memset(&item, 0, sizeof(item)); + item.lParam = (LPARAM)pTreeView->itemOld.hItem; + add_message(item_sequence, 0, &item); + + break; + } } } } @@ -1324,6 +1340,37 @@ static void test_WM_PAINT(void) DestroyWindow(hTree); } +static void test_delete_items(void) +{ + const struct message *msg; + HWND hTree; + INT ret; + + hTree = create_treeview_control(); + fill_tree(hTree); + + /* check delete order */ + flush_sequences(item_sequence, 1); + ret = SendMessage(hTree, TVM_DELETEITEM, 0, 0); + ok(ret == TRUE, "got %d\n", ret); + + msg = item_sequence[0]->sequence; + ok(item_sequence[0]->count == 2, "expected 2 items, got %d\n", item_sequence[0]->count); + + if (item_sequence[0]->count == 2) + { +todo_wine { + ok(msg[0].lParam == (LPARAM)hChild, "expected %p, got %lx\n", hChild, msg[0].lParam); + ok(msg[1].lParam == (LPARAM)hRoot, "expected %p, got %lx\n", hRoot, msg[1].lParam); +} + } + + ret = SendMessageA(hTree, TVM_GETCOUNT, 0, 0); + ok(ret == 0, "got %d\n", ret); + + DestroyWindow(hTree); +} + START_TEST(treeview) { HMODULE hComctl32; @@ -1348,6 +1395,7 @@ START_TEST(treeview) InitCommonControls(); init_msg_sequences(sequences, NUM_MSG_SEQUENCES); + init_msg_sequences(item_sequence, 1); wc.style = CS_HREDRAW | CS_VREDRAW; wc.cbClsExtra = 0; @@ -1390,6 +1438,7 @@ START_TEST(treeview) test_expandnotify(); test_TVS_SINGLEEXPAND(); test_WM_PAINT(); + test_delete_items(); if (!load_v6_module(&ctx_cookie, &hCtx)) { diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c index 1ffcf649649..1ca5639431a 100644 --- a/dlls/comctl32/treeview.c +++ b/dlls/comctl32/treeview.c @@ -1513,7 +1513,7 @@ TREEVIEW_DeleteItem(TREEVIEW_INFO *infoPtr, HTREEITEM wineItem) TREEVIEW_ITEM *parent, *prev = NULL; BOOL visible = FALSE; - if (wineItem == TVI_ROOT) + if (wineItem == TVI_ROOT || !wineItem) { TRACE("TVI_ROOT\n"); parent = infoPtr->root;