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

Use (semi)standard HitTest, rather then our own little invention.

Get rid of GetItemAtPt. Fix HitTest but in REPORT mode.
parent 20b26e71
...@@ -2527,38 +2527,6 @@ static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *infoPtr, INT nItem) ...@@ -2527,38 +2527,6 @@ static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *infoPtr, INT nItem)
return bResult; return bResult;
} }
/***
* DESCRIPTION:
* Selects an item based on coordinates.
*
* PARAMETER(S):
* [I] infoPtr : valid pointer to the listview structure
* [I] pt : mouse click ccordinates
*
* RETURN:
* SUCCESS : item index
* FAILURE : -1
*/
/* FIXME: get rid of this function, use HitTest instead */
static INT LISTVIEW_GetItemAtPt(LISTVIEW_INFO *infoPtr, POINT pt)
{
ITERATOR i;
RECT rcItem;
iterator_visibleitems(&i, infoPtr);
while(iterator_next(&i))
{
rcItem.left = LVIR_SELECTBOUNDS;
if (LISTVIEW_GetItemRect(infoPtr, i.nItem, &rcItem))
{
TRACE("i=%d, rcItem=%s\n", i.nItem, debugrect(&rcItem));
if (PtInRect(&rcItem, pt)) break;
}
}
iterator_destroy(&i);
return i.nItem;
}
/*** /***
* DESCRIPTION: * DESCRIPTION:
...@@ -5578,6 +5546,7 @@ static LRESULT LISTVIEW_GetStringWidthT(LISTVIEW_INFO *infoPtr, LPCWSTR lpszText ...@@ -5578,6 +5546,7 @@ static LRESULT LISTVIEW_GetStringWidthT(LISTVIEW_INFO *infoPtr, LPCWSTR lpszText
* [I] infoPtr : valid pointer to the listview structure * [I] infoPtr : valid pointer to the listview structure
* [IO] lpht : hit test information * [IO] lpht : hit test information
* [I] subitem : fill out iSubItem. * [I] subitem : fill out iSubItem.
* [I] select : return the index only if the hit selects the item
* *
* NOTE: * NOTE:
* (mm 20001022): We must not allow iSubItem to be touched, for * (mm 20001022): We must not allow iSubItem to be touched, for
...@@ -5588,12 +5557,12 @@ static LRESULT LISTVIEW_GetStringWidthT(LISTVIEW_INFO *infoPtr, LPCWSTR lpszText ...@@ -5588,12 +5557,12 @@ static LRESULT LISTVIEW_GetStringWidthT(LISTVIEW_INFO *infoPtr, LPCWSTR lpszText
* SUCCESS : item index * SUCCESS : item index
* FAILURE : -1 * FAILURE : -1
*/ */
static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BOOL subitem) static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BOOL subitem, BOOL select)
{ {
UINT uView = infoPtr->dwStyle & LVS_TYPEMASK; UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
RECT rcBounds, rcIcon, rcLabel; RECT rcBounds, rcIcon, rcLabel;
TRACE("(x=%ld, y=%ld)\n", lpht->pt.x, lpht->pt.y); TRACE("(pt=%s, subitem=%d, select=%d)\n", debugpoint(&lpht->pt), subitem, select);
lpht->flags = 0; lpht->flags = 0;
lpht->iItem = -1; lpht->iItem = -1;
...@@ -5643,15 +5612,18 @@ static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BO ...@@ -5643,15 +5612,18 @@ static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BO
else else
{ {
POINT Origin, Position; POINT Origin, Position;
INT nPerCol = LISTVIEW_GetCountPerColumn(infoPtr); INT nPerCol = (uView == LVS_REPORT) ? infoPtr->nItemCount : LISTVIEW_GetCountPerColumn(infoPtr);
if (!LISTVIEW_GetOrigin(infoPtr, &Origin)) return -1; 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",
debugpoint(&Position), nPerCol, infoPtr->nItemHeight, nPerCol * infoPtr->nItemHeight);
if (Position.y < nPerCol * infoPtr->nItemHeight) if (Position.y < nPerCol * infoPtr->nItemHeight)
{ {
lpht->iItem = (Position.x / infoPtr->nItemWidth) * nPerCol + (Position.y / infoPtr->nItemHeight); lpht->iItem = (Position.x / infoPtr->nItemWidth) * nPerCol + (Position.y / infoPtr->nItemHeight);
TRACE("iItem=%d\n", lpht->iItem);
if (lpht->iItem < 0 || lpht->iItem >= infoPtr->nItemCount) lpht->iItem = -1; if (lpht->iItem < 0 || lpht->iItem >= infoPtr->nItemCount) lpht->iItem = -1;
} }
} }
...@@ -5717,7 +5689,11 @@ static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BO ...@@ -5717,7 +5689,11 @@ static LRESULT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BO
} }
} }
return lpht->iItem; if (!select || lpht->iItem == -1) return lpht->iItem;
if (uView == LVS_REPORT && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT)) return lpht->iItem;
return lpht->flags & (LVHT_ONITEMICON | LVHT_ONITEMLABEL) ? lpht->iItem : -1;
} }
...@@ -7599,7 +7575,7 @@ static LRESULT LISTVIEW_LButtonDblClk(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS ...@@ -7599,7 +7575,7 @@ static LRESULT LISTVIEW_LButtonDblClk(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS
/* send NM_DBLCLK notification */ /* send NM_DBLCLK notification */
ZeroMemory(&nmlv, sizeof(NMLISTVIEW)); ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
LISTVIEW_HitTest(infoPtr, &htInfo, TRUE); LISTVIEW_HitTest(infoPtr, &htInfo, TRUE, FALSE);
nmlv.iItem = htInfo.iItem; nmlv.iItem = htInfo.iItem;
nmlv.iSubItem = htInfo.iSubItem; nmlv.iSubItem = htInfo.iSubItem;
nmlv.ptAction = htInfo.pt; nmlv.ptAction = htInfo.pt;
...@@ -7626,6 +7602,7 @@ static LRESULT LISTVIEW_LButtonDblClk(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS ...@@ -7626,6 +7602,7 @@ static LRESULT LISTVIEW_LButtonDblClk(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS
*/ */
static LRESULT LISTVIEW_LButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts) static LRESULT LISTVIEW_LButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
{ {
LVHITTESTINFO lvHitTestInfo;
LONG lStyle = infoPtr->dwStyle; LONG lStyle = infoPtr->dwStyle;
static BOOL bGroupSelect = TRUE; static BOOL bGroupSelect = TRUE;
POINT pt = { pts.x, pts.y }; POINT pt = { pts.x, pts.y };
...@@ -7643,7 +7620,10 @@ static LRESULT LISTVIEW_LButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pt ...@@ -7643,7 +7620,10 @@ static LRESULT LISTVIEW_LButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pt
/* set left button down flag */ /* set left button down flag */
infoPtr->bLButtonDown = TRUE; infoPtr->bLButtonDown = TRUE;
nItem = LISTVIEW_GetItemAtPt(infoPtr, pt); lvHitTestInfo.pt.x = pts.x;
lvHitTestInfo.pt.y = pts.y;
nItem = LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE, TRUE);
TRACE("at %s, nItem=%d\n", debugpoint(&pt), nItem); TRACE("at %s, nItem=%d\n", debugpoint(&pt), nItem);
if ((nItem >= 0) && (nItem < infoPtr->nItemCount)) if ((nItem >= 0) && (nItem < infoPtr->nItemCount))
{ {
...@@ -7734,7 +7714,7 @@ static LRESULT LISTVIEW_LButtonUp(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts) ...@@ -7734,7 +7714,7 @@ static LRESULT LISTVIEW_LButtonUp(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
/* send NM_CLICK notification */ /* send NM_CLICK notification */
ZeroMemory(&nmlv, sizeof(NMLISTVIEW)); ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE); LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE, FALSE);
nmlv.iItem = lvHitTestInfo.iItem; nmlv.iItem = lvHitTestInfo.iItem;
nmlv.iSubItem = lvHitTestInfo.iSubItem; nmlv.iSubItem = lvHitTestInfo.iSubItem;
nmlv.ptAction = lvHitTestInfo.pt; nmlv.ptAction = lvHitTestInfo.pt;
...@@ -7972,11 +7952,11 @@ static LRESULT LISTVIEW_RButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pt ...@@ -7972,11 +7952,11 @@ static LRESULT LISTVIEW_RButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pt
/* determine the index of the selected item */ /* determine the index of the selected item */
lvHitTestInfo.pt.x = pts.x; lvHitTestInfo.pt.x = pts.x;
lvHitTestInfo.pt.y = pts.y; lvHitTestInfo.pt.y = pts.y;
nItem = LISTVIEW_GetItemAtPt(infoPtr, lvHitTestInfo.pt); nItem = LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE, TRUE);
if ((nItem >= 0) && (nItem < infoPtr->nItemCount)) if ((nItem >= 0) && (nItem < infoPtr->nItemCount))
{ {
LISTVIEW_SetItemFocus(infoPtr,nItem); LISTVIEW_SetItemFocus(infoPtr, nItem);
if (!((wKey & MK_SHIFT) || (wKey & MK_CONTROL)) && if (!((wKey & MK_SHIFT) || (wKey & MK_CONTROL)) &&
!LISTVIEW_GetItemState(infoPtr, nItem, LVIS_SELECTED)) !LISTVIEW_GetItemState(infoPtr, nItem, LVIS_SELECTED))
LISTVIEW_SetSelection(infoPtr, nItem); LISTVIEW_SetSelection(infoPtr, nItem);
...@@ -7989,7 +7969,6 @@ static LRESULT LISTVIEW_RButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pt ...@@ -7989,7 +7969,6 @@ static LRESULT LISTVIEW_RButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pt
/* Send NM_RClICK notification */ /* Send NM_RClICK notification */
ZeroMemory(&nmlv, sizeof(nmlv)); ZeroMemory(&nmlv, sizeof(nmlv));
LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE);
nmlv.iItem = lvHitTestInfo.iItem; nmlv.iItem = lvHitTestInfo.iItem;
nmlv.iSubItem = lvHitTestInfo.iSubItem; nmlv.iSubItem = lvHitTestInfo.iSubItem;
nmlv.ptAction = lvHitTestInfo.pt; nmlv.ptAction = lvHitTestInfo.pt;
...@@ -8048,14 +8027,14 @@ static LRESULT LISTVIEW_RButtonUp(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts) ...@@ -8048,14 +8027,14 @@ static LRESULT LISTVIEW_RButtonUp(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
*/ */
static BOOL LISTVIEW_SetCursor(LISTVIEW_INFO *infoPtr, HWND hwnd, UINT nHittest, UINT wMouseMsg) static BOOL LISTVIEW_SetCursor(LISTVIEW_INFO *infoPtr, HWND hwnd, UINT nHittest, UINT wMouseMsg)
{ {
POINT pt; LVHITTESTINFO lvHitTestInfo;
if(!(infoPtr->dwLvExStyle & LVS_EX_TRACKSELECT)) return FALSE; if(!(infoPtr->dwLvExStyle & LVS_EX_TRACKSELECT)) return FALSE;
if(!infoPtr->hHotCursor) return FALSE; if(!infoPtr->hHotCursor) return FALSE;
GetCursorPos(&pt); GetCursorPos(&lvHitTestInfo.pt);
if (LISTVIEW_GetItemAtPt(infoPtr, pt) < 0) return FALSE; if (LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, FALSE, FALSE) < 0) return FALSE;
SetCursor(infoPtr->hHotCursor); SetCursor(infoPtr->hHotCursor);
...@@ -8592,7 +8571,7 @@ LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...@@ -8592,7 +8571,7 @@ LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
/* case LVN_HASGROUP: */ /* case LVN_HASGROUP: */
case LVM_HITTEST: case LVM_HITTEST:
return LISTVIEW_HitTest(infoPtr, (LPLVHITTESTINFO)lParam, FALSE); return LISTVIEW_HitTest(infoPtr, (LPLVHITTESTINFO)lParam, FALSE, FALSE);
case LVM_INSERTCOLUMNA: case LVM_INSERTCOLUMNA:
return LISTVIEW_InsertColumnT(infoPtr, (INT)wParam, (LPLVCOLUMNW)lParam, FALSE); return LISTVIEW_InsertColumnT(infoPtr, (INT)wParam, (LPLVCOLUMNW)lParam, FALSE);
...@@ -8742,7 +8721,7 @@ LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ...@@ -8742,7 +8721,7 @@ LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
return LISTVIEW_SortItems(infoPtr, (PFNLVCOMPARE)lParam, (LPARAM)wParam); return LISTVIEW_SortItems(infoPtr, (PFNLVCOMPARE)lParam, (LPARAM)wParam);
case LVM_SUBITEMHITTEST: case LVM_SUBITEMHITTEST:
return LISTVIEW_HitTest(infoPtr, (LPLVHITTESTINFO)lParam, TRUE); return LISTVIEW_HitTest(infoPtr, (LPLVHITTESTINFO)lParam, TRUE, FALSE);
case LVM_UPDATE: case LVM_UPDATE:
return LISTVIEW_Update(infoPtr, (INT)wParam); return LISTVIEW_Update(infoPtr, (INT)wParam);
......
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