7c442c1
From 8a745bffa40230e73fb229950d6d0520b474c8f3 Mon Sep 17 00:00:00 2001
7c442c1
From: Eric Williams
7c442c1
Date: Tue, 13 Feb 2018 14:25:46 -0500
7c442c1
Subject: Bug 511133: [GTK3.10+] Some critical icons missing on Ubuntu 16.04
7c442c1
7c442c1
This patch fixes Table/Tree drawing in EGit. It patch reverts the
7c442c1
changes introduced for bug 438505, which causes this regression. This
7c442c1
patch also contains fixes to prevent bug 438505 from being
7c442c1
re-introduced.
7c442c1
7c442c1
EGit drawing was broken because TableItem.getBounds() was taking the
7c442c1
position of the header into account. This is because we were drawing on
7c442c1
the fixedHandle instead of the GtkTreeView. The positioning of the Table
7c442c1
header broke simple drawing cases like Snippet051TableCenteredImage
7c442c1
(JFace snippet). Reverting the fix back to drawing on the handle has
7c442c1
fixed that issue.
7c442c1
7c442c1
Unfortunately this means bug 438505 is re-introduced. To fix that issue
7c442c1
I have tweaked the re-parenting logic found in
7c442c1
Table/Tree.setParentWindow(). GTK3.10+ onward only draws on toplevel or
7c442c1
native GdkWindows. This means the Text widgets used for Table/Tree
7c442c1
editing continue to get events, but they are not drawn. The solution to
7c442c1
this problem is call gdk_window_raise/lower on these Text widgets when
7c442c1
setVisible() is called. This raises and lowers the Text's GdkWindow when
7c442c1
the widget's visibility is changed, ensuring that it actually is drawn
7c442c1
when visible, and not when hidden. This isn't a huge change as the
7c442c1
GdkWindow re-parenting already existed in Table/Tree.setParentWindow(),
7c442c1
this patch just builds on that.
7c442c1
7c442c1
I have tested against the following cases/snippets:
7c442c1
Snippet88
7c442c1
Snippet019 (JFace snippets)
7c442c1
Snippet025 (JFace snippets)
7c442c1
Snippet026 (JFace snippets)
7c442c1
Snippet051 (JFace snippets)
7c442c1
use case from bug 438505
7c442c1
use case from bug 436324
7c442c1
use case from bug 460581
7c442c1
use case from bug 458630
7c442c1
7c442c1
Additionally, using a child Eclipse I have verified that the missing
7c442c1
EGit icons have returned. No AllNonBrowser JUnit tests fail.
7c442c1
7c442c1
Change-Id: I02b3fb30037a8f0f74de79144f8e563f5284d571
7c442c1
Signed-off-by: Eric Williams <ericwill@redhat.com>---
7c442c1
 .../gtk/org/eclipse/swt/widgets/Control.java       | 19 +++++++++++++--
7c442c1
 .../gtk/org/eclipse/swt/widgets/Table.java         | 28 ++++++++++++----------
7c442c1
 .../gtk/org/eclipse/swt/widgets/TableItem.java     |  3 ---
7c442c1
 .../gtk/org/eclipse/swt/widgets/Tree.java          | 28 ++++++++++++----------
7c442c1
 .../gtk/org/eclipse/swt/widgets/TreeItem.java      |  3 ---
7c442c1
 5 files changed, 49 insertions(+), 32 deletions(-)
7c442c1
7c442c1
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
7c442c1
index 5bb916a..e29d144 100644
7c442c1
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java	
7c442c1
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java	
7c442c1
@@ -64,6 +64,7 @@ public abstract class Control extends Widget implements Drawable {
7c442c1
 	Accessible accessible;
7c442c1
 	Control labelRelation;
7c442c1
 	String cssBackground, cssForeground = " ";
7c442c1
+	boolean reparentOnVisibility;
7c442c1
 
7c442c1
 	LinkedList <Event> dragDetectionQueue;
7c442c1
 
7c442c1
@@ -5286,7 +5287,7 @@ void setParentBackground () {
7c442c1
 	if (fixedHandle != 0) setBackgroundColor (fixedHandle, null);
7c442c1
 }
7c442c1
 
7c442c1
-void setParentWindow (long /*int*/ widget) {
7c442c1
+void setParentWindow (Control child) {
7c442c1
 }
7c442c1
 
7c442c1
 boolean setRadioSelection (boolean value) {
7c442c1
@@ -5491,6 +5492,13 @@ public void setVisible (boolean visible) {
7c442c1
 		state &= ~HIDDEN;
7c442c1
 		if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) {
7c442c1
 			if (enableWindow != 0) OS.gdk_window_show_unraised (enableWindow);
7c442c1
+			/*
7c442c1
+			 * Raise this widget's GdkWindow if the reparentOnVisibility
7c442c1
+			 * flag has been set and visible is true. See bug 511133.
7c442c1
+			 */
7c442c1
+			if (reparentOnVisibility && OS.GTK3) {
7c442c1
+				OS.gdk_window_raise(gtk_widget_get_window(topHandle));
7c442c1
+			}
7c442c1
 			OS.gtk_widget_show (topHandle);
7c442c1
 		}
7c442c1
 	} else {
7c442c1
@@ -5527,6 +5535,13 @@ public void setVisible (boolean visible) {
7c442c1
 		OS.gtk_widget_hide (topHandle);
7c442c1
 		if (isDisposed ()) return;
7c442c1
 		if (enableWindow != 0) OS.gdk_window_hide (enableWindow);
7c442c1
+		/*
7c442c1
+		 * Lower this widget's GdkWindow if the reparentOnVisibility
7c442c1
+		 * flag has been set and visible is false. See bug 511133.
7c442c1
+		 */
7c442c1
+		if (reparentOnVisibility && OS.GTK3) {
7c442c1
+			OS.gdk_window_lower(gtk_widget_get_window(topHandle));
7c442c1
+		}
7c442c1
 		sendEvent (SWT.Hide);
7c442c1
 	}
7c442c1
 }
7c442c1
@@ -5682,7 +5697,7 @@ void showWidget () {
7c442c1
 	state |= ZERO_WIDTH | ZERO_HEIGHT;
7c442c1
 	long /*int*/ topHandle = topHandle ();
7c442c1
 	long /*int*/ parentHandle = parent.parentingHandle ();
7c442c1
-	parent.setParentWindow (topHandle);
7c442c1
+	parent.setParentWindow (this);
7c442c1
 	OS.gtk_container_add (parentHandle, topHandle);
7c442c1
 	if (handle != 0 && handle != topHandle) OS.gtk_widget_show (handle);
7c442c1
 	if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) {
7c442c1
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
7c442c1
index e3d1441..b664f29 100644
7c442c1
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java	
7c442c1
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java	
7c442c1
@@ -1205,9 +1205,6 @@ Rectangle getClientAreaInPixels () {
7c442c1
 	int width = (state & ZERO_WIDTH) != 0 ? 0 : allocation.width;
7c442c1
 	int height = (state & ZERO_HEIGHT) != 0 ? 0 : allocation.height;
7c442c1
 	Rectangle rect = new Rectangle (fixedX [0] - binX [0], fixedY [0] - binY [0], width, height);
7c442c1
-	if (getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) {
7c442c1
-		rect.y += getHeaderHeightInPixels();
7c442c1
-	}
7c442c1
 	return rect;
7c442c1
 }
7c442c1
 
7c442c1
@@ -1601,9 +1598,6 @@ TableItem getItemInPixels (Point point) {
7c442c1
 	long /*int*/ [] path = new long /*int*/ [1];
7c442c1
 	OS.gtk_widget_realize (handle);
7c442c1
 	int y = point.y;
7c442c1
-	if (getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) {
7c442c1
-		y -= getHeaderHeightInPixels();
7c442c1
-	}
7c442c1
 	if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, y, path, null, null, null)) return null;
7c442c1
 	if (path [0] == 0) return null;
7c442c1
 	long /*int*/ indices = OS.gtk_tree_path_get_indices (path [0]);
7c442c1
@@ -2453,10 +2447,6 @@ boolean mnemonicMatch (char key) {
7c442c1
 @Override
7c442c1
 long /*int*/ paintWindow () {
7c442c1
 	OS.gtk_widget_realize (handle);
7c442c1
-	if (fixedHandle != 0 && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) {
7c442c1
-		OS.gtk_widget_realize (fixedHandle);
7c442c1
-		return OS.gtk_widget_get_window(fixedHandle);
7c442c1
-	}
7c442c1
 	return OS.gtk_tree_view_get_bin_window (handle);
7c442c1
 }
7c442c1
 
7c442c1
@@ -3659,9 +3649,23 @@ void setParentBackground () {
7c442c1
 }
7c442c1
 
7c442c1
 @Override
7c442c1
-void setParentWindow (long /*int*/ widget) {
7c442c1
+void setParentWindow (Control child) {
7c442c1
 	long /*int*/ window = eventWindow ();
7c442c1
-	OS.gtk_widget_set_parent_window (widget, window);
7c442c1
+	OS.gtk_widget_set_parent_window (child.topHandle(), window);
7c442c1
+	/*
7c442c1
+	 * Feature in GTK3: all children of Table have their GdkWindows
7c442c1
+	 * re-parented so they are siblings of the parent Table
7c442c1
+	 * (i.e. on the same level in the z-order).
7c442c1
+	 *
7c442c1
+	 * To fix table editing in GTK3: raise/lower the
7c442c1
+	 * GdkWindow of these child widgets to make them visible when
7c442c1
+	 * setVisible() is called on them. This ensures they are properly
7c442c1
+	 * drawn when setVisible(true) is called, and properly hidden
7c442c1
+	 * when setVisible(false) is called. See bug 511133.
7c442c1
+	 */
7c442c1
+	if (child != null && OS.GTK3) {
7c442c1
+		child.reparentOnVisibility = true;
7c442c1
+	}
7c442c1
 }
7c442c1
 
7c442c1
 @Override
7c442c1
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java
7c442c1
index 6efb227..f904159 100644
7c442c1
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java	
7c442c1
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java	
7c442c1
@@ -403,9 +403,6 @@ Rectangle getBoundsInPixels (int index) {
7c442c1
 	}
7c442c1
 	int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
7c442c1
 	Rectangle r = new Rectangle (rect.x, rect.y, width, rect.height + 1);
7c442c1
-	if (parent.getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) {
7c442c1
-		r.y += parent.getHeaderHeightInPixels();
7c442c1
-	}
7c442c1
 	return r;
7c442c1
 }
7c442c1
 
7c442c1
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
7c442c1
index 58e0382..2428361 100644
7c442c1
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java	
7c442c1
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java	
7c442c1
@@ -1203,9 +1203,6 @@ Rectangle getClientAreaInPixels () {
7c442c1
 	int width = (state & ZERO_WIDTH) != 0 ? 0 : allocation.width;
7c442c1
 	int height = (state & ZERO_HEIGHT) != 0 ? 0 : allocation.height;
7c442c1
 	Rectangle rect = new Rectangle (fixedX [0] - binX [0], fixedY [0] - binY [0], width, height);
7c442c1
-	if (getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) {
7c442c1
-		rect.y += getHeaderHeightInPixels();
7c442c1
-	}
7c442c1
 	return rect;
7c442c1
 }
7c442c1
 
7c442c1
@@ -1610,9 +1607,6 @@ TreeItem getItemInPixels (Point point) {
7c442c1
 	OS.gtk_widget_realize (handle);
7c442c1
 	int x = point.x;
7c442c1
 	int y = point.y;
7c442c1
-	if (getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) {
7c442c1
-		y -= getHeaderHeightInPixels();
7c442c1
-	}
7c442c1
 	if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x;
7c442c1
 	long /*int*/ [] columnHandle = new long /*int*/ [1];
7c442c1
 	if (!OS.gtk_tree_view_get_path_at_pos (handle, x, y, path, columnHandle, null, null)) return null;
7c442c1
@@ -2596,10 +2590,6 @@ boolean mnemonicMatch (char key) {
7c442c1
 @Override
7c442c1
 long /*int*/ paintWindow () {
7c442c1
 	OS.gtk_widget_realize (handle);
7c442c1
-	if (fixedHandle != 0 && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) {
7c442c1
-		OS.gtk_widget_realize (fixedHandle);
7c442c1
-		return OS.gtk_widget_get_window(fixedHandle);
7c442c1
-	}
7c442c1
 	return OS.gtk_tree_view_get_bin_window (handle);
7c442c1
 }
7c442c1
 
7c442c1
@@ -3664,9 +3654,23 @@ void setParentBackground () {
7c442c1
 }
7c442c1
 
7c442c1
 @Override
7c442c1
-void setParentWindow (long /*int*/ widget) {
7c442c1
+void setParentWindow (Control child) {
7c442c1
 	long /*int*/ window = eventWindow ();
7c442c1
-	OS.gtk_widget_set_parent_window (widget, window);
7c442c1
+	OS.gtk_widget_set_parent_window (child.topHandle(), window);
7c442c1
+	/*
7c442c1
+	 * Feature in GTK3: all children of Tree have their GdkWindows
7c442c1
+	 * re-parented so they are siblings of the parent Tree
7c442c1
+	 * (i.e. on the same level in the z-order).
7c442c1
+	 *
7c442c1
+	 * To fix table editing in GTK3: raise/lower the
7c442c1
+	 * GdkWindow of these child widgets to make them visible when
7c442c1
+	 * setVisible() is called on them. This ensures they are properly
7c442c1
+	 * drawn when setVisible(true) is called, and properly hidden
7c442c1
+	 * when setVisible(false) is called. See bug 511133.
7c442c1
+	 */
7c442c1
+	if (child != null && OS.GTK3) {
7c442c1
+		child.reparentOnVisibility = true;
7c442c1
+	}
7c442c1
 }
7c442c1
 
7c442c1
 void setScrollWidth (long /*int*/ column, TreeItem item) {
7c442c1
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java
7c442c1
index 25bb96b..802a1f9 100644
7c442c1
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java	
7c442c1
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java	
7c442c1
@@ -453,9 +453,6 @@ Rectangle getBoundsInPixels (int index) {
7c442c1
 	}
7c442c1
 	int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
7c442c1
 	Rectangle r = new Rectangle (rect.x, rect.y, width, rect.height + 1);
7c442c1
-	if (parent.getHeaderVisible() && OS.GTK_VERSION > OS.VERSION(3, 9, 0)) {
7c442c1
-		r.y += parent.getHeaderHeightInPixels();
7c442c1
-	}
7c442c1
 	return r;
7c442c1
 }
7c442c1
 
7c442c1
-- 
7c442c1
cgit v1.1
7c442c1