Fix the selected background in Toolbar on Windows#3202
Fix the selected background in Toolbar on Windows#3202vogella merged 1 commit intoeclipse-platform:masterfrom
Conversation
Test Results (win32) 28 files 28 suites 4m 46s ⏱️ Results for commit 0479587. ♻️ This comment has been updated with latest results. |
Take the same approach as Button.java, manually fill the background for checked items and tell Windows to skip its own background: Now in dark mode, for each toolbar item: - Checked: fill with getDifferentColor() (20% lighter shade) - Hot (hovered): fill with getSlightlyDifferentColor() (10% lighter shade) - Normal: fill with the background color Then TBCDRF_NOBACKGROUND prevents Windows from painting its own white highlight on top. Fixes: eclipse-platform#217
0c4acae to
0479587
Compare
|
Anyone interested in reviewing? Windows is not my turf so I would appretiate a second pair of eyes. |
There was a problem hiding this comment.
Pull request overview
Updates Win32 ToolBar custom-draw handling to better support Windows dark mode by manually painting checked/hovered item backgrounds and preventing the native toolbar control from drawing its own (light) highlight on top.
Changes:
- Always opt into toolbar item custom-draw when
Display.useDarkModeExplorerThemeis enabled. - In dark mode, manually fill the item background for
CDIS_CHECKEDandCDIS_HOTstates using lighter variants of the toolbar background. - Return
TBCDRF_NOBACKGROUNDfor those states to stop Windows from painting its default highlight.
| long result = OS.TBCDRF_USECDCOLORS; | ||
| nmcd.clrBtnFace = getBackgroundPixel (child); | ||
| int bgPixel = getBackgroundPixel (child); | ||
| nmcd.clrBtnFace = bgPixel; | ||
| nmcd.clrBtnHighlight = getDifferentColor (bgPixel); | ||
| nmcd.clrText = getForegroundPixel (child); | ||
| OS.MoveMemory (lParam, nmcd, NMTBCUSTOMDRAW.sizeof); |
There was a problem hiding this comment.
Because CDDS_PREPAINT now opts into item custom-draw whenever display.useDarkModeExplorerTheme is enabled, CDDS_ITEMPREPAINT will run even when the app hasn't set custom colors. Returning TBCDRF_USECDCOLORS and always setting nmcd.clrText via getForegroundPixel(child) can override the native dark-theme text color (similar to how Button.customForegroundDrawing() only changes text color when an explicit foreground is set). Consider only setting clrText (and/or returning TBCDRF_USECDCOLORS) when ToolBar/ToolItem has an explicit foreground/background override; for the dark-mode-only path you can just paint the hot/checked background and return TBCDRF_NOBACKGROUND to keep native text rendering.
There was a problem hiding this comment.
the TBCDRF_USECDCOLORS + clrText pattern is pre-existing and out of scope for this fix



Take the same approach as Button.java, manually fill the background for checked items and tell Windows to skip its own background:
Now in dark mode, for each toolbar item:
Then TBCDRF_NOBACKGROUND prevents Windows from painting its own white highlight on top.
Fixes: #217