Bug 464816 - [Gtk3] Adding SWT.EraseItem listener and drawing background
makes the TreeItem/TableItem text dissapear
- Updated Code for Table as well

The code change is related to setting the correct clipping during the EraseItem event.

This has been tested on Fedora 19 with GTK+ 3.8.8 and Ubuntu 14.04 with GTK+ 3.10.

Testing is done using the snippet provided and modified snippet for table as well. Ran the SWT junit test suite. 

For regression testing, used a self hosted eclipse and tested on multiple views like Call hierarchy, Type hierarchy, etc. Verified that they are working fine.

Change-Id: I8bdb7f219ccbfec467b85c88a1e72c5fdc3dcf3e
Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
Signed-off-by: Sravan Kumar Lakkimsetti <sravankumarl@in.ibm.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
index 6bfbfa9..cd9cb94 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java
@@ -2649,7 +2649,9 @@
 					if (control != null) {
 						if (cr != 0) {
 							Cairo.cairo_save (cr);
-							Cairo.cairo_reset_clip (cr);
+							if (!OS.GTK3){
+								Cairo.cairo_reset_clip (cr);
+							}
 						}
 						drawBackground (control, window, cr, 0, rect.x, rect.y, rect.width, rect.height);
 						if (cr != 0) {
@@ -2669,13 +2671,15 @@
 				if (wasSelected) {
 					Control control = findBackgroundControl ();
 					if (control == null) control = this;
-					if (cr != 0) {
-						Cairo.cairo_save (cr);
-						Cairo.cairo_reset_clip (cr);
-					}
-					drawBackground (control, window, cr, 0, rect.x, rect.y, rect.width, rect.height);
-					if (cr != 0) {
-						Cairo.cairo_restore (cr);
+					if (!OS.GTK3){
+						if (cr != 0) {
+							Cairo.cairo_save (cr);
+							Cairo.cairo_reset_clip (cr);
+						}
+						drawBackground (control, window, cr, 0, rect.x, rect.y, rect.width, rect.height);
+						if (cr != 0) {
+							Cairo.cairo_restore (cr);
+						}
 					}
 				}
 				GC gc = getGC(cr);
@@ -2688,7 +2692,11 @@
 				}
 				gc.setFont (item.getFont (columnIndex));
 				if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x;
-				if (!OS.GTK3) {
+				if (OS.GTK_VERSION >= OS.VERSION(3, 9, 0) && cr != 0) {
+					GdkRectangle r = new GdkRectangle();
+					OS.gdk_cairo_get_clip_rectangle(cr, r);
+					gc.setClipping(rect.x, r.y, r.width, r.height);
+				} else {
 					gc.setClipping (rect.x, rect.y, rect.width, rect.height);
 				}
 				Event event = new Event ();
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 cba55c3..7b88efe 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
@@ -2703,7 +2703,11 @@
 				gc.setFont (item.getFont (columnIndex));
 				if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x;
 
-				if (!OS.GTK3) {
+				if (OS.GTK_VERSION >= OS.VERSION(3, 9, 0) && cr != 0) {
+					GdkRectangle r = new GdkRectangle();
+					OS.gdk_cairo_get_clip_rectangle(cr, r);
+					gc.setClipping(rect.x, r.y, r.width, r.height);
+				} else {
 					gc.setClipping (rect.x, rect.y, rect.width, rect.height);
 				}
 				Event event = new Event ();