From: Piotr Pawłowski <p@perkele.cc> --- dlls/comctl32/tests/treeview.c | 4 ++-- dlls/comctl32/treeview.c | 33 +++++++++++++++++++++------------ 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c index 1974823b71b..cf17f9e13e4 100644 --- a/dlls/comctl32/tests/treeview.c +++ b/dlls/comctl32/tests/treeview.c @@ -2872,14 +2872,14 @@ static void test_TVS_CHECKBOXES(void) item.mask = TVIF_STATE; ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item); expect(TRUE, ret); - todo_wine ok((item.state&TVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(3), "item.state=%x\n", item.state); + ok((item.state&TVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(3), "item.state=%x\n", item.state); SendMessageA(hTree, WM_KEYDOWN, VK_SPACE, 0); item.hItem = hChild; item.mask = TVIF_STATE; ret = SendMessageA(hTree, TVM_GETITEMA, 0, (LPARAM)&item); expect(TRUE, ret); - todo_wine ok((item.state&TVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(1), "item.state=%x\n", item.state); + ok((item.state&TVIS_STATEIMAGEMASK) == INDEXTOSTATEIMAGEMASK(1), "item.state=%x\n", item.state); himl = (HIMAGELIST)SendMessageA(hTree, TVM_SETIMAGELIST, TVSIL_STATE, (LPARAM)himl); ok(himl == himl2, "got %p\n", himl); diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c index 8b38f098553..43191ce0f4c 100644 --- a/dlls/comctl32/treeview.c +++ b/dlls/comctl32/treeview.c @@ -2342,21 +2342,30 @@ TREEVIEW_ToggleItemState(const TREEVIEW_INFO *infoPtr, TREEVIEW_ITEM *item) { if (infoPtr->dwStyle & TVS_CHECKBOXES) { - static const unsigned int state_table[] = { 0, 2, 1 }; - - unsigned int state; - - state = STATEIMAGEINDEX(item->state); - TRACE("state: 0x%x\n", state); - item->state &= ~TVIS_STATEIMAGEMASK; + unsigned int state, stateImage, numStates; + + /* Toggle item state cycles through images other than zero, if image list with more state images is set */ + numStates = 0; + if ( infoPtr->himlState ) numStates = ImageList_GetImageCount(infoPtr->himlState); + if ( numStates < 3 ) numStates = 3; + + state = item->state; + stateImage = STATEIMAGEINDEX(state); + TRACE("stateImage: 0x%x\n", stateImage); + state &= ~TVIS_STATEIMAGEMASK; + + if ( stateImage > 0 ) + { + ++ stateImage; + if ( stateImage >= numStates ) stateImage = 1; + } - if (state < 3) - state = state_table[state]; + state |= INDEXTOSTATEIMAGEMASK(stateImage); - item->state |= INDEXTOSTATEIMAGEMASK(state); + TRACE("stateImage: 0x%x\n", stateImage); - TRACE("state: 0x%x\n", state); - TREEVIEW_Invalidate(infoPtr, item); + item->state = state; + TREEVIEW_Invalidate(infoPtr, item); } } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10207