From 0479587a7a05d5cfd031b29badd65eb800c07389 Mon Sep 17 00:00:00 2001 From: Lars Vogel Date: Tue, 7 Apr 2026 18:23:12 +0200 Subject: [PATCH] Fix the selected background in Toolbar on Windows 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: https://github.com/eclipse-platform/eclipse.platform.swt/issues/217 --- .../org/eclipse/swt/widgets/ToolBar.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java index c0e9186b6c..90ea3747dd 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java @@ -1688,17 +1688,30 @@ LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) { } case OS.CDDS_PREPAINT: { long result = OS.CDRF_DODEFAULT; - if (background != -1 || (foreground != -1 && OS.IsWindowEnabled (handle)) || (state & CUSTOM_DRAW_ITEM) != 0) { + if (background != -1 || (foreground != -1 && OS.IsWindowEnabled (handle)) || (state & CUSTOM_DRAW_ITEM) != 0 || display.useDarkModeExplorerTheme) { result = OS.CDRF_NOTIFYITEMDRAW; } return new LRESULT (result); } case OS.CDDS_ITEMPREPAINT: { 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); - if (child != null && child.background != -1) { + if (display.useDarkModeExplorerTheme && (nmcd.uItemState & (OS.CDIS_CHECKED | OS.CDIS_HOT)) != 0) { + int pixel; + if ((nmcd.uItemState & OS.CDIS_CHECKED) != 0) { + pixel = getDifferentColor (bgPixel); + } else { + pixel = getSlightlyDifferentColor (bgPixel); + } + RECT rect = new RECT (nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); + OS.SetDCBrushColor (nmcd.hdc, pixel); + OS.FillRect (nmcd.hdc, rect, OS.GetStockObject (OS.DC_BRUSH)); + result |= OS.TBCDRF_NOBACKGROUND; + } else if (child != null && child.background != -1) { RECT rect = new RECT (nmcd.left, nmcd.top, nmcd.right, nmcd.bottom); OS.SetDCBrushColor (nmcd.hdc, child.background); OS.FillRect (nmcd.hdc, rect, OS.GetStockObject (OS.DC_BRUSH));