Commit f378bbd5 authored by Dimitrie O. Paun's avatar Dimitrie O. Paun Committed by Alexandre Julliard

Fix iterator creation for LVS_LIST mode.

Use assert() instead of hand-made hack.
parent 3baa344a
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
#include "config.h" #include "config.h"
#include "wine/port.h" #include "wine/port.h"
#include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -883,7 +884,6 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT ...@@ -883,7 +884,6 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT
{ {
UINT uView = infoPtr->dwStyle & LVS_TYPEMASK; UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
RECT frame = *lprc, rcItem, rcTemp; RECT frame = *lprc, rcItem, rcTemp;
INT lower, upper, nItem;
POINT Origin; POINT Origin;
/* in case we fail, we want to return an empty iterator */ /* in case we fail, we want to return an empty iterator */
...@@ -895,6 +895,8 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT ...@@ -895,6 +895,8 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT
if (uView == LVS_ICON || uView == LVS_SMALLICON) if (uView == LVS_ICON || uView == LVS_SMALLICON)
{ {
INT nItem;
if (uView == LVS_ICON) if (uView == LVS_ICON)
{ {
if (LISTVIEW_GetItemBox(infoPtr, infoPtr->nFocusedItem, &rcItem) && IntersectRect(&rcTemp, &rcItem, lprc)) if (LISTVIEW_GetItemBox(infoPtr, infoPtr->nFocusedItem, &rcItem) && IntersectRect(&rcTemp, &rcItem, lprc))
...@@ -918,27 +920,44 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT ...@@ -918,27 +920,44 @@ static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT
} }
else if (uView == LVS_REPORT) else if (uView == LVS_REPORT)
{ {
INT lower, upper;
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 = frame.top / infoPtr->nItemHeight; lower = max(frame.top / infoPtr->nItemHeight, 0);
upper = (frame.bottom - 1) / infoPtr->nItemHeight; upper = min((frame.bottom - 1) / infoPtr->nItemHeight, infoPtr->nItemCount - 1);
if (upper < lower) return TRUE;
i->range.lower = lower;
i->range.upper = upper;
} }
else else
{ {
INT nPerCol = max((infoPtr->rcList.bottom - infoPtr->rcList.top) / infoPtr->nItemHeight, 1); INT nPerCol = max((infoPtr->rcList.bottom - infoPtr->rcList.top) / infoPtr->nItemHeight, 1);
if (frame.top >= infoPtr->nItemHeight * nPerCol) return TRUE; INT nFirstRow = max(frame.top / infoPtr->nItemHeight, 0);
lower = (frame.left / infoPtr->nItemWidth) * nPerCol + frame.top / infoPtr->nItemHeight; INT nLastRow = min((frame.bottom - 1) / infoPtr->nItemHeight, nPerCol - 1);
upper = ((frame.right - 1) / infoPtr->nItemWidth) * nPerCol + (frame.bottom - 1) / infoPtr->nItemHeight; INT nFirstCol = max(frame.left / infoPtr->nItemWidth, 0);
INT nLastCol = min((frame.right - 1) / infoPtr->nItemWidth, (infoPtr->nItemCount + nPerCol - 1) / nPerCol);
INT lower = nFirstCol * nPerCol + nFirstRow;
RANGE item_range;
INT nCol;
TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
nPerCol, nFirstRow, nLastRow, nFirstCol, nLastCol, lower);
if (nLastCol < nFirstCol || nLastRow < nFirstRow) return TRUE;
if (!(i->ranges = DPA_Create(nLastCol - nFirstCol + 1))) return FALSE;
for (nCol = nFirstCol; nCol < nLastCol; nCol++)
{
item_range.lower = nCol * nPerCol + nFirstRow;
if(item_range.lower >= infoPtr->nItemCount) break;
item_range.upper = min(nCol * nPerCol + nLastRow, infoPtr->nItemCount - 1);
TRACE(" range=[%d,%d]\n", item_range.lower, item_range.upper);
ranges_add(i->ranges, item_range);
}
} }
if (upper < 0 || lower >= infoPtr->nItemCount) return TRUE;
lower = max(lower, 0);
upper = min(upper, infoPtr->nItemCount - 1);
if (upper < lower) return TRUE;
i->range.lower = lower;
i->range.upper = upper;
return TRUE; return TRUE;
} }
...@@ -1560,11 +1579,8 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem, ...@@ -1560,11 +1579,8 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem,
} }
if (uView == LVS_ICON && (lprcBox || lprcBounds || lprcLabel)) if (uView == LVS_ICON && (lprcBox || lprcBounds || lprcLabel))
{ {
if (!(lpLVItem->mask & LVIF_STATE) || assert((lpLVItem->mask & LVIF_STATE) && (lpLVItem->stateMask & LVIS_FOCUSED));
!(lpLVItem->stateMask & LVIS_FOCUSED)) if (lpLVItem->state & LVIS_FOCUSED) oversizedBox = doLabel = TRUE;
goto fail;
if (lpLVItem->state & LVIS_FOCUSED)
oversizedBox = doLabel = TRUE;
} }
if (lprcLabel) doLabel = TRUE; if (lprcLabel) doLabel = TRUE;
if (doLabel || lprcIcon) doIcon = TRUE; if (doLabel || lprcIcon) doIcon = TRUE;
...@@ -1593,7 +1609,7 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem, ...@@ -1593,7 +1609,7 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem,
else else
{ {
/* we need the ident in report mode, if we don't have it, we fail */ /* we need the ident in report mode, if we don't have it, we fail */
if (uView == LVS_REPORT && !(lpLVItem->mask & LVIF_INDENT)) goto fail; assert(uView != LVS_REPORT || (lpLVItem->mask & LVIF_INDENT));
State.left = Box.left; State.left = Box.left;
if (uView == LVS_REPORT) State.left += infoPtr->iconSize.cx * lpLVItem->iIndent; if (uView == LVS_REPORT) State.left += infoPtr->iconSize.cx * lpLVItem->iIndent;
State.top = Box.top; State.top = Box.top;
...@@ -1655,7 +1671,7 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem, ...@@ -1655,7 +1671,7 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem,
goto calc_label; goto calc_label;
} }
/* we need the text in non owner draw mode */ /* we need the text in non owner draw mode */
if (!(lpLVItem->mask & LVIF_TEXT)) goto fail; assert(lpLVItem->mask & LVIF_TEXT);
if (is_textT(lpLVItem->pszText, TRUE)) if (is_textT(lpLVItem->pszText, TRUE))
{ {
HFONT hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont; HFONT hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont;
...@@ -1740,11 +1756,6 @@ calc_label: ...@@ -1740,11 +1756,6 @@ calc_label:
TRACE(" - box=%s\n", debugrect(&Box)); TRACE(" - box=%s\n", debugrect(&Box));
return TRUE; return TRUE;
fail:
ERR("Incorrect item=%s; please report.\n", debuglvitem_t(lpLVItem, TRUE));
*((char *)0) = 0; /* it's an internal function, should never happen */
return FALSE;
} }
/*** /***
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment