From: Piotr Pawłowski <p@perkele.cc> --- dlls/comctl32/treeview.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/dlls/comctl32/treeview.c b/dlls/comctl32/treeview.c index 6cc49fa02ab..bdcbaa0dd2c 100644 --- a/dlls/comctl32/treeview.c +++ b/dlls/comctl32/treeview.c @@ -2342,21 +2342,29 @@ 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