Small iterator-over-range[s] cleanup.

This commit is contained in:
Dimitrie O. Paun 2002-10-25 03:18:47 +00:00 committed by Alexandre Julliard
parent 83679e6b88
commit 863d6a87f5
1 changed files with 19 additions and 11 deletions

View File

@ -1011,13 +1011,22 @@ static inline BOOL iterator_empty(ITERATOR* i)
return TRUE; return TRUE;
} }
/***
* Create an iterator over a range.
*/
static inline BOOL iterator_rangeitems(ITERATOR* i, RANGE range)
{
iterator_empty(i);
i->range = range;
return TRUE;
}
/*** /***
* Create an iterator over a bunch of ranges. * Create an iterator over a bunch of ranges.
* Please note that the iterator will take ownership of the ranges, * Please note that the iterator will take ownership of the ranges,
* and will free them upon destruction. * and will free them upon destruction.
*/ */
static inline BOOL iterator_ranges(ITERATOR* i, RANGES ranges) static inline BOOL iterator_rangesitems(ITERATOR* i, RANGES ranges)
{ {
iterator_empty(i); iterator_empty(i);
i->ranges = ranges; i->ranges = ranges;
@ -1051,7 +1060,7 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT
if (IntersectRect(&rcTemp, &rcItem, lprc)) if (IntersectRect(&rcTemp, &rcItem, lprc))
i->nSpecial = infoPtr->nFocusedItem; i->nSpecial = infoPtr->nFocusedItem;
} }
if (!(i->ranges = ranges_create(50))) return FALSE; if (!(iterator_rangesitems(i, 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"); TRACE("building icon ranges:\n");
for (nItem = 0; nItem < infoPtr->nItemCount; nItem++) for (nItem = 0; nItem < infoPtr->nItemCount; nItem++)
@ -1067,16 +1076,15 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT
} }
else if (uView == LVS_REPORT) else if (uView == LVS_REPORT)
{ {
INT lower, upper; RANGE range;
if (frame.left >= infoPtr->nItemWidth) return TRUE; if (frame.left >= infoPtr->nItemWidth) return TRUE;
if (frame.top >= infoPtr->nItemHeight * infoPtr->nItemCount) return TRUE; if (frame.top >= infoPtr->nItemHeight * infoPtr->nItemCount) return TRUE;
lower = max(frame.top / infoPtr->nItemHeight, 0); range.lower = max(frame.top / infoPtr->nItemHeight, 0);
upper = min((frame.bottom - 1) / infoPtr->nItemHeight, infoPtr->nItemCount - 1); range.upper = min((frame.bottom - 1) / infoPtr->nItemHeight, infoPtr->nItemCount - 1) + 1;
if (upper < lower) return TRUE; if (range.upper <= range.lower) return TRUE;
i->range.lower = lower; if (!iterator_rangeitems(i, range)) return FALSE;
i->range.upper = upper + 1;
TRACE(" report=%s\n", debugrange(&i->range)); TRACE(" report=%s\n", debugrange(&i->range));
} }
else else
@ -1095,7 +1103,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 (!(iterator_rangesitems(i, ranges_create(nLastCol - nFirstCol + 1)))) return FALSE;
TRACE("building list ranges:\n"); TRACE("building list ranges:\n");
for (nCol = nFirstCol; nCol <= nLastCol; nCol++) for (nCol = nFirstCol; nCol <= nLastCol; nCol++)
{ {
@ -2650,7 +2658,7 @@ static BOOL LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO *infoPtr, RANGES toSkip)
/* need to clone the DPA because callbacks can change it */ /* need to clone the DPA because callbacks can change it */
if (!(clone = ranges_clone(infoPtr->selectionRanges))) return FALSE; if (!(clone = ranges_clone(infoPtr->selectionRanges))) return FALSE;
iterator_ranges(&i, ranges_diff(clone, toSkip)); iterator_rangesitems(&i, ranges_diff(clone, toSkip));
while(iterator_next(&i)) while(iterator_next(&i))
LISTVIEW_SetItemState(infoPtr, i.nItem, &lvItem); LISTVIEW_SetItemState(infoPtr, i.nItem, &lvItem);
/* note that the iterator destructor will free the cloned range */ /* note that the iterator destructor will free the cloned range */
@ -2868,7 +2876,7 @@ static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO *infoPtr, INT nItem)
} }
LISTVIEW_DeselectAllSkipItems(infoPtr, selection); LISTVIEW_DeselectAllSkipItems(infoPtr, selection);
iterator_ranges(&i, selection); iterator_rangesitems(&i, selection);
while(iterator_next(&i)) while(iterator_next(&i))
LISTVIEW_SetItemState(infoPtr, i.nItem, &item); LISTVIEW_SetItemState(infoPtr, i.nItem, &item);
/* this will also destroy the selection */ /* this will also destroy the selection */