Teach GetItemMetrics to deal with subitems in report mode as well.

Unify Draw{,Sub}Item, simplify RefreshReport.
This commit is contained in:
Dimitrie O. Paun 2002-10-15 21:06:14 +00:00 committed by Alexandre Julliard
parent f378bbd5a5
commit 3a5105c957
1 changed files with 89 additions and 123 deletions

View File

@ -1572,6 +1572,7 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem,
TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem, TRUE)); TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem, TRUE));
/* Be smart and try to figure out the minimum we have to do */ /* Be smart and try to figure out the minimum we have to do */
if (lpLVItem->iSubItem) assert(uView == LVS_REPORT);
if (lprcBounds) if (lprcBounds)
{ {
if (uView == LVS_REPORT) doIcon = TRUE; if (uView == LVS_REPORT) doIcon = TRUE;
@ -1589,9 +1590,16 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem,
/************************************************************/ /************************************************************/
/* compute the box rectangle (it should be cheap to do) */ /* compute the box rectangle (it should be cheap to do) */
/************************************************************/ /************************************************************/
Box.left = 0; if (lpLVItem->iSubItem)
{
if (!Header_GetItemRect(infoPtr->hwndHeader, lpLVItem->iSubItem, &Box)) return FALSE;
}
else
{
Box.left = 0;
Box.right = infoPtr->nItemWidth;
}
Box.top = 0; Box.top = 0;
Box.right = infoPtr->nItemWidth;
Box.bottom = infoPtr->nItemHeight; Box.bottom = infoPtr->nItemHeight;
/************************************************************/ /************************************************************/
@ -1609,14 +1617,21 @@ 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 */
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 += REPORT_MARGINX;
if (lpLVItem->iSubItem == 0)
{
assert(lpLVItem->mask & LVIF_INDENT);
State.left += infoPtr->iconSize.cx * lpLVItem->iIndent;
}
}
State.top = Box.top; State.top = Box.top;
} }
State.right = State.left; State.right = State.left;
State.bottom = State.top; State.bottom = State.top;
if (infoPtr->himlState) if (infoPtr->himlState && lpLVItem->iSubItem == 0)
{ {
State.right += infoPtr->iconStateSize.cx; State.right += infoPtr->iconStateSize.cx;
State.bottom += infoPtr->iconStateSize.cy; State.bottom += infoPtr->iconStateSize.cy;
@ -1647,10 +1662,11 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem,
else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */ else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
{ {
Icon.left = State.right; Icon.left = State.right;
if (infoPtr->himlState) Icon.left += IMAGE_PADDING; if (!IsRectEmpty(&State)) Icon.left += IMAGE_PADDING;
Icon.top = Box.top; Icon.top = Box.top;
Icon.right = Icon.left; Icon.right = Icon.left;
if (infoPtr->himlSmall) Icon.right += infoPtr->iconSize.cx; /* FIXME: add suport for icons for subitems */
if (infoPtr->himlSmall && lpLVItem->iSubItem == 0) Icon.right += infoPtr->iconSize.cx;
Icon.bottom = Icon.top + infoPtr->nItemHeight; Icon.bottom = Icon.top + infoPtr->nItemHeight;
} }
if(lprcIcon) *lprcIcon = Icon; if(lprcIcon) *lprcIcon = Icon;
@ -1664,12 +1680,13 @@ static BOOL LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, LVITEMW *lpLVItem,
{ {
SIZE labelSize = { 0, 0 }; SIZE labelSize = { 0, 0 };
if ((infoPtr->dwStyle & LVS_OWNERDRAWFIXED) && (uView == LVS_REPORT)) if (lpLVItem->iSubItem || ((infoPtr->dwStyle & LVS_OWNERDRAWFIXED) && uView == LVS_REPORT))
{ {
labelSize.cx = infoPtr->nItemWidth; labelSize.cx = infoPtr->nItemWidth;
labelSize.cy = infoPtr->nItemHeight; labelSize.cy = infoPtr->nItemHeight;
goto calc_label; goto calc_label;
} }
/* we need the text in non owner draw mode */ /* we need the text in non owner draw mode */
assert(lpLVItem->mask & LVIF_TEXT); assert(lpLVItem->mask & LVIF_TEXT);
if (is_textT(lpLVItem->pszText, TRUE)) if (is_textT(lpLVItem->pszText, TRUE))
@ -1722,10 +1739,9 @@ calc_label:
else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */ else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
{ {
Label.left = Icon.right; Label.left = Icon.right;
if (infoPtr->himlSmall) Label.left += IMAGE_PADDING; if (!IsRectEmpty(&Icon) || !IsRectEmpty(&State)) Label.left += IMAGE_PADDING;
Label.top = Box.top; Label.top = Box.top;
Label.right = Label.left + labelSize.cx; Label.right = min(Label.left + labelSize.cx, Box.right - (uView == LVS_REPORT ? REPORT_MARGINX : 0));
if (Label.right > Box.right) Label.right = Box.right;
Label.bottom = Label.top + infoPtr->nItemHeight; Label.bottom = Label.top + infoPtr->nItemHeight;
} }
@ -3225,60 +3241,6 @@ static inline BOOL LISTVIEW_FillBkgnd(LISTVIEW_INFO *infoPtr, HDC hdc, const REC
return FillRect(hdc, lprcBox, infoPtr->hBkBrush); return FillRect(hdc, lprcBox, infoPtr->hBkBrush);
} }
/***
* DESCRIPTION:
* Draws a subitem.
*
* PARAMETER(S):
* [I] infoPtr : valid pointer to the listview structure
* [I] HDC : device context handle
* [I] INT : item index
* [I] INT : subitem index
* [I] RECT * : clipping rectangle
* [I] cdmode : custom draw mode
*
* RETURN:
* Success: TRUE
* Failure: FALSE
*/
static BOOL LISTVIEW_DrawSubItem(LISTVIEW_INFO *infoPtr, HDC hdc, INT nItem,
INT nSubItem, RECT rcItem, UINT align, DWORD cdmode)
{
WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
DWORD cditemmode = CDRF_DODEFAULT;
NMLVCUSTOMDRAW nmlvcd;
LVITEMW lvItem;
TRACE("(hdc=%x, nItem=%d, nSubItem=%d, rcItem=%s)\n",
hdc, nItem, nSubItem, debugrect(&rcItem));
/* get information needed for drawing the item */
lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
lvItem.iItem = nItem;
lvItem.iSubItem = nSubItem;
lvItem.cchTextMax = DISP_TEXT_SIZE;
lvItem.pszText = szDispText;
if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return FALSE;
TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem, TRUE));
customdraw_fill(&nmlvcd, infoPtr, hdc, &rcItem, &lvItem);
if (cdmode & CDRF_NOTIFYITEMDRAW)
cditemmode = notify_customdraw (infoPtr, CDDS_ITEMPREPAINT, &nmlvcd);
if (cditemmode & CDRF_SKIPDEFAULT) goto postpaint;
if (lvItem.iImage) FIXME("Draw the image for the subitem\n");
select_text_attr(infoPtr, hdc, &nmlvcd);
DrawTextW(hdc, lvItem.pszText, -1, &rcItem, LV_SL_DT_FLAGS | align);
postpaint:
if (cditemmode & CDRF_NOTIFYPOSTPAINT)
notify_customdraw(infoPtr, CDDS_ITEMPOSTPAINT, &nmlvcd);
return TRUE;
}
/*** /***
* DESCRIPTION: * DESCRIPTION:
* Draws an item. * Draws an item.
@ -3287,6 +3249,7 @@ postpaint:
* [I] infoPtr : valid pointer to the listview structure * [I] infoPtr : valid pointer to the listview structure
* [I] hdc : device context handle * [I] hdc : device context handle
* [I] nItem : item index * [I] nItem : item index
* [I] nSubItem : subitem index
* [I] pos : item position in client coordinates * [I] pos : item position in client coordinates
* [I] cdmode : custom draw mode * [I] cdmode : custom draw mode
* *
@ -3294,7 +3257,7 @@ postpaint:
* Success: TRUE * Success: TRUE
* Failure: FALSE * Failure: FALSE
*/ */
static BOOL LISTVIEW_DrawItem(LISTVIEW_INFO *infoPtr, HDC hdc, INT nItem, POINT pos, DWORD cdmode) static BOOL LISTVIEW_DrawItem(LISTVIEW_INFO *infoPtr, HDC hdc, INT nItem, INT nSubItem, POINT pos, DWORD cdmode)
{ {
UINT uFormat, uView = infoPtr->dwStyle & LVS_TYPEMASK; UINT uFormat, uView = infoPtr->dwStyle & LVS_TYPEMASK;
WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' }; WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
@ -3307,11 +3270,12 @@ static BOOL LISTVIEW_DrawItem(LISTVIEW_INFO *infoPtr, HDC hdc, INT nItem, POINT
TRACE("(hdc=%x, nItem=%d)\n", hdc, nItem); TRACE("(hdc=%x, nItem=%d)\n", hdc, nItem);
/* get information needed for drawing the item */ /* get information needed for drawing the item */
lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE; lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
if (nSubItem == 0) lvItem.mask |= LVIF_STATE;
if (uView == LVS_REPORT) lvItem.mask |= LVIF_INDENT; if (uView == LVS_REPORT) lvItem.mask |= LVIF_INDENT;
lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED | LVIS_STATEIMAGEMASK; lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED | LVIS_STATEIMAGEMASK;
lvItem.iItem = nItem; lvItem.iItem = nItem;
lvItem.iSubItem = 0; lvItem.iSubItem = nSubItem;
lvItem.cchTextMax = DISP_TEXT_SIZE; lvItem.cchTextMax = DISP_TEXT_SIZE;
lvItem.pszText = szDispText; lvItem.pszText = szDispText;
if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return FALSE; if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return FALSE;
@ -3333,7 +3297,7 @@ static BOOL LISTVIEW_DrawItem(LISTVIEW_INFO *infoPtr, HDC hdc, INT nItem, POINT
if (cditemmode & CDRF_SKIPDEFAULT) goto postpaint; if (cditemmode & CDRF_SKIPDEFAULT) goto postpaint;
/* state icons */ /* state icons */
if (infoPtr->himlState) if (infoPtr->himlState && !IsRectEmpty(&rcState))
{ {
UINT uStateImage = (lvItem.state & LVIS_STATEIMAGEMASK) >> 12; UINT uStateImage = (lvItem.state & LVIS_STATEIMAGEMASK) >> 12;
if (uStateImage) if (uStateImage)
@ -3342,24 +3306,46 @@ static BOOL LISTVIEW_DrawItem(LISTVIEW_INFO *infoPtr, HDC hdc, INT nItem, POINT
/* small icons */ /* small icons */
himl = (uView == LVS_ICON ? infoPtr->himlNormal : infoPtr->himlSmall); himl = (uView == LVS_ICON ? infoPtr->himlNormal : infoPtr->himlSmall);
if (himl && lvItem.iImage >= 0) if (himl && lvItem.iImage >= 0 && !IsRectEmpty(&rcIcon))
ImageList_Draw(himl, lvItem.iImage, hdc, rcIcon.left, rcIcon.top, ImageList_Draw(himl, lvItem.iImage, hdc, rcIcon.left, rcIcon.top,
(lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus) ? ILD_SELECTED : ILD_NORMAL); (lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus) ? ILD_SELECTED : ILD_NORMAL);
/* Don't bother painting item being edited */ /* Don't bother painting item being edited */
if (infoPtr->bEditing && lprcFocus) goto postpaint; if (infoPtr->bEditing && lprcFocus && nSubItem == 0) goto postpaint;
select_text_attr(infoPtr, hdc, &nmlvcd); select_text_attr(infoPtr, hdc, &nmlvcd);
rcSelect = rcLabel; /* draw the selection background, if we're drawing the main item */
if (uView == LVS_REPORT && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT)) if (nSubItem == 0)
rcSelect.right = rcBox.right; {
rcSelect = rcLabel;
if (uView == LVS_REPORT && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT))
rcSelect.right = rcBox.right;
if (lvItem.state & LVIS_SELECTED) if (lvItem.state & LVIS_SELECTED)
ExtTextOutW(hdc, rcSelect.left, rcSelect.top, ETO_OPAQUE, &rcSelect, 0, 0, 0); ExtTextOutW(hdc, rcSelect.left, rcSelect.top, ETO_OPAQUE, &rcSelect, 0, 0, 0);
if(lprcFocus) *lprcFocus = rcSelect; if(lprcFocus) *lprcFocus = rcSelect;
}
uFormat = (uView == LVS_ICON ? (lprcFocus ? LV_FL_DT_FLAGS : LV_ML_DT_FLAGS) : LV_SL_DT_FLAGS | DT_CENTER); /* figure out the text drawing flags */
uFormat = (uView == LVS_ICON ? (lprcFocus ? LV_FL_DT_FLAGS : LV_ML_DT_FLAGS) : LV_SL_DT_FLAGS);
if (uView == LVS_ICON)
uFormat = (lprcFocus ? LV_FL_DT_FLAGS : LV_ML_DT_FLAGS);
else
{
INT align = DT_LEFT;
if (nSubItem)
{
LVCOLUMNW lvColumn;
lvColumn.mask = LVCF_FMT;
LISTVIEW_GetColumnT(infoPtr, nSubItem, &lvColumn, TRUE);
TRACE("lvColumn=%s\n", debuglvcolumn_t(&lvColumn, TRUE));
if (lvColumn.fmt & LVCFMT_RIGHT) align = DT_RIGHT;
else if (lvColumn.fmt & LVCFMT_CENTER)align = DT_CENTER;
}
uFormat |= align;
}
DrawTextW(hdc, lvItem.pszText, -1, &rcLabel, uFormat); DrawTextW(hdc, lvItem.pszText, -1, &rcLabel, uFormat);
postpaint: postpaint:
@ -3454,12 +3440,10 @@ static void LISTVIEW_RefreshOwnerDraw(LISTVIEW_INFO *infoPtr, HDC hdc)
*/ */
static void LISTVIEW_RefreshReport(LISTVIEW_INFO *infoPtr, HDC hdc, DWORD cdmode) static void LISTVIEW_RefreshReport(LISTVIEW_INFO *infoPtr, HDC hdc, DWORD cdmode)
{ {
INT rgntype, nDrawPosY, j; INT rgntype, nColumnCount, nFirstCol, nLastCol, nCol;
INT nColumnCount, nFirstCol, nLastCol; RECT rcClip;
RECT rcItem, rcClip;
COLUMNCACHE *lpCols; COLUMNCACHE *lpCols;
LVCOLUMNW lvColumn; POINT Origin, Position;
POINT ptOrig;
ITERATOR i; ITERATOR i;
TRACE("()\n"); TRACE("()\n");
@ -3472,34 +3456,21 @@ static void LISTVIEW_RefreshReport(LISTVIEW_INFO *infoPtr, HDC hdc, DWORD cdmode
nColumnCount = Header_GetItemCount(infoPtr->hwndHeader); nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);
lpCols = COMCTL32_Alloc(nColumnCount * sizeof(COLUMNCACHE)); lpCols = COMCTL32_Alloc(nColumnCount * sizeof(COLUMNCACHE));
if (!lpCols) return; if (!lpCols) return;
for (j = 0; j < nColumnCount; j++) for (nCol = 0; nCol < nColumnCount; nCol++)
{ {
Header_GetItemRect(infoPtr->hwndHeader, j, &lpCols[j].rc); Header_GetItemRect(infoPtr->hwndHeader, nCol, &lpCols[nCol].rc);
TRACE("lpCols[%d].rc=%s\n", j, debugrect(&lpCols[j].rc)); TRACE("lpCols[%d].rc=%s\n", nCol, debugrect(&lpCols[nCol].rc));
} }
/* Get scroll info once before loop */ /* Get scroll info once before loop */
if (!LISTVIEW_GetOrigin(infoPtr, &ptOrig)) return; if (!LISTVIEW_GetOrigin(infoPtr, &Origin)) return;
/* we now narrow the columns as well */ /* we now narrow the columns as well */
nLastCol = nColumnCount - 1; nLastCol = nColumnCount - 1;
for(nFirstCol = 0; nFirstCol < nColumnCount; nFirstCol++) for(nFirstCol = 0; nFirstCol < nColumnCount; nFirstCol++)
if (lpCols[nFirstCol].rc.right + ptOrig.x >= rcClip.left) break; if (lpCols[nFirstCol].rc.right + Origin.x >= rcClip.left) break;
for(nLastCol = nColumnCount - 1; nLastCol >= 0; nLastCol--) for(nLastCol = nColumnCount - 1; nLastCol >= 0; nLastCol--)
if (lpCols[nLastCol].rc.left + ptOrig.x < rcClip.right) break; if (lpCols[nLastCol].rc.left + Origin.x < rcClip.right) break;
/* cache the per-column information before we start drawing */
for (j = nFirstCol; j <= nLastCol; j++)
{
lvColumn.mask = LVCF_FMT;
LISTVIEW_GetColumnT(infoPtr, j, &lvColumn, TRUE);
TRACE("lvColumn=%s\n", debuglvcolumn_t(&lvColumn, TRUE));
lpCols[j].align = DT_LEFT;
if (lvColumn.fmt & LVCFMT_RIGHT)
lpCols[j].align = DT_RIGHT;
else if (lvColumn.fmt & LVCFMT_CENTER)
lpCols[j].align = DT_CENTER;
}
/* figure out what we need to draw */ /* figure out what we need to draw */
iterator_visibleitems(&i, infoPtr, hdc); iterator_visibleitems(&i, infoPtr, hdc);
@ -3510,29 +3481,24 @@ static void LISTVIEW_RefreshReport(LISTVIEW_INFO *infoPtr, HDC hdc, DWORD cdmode
/* iterate through the invalidated rows */ /* iterate through the invalidated rows */
while(iterator_prev(&i)) while(iterator_prev(&i))
{ {
nDrawPosY = i.nItem * infoPtr->nItemHeight;
/* iterate through the invalidated columns */ /* iterate through the invalidated columns */
for (j = nFirstCol; j <= nLastCol; j++) for (nCol = nFirstCol; nCol <= nLastCol; nCol++)
{ {
rcItem = lpCols[j].rc; if (!LISTVIEW_GetItemListOrigin(infoPtr, i.nItem, &Position)) continue;
rcItem.left += REPORT_MARGINX; Position.x += Origin.x;
rcItem.right = max(rcItem.left, rcItem.right - REPORT_MARGINX); Position.y += Origin.y;
rcItem.top = nDrawPosY;
rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
/* Offset the Scroll Bar Pos */ if (rgntype == COMPLEXREGION)
OffsetRect(&rcItem, ptOrig.x, ptOrig.y);
if (rgntype == COMPLEXREGION && !RectVisible(hdc, &rcItem)) continue;
if (j == 0)
{ {
POINT pos = { rcItem.left, rcItem.top }; RECT rcItem;
LISTVIEW_DrawItem(infoPtr, hdc, i.nItem, pos, cdmode); rcItem.left = Position.x + lpCols[nCol].rc.left;
rcItem.right = rcItem.left + (lpCols[nCol].rc.right - lpCols[nCol].rc.left);
rcItem.top = Position.y;
rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
if (!RectVisible(hdc, &rcItem)) continue;
} }
else
LISTVIEW_DrawSubItem(infoPtr, hdc, i.nItem, j, rcItem, lpCols[j].align, cdmode); LISTVIEW_DrawItem(infoPtr, hdc, i.nItem, nCol, Position, cdmode);
} }
} }
iterator_destroy(&i); iterator_destroy(&i);
@ -3570,7 +3536,7 @@ static void LISTVIEW_RefreshList(LISTVIEW_INFO *infoPtr, HDC hdc, DWORD cdmode)
Position.x += Origin.x; Position.x += Origin.x;
Position.y += Origin.y; Position.y += Origin.y;
LISTVIEW_DrawItem(infoPtr, hdc, i.nItem, Position, cdmode); LISTVIEW_DrawItem(infoPtr, hdc, i.nItem, 0, Position, cdmode);
} }
iterator_destroy(&i); iterator_destroy(&i);
} }