Skip to main content
aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEric Williams2018-01-03 10:35:15 -0500
committerEric Williams2018-01-04 14:29:44 -0500
commitca42124d01c6987adde92880f9ba6d7d97f9f982 (patch)
tree7b7ca3e8218a95f9befcd443b9ee5d678d51a24d /tests
parent655b31c499816e2a0b21c8f8f215c8b1a4f7920d (diff)
downloadeclipse.platform.swt-ca42124d01c6987adde92880f9ba6d7d97f9f982.tar.gz
eclipse.platform.swt-ca42124d01c6987adde92880f9ba6d7d97f9f982.tar.xz
eclipse.platform.swt-ca42124d01c6987adde92880f9ba6d7d97f9f982.zip
Bug 528155: [GTK] Table/Tree forgets to set SWT.SELECTED bit on
PaintItem Bug snippet to reproduce the issue. Change-Id: I7047c7cae0fc126b6c7be3db7814b836b9234b43 Signed-off-by: Eric Williams <ericwill@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug528155_TableTreeForegroundDrawing.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug528155_TableTreeForegroundDrawing.java b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug528155_TableTreeForegroundDrawing.java
new file mode 100644
index 0000000000..85c795378a
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug528155_TableTreeForegroundDrawing.java
@@ -0,0 +1,112 @@
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+/*
+ * Title: Bug 528155: [GTK] Table/Tree forgets to set SWT.SELECTED bit on PaintItem
+ * How to run: launch snippet and click the first row of either Table/Tree widget
+ * Bug description: The red selection foreground color is not displayed for either Table/Tree
+ * Expected results: The selected items of each widget should have a red foreground color
+ * GTK Version(s): GTK2, GTK3
+ */
+public class Bug528155_TableTreeForegroundDrawing {
+
+ public static void main(String[] args) {
+ final Display display = new Display();
+
+ final Shell shell = new Shell(display);
+ shell.setLayout(new FillLayout());
+
+ final Color defaultBack = display.getSystemColor(SWT.COLOR_YELLOW);
+ final Color defaultFore = display.getSystemColor(SWT.COLOR_DARK_GRAY);
+ final Color selectionBack = display.getSystemColor(SWT.COLOR_BLUE);
+ final Color selectionBackUnfocused = display.getSystemColor(SWT.COLOR_GRAY);
+ final Color selectionFore = display.getSystemColor(SWT.COLOR_RED);
+
+ final Tree tree = new Tree(shell, SWT.BORDER);
+ tree.setBackground(defaultBack);
+ tree.setForeground(defaultFore);
+ final Listener treeListener = event -> {
+ if (event.type == SWT.MeasureItem) {
+ event.width = 50;
+ }
+ else if (event.type == SWT.EraseItem) {
+ if ((event.detail & SWT.SELECTED) != 0) {
+ event.gc.setBackground(tree.isFocusControl() ? selectionBack : selectionBackUnfocused);
+ event.gc.fillRectangle(event.x, event.y, event.width, event.height);
+ event.detail &= ~SWT.SELECTED;
+ }
+ }
+ else if (event.type == SWT.PaintItem) {
+ if ((event.detail & SWT.SELECTED) != 0) {
+ event.gc.setForeground(selectionFore);
+ }
+ event.gc.drawString("Node " + event.index, event.x, event.y, true);
+ }
+ };
+ tree.addListener(SWT.MeasureItem, treeListener);
+ tree.addListener(SWT.EraseItem, treeListener);
+ tree.addListener(SWT.PaintItem, treeListener);
+
+ new TreeItem(tree, SWT.NONE);
+ new TreeItem(tree, SWT.NONE);
+
+ final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL);
+ table.setBackground(defaultBack);
+ table.setForeground(defaultFore);
+ table.setHeaderVisible(true);
+
+ final TableColumn column = new TableColumn(table, SWT.LEFT);
+ column.setText("Column 1");
+ column.setWidth(400);
+
+ final Listener tableListener = event -> {
+ if (event.type == SWT.MeasureItem) {
+ event.width = 50;
+ }
+ else if (event.type == SWT.EraseItem) {
+ if ((event.detail & SWT.SELECTED) != 0) {
+ event.gc.setBackground(table.isFocusControl() ? selectionBack : selectionBackUnfocused);
+ event.gc.fillRectangle(event.x, event.y, event.width, event.height);
+// cachedDetail = event.detail;
+ event.detail &= ~SWT.SELECTED;
+ }
+ }
+ else if (event.type == SWT.PaintItem) {
+// if ((cachedDetail & SWT.SELECTED) != 0) {
+ if ((event.detail & SWT.SELECTED) != 0) {
+ event.gc.setForeground(selectionFore);
+ }
+ event.gc.drawString("Row " + event.index, event.x, event.y, true);
+ }
+ else if (event.type == SWT.SetData) {
+ }
+ };
+ table.addListener(SWT.SetData, tableListener);
+ table.addListener(SWT.MeasureItem, tableListener);
+ table.addListener(SWT.EraseItem, tableListener);
+ table.addListener(SWT.PaintItem, tableListener);
+
+ table.setItemCount(2);
+
+ shell.setSize(500, 400);
+ shell.open();
+
+ while (!shell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+
+ display.dispose();
+ }
+}

Back to the top