diff options
author | Eric Williams | 2017-12-22 16:38:15 +0000 |
---|---|---|
committer | Eric Williams | 2017-12-22 16:39:22 +0000 |
commit | b604eee7de39f258e1c9d04e70a0f98aaf17a4f2 (patch) | |
tree | 4f45b9f63b1b34988e12b65b6e50421b1243ee82 /tests | |
parent | 9913c5a1d7242c20e4a6f4f111e4d54e5569991f (diff) | |
download | eclipse.platform.swt-b604eee7de39f258e1c9d04e70a0f98aaf17a4f2.tar.gz eclipse.platform.swt-b604eee7de39f258e1c9d04e70a0f98aaf17a4f2.tar.xz eclipse.platform.swt-b604eee7de39f258e1c9d04e70a0f98aaf17a4f2.zip |
Bug 529126: [Wayland][GTK3] Tree does not notify SWT.MouseDown listeners
Added bug snippet to reproduce the issue.
Change-Id: Ib4bfdab5fb2230ea7a33898af7db069704548216
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/Bug529126_TreeMouseDown.java | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug529126_TreeMouseDown.java b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug529126_TreeMouseDown.java new file mode 100644 index 0000000000..dece34c7fa --- /dev/null +++ b/tests/org.eclipse.swt.tests.gtk/Bug Snippets/org/eclipse/swt/tests/gtk/snippets/Bug529126_TreeMouseDown.java @@ -0,0 +1,134 @@ +package org.eclipse.swt.tests.gtk.snippets; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.Region; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.swt.widgets.TreeItem; + +/* + * Title: Bug 529126: [Wayland][GTK3] Tree does not notify SWT.MouseDown listeners + * How to run: launch snippet and click on TreeItems + * Bug description: No output is printed to the console + * Expected results: Output with event info should be printed to the console for each + * mouse down. + * GTK Version(s): GTK3 (Wayland only) + */ +public class Bug529126_TreeMouseDown { + + // Static ================================================================= + + public static void main(String[] args) { + final Display display = new Display(); + final Shell shell = new Shell(display); + shell.setText("Custom gradient selection for Tree"); + shell.setLayout(new FillLayout()); + final Tree tree = new Tree(shell, SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL); + tree.setHeaderVisible(true); + tree.setLinesVisible(true); + final int columnCount = 4; + for (int i = 0; i < columnCount; i++) { + final TreeColumn column = new TreeColumn(tree, SWT.NONE); + column.setText("Column " + i); + } + + final int itemCount = 5; + for (int i = 0; i < itemCount; i++) { + final TreeItem item1 = new TreeItem(tree, SWT.NONE); + + for (int j = 0; j < i; j++) { + final TreeItem item2 = new TreeItem(item1, SWT.NONE); + + for (int k = 0; k < j; k++) { + new TreeItem(item2, SWT.NONE); + } + } + } + + tree.addListener(SWT.SetData, event -> { + final TreeItem item = (TreeItem)event.item; + + final TreeItem parentItem = item.getParentItem(); + final String text; + + if (parentItem != null) { + final String parentText = (String)parentItem.getData(); + text = parentText + event.index + "/"; + } + else { + text = "/"; + } + + item.setData(text); + }); + + tree.addListener(SWT.PaintItem, event -> { + final TreeItem item = (TreeItem)event.item; + final String text = (String)item.getData(); + event.gc.drawText(text + " [" + event.index + "]", event.x, event.y, true); + }); + + /* + * NOTE: MeasureItem, PaintItem and EraseItem are called repeatedly. + * Therefore, it is critical for performance that these methods be + * as efficient as possible. + */ + tree.addListener(SWT.EraseItem, event -> { + event.detail &= ~SWT.HOT; + if ((event.detail & SWT.SELECTED) != 0) { + final GC gc = event.gc; + final Rectangle area = tree.getClientArea(); + /* + * If you wish to paint the selection beyond the end of + * last column, you must change the clipping region. + */ + final int columnCount1 = tree.getColumnCount(); + if (event.index == columnCount1 - 1 || columnCount1 == 0) { + final int width = area.x + area.width - event.x; + if (width > 0) { + final Region region = new Region(); + gc.getClipping(region); + region.add(event.x, event.y, width, event.height); + gc.setClipping(region); + region.dispose(); + } + } + gc.setAdvanced(true); + if (gc.getAdvanced()) { + gc.setAlpha(127); + } + final Rectangle rect = event.getBounds(); + final Color foreground = gc.getForeground(); + final Color background = gc.getBackground(); + gc.setForeground(display.getSystemColor(SWT.COLOR_RED)); + gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND)); + gc.fillGradientRectangle(0, rect.y, 500, rect.height, false); + // restore colors for subsequent drawing + gc.setForeground(foreground); + gc.setBackground(background); + event.detail &= ~SWT.SELECTED; + } + }); + tree.getColumn(0).setWidth(200); + for (int i = 1; i < columnCount; i++) { + tree.getColumn(i).pack(); + } + tree.setSelection(tree.getItem(0)); + + tree.addListener(SWT.MouseDown, event -> System.out.println("event = " + event)); + shell.setSize(500, 500); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + display.dispose(); + } +} |