]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed OrderedLayout size calculation issues
authorArtur Signell <artur.signell@itmill.com>
Fri, 24 Oct 2008 11:13:40 +0000 (11:13 +0000)
committerArtur Signell <artur.signell@itmill.com>
Fri, 24 Oct 2008 11:13:40 +0000 (11:13 +0000)
svn changeset:5709/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IOrderedLayout.java

index fe5373fd1f669cd59f6ff5966c292d4621d443cd..6922d3dcc094d1dbd4366597f40b0a24973b2092 100644 (file)
@@ -33,6 +33,8 @@ public class IOrderedLayout extends CellBasedLayout {
 \r
     private boolean isRendering = false;\r
 \r
+    private String width = null;\r
+\r
     @Override\r
     public void setStyleName(String styleName) {\r
         super.setStyleName(styleName);\r
@@ -54,6 +56,7 @@ public class IOrderedLayout extends CellBasedLayout {
 \r
     public IOrderedLayout() {\r
         setStyleName(CLASSNAME);\r
+        // DOM.setStyleAttribute(getElement(), "overflow", "hidden");\r
     }\r
 \r
     @Override\r
@@ -169,6 +172,16 @@ public class IOrderedLayout extends CellBasedLayout {
 \r
         // w.mark("Widget sizes updated");\r
 \r
+        /*\r
+         * Components with relative size in main direction may affect the layout\r
+         * size in the other direction\r
+         */\r
+        if ((isHorizontal() && isDynamicHeight())\r
+                || (isVertical() && isDynamicWidth())) {\r
+            calculateLayoutDimensions();\r
+        }\r
+        // w.mark("Layout dimensions updated");\r
+\r
         /* Update component spacing */\r
         updateContainerMargins();\r
 \r
@@ -286,32 +299,19 @@ public class IOrderedLayout extends CellBasedLayout {
         for (ChildComponentContainer childComponentContainer : widgetToComponentContainer\r
                 .values()) {\r
 \r
+            int widgetHeight = 0;\r
+            int widgetWidth = 0;\r
             if (childComponentContainer.isComponentRelativeSized(orientation)) {\r
-                continue;\r
-            }\r
-\r
-            Size s = childComponentContainer.getWidgetSize();\r
-            int widgetWidth = s.getWidth()\r
-                    + childComponentContainer.getCaptionWidthAfterComponent();\r
-\r
-            /*\r
-             * If the component does not have a specified size in the main\r
-             * direction the caption may determine the space used by the\r
-             * component\r
-             */\r
-            if (!childComponentContainer.widgetHasSizeSpecified(orientation)) {\r
-                int captionWidth = childComponentContainer.getCaptionWidth();\r
-                if (captionWidth > widgetWidth) {\r
-                    widgetWidth = captionWidth;\r
+                if (orientation == ORIENTATION_HORIZONTAL) {\r
+                    widgetHeight = getWidgetHeight(childComponentContainer);\r
+                } else {\r
+                    widgetWidth = getWidgetWidth(childComponentContainer);\r
                 }\r
+            } else {\r
+                widgetWidth = getWidgetWidth(childComponentContainer);\r
+                widgetHeight = getWidgetHeight(childComponentContainer);\r
             }\r
 \r
-            int widgetHeight = s.getHeight()\r
-                    + childComponentContainer.getCaptionHeightAboveComponent();\r
-\r
-            // ApplicationConnection.getConsole().log(\r
-            // "Container width: " + widgetWidth);\r
-\r
             summedWidgetWidth += widgetWidth;\r
             summedWidgetHeight += widgetHeight;\r
 \r
@@ -345,6 +345,31 @@ public class IOrderedLayout extends CellBasedLayout {
         return remainingSpace;\r
     }\r
 \r
+    private int getWidgetHeight(ChildComponentContainer childComponentContainer) {\r
+        Size s = childComponentContainer.getWidgetSize();\r
+        return s.getHeight()\r
+                + childComponentContainer.getCaptionHeightAboveComponent();\r
+    }\r
+\r
+    private int getWidgetWidth(ChildComponentContainer childComponentContainer) {\r
+        Size s = childComponentContainer.getWidgetSize();\r
+        int widgetWidth = s.getWidth()\r
+                + childComponentContainer.getCaptionWidthAfterComponent();\r
+\r
+        /*\r
+         * If the component does not have a specified size in the main direction\r
+         * the caption may determine the space used by the component\r
+         */\r
+        if (!childComponentContainer.widgetHasSizeSpecified(orientation)) {\r
+            int captionWidth = childComponentContainer.getCaptionWidth();\r
+            if (captionWidth > widgetWidth) {\r
+                widgetWidth = captionWidth;\r
+            }\r
+        }\r
+\r
+        return widgetWidth;\r
+    }\r
+\r
     private void calculateAlignments() {\r
         int w = 0;\r
         int h = 0;\r
@@ -442,6 +467,11 @@ public class IOrderedLayout extends CellBasedLayout {
             int totalComponentHeight, int maxComponentWidth,\r
             int maxComponentHeight) {\r
 \r
+        /* Only need to calculate dynamic dimensions */\r
+        if (!isDynamicHeight() && !isDynamicWidth()) {\r
+            return activeLayoutSize;\r
+        }\r
+\r
         int activeLayoutWidth = 0;\r
         int activeLayoutHeight = 0;\r
 \r
@@ -450,42 +480,32 @@ public class IOrderedLayout extends CellBasedLayout {
             // Horizontal\r
             if (isDynamicWidth()) {\r
                 activeLayoutWidth = totalComponentWidth;\r
-                setOuterLayoutWidth(activeLayoutWidth);\r
-            } else {\r
-                activeLayoutWidth = getOffsetWidth()\r
-                        - activeMargins.getHorizontal();\r
             }\r
 \r
             if (isDynamicHeight()) {\r
                 activeLayoutHeight = maxComponentHeight;\r
-                setOuterLayoutHeight(maxComponentHeight);\r
-            } else {\r
-                activeLayoutHeight = getOffsetHeight()\r
-                        - activeMargins.getVertical();\r
-\r
             }\r
 \r
         } else {\r
             // Vertical\r
             if (isDynamicWidth()) {\r
                 activeLayoutWidth = maxComponentWidth;\r
-                setOuterLayoutWidth(maxComponentWidth);\r
-            } else {\r
-                activeLayoutWidth = getOffsetWidth()\r
-                        - activeMargins.getHorizontal();\r
             }\r
 \r
             if (isDynamicHeight()) {\r
                 activeLayoutHeight = totalComponentHeight;\r
-                setOuterLayoutHeight(totalComponentHeight);\r
-            } else {\r
-                activeLayoutHeight = getOffsetHeight()\r
-                        - activeMargins.getVertical();\r
             }\r
         }\r
 \r
-        activeLayoutSize.setWidth(activeLayoutWidth);\r
-        activeLayoutSize.setHeight(activeLayoutHeight);\r
+        if (isDynamicWidth()) {\r
+            setOuterLayoutWidth(activeLayoutWidth);\r
+            activeLayoutSize.setWidth(activeLayoutWidth);\r
+        }\r
+\r
+        if (isDynamicHeight()) {\r
+            activeLayoutSize.setHeight(activeLayoutHeight);\r
+            setOuterLayoutHeight(activeLayoutHeight);\r
+        }\r
 \r
         return activeLayoutSize;\r
     }\r
@@ -610,6 +630,9 @@ public class IOrderedLayout extends CellBasedLayout {
     public void setHeight(String height) {\r
         super.setHeight(height);\r
 \r
+        activeLayoutSize.setHeight(getOffsetHeight()\r
+                - activeMargins.getVertical());\r
+\r
         if (!isRendering) {\r
             if (recalculateLayoutAndComponentSizes()) {\r
                 /* Must inform child components about possible size updates */\r
@@ -621,6 +644,10 @@ public class IOrderedLayout extends CellBasedLayout {
     @Override\r
     public void setWidth(String width) {\r
         super.setWidth(width);\r
+        this.width = width;\r
+\r
+        activeLayoutSize.setWidth(getOffsetWidth()\r
+                - activeMargins.getHorizontal());\r
 \r
         if (!isRendering) {\r
             if (recalculateLayoutAndComponentSizes()) {\r