Bug 340752 - [GTK3] Control getSize() behaves different in Linux and
Windows. Getting wrong value on linux

Removed visible check in ExpandItem#resizeControl to set bounds for
items not expanded.

Change-Id: Ibb926eb7784113d5b800eb236d8432a35e6f9df5
Signed-off-by: Xi Yan <xixiyan@redhat.com>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
index 6e48823..dac7f76 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
@@ -425,52 +425,50 @@
 void resizeControl (int yScroll) {
 	if (control != null && !control.isDisposed ()) {
 		boolean visible = GTK.gtk_expander_get_expanded (handle);
-		if (visible) {
-			GtkAllocation allocation = new GtkAllocation ();
-			GTK.gtk_widget_get_allocation (clientHandle, allocation);
+		GtkAllocation allocation = new GtkAllocation ();
+		GTK.gtk_widget_get_allocation (clientHandle, allocation);
 
-			//454940 change in hierarchy
-			/* SWT's calls to gtk_widget_size_allocate and gtk_widget_set_allocation
-			* causes GTK+ to move the clientHandle's SwtFixed down by the size of the label.
-			* These calls can come up from 'shell' and ExpandItem has no control over these calls.
-			* This is an undesired side-effect. Client handle's x & y positions should never
-			* be incremented as this is an internal sub-container.
-			* As of GTK3, the hierarchy is changed, this affected child-size allocation and a fix
-			* is now neccessary.
-			* See also other 454940 notes and similar fix in: 453827 */
-			int x = (GTK.GTK3) ? 0 : allocation.x;
-			int y = (GTK.GTK3) ? 0 : allocation.y;
+		//454940 change in hierarchy
+		/* SWT's calls to gtk_widget_size_allocate and gtk_widget_set_allocation
+		* causes GTK+ to move the clientHandle's SwtFixed down by the size of the label.
+		* These calls can come up from 'shell' and ExpandItem has no control over these calls.
+		* This is an undesired side-effect. Client handle's x & y positions should never
+		* be incremented as this is an internal sub-container.
+		* As of GTK3, the hierarchy is changed, this affected child-size allocation and a fix
+		* is now neccessary.
+		* See also other 454940 notes and similar fix in: 453827 */
+		int x = (GTK.GTK3) ? 0 : allocation.x;
+		int y = (GTK.GTK3) ? 0 : allocation.y;
 
-			if (x != -1 && y != -1) {
-				int width = allocation.width;
-				int height = allocation.height;
-				int [] property = new int [1];
-				GTK.gtk_widget_style_get (handle, OS.focus_line_width, property, 0);
-				y += property [0] * 2;
-				height -= property [0] * 2;
+		if (x != -1 && y != -1) {
+			int width = allocation.width;
+			int height = allocation.height;
+			int [] property = new int [1];
+			GTK.gtk_widget_style_get (handle, OS.focus_line_width, property, 0);
+			y += property [0] * 2;
+			height -= property [0] * 2;
 
-				/*
-				* Feature in GTK. When the ExpandBar is resize too small the control
-				* shows up on top of the vertical scrollbar. This happen because the
-				* GtkExpander does not set the size of child smaller than the request
-				* size of its parent and because the control is not parented in the
-				* hierarchy of the GtkScrolledWindow.
-				* The fix is calculate the width ourselves when the scrollbar is visible.
-				*/
-				ScrollBar vBar = parent.verticalBar;
-				if (vBar != null) {
-					if (GTK.gtk_widget_get_visible (vBar.handle)) {
-						GTK.gtk_widget_get_allocation (parent.scrolledHandle, allocation);
-						width = allocation.width - parent.vScrollBarWidth () - 2 * parent.spacing;
-					}
+			/*
+			* Feature in GTK. When the ExpandBar is resize too small the control
+			* shows up on top of the vertical scrollbar. This happen because the
+			* GtkExpander does not set the size of child smaller than the request
+			* size of its parent and because the control is not parented in the
+			* hierarchy of the GtkScrolledWindow.
+			* The fix is calculate the width ourselves when the scrollbar is visible.
+			*/
+			ScrollBar vBar = parent.verticalBar;
+			if (vBar != null) {
+				if (GTK.gtk_widget_get_visible (vBar.handle)) {
+					GTK.gtk_widget_get_allocation (parent.scrolledHandle, allocation);
+					width = allocation.width - parent.vScrollBarWidth () - 2 * parent.spacing;
 				}
-				// Bug 479242: Bound calculation is correct without needing to use yScroll in GTK3
-				if (GTK.GTK3) {
-					control.setBounds (x, y, width, Math.max (0, height), true, true);
-				}
-				else {
-					control.setBounds (x, y - yScroll, width, Math.max (0, height), true, true);
-				}
+			}
+			// Bug 479242: Bound calculation is correct without needing to use yScroll in GTK3
+			if (GTK.GTK3) {
+				control.setBounds (x, y, width, Math.max (0, height), true, true);
+			}
+			else {
+				control.setBounds (x, y - yScroll, width, Math.max (0, height), true, true);
 			}
 		}
 		control.setVisible (visible);
diff --git a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug340752_ControlGetSize.java b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug340752_ControlGetSize.java
index 940f822..675e59d 100644
--- a/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug340752_ControlGetSize.java
+++ b/tests/org.eclipse.swt.tests.gtk/ManualTests/org/eclipse/swt/tests/gtk/snippets/Bug340752_ControlGetSize.java
@@ -10,125 +10,138 @@
  *******************************************************************************/
 package org.eclipse.swt.tests.gtk.snippets;
 
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.layout.*;
-import org.eclipse.swt.widgets.*;
-import org.eclipse.swt.graphics.*;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.ExpandBar;
+import org.eclipse.swt.widgets.ExpandItem;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
 
 public class Bug340752_ControlGetSize {
-static ExpandBar bar;
-static Image image;
-static MenuItem item;
+	static ExpandBar bar;
+	static Image image;
+	static MenuItem item;
 
-public static void main(String[] args) {
-Shell shell = new Shell();
-Display display = shell.getDisplay();
-shell.setLayout(new FillLayout());
-shell.setText("ExpandBar Example");
+	public static void main(String[] args) {
+		Shell shell = new Shell();
+		Display display = shell.getDisplay();
+		shell.setLayout(new FillLayout());
+		shell.setText("ExpandBar Example");
 
-Menu menubar = new Menu(shell, SWT.BAR);
-shell.setMenuBar(menubar);
-MenuItem fileItem = new MenuItem(menubar, SWT.CASCADE);
-fileItem.setText("&File");
-Menu submenu = new Menu(shell, SWT.DROP_DOWN);
-fileItem.setMenu(submenu);
-item = new MenuItem(submenu, SWT.PUSH);
-item.setText("New ExpandItem");
+		Menu menubar = new Menu(shell, SWT.BAR);
+		shell.setMenuBar(menubar);
+		MenuItem fileItem = new MenuItem(menubar, SWT.CASCADE);
+		fileItem.setText("&File");
+		Menu submenu = new Menu(shell, SWT.DROP_DOWN);
+		fileItem.setMenu(submenu);
+		item = new MenuItem(submenu, SWT.PUSH);
+		item.setText("New ExpandItem");
 
-bar = new ExpandBar(shell, SWT.V_SCROLL);
-image = display.getSystemImage(SWT.ICON_QUESTION);
+		bar = new ExpandBar(shell, SWT.V_SCROLL);
+		image = display.getSystemImage(SWT.ICON_QUESTION);
 
-// First item
-Composite composite = new Composite(bar, SWT.NONE);
-Menu popupmenu = new Menu(shell, SWT.POP_UP);
-MenuItem popupItem = new MenuItem(popupmenu, SWT.PUSH);
-popupItem.setText("Popup");
-composite.setMenu(popupmenu);
+		// First item
+		Composite composite = new Composite(bar, SWT.NONE);
+		Menu popupmenu = new Menu(shell, SWT.POP_UP);
+		MenuItem popupItem = new MenuItem(popupmenu, SWT.PUSH);
+		popupItem.setText("Popup");
+		composite.setMenu(popupmenu);
 
-GridLayout layout = new GridLayout(2, false);
-layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
-layout.verticalSpacing = 10;
-composite.setLayout(layout);
-Label label = new Label(composite, SWT.NONE);
-label.setImage(display.getSystemImage(SWT.ICON_ERROR));
-label = new Label(composite, SWT.NONE);
-label.setText("SWT.ICON_ERROR");
-label = new Label(composite, SWT.NONE);
-label.setImage(display.getSystemImage(SWT.ICON_INFORMATION)) ;
-label = new Label(composite, SWT.NONE);
-label.setText("SWT.ICON_INFORMATION");
-label = new Label(composite, SWT.NONE);
-label.setImage(display.getSystemImage(SWT.ICON_WARNING));
-label = new Label(composite, SWT.NONE);
-label.setText("SWT.ICON_WARNING");
-label = new Label(composite, SWT.NONE);
-label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
-label = new Label(composite, SWT.NONE);
-label.setText("SWT.ICON_QUESTION");
-ExpandItem item1 = new ExpandItem(bar, SWT.NONE);
-item1.setText("What is your favorite icon");
-item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
-item1.setControl(composite);
-item1.setImage(image);
+		GridLayout layout = new GridLayout(2, false);
+		layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
+		layout.verticalSpacing = 10;
+		composite.setLayout(layout);
+		Label label = new Label(composite, SWT.NONE);
+		label.setImage(display.getSystemImage(SWT.ICON_ERROR));
+		label = new Label(composite, SWT.NONE);
+		label.setText("SWT.ICON_ERROR");
+		label = new Label(composite, SWT.NONE);
+		label.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
+		label = new Label(composite, SWT.NONE);
+		label.setText("SWT.ICON_INFORMATION");
+		label = new Label(composite, SWT.NONE);
+		label.setImage(display.getSystemImage(SWT.ICON_WARNING));
+		label = new Label(composite, SWT.NONE);
+		label.setText("SWT.ICON_WARNING");
+		label = new Label(composite, SWT.NONE);
+		label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
+		label = new Label(composite, SWT.NONE);
+		label.setText("SWT.ICON_QUESTION");
+		ExpandItem item1 = new ExpandItem(bar, SWT.NONE);
+		item1.setText("What is your favorite icon");
+		item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
+		item1.setControl(composite);
+		item1.setImage(image);
 
-// Second item
-composite = new Composite(bar, SWT.NONE);
-layout = new GridLayout(2, true);
-layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
-layout.verticalSpacing = 10;
-composite.setLayout(layout);
-Button button1 = new Button(composite, SWT.PUSH);
-button1.setText("Button 1");
-Button button2 = new Button(composite, SWT.PUSH);
-button2.setText("Button 2");
+		// Second item
+		composite = new Composite(bar, SWT.NONE);
+		layout = new GridLayout(2, true);
+		layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
+		layout.verticalSpacing = 10;
+		composite.setLayout(layout);
+		Button button1 = new Button(composite, SWT.PUSH);
+		button1.setText("Button 1");
+		Button button2 = new Button(composite, SWT.PUSH);
+		button2.setText("Button 2");
 
-ExpandItem item0 = new ExpandItem(bar, SWT.NONE);
-item0.setText("What is your favorite button");
-item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
-item0.setControl(composite);
-item0.setImage(image);
-item0.setExpanded(false);
+		ExpandItem item0 = new ExpandItem(bar, SWT.NONE);
+		item0.setText("What is your favorite button");
+		item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
+		item0.setControl(composite);
+		item0.setImage(image);
+		item0.setExpanded(false);
 
-item.addListener(SWT.Selection, new Listener(){
-@Override
-public void handleEvent(Event e) {
-ExpandItem item2 = new ExpandItem(bar, SWT.NONE);
-Composite composite = new Composite(bar, SWT.NONE);
-GridLayout layout = new GridLayout(2, false);
-composite.setLayout(layout);
-Label label = new Label(composite, SWT.NONE);
-label.setText("What is your name?");
-Composite pcomposite = new Composite(composite, SWT.NONE);
-Text text = new Text(pcomposite, SWT.NONE);
-item2.setText("New Question");
-text.pack();
-composite.pack();
-Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
-item2.setHeight(size.y);
-item2.setControl(composite);
-item2.setImage(image);
-item2.setExpanded(true);
-}
-});
+		item.addListener(SWT.Selection, e -> {
+			ExpandItem item2 = new ExpandItem(bar, SWT.NONE);
+			Composite composite1 = new Composite(bar, SWT.NONE);
+			GridLayout layout1 = new GridLayout(2, false);
+			composite1.setLayout(layout1);
+			Label label1 = new Label(composite1, SWT.NONE);
+			label1.setText("What is your name?");
+			Composite pcomposite = new Composite(composite1, SWT.NONE);
+			Text text = new Text(pcomposite, SWT.NONE);
+			item2.setText("New Question");
+			text.pack();
+			composite1.pack();
+			Point size = composite1.computeSize(SWT.DEFAULT, SWT.DEFAULT);
+			item2.setHeight(size.y);
+			item2.setControl(composite1);
+			item2.setImage(image);
+			item2.setExpanded(true);
+		});
 
-bar.setSpacing(8);
-shell.setSize(400, 550);
-shell.open();
-System.out.println("------------------------------");
-System.out.println("getSize: " + button1.getSize());
-System.out.println("getBounds: " + button1.getBounds());
-System.out.println("computeSize: "
-+ button1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
-System.out.println("getLocation: " + button1.getLocation());
+		bar.setSpacing(8);
+		shell.setSize(400, 550);
+		shell.open();
+		System.out.println("---------------BUTTON 1---------------");
+		System.out.println("getSize: " + button1.getSize());
+		System.out.println("getBounds: " + button1.getBounds());
+		System.out.println("computeSize: " + button1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+		System.out.println("getLocation: " + button1.getLocation());
 
-while (!shell.isDisposed()) {
-if (!display.readAndDispatch()) {
-display.sleep();
-}
-}
-image.dispose();
-display.dispose();
-}
+		System.out.println("---------------LABEL---------------");
+		System.out.println("getSize: " + label.getSize());
+		System.out.println("getBounds: " + label.getBounds());
+		System.out.println("computeSize: " + label.computeSize(SWT.DEFAULT, SWT.DEFAULT));
+		System.out.println("getLocation: " + label.getLocation());
+
+
+		while (!shell.isDisposed()) {
+			if (!display.readAndDispatch()) {
+				display.sleep();
+			}
+		}
+		image.dispose();
+		display.dispose();
+	}
 
 }
\ No newline at end of file