Commit 4c799937 authored by Joachim Priesner's avatar Joachim Priesner Committed by Alexandre Julliard

comctl32: Treeview: Fix crash when deleting the first visible item while bRedraw == false.

parent 3e028825
...@@ -1878,8 +1878,13 @@ static void test_delete_items(void) ...@@ -1878,8 +1878,13 @@ static void test_delete_items(void)
{ {
const struct message *msg; const struct message *msg;
HWND hTree; HWND hTree;
HTREEITEM hItem1, hItem2;
TVINSERTSTRUCTA ins;
INT ret; INT ret;
static CHAR item1[] = "Item 1";
static CHAR item2[] = "Item 2";
hTree = create_treeview_control(0); hTree = create_treeview_control(0);
fill_tree(hTree); fill_tree(hTree);
...@@ -1901,6 +1906,34 @@ static void test_delete_items(void) ...@@ -1901,6 +1906,34 @@ static void test_delete_items(void)
ok(ret == 0, "got %d\n", ret); ok(ret == 0, "got %d\n", ret);
DestroyWindow(hTree); DestroyWindow(hTree);
/* Regression test for a crash when deleting the first visible item while bRedraw == false. */
hTree = create_treeview_control(0);
ins.hParent = TVI_ROOT;
ins.hInsertAfter = TVI_ROOT;
U(ins).item.mask = TVIF_TEXT;
U(ins).item.pszText = item1;
hItem1 = TreeView_InsertItemA(hTree, &ins);
ok(hItem1 != NULL, "InsertItem failed\n");
ins.hParent = TVI_ROOT;
ins.hInsertAfter = hItem1;
U(ins).item.mask = TVIF_TEXT;
U(ins).item.pszText = item2;
hItem2 = TreeView_InsertItemA(hTree, &ins);
ok(hItem2 != NULL, "InsertItem failed\n");
ret = SendMessageA(hTree, WM_SETREDRAW, FALSE, 0);
ok(ret == 0, "got %d\n", ret);
ret = SendMessageA(hTree, TVM_DELETEITEM, 0, (LPARAM)hItem1);
ok(ret == TRUE, "got %d\n", ret);
ret = SendMessageA(hTree, WM_SETREDRAW, TRUE, 0);
ok(ret == 0, "got %d\n", ret);
DestroyWindow(hTree);
} }
static void test_cchildren(void) static void test_cchildren(void)
......
...@@ -1580,11 +1580,13 @@ TREEVIEW_DeleteItem(TREEVIEW_INFO *infoPtr, HTREEITEM item) ...@@ -1580,11 +1580,13 @@ TREEVIEW_DeleteItem(TREEVIEW_INFO *infoPtr, HTREEITEM item)
TREEVIEW_VerifyTree(infoPtr); TREEVIEW_VerifyTree(infoPtr);
if (visible)
TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
if (!infoPtr->bRedraw) return TRUE; if (!infoPtr->bRedraw) return TRUE;
if (visible) if (visible)
{ {
TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
TREEVIEW_RecalculateVisibleOrder(infoPtr, prev); TREEVIEW_RecalculateVisibleOrder(infoPtr, prev);
TREEVIEW_UpdateScrollBars(infoPtr); TREEVIEW_UpdateScrollBars(infoPtr);
TREEVIEW_Invalidate(infoPtr, NULL); TREEVIEW_Invalidate(infoPtr, NULL);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment