Commit 0e73e478 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

comctl32/tab: Fix TCM_SETCURSEL on negative indices.

parent 8c2b4bfe
......@@ -252,22 +252,29 @@ static inline LRESULT TAB_SetCurSel (TAB_INFO *infoPtr, INT iItem)
TRACE("(%p %d)\n", infoPtr, iItem);
if (iItem < 0)
infoPtr->iSelected = -1;
else if (iItem >= infoPtr->uNumItem)
if (iItem >= (INT)infoPtr->uNumItem)
return -1;
else {
if (prevItem != iItem) {
if (prevItem != -1)
TAB_GetItem(infoPtr, prevItem)->dwState &= ~TCIS_BUTTONPRESSED;
TAB_GetItem(infoPtr, iItem)->dwState |= TCIS_BUTTONPRESSED;
if (prevItem != iItem) {
if (prevItem != -1)
TAB_GetItem(infoPtr, prevItem)->dwState &= ~TCIS_BUTTONPRESSED;
if (iItem >= 0)
{
TAB_GetItem(infoPtr, iItem)->dwState |= TCIS_BUTTONPRESSED;
infoPtr->iSelected = iItem;
infoPtr->uFocus = iItem;
TAB_EnsureSelectionVisible(infoPtr);
TAB_InvalidateTabArea(infoPtr);
}
else
{
infoPtr->iSelected = -1;
infoPtr->uFocus = -1;
}
TAB_EnsureSelectionVisible(infoPtr);
TAB_InvalidateTabArea(infoPtr);
}
return prevItem;
}
......
......@@ -746,6 +746,24 @@ static void test_cursel(void)
ok (tcItem.dwState & TCIS_BUTTONPRESSED || broken(tcItem.dwState == 0), /* older comctl32 */
"Selected item should have TCIS_BUTTONPRESSED\n");
/* now deselect all and check previously selected item state */
focusIndex = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
ok(focusIndex == 1, "got %d\n", focusIndex);
selectionIndex = SendMessageA(hTab, TCM_SETCURSEL, -1, 0);
ok(selectionIndex == 1, "got %d\n", selectionIndex);
memset(&tcItem, 0, sizeof(TCITEMA));
/* focus is reset too */
focusIndex = SendMessageA(hTab, TCM_GETCURFOCUS, 0, 0);
ok(focusIndex == -1, "got %d\n", focusIndex);
tcItem.mask = TCIF_STATE;
tcItem.dwStateMask = TCIS_BUTTONPRESSED;
SendMessageA(hTab, TCM_GETITEMA, selectionIndex, (LPARAM)&tcItem);
ok(tcItem.dwState == 0, "got state %d\n", tcItem.dwState);
DestroyWindow(hTab);
}
......
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