Reorganize the item size calculation (a bit simpler, and faster).

This commit is contained in:
Rein Klazes 2002-10-23 22:28:44 +00:00 committed by Alexandre Julliard
parent 1fd077939f
commit 7d9b04dbe2
1 changed files with 60 additions and 77 deletions

View File

@ -2189,55 +2189,39 @@ static SUBITEM_INFO* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems, INT nSubItem)
/*** /***
* DESCRIPTION: * DESCRIPTION:
* Calculates the width of a specific item. * Caclulates the desired item width.
* *
* PARAMETER(S): * PARAMETER(S):
* [I] infoPtr : valid pointer to the listview structure * [I] infoPtr : valid pointer to the listview structure
* [I] nItem : item to calculate width, or -1 for max of all
* *
* RETURN: * RETURN:
* Returns the width of an item width an item. * The desired item width.
*/ */
static INT LISTVIEW_CalculateItemWidth(LISTVIEW_INFO *infoPtr, INT nItem) static INT LISTVIEW_CalculateItemWidth(LISTVIEW_INFO *infoPtr)
{ {
UINT uView = infoPtr->dwStyle & LVS_TYPEMASK; UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
INT nItemWidth = 0, i; INT nItemWidth;
if (uView == LVS_ICON) if (uView == LVS_ICON)
nItemWidth = infoPtr->iconSpacing.cx; nItemWidth = infoPtr->iconSpacing.cx;
else if (uView == LVS_REPORT) else if (uView == LVS_REPORT)
{ {
RECT rcHeaderItem; RECT rcHeader;
/* calculate width of header */ LISTVIEW_GetHeaderRect(infoPtr, infoPtr->hdpaColumns->nItemCount - 1, &rcHeader);
for (i = 0; i < infoPtr->hdpaColumns->nItemCount; i++) nItemWidth = rcHeader.right;
{
LISTVIEW_GetHeaderRect(infoPtr, i, &rcHeaderItem);
nItemWidth += (rcHeaderItem.right - rcHeaderItem.left);
}
} }
else else /* LVS_SMALLICON, or LVS_LIST */
{ {
INT nLabelWidth; INT i;
if (infoPtr->nItemCount == 0) return DEFAULT_COLUMN_WIDTH; for (nItemWidth = i = 0; i < infoPtr->nItemCount; i++)
nItemWidth = max(LISTVIEW_GetLabelWidth(infoPtr, i), nItemWidth);
/* get width of string */
if (nItem == -1) if (infoPtr->himlSmall) nItemWidth += infoPtr->iconSize.cx + IMAGE_PADDING;
{ if (infoPtr->himlState) nItemWidth += infoPtr->iconStateSize.cx + IMAGE_PADDING;
for (i = 0; i < infoPtr->nItemCount; i++)
{ nItemWidth = max(DEFAULT_COLUMN_WIDTH, nItemWidth + WIDTH_PADDING);
nLabelWidth = LISTVIEW_GetLabelWidth(infoPtr, i);
nItemWidth = max(nItemWidth, nLabelWidth);
}
}
else
nItemWidth = LISTVIEW_GetLabelWidth(infoPtr, nItem);
if (!nItemWidth) return DEFAULT_COLUMN_WIDTH;
nItemWidth += WIDTH_PADDING;
if (infoPtr->himlSmall) nItemWidth += infoPtr->iconSize.cx;
if (infoPtr->himlState) nItemWidth += infoPtr->iconStateSize.cx;
if (nItem == -1) nItemWidth = max(DEFAULT_COLUMN_WIDTH, nItemWidth);
} }
return max(nItemWidth, 1); return max(nItemWidth, 1);
@ -2245,19 +2229,52 @@ static INT LISTVIEW_CalculateItemWidth(LISTVIEW_INFO *infoPtr, INT nItem)
/*** /***
* DESCRIPTION: * DESCRIPTION:
* Calculates the max width of any item in the list. * Caclulates the desired item height.
* *
* PARAMETER(S): * PARAMETER(S):
* [I] infoPtr : valid pointer to the listview structure * [I] infoPtr : valid pointer to the listview structure
* *
* RETURN: * RETURN:
* Returns item width. * The desired item height.
*/ */
static inline INT LISTVIEW_CalculateMaxWidth(LISTVIEW_INFO *infoPtr) static INT LISTVIEW_CalculateItemHeight(LISTVIEW_INFO *infoPtr)
{ {
return LISTVIEW_CalculateItemWidth(infoPtr, -1); UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
INT nItemHeight;
if (uView == LVS_ICON)
nItemHeight = infoPtr->iconSpacing.cy;
else
{
nItemHeight = infoPtr->ntmHeight;
if (infoPtr->himlState)
nItemHeight = max(nItemHeight, infoPtr->iconStateSize.cy);
if (infoPtr->himlSmall)
nItemHeight = max(nItemHeight, infoPtr->iconSize.cy);
if (infoPtr->himlState || infoPtr->himlSmall)
nItemHeight += HEIGHT_PADDING;
}
return max(nItemHeight, 1);
} }
/***
* DESCRIPTION:
* Updates the width, and height of an item.
*
* PARAMETER(S):
* [I] infoPtr : valid pointer to the listview structure
*
* RETURN:
* None.
*/
static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO *infoPtr)
{
infoPtr->nItemWidth = LISTVIEW_CalculateItemWidth(infoPtr);
infoPtr->nItemHeight = LISTVIEW_CalculateItemHeight(infoPtr);
}
/*** /***
* DESCRIPTION: * DESCRIPTION:
* Retrieves and saves important text metrics info for the current * Retrieves and saves important text metrics info for the current
@ -2282,36 +2299,6 @@ static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO *infoPtr)
TRACE("tmHeight=%d\n", infoPtr->ntmHeight); TRACE("tmHeight=%d\n", infoPtr->ntmHeight);
} }
/***
* DESCRIPTION:
* Calculates the height of an item.
*
* PARAMETER(S):
* [I] infoPtr : valid pointer to the listview structure
*
* RETURN:
* Returns item height.
*/
static INT LISTVIEW_CalculateMaxHeight(LISTVIEW_INFO *infoPtr)
{
INT nItemHeight;
if ((infoPtr->dwStyle & LVS_TYPEMASK) == LVS_ICON)
nItemHeight = infoPtr->iconSpacing.cy;
else
{
nItemHeight = infoPtr->ntmHeight;
if (infoPtr->himlState)
nItemHeight = max(nItemHeight, infoPtr->iconStateSize.cy);
if (infoPtr->himlSmall)
nItemHeight = max(nItemHeight, infoPtr->iconSize.cy);
if (infoPtr->himlState || infoPtr->himlSmall)
nItemHeight += HEIGHT_PADDING;
}
return nItemHeight;
}
/*** /***
* DESCRIPTION: * DESCRIPTION:
* A compare function for ranges * A compare function for ranges
@ -6415,8 +6402,7 @@ static DWORD LISTVIEW_SetIconSpacing(LISTVIEW_INFO *infoPtr, DWORD spacing)
infoPtr->ntmHeight); infoPtr->ntmHeight);
/* these depend on the iconSpacing */ /* these depend on the iconSpacing */
infoPtr->nItemWidth = LISTVIEW_CalculateMaxWidth(infoPtr); LISTVIEW_UpdateItemSize(infoPtr);
infoPtr->nItemHeight = LISTVIEW_CalculateMaxHeight(infoPtr);
return oldspacing; return oldspacing;
} }
@ -6483,7 +6469,7 @@ static HIMAGELIST LISTVIEW_SetImageList(LISTVIEW_INFO *infoPtr, INT nType, HIMAG
return NULL; return NULL;
} }
infoPtr->nItemHeight = LISTVIEW_CalculateMaxHeight(infoPtr); infoPtr->nItemHeight = LISTVIEW_CalculateItemHeight(infoPtr);
if (infoPtr->nItemHeight != oldHeight) if (infoPtr->nItemHeight != oldHeight)
LISTVIEW_UpdateScroll(infoPtr); LISTVIEW_UpdateScroll(infoPtr);
@ -6525,8 +6511,7 @@ static BOOL LISTVIEW_SetItemCount(LISTVIEW_INFO *infoPtr, INT nItems, DWORD dwFl
LISTVIEW_GetCountPerColumn(infoPtr) + 1; LISTVIEW_GetCountPerColumn(infoPtr) + 1;
infoPtr->nItemCount = nItems; infoPtr->nItemCount = nItems;
infoPtr->nItemWidth = max(LISTVIEW_CalculateMaxWidth(infoPtr), LISTVIEW_UpdateItemSize(infoPtr);
DEFAULT_COLUMN_WIDTH);
LISTVIEW_UpdateSize(infoPtr); LISTVIEW_UpdateSize(infoPtr);
LISTVIEW_UpdateScroll(infoPtr); LISTVIEW_UpdateScroll(infoPtr);
@ -6974,8 +6959,7 @@ static LRESULT LISTVIEW_Create(HWND hwnd, LPCREATESTRUCTW lpcs)
infoPtr->hdpaPosY = DPA_Create(10); infoPtr->hdpaPosY = DPA_Create(10);
/* initialize size of items */ /* initialize size of items */
infoPtr->nItemWidth = LISTVIEW_CalculateMaxWidth(infoPtr); LISTVIEW_UpdateItemSize(infoPtr);
infoPtr->nItemHeight = LISTVIEW_CalculateMaxHeight(infoPtr);
/* initialize the hover time to -1(indicating the default system hover time) */ /* initialize the hover time to -1(indicating the default system hover time) */
infoPtr->dwHoverTime = -1; infoPtr->dwHoverTime = -1;
@ -8139,8 +8123,7 @@ static INT LISTVIEW_StyleChanged(LISTVIEW_INFO *infoPtr, WPARAM wStyleType,
SetWindowPos(infoPtr->hwndHeader, infoPtr->hwndSelf, wp.x, wp.y, wp.cx, wp.cy, wp.flags); SetWindowPos(infoPtr->hwndHeader, infoPtr->hwndSelf, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
} }
infoPtr->nItemWidth = LISTVIEW_CalculateMaxWidth(infoPtr); LISTVIEW_UpdateItemSize(infoPtr);
infoPtr->nItemHeight = LISTVIEW_CalculateMaxHeight(infoPtr);
} }
if (uNewView == LVS_REPORT) if (uNewView == LVS_REPORT)