Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexandr Miloslavskiy2020-05-13 20:52:54 +0000
committerNiraj Modi2020-05-15 14:07:48 +0000
commitfdad775eff1272fde91253a01f85ee57d35b3ec6 (patch)
tree397393c16c8d55246022b385c53447c088c3e9b7
parent3cd2dc7cb792b9be2c78013774b23a7cbecd4560 (diff)
downloadeclipse.platform.swt-fdad775eff1272fde91253a01f85ee57d35b3ec6.tar.gz
eclipse.platform.swt-fdad775eff1272fde91253a01f85ee57d35b3ec6.tar.xz
eclipse.platform.swt-fdad775eff1272fde91253a01f85ee57d35b3ec6.zip
Bug 560284 - [win32][Dark] Table header delimiters color is bad for dark theme
The color is configurable, because Eclipse and the product I'm working on are likely to use different colors. For API design goals, see recent patch for Bug 444560. Change-Id: I9a1dec43d6081097bb0db0a47a0f381163ba5b32 Signed-off-by: Alexandr Miloslavskiy <alexandr.miloslavskiy@syntevo.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java10
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java14
-rw-r--r--tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560284_DarkTableHeaderLineColor.java221
4 files changed, 242 insertions, 4 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
index 6ca6bfc5af..f75d045cc0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/win32/org/eclipse/swt/internal/win32/OS.java
@@ -2361,6 +2361,7 @@ public static final void setTheme(boolean isDarkTheme) {
display.setData("org.eclipse.swt.internal.win32.Table.use_WS_BORDER", isDarkTheme);
display.setData("org.eclipse.swt.internal.win32.Text.use_WS_BORDER", isDarkTheme);
display.setData("org.eclipse.swt.internal.win32.Tree.use_WS_BORDER", isDarkTheme);
+ display.setData("org.eclipse.swt.internal.win32.Table.headerLineColor", isDarkTheme ? new Color(display, 0x50, 0x50, 0x50) : null);
}
public static final boolean SetDllDirectory (TCHAR lpPathName) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 15f321386b..b25dc66b7a 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -222,6 +222,13 @@ public class Display extends Device {
boolean useWsBorderText = false;
static final String USE_WS_BORDER_TREE_KEY = "org.eclipse.swt.internal.win32.Tree.use_WS_BORDER"; //$NON-NLS-1$
boolean useWsBorderTree = false;
+ /**
+ * Changes the color of Table header's column delimiters.
+ * Only affects custom-drawn header, that is when background/foreground header color is set.
+ * Expects a <code>Color</code> value.
+ */
+ static final String TABLE_HEADER_LINE_COLOR_KEY = "org.eclipse.swt.internal.win32.Table.headerLineColor"; //$NON-NLS-1$
+ int tableHeaderLinePixel = -1;
/* Custom icons */
long hIconSearch;
@@ -4401,6 +4408,9 @@ public void setData (String key, Object value) {
case USE_WS_BORDER_TREE_KEY:
useWsBorderTree = !disableCustomThemeTweaks && _toBoolean(value);
return;
+ case TABLE_HEADER_LINE_COLOR_KEY:
+ tableHeaderLinePixel = disableCustomThemeTweaks ? -1 : _toColorPixel(value);
+ return;
}
/* Remove the key/value pair */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java
index 8c50ec196f..efd4d1f913 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Table.java
@@ -6954,18 +6954,24 @@ LRESULT wmNotifyHeader (NMHDR hdr, long wParam, long lParam) {
OS.DeleteObject (pen);
}
+ int alignmentCorrection = _getLinesVisible () ? 0 : 1;
+
/* Windows 7 and 10 always draw a nearly invisible vertical line between the columns, even if lines are disabled.
This line uses no fixed color constant, but calculates it from the background color.
- The method getSlightlyDifferentColor gives us a color, that is near enough to the windows algorithm. */
+ The method getSlightlyDifferentColor gives us a color, that is near enough to the windows algorithm.
+
+ NOTE: This code has no effect since Bug 517003, because next OS.Polyline() draws over the same coords.
+
long pen = OS.CreatePen (OS.PS_SOLID, getGridLineWidthInPixels(), getSlightlyDifferentColor(getHeaderBackgroundPixel()));
long oldPen = OS.SelectObject (nmcd.hdc, pen);
- int alignmentCorrection = _getLinesVisible () ? 0 : 1;
OS.Polyline(nmcd.hdc, new int[] {rects[i].right-alignmentCorrection, rects[i].top, rects[i].right-alignmentCorrection, rects[i].bottom}, 2);
OS.SelectObject (nmcd.hdc, oldPen);
OS.DeleteObject (pen);
+ */
- pen = OS.CreatePen (OS.PS_SOLID, getGridLineWidthInPixels(), OS.GetSysColor(OS.COLOR_3DFACE));
- oldPen = OS.SelectObject (nmcd.hdc, pen);
+ int lineColor = (display.tableHeaderLinePixel != -1) ? display.tableHeaderLinePixel : OS.GetSysColor(OS.COLOR_3DFACE);
+ long pen = OS.CreatePen (OS.PS_SOLID, getGridLineWidthInPixels(), lineColor);
+ long oldPen = OS.SelectObject (nmcd.hdc, pen);
/* To differentiate headers, always draw header column separator. */
OS.Polyline(nmcd.hdc, new int[] {rects[i].right - alignmentCorrection, rects[i].top, rects[i].right - alignmentCorrection, rects[i].bottom}, 2);
/* To differentiate header & content area, always draw the line separator between header & first row. */
diff --git a/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560284_DarkTableHeaderLineColor.java b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560284_DarkTableHeaderLineColor.java
new file mode 100644
index 0000000000..a54512da81
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.win32/ManualTests/org/eclipse/swt/tests/win32/snippets/Bug560284_DarkTableHeaderLineColor.java
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Syntevo and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Syntevo - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.swt.tests.win32.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.RowLayout;
+import org.eclipse.swt.widgets.*;
+
+public class Bug560284_DarkTableHeaderLineColor {
+ static class EmptyListener implements Listener {
+ @Override
+ public void handleEvent(Event event) {
+ }
+ }
+
+ static EmptyListener emptyListener = new EmptyListener();
+
+ static void setColors(Control control, Color backColor, Color foreColor) {
+ control.setBackground(backColor);
+ control.setForeground(foreColor);
+
+ if (control instanceof Table) {
+ Table table = (Table)control;
+ table.setHeaderBackground(backColor);
+ table.setHeaderForeground(foreColor);
+ }
+
+ if (control instanceof Composite) {
+ for (Control child : ((Composite)control).getChildren()) {
+ setColors(child, backColor, foreColor);
+ }
+ }
+ }
+
+ public static void setTableHeaderLineColor(Table table, Color color) {
+ table.getDisplay().setData("org.eclipse.swt.internal.win32.Table.headerLineColor", color);
+ table.redraw();
+
+ // Hack to trigger header redraw
+ table.setSize(table.getSize());
+ }
+
+ public static void main (String [] args) {
+ Display display = new Display ();
+
+ Shell shell = new Shell (display);
+ RowLayout layout = new RowLayout(SWT.VERTICAL);
+ layout.marginHeight = 10;
+ layout.marginWidth = 10;
+ layout.spacing = 10;
+ shell.setLayout(layout);
+
+ final Text labelInfo = new Text(shell, SWT.READ_ONLY | SWT.MULTI);
+ labelInfo.setText(
+ "Notice that table header delimiter lines are too bright"
+ );
+
+ final Table table = new Table(shell, SWT.BORDER);
+ table.setHeaderVisible(true);
+ TableColumn column1 = new TableColumn(table, SWT.NONE);
+ column1.setText("Column");
+ column1.setWidth(100);
+ TableColumn column2 = new TableColumn(table, SWT.NONE);
+ column2.setText("Column");
+ column2.setWidth(100);
+ TableItem item1 = new TableItem(table, SWT.NONE);
+ item1.setText("Item");
+
+ Composite options = new Composite(shell, SWT.NONE);
+ options.setLayout(new RowLayout(SWT.HORIZONTAL));
+ {
+ Group grpTableOwnerDraw = new Group(options, SWT.NONE);
+ grpTableOwnerDraw.setText("Owner draw");
+ grpTableOwnerDraw.setLayout(new RowLayout(SWT.VERTICAL));
+ {
+ Button btnNo = new Button(grpTableOwnerDraw, SWT.RADIO);
+ btnNo.setText("No");
+ btnNo.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+
+ table.removeListener(SWT.EraseItem, emptyListener);
+ table.removeListener(SWT.MeasureItem, emptyListener);
+ table.removeListener(SWT.PaintItem, emptyListener);
+
+ // owner draw is only disabled after last item was removed
+ table.removeAll();
+ new TableItem(table, SWT.NONE).setText("Item");
+ });
+
+ Button btnYes = new Button(grpTableOwnerDraw, SWT.RADIO);
+ btnYes.setText("Yes");
+ btnYes.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+
+ table.addListener(SWT.EraseItem, emptyListener);
+ table.addListener(SWT.MeasureItem, emptyListener);
+ table.addListener(SWT.PaintItem, emptyListener);
+ });
+
+ btnNo.setSelection(true);
+ }
+
+ Group grpTableLinesVisible = new Group(options, SWT.NONE);
+ grpTableLinesVisible.setText("Table lines");
+ grpTableLinesVisible.setLayout(new RowLayout(SWT.VERTICAL));
+ {
+ Button btnNo = new Button(grpTableLinesVisible, SWT.RADIO);
+ btnNo.setText("No");
+ btnNo.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+
+ table.setLinesVisible(false);
+ });
+
+ Button btnYes = new Button(grpTableLinesVisible, SWT.RADIO);
+ btnYes.setText("Yes");
+ btnYes.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+
+ table.setLinesVisible(true);
+ });
+
+ btnNo.setSelection(true);
+ }
+
+ Group grpTheme = new Group(options, SWT.NONE);
+ grpTheme.setText("Theme");
+ grpTheme.setLayout(new RowLayout(SWT.VERTICAL));
+ {
+ Button btnDefault = new Button(grpTheme, SWT.RADIO);
+ btnDefault.setText("Default");
+ btnDefault.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+
+ setColors(shell, null, null);
+ });
+
+ Button btnLight = new Button(grpTheme, SWT.RADIO);
+ btnLight.setText("Light");
+ btnLight.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+
+ Color backColor = new Color(display, 0xFF, 0xFF, 0xFF);
+ Color foreColor = new Color(display, 0x00, 0x00, 0x00);
+ setColors(shell, backColor, foreColor);
+ });
+
+ Button btnDark = new Button(grpTheme, SWT.RADIO);
+ btnDark.setText("Dark");
+ btnDark.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+
+ Color backColor = new Color(display, 0x30, 0x30, 0x30);
+ Color foreColor = new Color(display, 0xD0, 0xD0, 0xD0);
+ setColors(shell, backColor, foreColor);
+
+ // Somehow fixes table's border. Another bug?
+ table.redraw();
+ });
+
+ btnDefault.setSelection(true);
+ }
+
+ Group grpTableHeaderLineColor = new Group(options, SWT.NONE);
+ grpTableHeaderLineColor.setText("Header lines");
+ grpTableHeaderLineColor.setLayout(new RowLayout(SWT.VERTICAL));
+ {
+ Button btnDefault = new Button(grpTableHeaderLineColor, SWT.RADIO);
+ btnDefault.setText("Default");
+ btnDefault.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+ setTableHeaderLineColor(table, null);
+ });
+
+ Button btnLight = new Button(grpTableHeaderLineColor, SWT.RADIO);
+ btnLight.setText("For light");
+ btnLight.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+ setTableHeaderLineColor(table, new Color(display, 0xE5, 0xE5, 0xE5));
+ });
+
+ Button btnDark = new Button(grpTableHeaderLineColor, SWT.RADIO);
+ btnDark.setText("For dark");
+ btnDark.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+ setTableHeaderLineColor(table, new Color(display, 0x50, 0x50, 0x50));
+ });
+
+ Button btnRed = new Button(grpTableHeaderLineColor, SWT.RADIO);
+ btnRed.setText("Red");
+ btnRed.addListener(SWT.Selection, event -> {
+ if (!((Button)event.widget).getSelection()) return;
+ setTableHeaderLineColor(table, new Color(display, 0xFF, 0x00, 0x00));
+ });
+
+ btnDefault.setSelection(true);
+ }
+ }
+
+ shell.pack();
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch ()) display.sleep ();
+ }
+
+ display.dispose ();
+ }
+}

Back to the top