When items are inserted in a partially populated treeview, the first

visible item was not correctly updated.
The first visible item was sometimes used to calculate the location of
other items when it had been freed.
This commit is contained in:
Adam Gundy 2003-05-02 20:15:36 +00:00 committed by Alexandre Julliard
parent 06d610ec9b
commit a982259e3e
1 changed files with 18 additions and 4 deletions

View File

@ -988,6 +988,16 @@ TREEVIEW_FreeItem(TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item)
COMCTL32_Free(item); COMCTL32_Free(item);
if (infoPtr->selectedItem == item) if (infoPtr->selectedItem == item)
infoPtr->selectedItem = NULL; infoPtr->selectedItem = NULL;
if (infoPtr->hotItem == item)
infoPtr->hotItem = NULL;
if (infoPtr->focusedItem == item)
infoPtr->focusedItem = NULL;
if (infoPtr->firstVisible == item)
infoPtr->firstVisible = NULL;
if (infoPtr->dropItem == item)
infoPtr->dropItem = NULL;
if (infoPtr->insertMarkItem == item)
infoPtr->insertMarkItem = NULL;
} }
@ -1216,9 +1226,12 @@ TREEVIEW_InsertItemA(TREEVIEW_INFO *infoPtr, LPARAM lParam)
switch ((DWORD)insertAfter) switch ((DWORD)insertAfter)
{ {
case (DWORD)TVI_FIRST: case (DWORD)TVI_FIRST:
TREEVIEW_InsertBefore(newItem, parentItem->firstChild, parentItem); {
if (infoPtr->firstVisible == parentItem->firstChild) TREEVIEW_ITEM *originalFirst = parentItem->firstChild;
TREEVIEW_SetFirstVisible(infoPtr, newItem, TRUE); TREEVIEW_InsertBefore(newItem, parentItem->firstChild, parentItem);
if (infoPtr->firstVisible == originalFirst)
TREEVIEW_SetFirstVisible(infoPtr, newItem, TRUE);
}
break; break;
case (DWORD)TVI_LAST: case (DWORD)TVI_LAST:
@ -1531,6 +1544,7 @@ TREEVIEW_DeleteItem(TREEVIEW_INFO *infoPtr, HTREEITEM wineItem)
newFirstVisible = wineItem->prevSibling; newFirstVisible = wineItem->prevSibling;
else if (wineItem->parent != infoPtr->root) else if (wineItem->parent != infoPtr->root)
newFirstVisible = wineItem->parent; newFirstVisible = wineItem->parent;
TREEVIEW_SetFirstVisible(infoPtr, NULL, TRUE);
} }
else else
newFirstVisible = infoPtr->firstVisible; newFirstVisible = infoPtr->firstVisible;
@ -1564,8 +1578,8 @@ TREEVIEW_DeleteItem(TREEVIEW_INFO *infoPtr, HTREEITEM wineItem)
if (visible) if (visible)
{ {
TREEVIEW_RecalculateVisibleOrder(infoPtr, prev);
TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE); TREEVIEW_SetFirstVisible(infoPtr, newFirstVisible, TRUE);
TREEVIEW_RecalculateVisibleOrder(infoPtr, prev);
TREEVIEW_UpdateScrollBars(infoPtr); TREEVIEW_UpdateScrollBars(infoPtr);
TREEVIEW_Invalidate(infoPtr, NULL); TREEVIEW_Invalidate(infoPtr, NULL);
} }