Make use of the new GetItemMetrics in HitTest, to avoid code
duplication.
This commit is contained in:
parent
f1f447931e
commit
01b5226508
|
@ -5478,8 +5478,11 @@ static LRESULT LISTVIEW_GetStringWidthT(LISTVIEW_INFO *infoPtr, LPCWSTR lpszText
|
||||||
*/
|
*/
|
||||||
static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BOOL subitem, BOOL select)
|
static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BOOL subitem, BOOL select)
|
||||||
{
|
{
|
||||||
|
WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
|
||||||
UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
|
UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
|
||||||
RECT rcBounds, rcIcon, rcLabel;
|
RECT rcBounds, rcState, rcIcon, rcLabel;
|
||||||
|
POINT Origin, Position, opt;
|
||||||
|
LVITEMW lvItem;
|
||||||
|
|
||||||
TRACE("(pt=%s, subitem=%d, select=%d)\n", debugpoint(&lpht->pt), subitem, select);
|
TRACE("(pt=%s, subitem=%d, select=%d)\n", debugpoint(&lpht->pt), subitem, select);
|
||||||
|
|
||||||
|
@ -5501,8 +5504,10 @@ static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BO
|
||||||
|
|
||||||
lpht->flags |= LVHT_NOWHERE;
|
lpht->flags |= LVHT_NOWHERE;
|
||||||
|
|
||||||
|
if (!LISTVIEW_GetOrigin(infoPtr, &Origin)) return -1;
|
||||||
|
|
||||||
/* first deal with the large items */
|
/* first deal with the large items */
|
||||||
if (uView == LVS_ICON && (infoPtr->dwStyle & LVS_OWNERDRAWFIXED) &&
|
if (uView == LVS_ICON && !(infoPtr->dwStyle & LVS_OWNERDRAWFIXED) &&
|
||||||
PtInRect (&infoPtr->rcFocus, lpht->pt))
|
PtInRect (&infoPtr->rcFocus, lpht->pt))
|
||||||
{
|
{
|
||||||
lpht->iItem = infoPtr->nFocusedItem;
|
lpht->iItem = infoPtr->nFocusedItem;
|
||||||
|
@ -5530,10 +5535,8 @@ static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BO
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
POINT Origin, Position;
|
|
||||||
INT nPerCol = (uView == LVS_REPORT) ? infoPtr->nItemCount : LISTVIEW_GetCountPerColumn(infoPtr);
|
INT nPerCol = (uView == LVS_REPORT) ? infoPtr->nItemCount : LISTVIEW_GetCountPerColumn(infoPtr);
|
||||||
|
|
||||||
if (!LISTVIEW_GetOrigin(infoPtr, &Origin)) return -1;
|
|
||||||
Position.x = lpht->pt.x - Origin.x;
|
Position.x = lpht->pt.x - Origin.x;
|
||||||
Position.y = lpht->pt.y - Origin.y;
|
Position.y = lpht->pt.y - Origin.y;
|
||||||
TRACE("Position=%s, nPerCol=%d, nItemHeight=%d, nColHeight=%d\n",
|
TRACE("Position=%s, nPerCol=%d, nItemHeight=%d, nColHeight=%d\n",
|
||||||
|
@ -5550,45 +5553,29 @@ static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BO
|
||||||
|
|
||||||
if (lpht->iItem == -1) return -1;
|
if (lpht->iItem == -1) return -1;
|
||||||
|
|
||||||
if (!LISTVIEW_GetItemMeasures(infoPtr, lpht->iItem, 0, &rcBounds, &rcIcon, &rcLabel)) return -1;
|
lvItem.mask = LVIF_STATE | LVIF_TEXT;
|
||||||
|
if (uView == LVS_REPORT) lvItem.mask |= LVIF_INDENT;
|
||||||
if (!PtInRect(&rcBounds, lpht->pt)) return -1;
|
|
||||||
|
|
||||||
if (PtInRect(&rcIcon, lpht->pt))
|
|
||||||
lpht->flags |= LVHT_ONITEMICON;
|
|
||||||
else if (PtInRect(&rcLabel, lpht->pt))
|
|
||||||
lpht->flags |= LVHT_ONITEMLABEL;
|
|
||||||
else if (infoPtr->himlState)
|
|
||||||
{
|
|
||||||
/* FIXME: move this to GetItemMeasures */
|
|
||||||
LVITEMW lvItem;
|
|
||||||
|
|
||||||
lvItem.mask = LVIF_STATE;
|
|
||||||
lvItem.stateMask = LVIS_STATEIMAGEMASK;
|
lvItem.stateMask = LVIS_STATEIMAGEMASK;
|
||||||
|
if (uView == LVS_ICON && infoPtr->bFocus) lvItem.stateMask |= LVIS_FOCUSED;
|
||||||
lvItem.iItem = lpht->iItem;
|
lvItem.iItem = lpht->iItem;
|
||||||
lvItem.iSubItem = 0;
|
lvItem.iSubItem = 0;
|
||||||
|
lvItem.pszText = szDispText;
|
||||||
|
lvItem.cchTextMax = DISP_TEXT_SIZE;
|
||||||
if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return -1;
|
if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return -1;
|
||||||
{
|
|
||||||
UINT uStateImage = (lvItem.state & LVIS_STATEIMAGEMASK) >> 12;
|
|
||||||
RECT rcState;
|
|
||||||
|
|
||||||
if (uView == LVS_ICON)
|
if (!LISTVIEW_GetItemMetrics(infoPtr, &lvItem, 0, &rcBounds, &rcState, &rcIcon, &rcLabel)) return -1;
|
||||||
{
|
if (!LISTVIEW_GetItemListOrigin(infoPtr, lpht->iItem, &Position)) return -1;
|
||||||
rcState.left = rcIcon.left - infoPtr->iconStateSize.cx + 10;
|
opt.x = lpht->pt.x - Position.x - Origin.x;
|
||||||
rcState.top = rcIcon.top + infoPtr->iconSize.cy - infoPtr->iconStateSize.cy + 4;
|
opt.y = lpht->pt.y - Position.y - Origin.y;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
rcState.left = rcIcon.left - infoPtr->iconStateSize.cx - IMAGE_PADDING;
|
|
||||||
rcState.top = rcIcon.top;
|
|
||||||
}
|
|
||||||
rcState.right = rcState.left + infoPtr->iconStateSize.cx;
|
|
||||||
rcState.bottom = rcState.top + infoPtr->iconStateSize.cy;
|
|
||||||
|
|
||||||
if (uStateImage > 0 && PtInRect(&rcState, lpht->pt))
|
if (!PtInRect(&rcBounds, opt)) return -1;
|
||||||
|
|
||||||
|
if (PtInRect(&rcIcon, opt))
|
||||||
|
lpht->flags |= LVHT_ONITEMICON;
|
||||||
|
else if (PtInRect(&rcLabel, opt))
|
||||||
|
lpht->flags |= LVHT_ONITEMLABEL;
|
||||||
|
else if (infoPtr->himlState && ((lvItem.state & LVIS_STATEIMAGEMASK) >> 12) && PtInRect(&rcState, opt))
|
||||||
lpht->flags |= LVHT_ONITEMSTATEICON;
|
lpht->flags |= LVHT_ONITEMSTATEICON;
|
||||||
}
|
|
||||||
}
|
|
||||||
if (lpht->flags & LVHT_ONITEM)
|
if (lpht->flags & LVHT_ONITEM)
|
||||||
lpht->flags &= ~LVHT_NOWHERE;
|
lpht->flags &= ~LVHT_NOWHERE;
|
||||||
|
|
||||||
|
@ -5600,7 +5587,7 @@ static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BO
|
||||||
{
|
{
|
||||||
rcBounds.left = rcBounds.right;
|
rcBounds.left = rcBounds.right;
|
||||||
rcBounds.right += LISTVIEW_GetColumnWidth(infoPtr, j);
|
rcBounds.right += LISTVIEW_GetColumnWidth(infoPtr, j);
|
||||||
if (PtInRect(&rcBounds, lpht->pt))
|
if (PtInRect(&rcBounds, opt))
|
||||||
{
|
{
|
||||||
lpht->iSubItem = j;
|
lpht->iSubItem = j;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue