466390: Behaviour of fields, labels and scrollbar on narrow windows is
incorrect
https://bugs.eclipse.org/bugs/show_bug.cgi?id=466390

Change-Id: Iddfecb0b8968da8fef70ae3d7cc4079a73d6cf72
diff --git a/org.eclipse.scout.rt.ui.swt/src/org/eclipse/scout/rt/ui/swt/LogicalGridLayout.java b/org.eclipse.scout.rt.ui.swt/src/org/eclipse/scout/rt/ui/swt/LogicalGridLayout.java
index 0d85789..ca631da 100644
--- a/org.eclipse.scout.rt.ui.swt/src/org/eclipse/scout/rt/ui/swt/LogicalGridLayout.java
+++ b/org.eclipse.scout.rt.ui.swt/src/org/eclipse/scout/rt/ui/swt/LogicalGridLayout.java
@@ -12,6 +12,7 @@
 
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.List;
 
 import org.eclipse.scout.commons.CompositeObject;
 import org.eclipse.scout.commons.logger.IScoutLogger;
@@ -42,14 +43,20 @@
   public static final float EPS = 1E-6f;
 
   private boolean m_debug;
-  private int m_hgap;
-  private int m_vgap;
+  private final int m_hgap;
+  private final int m_vgap;
+  private final int m_minWidth;
   private LogicalGridLayoutInfo m_info;
   private CompositeObject m_infoCacheKey;
 
   public LogicalGridLayout(int hgap, int vgap) {
+    this(hgap, vgap, -1);
+  }
+
+  public LogicalGridLayout(int hgap, int vgap, int minWidth) {
     m_hgap = hgap;
     m_vgap = vgap;
+    m_minWidth = minWidth;
   }
 
   public LogicalGridLayoutInfo getInfo() {
@@ -116,7 +123,12 @@
     Point size = new Point(0, 0);
     switch (sizeFlag) {
       case MIN:
-        size.x = min.x;
+        if (m_minWidth < 0) {
+          size.x = min.x;
+        }
+        else {
+          size.x = m_minWidth;
+        }
         size.y = min.y;
         break;
       case MAX:
@@ -133,7 +145,7 @@
           size.x = Math.min(max.x, size.x);
           size.x = Math.max(min.x, size.x);
         }
-        // adjust heigth
+        // adjust height
         if (hHint == SWT.DEFAULT) {
           size.y = pref.y;
         }
@@ -152,8 +164,8 @@
     if (flushCache) {
       m_info = null;
     }
-    validateLayout(parent, parent.getSize().x, flushCache);
     Rectangle clientArea = parent.getClientArea();
+    validateLayout(parent, clientArea.width, flushCache);
     Point size = new Point(clientArea.width, clientArea.height);
     Rectangle[][] cellBounds = m_info.layoutCellBounds(size);
     if (m_debug || LOG.isDebugEnabled()) {
@@ -267,8 +279,8 @@
     if (m_info != null && m_infoCacheKey != null) {
       return;
     }
-    ArrayList<Control> visibleComps = new ArrayList<Control>();
-    ArrayList<LogicalGridData> visibleCons = new ArrayList<LogicalGridData>();
+    List<Control> visibleComps = new ArrayList<>();
+    List<LogicalGridData> visibleCons = new ArrayList<>();
     for (Control comp : parent.getChildren()) {
       if (comp.getVisible() && comp.getLayoutData() instanceof LogicalGridData) {
         visibleComps.add(comp);
diff --git a/org.eclipse.scout.rt.ui.swt/src/org/eclipse/scout/rt/ui/swt/form/fields/groupbox/SwtScoutGroupBox.java b/org.eclipse.scout.rt.ui.swt/src/org/eclipse/scout/rt/ui/swt/form/fields/groupbox/SwtScoutGroupBox.java
index f71613a..0c0fb07 100644
--- a/org.eclipse.scout.rt.ui.swt/src/org/eclipse/scout/rt/ui/swt/form/fields/groupbox/SwtScoutGroupBox.java
+++ b/org.eclipse.scout.rt.ui.swt/src/org/eclipse/scout/rt/ui/swt/form/fields/groupbox/SwtScoutGroupBox.java
@@ -58,7 +58,7 @@
     m_containerBorderEnabled = getScoutObject().isBorderVisible();
     Composite rootPane = createContainer(parent);
     if (getScoutObject().isScrollable()) {
-      m_scrolledForm = getEnvironment().getFormToolkit().createScrolledFormEx(rootPane, SWT.V_SCROLL);
+      m_scrolledForm = getEnvironment().getFormToolkit().createScrolledFormEx(rootPane, SWT.H_SCROLL | SWT.V_SCROLL);
       m_swtBodyPart = m_scrolledForm.getBody();
       m_scrolledForm.setData(ISwtScoutPart.MARKER_SCOLLED_FORM, new Object());
 
@@ -89,7 +89,11 @@
     createButtonbar(rootPane);
 
     IUiDecoration deco = UiDecorationExtensionPoint.getLookAndFeel();
-    LogicalGridLayout bodyLayout = new LogicalGridLayout(deco.getLogicalGridLayoutHorizontalGap(), deco.getLogicalGridLayoutVerticalGap());
+    int minWidth = -1;
+    if (getScoutObject().isScrollable()) {
+      minWidth = (int) (getScoutObject().getGridData().w * deco.getLogicalGridLayoutDefaultColumnWidth() * 0.8);
+    }
+    LogicalGridLayout bodyLayout = new LogicalGridLayout(deco.getLogicalGridLayoutHorizontalGap(), deco.getLogicalGridLayoutVerticalGap(), minWidth);
     m_swtBodyPart.setLayout(bodyLayout);
     installSwtContainerBorder();
     // FIELDS: