Bug 568185 - [GTK4] Port SWT Tree snippets - Header button set visible
when Tree disables headers

- Place GTK4 guard on forcing the column.buttonHandle visibility to true
in computeSizeInPixels. Fixes GTK4 initial GtkTreeView allocation
errors.

- Improve readability in TreeColumn.pack when setting visibility of
buttonHandle

Change-Id: Id741f09aace11b43099fa2726af9f80d9074b6a4
Signed-off-by: Paul D'Pong <sdamrong@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 6d98dfe..d54d9e9 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
@@ -600,17 +600,19 @@
 	if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
 	if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
 	/*
-	 * Set all the TreeColumn buttons visible otherwise
+	 * Bug 546490: Set all the TreeColumn buttons visible otherwise
 	 * gtk_widget_get_preferred_size() will not take their size
 	 * into account.
 	 */
-	if (firstCompute) {
-		for (int x = 0; x < columns.length; x++) {
-			TreeColumn column = columns[x];
-			if (column != null) GTK.gtk_widget_set_visible(column.buttonHandle, true);
+	if (!GTK.GTK4) {
+		if (firstCompute) {
+			for (TreeColumn column : columns) {
+				if (column != null) GTK.gtk_widget_set_visible(column.buttonHandle, true);
+			}
+			firstCompute = false;
 		}
-		firstCompute = false;
 	}
+
 	GTK.gtk_widget_realize(handle);
 	Point size = computeNativeSize (handle, wHint, hHint, changed);
 
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
index 5ad89f2..d3d9e82 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
@@ -459,13 +459,14 @@
 	checkWidget();
 	int width = 0;
 	if (buttonHandle != 0) {
-		GtkRequisition requisition = new GtkRequisition ();
 		/*
-		 * Check if the header button is hidden, otherwise GTK will
-		 * return a 1x1 size. See bug 546490.
+		 * Bug 546490: Ensure the header button is set to
+		 * true before getting preferred size of GtkTreeView
 		 */
 		boolean visible = GTK.gtk_widget_get_visible(buttonHandle);
-		if (!visible) GTK.gtk_widget_set_visible(buttonHandle, !visible);
+		if (!visible) GTK.gtk_widget_set_visible(buttonHandle, true);
+
+		GtkRequisition requisition = new GtkRequisition ();
 		gtk_widget_get_preferred_size (buttonHandle, requisition);
 		width = requisition.width;
 	}