Bug 536934 - [GTK3] Tree does not allow painting the full item

Changes made to custom drawn trees which updates event.x from Cairo
context causes paint to "jump" when scrolling horizontally and not
scrolling to the end of the text on GTK3.16 and above. Checks for GTK
versions >3.9 and <3.14.8 when making updating event.x from Cairo
context. See bug 535124, and bug 465309.

Tested on GTK3.22 with snippet attached to this patch, sample project in
bug 535124, and the open type dialog, package explorer in a child
Eclipse.

Change-Id: Iaf464c6fee1d5ef288346abbd0ab5a60f20f1a95
Signed-off-by: Xi Yan <xixiyan@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
index 49200c0..b92fbc5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java
@@ -3158,8 +3158,8 @@
 				long /*int*/ path = GTK.gtk_tree_model_get_path (modelHandle, iter);
 				GTK.gtk_tree_view_get_background_area (handle, path, columnHandle, rect);
 				GTK.gtk_tree_path_free (path);
-				// Use the x and width information from the Cairo context. See bug 535124.
-				if (cr != 0 && GTK.GTK3) {
+				// Use the x and width information from the Cairo context. See bug 535124 and 465309.
+				if (cr != 0 && GTK.GTK_VERSION > OS.VERSION(3, 9, 0) && GTK.GTK_VERSION <= OS.VERSION(3, 14, 8)) {
 					GdkRectangle r2 = new GdkRectangle ();
 					GDK.gdk_cairo_get_clip_rectangle (cr, r2);
 					rect.x = r2.x;
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug536934_TreeFullItem.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug536934_TreeFullItem.java
new file mode 100644
index 0000000..afcb837
--- /dev/null
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug536934_TreeFullItem.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * Copyright (c) 2018 Red Hat and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Thomas Singer
+ *******************************************************************************/
+package org.eclipse.swt.tests.gtk.snippets;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+
+public class Bug536934_TreeFullItem {
+
+	public static void main(String[] args) {
+		final Display display = new Display();
+
+		final Shell shell = new Shell(display);
+		shell.setLayout(new FillLayout());
+
+		final Tree tree = new Tree(shell, SWT.BORDER);
+
+		final TreeItem item1 = new TreeItem(tree, SWT.None);
+		new TreeItem(item1, SWT.NONE);
+		final TreeItem item2 = new TreeItem(tree, SWT.None);
+		new TreeItem(item2, SWT.NONE);
+
+		final Listener listener = new Listener() {
+			private final String text = "item fkds fjsd fd  dsf d fd sfkl dsl fsld fl sfl sd f dflk sd flds fds END";
+
+			@Override
+			public void handleEvent(Event event) {
+				if (event.type == SWT.MeasureItem) {
+					final Point size = event.gc.textExtent(text);
+					event.width = size.x;
+					event.height = size.y;
+				}
+				else if (event.type == SWT.EraseItem) {
+					if ((event.detail & SWT.SELECTED) > 0) {
+						event.gc.setBackground(display.getSystemColor(SWT.COLOR_BLUE));
+						event.gc.setForeground(display.getSystemColor(SWT.COLOR_YELLOW));
+					}
+					else {
+						event.gc.setBackground(display.getSystemColor(SWT.COLOR_MAGENTA));
+						event.gc.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
+					}
+					event.gc.fillRectangle(event.x, event.y, event.width, event.height);
+					event.detail &= ~SWT.SELECTED;
+				}
+				else if (event.type == SWT.PaintItem) {
+					event.gc.drawText(text, event.x, event.y, true);
+				}
+			}
+		};
+		tree.addListener(SWT.MeasureItem, listener);
+		tree.addListener(SWT.EraseItem, listener);
+		tree.addListener(SWT.PaintItem, listener);
+
+		shell.setSize(300, 300);
+		shell.open();
+
+		while (!shell.isDisposed()) {
+			if (!display.readAndDispatch()) {
+				display.sleep();
+			}
+		}
+
+		display.dispose();
+	}
+}
\ No newline at end of file