Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbeyj@wpi.edu>

Cleaned up LISTVIEW_KeyDown by using LISTVIEW_GetNextItem.  Removed unused
variable in LISTVIEW_GetNextItem.
This commit is contained in:
Alexandre Julliard 1999-05-24 08:06:39 +00:00
parent d131a17ee0
commit 37c07bc74c
1 changed files with 10 additions and 139 deletions

View File

@ -3945,7 +3945,6 @@ static LRESULT LISTVIEW_GetNextItem(HWND hwnd, INT iStart, UINT uFlags)
{ {
LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0); LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE); LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
LISTVIEW_ITEM *lpItem;
UINT style_mask = LVS_TYPEMASK & lStyle; UINT style_mask = LVS_TYPEMASK & lStyle;
UINT uMask = 0; UINT uMask = 0;
INT nItems = GETITEMCOUNT(infoPtr); INT nItems = GETITEMCOUNT(infoPtr);
@ -5541,14 +5540,11 @@ static LRESULT LISTVIEW_HScroll(HWND hwnd, INT nScrollCode,
static LRESULT LISTVIEW_KeyDown(HWND hwnd, INT nVirtualKey, LONG lKeyData) static LRESULT LISTVIEW_KeyDown(HWND hwnd, INT nVirtualKey, LONG lKeyData)
{ {
LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0); LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
INT nCtrlId = GetWindowLongA(hwnd, GWL_ID); INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
INT nCountPerColumn;
INT nCountPerRow;
HWND hwndParent = GetParent(hwnd); HWND hwndParent = GetParent(hwnd);
NMLVKEYDOWN nmKeyDown; NMLVKEYDOWN nmKeyDown;
NMHDR nmh; NMHDR nmh;
INT oldFocusedItem = infoPtr->nFocusedItem; INT nextItem = -1;
/* send LVN_KEYDOWN notification */ /* send LVN_KEYDOWN notification */
ZeroMemory(&nmKeyDown, sizeof(NMLVKEYDOWN)); ZeroMemory(&nmKeyDown, sizeof(NMLVKEYDOWN));
@ -5580,154 +5576,28 @@ static LRESULT LISTVIEW_KeyDown(HWND hwnd, INT nVirtualKey, LONG lKeyData)
case VK_HOME: case VK_HOME:
if (GETITEMCOUNT(infoPtr) > 0) if (GETITEMCOUNT(infoPtr) > 0)
{ nextItem = 0;
LISTVIEW_KeySelection(hwnd, 0);
}
break; break;
case VK_END: case VK_END:
if (GETITEMCOUNT(infoPtr) > 0) if (GETITEMCOUNT(infoPtr) > 0)
{ nextItem = GETITEMCOUNT(infoPtr) - 1;
LISTVIEW_KeySelection(hwnd, GETITEMCOUNT(infoPtr) - 1);
}
break; break;
case VK_LEFT: case VK_LEFT:
switch (LVS_TYPEMASK & lStyle) nextItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TOLEFT);
{
case LVS_LIST:
if (infoPtr->nFocusedItem >= infoPtr->nCountPerColumn)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem -
infoPtr->nCountPerColumn);
}
break;
case LVS_SMALLICON:
case LVS_ICON:
if (lStyle & LVS_ALIGNLEFT)
{
nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
infoPtr->nItemHeight, 1);
if (infoPtr->nFocusedItem >= nCountPerColumn)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem - nCountPerColumn);
}
}
else
{
nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
infoPtr->nItemWidth, 1);
if (infoPtr->nFocusedItem % nCountPerRow != 0)
{
LISTVIEW_SetSelection(hwnd, infoPtr->nFocusedItem - 1);
}
}
break;
}
break; break;
case VK_UP: case VK_UP:
switch (LVS_TYPEMASK & lStyle) nextItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_ABOVE);
{
case LVS_LIST:
case LVS_REPORT:
if (infoPtr->nFocusedItem > 0)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem - 1);
}
break;
default:
if (lStyle & LVS_ALIGNLEFT)
{
nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
infoPtr->nItemHeight, 1);
if (infoPtr->nFocusedItem % nCountPerColumn != 0)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem - 1);
}
}
else
{
nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
infoPtr->nItemWidth, 1);
if (infoPtr->nFocusedItem >= nCountPerRow)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem - nCountPerRow);
}
}
}
break; break;
case VK_RIGHT: case VK_RIGHT:
switch (LVS_TYPEMASK & lStyle) nextItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TORIGHT);
{
case LVS_LIST:
if (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) -
infoPtr->nCountPerColumn)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem +
infoPtr->nCountPerColumn);
}
break;
case LVS_ICON:
case LVS_SMALLICON:
if (lStyle & LVS_ALIGNLEFT)
{
nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
infoPtr->nItemHeight, 1);
if (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) - nCountPerColumn)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + nCountPerColumn);
}
}
else
{
nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
infoPtr->nItemWidth, 1);
if ((infoPtr->nFocusedItem % nCountPerRow != nCountPerRow - 1) &&
(infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) - 1))
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + 1);
}
}
}
break; break;
case VK_DOWN: case VK_DOWN:
switch (LVS_TYPEMASK & lStyle) nextItem = LISTVIEW_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_BELOW);
{
case LVS_LIST:
case LVS_REPORT:
if (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) - 1)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + 1);
}
break;
case LVS_SMALLICON:
case LVS_ICON:
if (lStyle & LVS_ALIGNLEFT)
{
nCountPerColumn = max((infoPtr->rcList.bottom - infoPtr->rcList.top) /
infoPtr->nItemHeight, 1);
if (infoPtr->nFocusedItem % nCountPerColumn != nCountPerColumn - 1)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + 1);
}
}
else
{
nCountPerRow = max((infoPtr->rcList.right - infoPtr->rcList.left) /
infoPtr->nItemWidth, 1);
if (infoPtr->nFocusedItem < GETITEMCOUNT(infoPtr) - nCountPerRow)
{
LISTVIEW_KeySelection(hwnd, infoPtr->nFocusedItem + nCountPerRow);
}
}
}
break; break;
case VK_PRIOR: case VK_PRIOR:
@ -5737,9 +5607,10 @@ static LRESULT LISTVIEW_KeyDown(HWND hwnd, INT nVirtualKey, LONG lKeyData)
break; break;
} }
/* refresh client area if necessary*/ if((nextItem != infoPtr->nFocusedItem) && (nextItem != -1)) {
if(oldFocusedItem != infoPtr->nFocusedItem) LISTVIEW_KeySelection(hwnd, nextItem);
InvalidateRect(hwnd, NULL, TRUE); InvalidateRect(hwnd, NULL, TRUE);
}
return 0; return 0;
} }