From: Piotr Pawłowski <p@perkele.cc> --- dlls/comctl32/tests/treeview.c | 4 ++-- dlls/comctl32/treeview.c | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/dlls/comctl32/tests/treeview.c b/dlls/comctl32/tests/treeview.c index 1265bafcfbd..4af67ccd660 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..94ff829ff9d 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, stateImage, numStates; - unsigned int state; + /* 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 = STATEIMAGEINDEX(item->state); - TRACE("state: 0x%x\n", state); - item->state &= ~TVIS_STATEIMAGEMASK; + state = item->state; + stateImage = STATEIMAGEINDEX(state); + TRACE("stateImage: 0x%x\n", stateImage); + state &= ~TVIS_STATEIMAGEMASK; - if (state < 3) - state = state_table[state]; + if ( stateImage > 0 ) + { + ++ stateImage; + if ( stateImage >= numStates ) stateImage = 1; + } - item->state |= INDEXTOSTATEIMAGEMASK(state); + state |= INDEXTOSTATEIMAGEMASK(stateImage); - TRACE("state: 0x%x\n", state); - TREEVIEW_Invalidate(infoPtr, item); + TRACE("stateImage: 0x%x\n", stateImage); + + item->state = state; + TREEVIEW_Invalidate(infoPtr, item); } } -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10207