Skip to content

Commit 0c4acae

Browse files
committed
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: #217
1 parent 9e86574 commit 0c4acae

File tree

1 file changed

+16
-3
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+16
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolBar.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1688,17 +1688,30 @@ LRESULT wmNotifyChild (NMHDR hdr, long wParam, long lParam) {
16881688
}
16891689
case OS.CDDS_PREPAINT: {
16901690
long result = OS.CDRF_DODEFAULT;
1691-
if (background != -1 || (foreground != -1 && OS.IsWindowEnabled (handle)) || (state & CUSTOM_DRAW_ITEM) != 0) {
1691+
if (background != -1 || (foreground != -1 && OS.IsWindowEnabled (handle)) || (state & CUSTOM_DRAW_ITEM) != 0 || display.useDarkModeExplorerTheme) {
16921692
result = OS.CDRF_NOTIFYITEMDRAW;
16931693
}
16941694
return new LRESULT (result);
16951695
}
16961696
case OS.CDDS_ITEMPREPAINT: {
16971697
long result = OS.TBCDRF_USECDCOLORS;
1698-
nmcd.clrBtnFace = getBackgroundPixel (child);
1698+
int bgPixel = getBackgroundPixel (child);
1699+
nmcd.clrBtnFace = bgPixel;
1700+
nmcd.clrBtnHighlight = getDifferentColor (bgPixel);
16991701
nmcd.clrText = getForegroundPixel (child);
17001702
OS.MoveMemory (lParam, nmcd, NMTBCUSTOMDRAW.sizeof);
1701-
if (child != null && child.background != -1) {
1703+
if (display.useDarkModeExplorerTheme && (nmcd.uItemState & (OS.CDIS_CHECKED | OS.CDIS_HOT)) != 0) {
1704+
int pixel;
1705+
if ((nmcd.uItemState & OS.CDIS_CHECKED) != 0) {
1706+
pixel = getDifferentColor (bgPixel);
1707+
} else {
1708+
pixel = getSlightlyDifferentColor (bgPixel);
1709+
}
1710+
RECT rect = new RECT (nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
1711+
OS.SetDCBrushColor (nmcd.hdc, pixel);
1712+
OS.FillRect (nmcd.hdc, rect, OS.GetStockObject (OS.DC_BRUSH));
1713+
result |= OS.TBCDRF_NOBACKGROUND;
1714+
} else if (child != null && child.background != -1) {
17021715
RECT rect = new RECT (nmcd.left, nmcd.top, nmcd.right, nmcd.bottom);
17031716
OS.SetDCBrushColor (nmcd.hdc, child.background);
17041717
OS.FillRect (nmcd.hdc, rect, OS.GetStockObject (OS.DC_BRUSH));

0 commit comments

Comments
 (0)