More traces to help us make sense of the output.

Faster, cleaner ranges_{add,del}.
This commit is contained in:
Dimitrie O. Paun 2002-10-19 00:21:02 +00:00 committed by Alexandre Julliard
parent c79eb2de5f
commit 0ba3dc7589
1 changed files with 33 additions and 26 deletions

View File

@ -926,6 +926,7 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT
if (!LISTVIEW_GetOrigin(infoPtr, &Origin)) return FALSE; if (!LISTVIEW_GetOrigin(infoPtr, &Origin)) return FALSE;
TRACE("(lprc=%s)\n", debugrect(lprc));
OffsetRect(&frame, -Origin.x, -Origin.y); OffsetRect(&frame, -Origin.x, -Origin.y);
if (uView == LVS_ICON || uView == LVS_SMALLICON) if (uView == LVS_ICON || uView == LVS_SMALLICON)
@ -939,6 +940,7 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT
} }
if (!(i->ranges = ranges_create(50))) return FALSE; if (!(i->ranges = ranges_create(50))) return FALSE;
/* to do better here, we need to have PosX, and PosY sorted */ /* to do better here, we need to have PosX, and PosY sorted */
TRACE("building icon ranges:\n");
for (nItem = 0; nItem < infoPtr->nItemCount; nItem++) for (nItem = 0; nItem < infoPtr->nItemCount; nItem++)
{ {
rcItem.left = (LONG)DPA_GetPtr(infoPtr->hdpaPosX, nItem); rcItem.left = (LONG)DPA_GetPtr(infoPtr->hdpaPosX, nItem);
@ -986,6 +988,7 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT
if (nLastCol < nFirstCol || nLastRow < nFirstRow) return TRUE; if (nLastCol < nFirstCol || nLastRow < nFirstRow) return TRUE;
if (!(i->ranges = ranges_create(nLastCol - nFirstCol + 1))) return FALSE; if (!(i->ranges = ranges_create(nLastCol - nFirstCol + 1))) return FALSE;
TRACE("building list ranges:\n");
for (nCol = nFirstCol; nCol <= nLastCol; nCol++) for (nCol = nFirstCol; nCol <= nLastCol; nCol++)
{ {
item_range.lower = nCol * nPerCol + nFirstRow; item_range.lower = nCol * nPerCol + nFirstRow;
@ -1019,6 +1022,7 @@ static BOOL iterator_visibleitems(ITERATOR* i, LISTVIEW_INFO *infoPtr, HDC hdc)
/* if we can't deal with the region, we'll just go with the simple range */ /* if we can't deal with the region, we'll just go with the simple range */
if (!LISTVIEW_GetOrigin(infoPtr, &Origin)) return TRUE; if (!LISTVIEW_GetOrigin(infoPtr, &Origin)) return TRUE;
TRACE("building visible range:\n");
if (!i->ranges) if (!i->ranges)
{ {
if (!(i->ranges = ranges_create(50))) return TRUE; if (!(i->ranges = ranges_create(50))) return TRUE;
@ -1042,6 +1046,7 @@ static BOOL iterator_visibleitems(ITERATOR* i, LISTVIEW_INFO *infoPtr, HDC hdc)
ranges_delitem(i->ranges, i->nItem); ranges_delitem(i->ranges, i->nItem);
} }
/* the iterator should restart on the next iterator_next */ /* the iterator should restart on the next iterator_next */
TRACE("done\n");
return TRUE; return TRUE;
} }
@ -2232,7 +2237,7 @@ static void ranges_assert(RANGES ranges, LPCSTR desc)
assert (ranges); assert (ranges);
assert (ranges->hdpa->nItemCount >= 0); assert (ranges->hdpa->nItemCount >= 0);
if (ranges->hdpa->nItemCount == 0) return; if (ranges->hdpa->nItemCount == 0) return;
TRACE("Checking %s:\n", desc); TRACE("*** Checking %s ***\n", desc);
ranges_dump(ranges); ranges_dump(ranges);
assert ((prev = (RANGE *)DPA_GetPtr(ranges->hdpa, 0))->lower >= 0); assert ((prev = (RANGE *)DPA_GetPtr(ranges->hdpa, 0))->lower >= 0);
/* assert (((RANGE *)DPA_GetPtr(ranges->hdpa, ranges->hdpa->nItemCount - 1))->upper <= nUpper); */ /* assert (((RANGE *)DPA_GetPtr(ranges->hdpa, ranges->hdpa->nItemCount - 1))->upper <= nUpper); */
@ -2242,6 +2247,7 @@ static void ranges_assert(RANGES ranges, LPCSTR desc)
assert (prev->upper <= curr->lower); assert (prev->upper <= curr->lower);
prev = curr; prev = curr;
} }
TRACE("--- Done checking---\n");
} }
static RANGES ranges_create(int count) static RANGES ranges_create(int count)
@ -2370,7 +2376,7 @@ static BOOL ranges_add(RANGES ranges, RANGE range)
/* try find overlapping regions first */ /* try find overlapping regions first */
srchrgn.lower = range.lower - 1; srchrgn.lower = range.lower - 1;
srchrgn.upper = range.upper + 1; srchrgn.upper = range.upper + 1;
index = DPA_Search(ranges->hdpa, &srchrgn, 0, ranges_cmp, 0, 0); index = DPA_Search(ranges->hdpa, &srchrgn, 0, ranges_cmp, 0, DPAS_SORTED);
if (index == -1) if (index == -1)
{ {
@ -2444,64 +2450,65 @@ fail:
static BOOL ranges_del(RANGES ranges, RANGE range) static BOOL ranges_del(RANGES ranges, RANGE range)
{ {
RANGE remrgn, tmprgn, *chkrgn; RANGE *chkrgn;
BOOL done = FALSE;
INT index; INT index;
TRACE("(%s)\n", debugrange(&range)); TRACE("(%s)\n", debugrange(&range));
ranges_check(ranges, "before del"); ranges_check(ranges, "before del");
if (!ranges) goto fail; if (!ranges) goto fail;
remrgn = range; /* we don't use DPAS_SORTED here, since we need *
do * to find the first overlapping range */
index = DPA_Search(ranges->hdpa, &range, 0, ranges_cmp, 0, 0);
while(index != -1)
{ {
index = DPA_Search(ranges->hdpa, &remrgn, 0, ranges_cmp, 0, 0);
if (index == -1) break;
chkrgn = DPA_GetPtr(ranges->hdpa, index); chkrgn = DPA_GetPtr(ranges->hdpa, index);
if (!chkrgn) goto fail; if (!chkrgn) goto fail;
TRACE("Matches range %s @%d\n", debugrange(chkrgn), index); TRACE("Matches range %s @%d\n", debugrange(chkrgn), index);
/* case 1: Same range */ /* case 1: Same range */
if ( (chkrgn->upper == remrgn.upper) && if ( (chkrgn->upper == range.upper) &&
(chkrgn->lower == remrgn.lower) ) (chkrgn->lower == range.lower) )
{ {
DPA_DeletePtr(ranges->hdpa, index); DPA_DeletePtr(ranges->hdpa, index);
done = TRUE; break;
} }
/* case 2: engulf */ /* case 2: engulf */
else if ( (chkrgn->upper <= remrgn.upper) && else if ( (chkrgn->upper <= range.upper) &&
(chkrgn->lower >= remrgn.lower) ) (chkrgn->lower >= range.lower) )
{ {
DPA_DeletePtr(ranges->hdpa, index); DPA_DeletePtr(ranges->hdpa, index);
} }
/* case 3: overlap upper */ /* case 3: overlap upper */
else if ( (chkrgn->upper <= remrgn.upper) && else if ( (chkrgn->upper <= range.upper) &&
(chkrgn->lower < remrgn.lower) ) (chkrgn->lower < range.lower) )
{ {
chkrgn->upper = remrgn.lower; chkrgn->upper = range.lower;
} }
/* case 4: overlap lower */ /* case 4: overlap lower */
else if ( (chkrgn->upper > remrgn.upper) && else if ( (chkrgn->upper > range.upper) &&
(chkrgn->lower >= remrgn.lower) ) (chkrgn->lower >= range.lower) )
{ {
chkrgn->lower = remrgn.upper; chkrgn->lower = range.upper;
break;
} }
/* case 5: fully internal */ /* case 5: fully internal */
else else
{ {
RANGE *newrgn = (RANGE *)COMCTL32_Alloc(sizeof(RANGE)); RANGE tmprgn = *chkrgn, *newrgn;
if (!newrgn) goto fail;
tmprgn = *chkrgn; if (!(newrgn = (RANGE *)COMCTL32_Alloc(sizeof(RANGE)))) goto fail;
newrgn->lower = chkrgn->lower; newrgn->lower = chkrgn->lower;
newrgn->upper = remrgn.lower; newrgn->upper = range.lower;
chkrgn->lower = remrgn.upper; chkrgn->lower = range.upper;
DPA_InsertPtr(ranges->hdpa, index, newrgn); DPA_InsertPtr(ranges->hdpa, index, newrgn);
chkrgn = &tmprgn; chkrgn = &tmprgn;
break;
} }
index = DPA_Search(ranges->hdpa, &range, index, ranges_cmp, 0, 0);
} }
while(!done);
ranges_check(ranges, "after del"); ranges_check(ranges, "after del");
return TRUE; return TRUE;