Split ranges_destroy in ranges_clear, and ranges_destroy.
Rewrite DeleteAllItems, for cleaner, faster, more correct code.
This commit is contained in:
parent
62f4c61d22
commit
c9e0133357
|
@ -2320,17 +2320,20 @@ static RANGES ranges_create(int count)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ranges_destroy(RANGES ranges)
|
static void ranges_clear(RANGES ranges)
|
||||||
{
|
|
||||||
if (ranges && ranges->hdpa)
|
|
||||||
{
|
{
|
||||||
INT i;
|
INT i;
|
||||||
|
|
||||||
for(i = 0; i < ranges->hdpa->nItemCount; i++)
|
for(i = 0; i < ranges->hdpa->nItemCount; i++)
|
||||||
COMCTL32_Free(DPA_GetPtr(ranges->hdpa, i));
|
COMCTL32_Free(DPA_GetPtr(ranges->hdpa, i));
|
||||||
DPA_Destroy(ranges->hdpa);
|
DPA_DeleteAllPtrs(ranges->hdpa);
|
||||||
ranges->hdpa = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void ranges_destroy(RANGES ranges)
|
||||||
|
{
|
||||||
|
ranges_clear(ranges);
|
||||||
|
DPA_Destroy(ranges->hdpa);
|
||||||
COMCTL32_Free(ranges);
|
COMCTL32_Free(ranges);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3825,84 +3828,57 @@ static BOOL LISTVIEW_Arrange(LISTVIEW_INFO *infoPtr, INT nAlignCode)
|
||||||
*/
|
*/
|
||||||
static BOOL LISTVIEW_DeleteAllItems(LISTVIEW_INFO *infoPtr)
|
static BOOL LISTVIEW_DeleteAllItems(LISTVIEW_INFO *infoPtr)
|
||||||
{
|
{
|
||||||
LISTVIEW_ITEM *lpItem;
|
|
||||||
LISTVIEW_SUBITEM *lpSubItem;
|
|
||||||
NMLISTVIEW nmlv;
|
NMLISTVIEW nmlv;
|
||||||
|
HDPA hdpaSubItems = NULL;
|
||||||
BOOL bSuppress;
|
BOOL bSuppress;
|
||||||
BOOL bResult = FALSE;
|
ITEMHDR *hdrItem;
|
||||||
HDPA hdpaSubItems;
|
INT i, j;
|
||||||
|
|
||||||
TRACE("()\n");
|
TRACE("()\n");
|
||||||
|
|
||||||
LISTVIEW_DeselectAll(infoPtr);
|
/* we do it directly, to avoid notifications */
|
||||||
|
ranges_clear(infoPtr->selectionRanges);
|
||||||
infoPtr->nSelectionMark = -1;
|
infoPtr->nSelectionMark = -1;
|
||||||
infoPtr->nFocusedItem = -1;
|
infoPtr->nFocusedItem = -1;
|
||||||
SetRectEmpty(&infoPtr->rcFocus);
|
SetRectEmpty(&infoPtr->rcFocus);
|
||||||
/* But we are supposed to leave nHotItem as is! */
|
/* But we are supposed to leave nHotItem as is! */
|
||||||
|
|
||||||
if (infoPtr->dwStyle & LVS_OWNERDATA)
|
|
||||||
{
|
|
||||||
infoPtr->nItemCount = 0;
|
|
||||||
LISTVIEW_InvalidateList(infoPtr);
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (infoPtr->nItemCount > 0)
|
|
||||||
{
|
|
||||||
INT i, j;
|
|
||||||
|
|
||||||
/* send LVN_DELETEALLITEMS notification */
|
/* send LVN_DELETEALLITEMS notification */
|
||||||
/* verify if subsequent LVN_DELETEITEM notifications should be
|
|
||||||
suppressed */
|
|
||||||
ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
|
ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
|
||||||
nmlv.iItem = -1;
|
nmlv.iItem = -1;
|
||||||
bSuppress = notify_listview(infoPtr, LVN_DELETEALLITEMS, &nmlv);
|
bSuppress = notify_listview(infoPtr, LVN_DELETEALLITEMS, &nmlv);
|
||||||
|
|
||||||
for (i = 0; i < infoPtr->nItemCount; i++)
|
for (i = infoPtr->nItemCount - 1; i >= 0; i--)
|
||||||
{
|
{
|
||||||
hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, i);
|
/* send LVN_DELETEITEM notification, if not supressed */
|
||||||
for (j = 1; j < hdpaSubItems->nItemCount; j++)
|
|
||||||
{
|
|
||||||
lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems, j);
|
|
||||||
/* free subitem string */
|
|
||||||
if (is_textW(lpSubItem->hdr.pszText))
|
|
||||||
COMCTL32_Free(lpSubItem->hdr.pszText);
|
|
||||||
|
|
||||||
/* free subitem */
|
|
||||||
COMCTL32_Free(lpSubItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
|
|
||||||
if (!bSuppress)
|
if (!bSuppress)
|
||||||
{
|
{
|
||||||
/* send LVN_DELETEITEM notification */
|
|
||||||
nmlv.iItem = i;
|
nmlv.iItem = i;
|
||||||
nmlv.lParam = lpItem->lParam;
|
|
||||||
notify_listview(infoPtr, LVN_DELETEITEM, &nmlv);
|
notify_listview(infoPtr, LVN_DELETEITEM, &nmlv);
|
||||||
}
|
}
|
||||||
|
if (infoPtr->dwStyle & LVS_OWNERDATA)
|
||||||
/* free item string */
|
{
|
||||||
if (is_textW(lpItem->hdr.pszText))
|
hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, i);
|
||||||
COMCTL32_Free(lpItem->hdr.pszText);
|
for (j = 0; j < hdpaSubItems->nItemCount; j++)
|
||||||
|
{
|
||||||
/* free item */
|
hdrItem = (ITEMHDR *)DPA_GetPtr(hdpaSubItems, j);
|
||||||
COMCTL32_Free(lpItem);
|
if (is_textW(hdrItem->pszText)) COMCTL32_Free(hdrItem->pszText);
|
||||||
|
COMCTL32_Free(hdrItem);
|
||||||
DPA_Destroy(hdpaSubItems);
|
}
|
||||||
|
DPA_Destroy(hdpaSubItems);
|
||||||
|
DPA_DeletePtr(infoPtr->hdpaItems, i);
|
||||||
|
}
|
||||||
|
DPA_DeletePtr(infoPtr->hdpaPosX, i);
|
||||||
|
DPA_DeletePtr(infoPtr->hdpaPosY, i);
|
||||||
|
infoPtr->nItemCount --;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reinitialize listview memory */
|
|
||||||
bResult = DPA_DeleteAllPtrs(infoPtr->hdpaItems);
|
|
||||||
infoPtr->nItemCount = 0;
|
|
||||||
DPA_DeleteAllPtrs(infoPtr->hdpaPosX);
|
|
||||||
DPA_DeleteAllPtrs(infoPtr->hdpaPosY);
|
|
||||||
|
|
||||||
LISTVIEW_UpdateScroll(infoPtr);
|
LISTVIEW_UpdateScroll(infoPtr);
|
||||||
|
|
||||||
LISTVIEW_InvalidateList(infoPtr);
|
LISTVIEW_InvalidateList(infoPtr);
|
||||||
}
|
|
||||||
|
|
||||||
return bResult;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -7591,7 +7567,7 @@ static LRESULT LISTVIEW_NCDestroy(LISTVIEW_INFO *infoPtr)
|
||||||
|
|
||||||
/* destroy data structure */
|
/* destroy data structure */
|
||||||
DPA_Destroy(infoPtr->hdpaItems);
|
DPA_Destroy(infoPtr->hdpaItems);
|
||||||
ranges_destroy(infoPtr->selectionRanges);
|
if (infoPtr->selectionRanges) ranges_destroy(infoPtr->selectionRanges);
|
||||||
|
|
||||||
/* destroy image lists */
|
/* destroy image lists */
|
||||||
if (!(infoPtr->dwStyle & LVS_SHAREIMAGELISTS))
|
if (!(infoPtr->dwStyle & LVS_SHAREIMAGELISTS))
|
||||||
|
|
Loading…
Reference in New Issue