[Win32] Keep tool bar normal, hot and disabled image lists index-aligned - #3471
Open
HeikoKlare wants to merge 1 commit into
Open
[Win32] Keep tool bar normal, hot and disabled image lists index-aligned#3471HeikoKlare wants to merge 1 commit into
HeikoKlare wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a Win32-specific toolbar rendering defect where a ToolItem could show another item’s hot (hover) or disabled image due to the native image lists (normal/hot/disabled) becoming index-misaligned. It enforces a single authoritative slot index per item across all three image lists to prevent stale or cross-item icon lookups.
Changes:
ToolItem.updateImages: derive the slot index once from the normal image list and write hot/disabled images at that same index; additionally clear the hot slot when the normal image is cleared.ToolBar.updateOrientation: when rebuilding image lists, keep new hot/disabled lists aligned by writing at the normal list’s returned index (instead of independentadd(...)calls).ImageList: introduceputAt(index, image)and implementadd(image)on top of it.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolItem.java | Keeps normal/hot/disabled image list indices aligned and clears hot slots when the normal image is cleared. |
| bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java | Preserves index alignment across rebuilt image lists during orientation updates. |
| bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/ImageList.java | Adds putAt(...) to support caller-chosen indices and refactors add(...) to use it. |
A ToolItem could render another item's hot (hover) icon without any multiple monitors or image disposal involved: setting an image, then a hot image, then clearing the image while adding a new item to the tool bar was enough. A tool bar keeps three native image lists (normal, hot, disabled) but each button stores a single image index that addresses all three at once, so the three lists must stay index-aligned. Two code paths in ToolItem.updateImages broke that: - Clearing the normal image while a hot image was still set freed the normal and disabled slots but kept the hot slot occupied. A later item reusing the freed normal slot then rendered the first item's stale hot icon on hover. - A first image was appended to each list with three independent add() calls that could return different indices once the lists' free-slot patterns diverged. Only the normal list's index was written to the button, so its slot could point at another item's hot or disabled image. ToolBar.updateOrientation used the same pattern. With this change, we enforce one index per item across all three lists: free the hot slot too when the normal image is cleared, and derive the index once from the normal list and write the hot and disabled lists at that same index. Contributes to eclipse-platform#3466 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
HeikoKlare
force-pushed
the
toolitem-align-image-lists
branch
from
July 29, 2026 15:04
4438236 to
6941171
Compare
r-mennig
reviewed
Jul 29, 2026
| * method does nothing.</li> | ||
| * </ul> | ||
| */ | ||
| public void putAt (int index, Image image) { |
There was a problem hiding this comment.
ImageList now contains both a public putAt(int index, Image image) and a public put(int index, Image image) method where putAt allows appending and put does not. So maybe putOrAppend would be a better name for this method?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows a
ToolItemcould render another item's hot (hover) or disabled icon — no multiple monitors and no image disposal required. Setting an image, then a hot image, then clearing the image while adding a new item to the tool bar is already enough to trigger it.A tool bar keeps three native image lists (normal, hot, disabled), but each button stores a single image index that addresses all three lists at once. The three lists therefore have to stay index-aligned. Two code paths in
ToolItem.updateImagesbroke that invariant:add()calls. Once the lists' free-slot patterns diverged (as caused by the first defect), those calls could return different indices. Only the normal list's index is written to the button, so its slot could end up pointing at another item's hot or disabled image.Contributes to #3466.
Fix
Enforce one index per item across all three lists:
add()calls returning matching indices).ToolBar.updateOrientationadopts the same discipline.This is implemented with a small
ImageList.putAt(index, image)that stores an image at a caller-chosen index (appending when the index equals the current size, otherwise replacing or, for anullimage, clearing the slot).add(image)is now implemented on top of it by first computing the target index.Reproduction
Run the snippet below and hover the mouse over the second (blue) button:
Before (wrong behavior):

After (corrected behavior):
