From 19f83e2f6a6910a57ab5f2052ff7cdf6210a5b39 Mon Sep 17 00:00:00 2001 From: Aric Stewart Date: Thu, 8 Jun 2000 19:21:41 +0000 Subject: [PATCH] Properly handle InsertItem with an invalid HTREEITEM. Windows handles these like a TVI_LAST. --- dlls/comctl32/treeview.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c index 0d808fef0d4..f3c59294083 100644 --- a/dlls/comctl32/treeview.c +++ b/dlls/comctl32/treeview.c @@ -1986,25 +1986,39 @@ TREEVIEW_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam) wineItem->upsibling=sibItem->hItem; break; default: - while ((sibItem->sibling) && (sibItem->hItem!=ptdi->hInsertAfter)) + { + TREEVIEW_ITEM *localsibItem = sibItem; + while ((localsibItem->sibling) && + (localsibItem->hItem!=ptdi->hInsertAfter)) { - prevsib=sibItem; - sibItem=&infoPtr->items [(INT)sibItem->sibling]; + prevsib=localsibItem; + localsibItem=&infoPtr->items [(INT)localsibItem->sibling]; } - if (sibItem->hItem!=ptdi->hInsertAfter) { - ERR("tried to insert item after nonexisting handle %d.\n", + if (localsibItem->hItem!=ptdi->hInsertAfter) { + WARN("tried to insert item after nonexisting handle %d treating as TVI_LAST.\n", (INT) ptdi->hInsertAfter); - break; + /* + * retry placing it last + */ + if (sibItem==wineItem) break; + while (sibItem->sibling) { + prevsib=sibItem; + sibItem=&infoPtr->items [(INT)sibItem->sibling]; + } + sibItem->sibling=(HTREEITEM)iItem; + wineItem->upsibling=sibItem->hItem; + break; } - prevsib=sibItem; - if (sibItem->sibling) { - sibItem=&infoPtr->items [(INT)sibItem->sibling]; - sibItem->upsibling=(HTREEITEM)iItem; - wineItem->sibling=sibItem->hItem; + prevsib=localsibItem; + if (localsibItem->sibling) { + localsibItem=&infoPtr->items [(INT)localsibItem->sibling]; + localsibItem->upsibling=(HTREEITEM)iItem; + wineItem->sibling=localsibItem->hItem; } prevsib->sibling=(HTREEITEM)iItem; wineItem->upsibling=prevsib->hItem; break; + } } }