]> source.dussan.org Git - vaadin-framework.git/commitdiff
layout changes
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 9 Oct 2007 09:04:04 +0000 (09:04 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 9 Oct 2007 09:04:04 +0000 (09:04 +0000)
svn changeset:2462/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java
src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java
src/com/itmill/toolkit/terminal/gwt/client/ui/ISplitPanel.java

index 953b5efd4dcc590eee263c1890e7d6ec48f75e96..5db103507315be050300eb86c54efa89806a4366 100644 (file)
@@ -144,13 +144,15 @@ public class IExpandLayout extends IOrderedLayout implements
                int usedSpace = DOM.getElementPropertyInt(meter, "offsetTop")
                                - DOM.getElementPropertyInt(DOM.getFirstChild(childContainer),
                                                "offsetTop");
-               // ApplicationConnection.getConsole().log("EL h" + getOffsetHeight());
-               // ApplicationConnection.getConsole().log("EL h" + getOffsetHeight());
+
                int freeSpace = getOffsetHeight() - usedSpace;
 
+               if (freeSpace < 0)
+                       freeSpace = 0;
+
                DOM.setStyleAttribute(expandedElement, "height", freeSpace + "px");
                // Component margins will bleed if overflow is not hidden
-               DOM.setStyleAttribute(expandedElement, "overflow", "hidden");
+               DOM.setStyleAttribute(expandedElement, "overflow", "auto");
 
                DOM.setStyleAttribute(expandedWidget.getElement(), "position",
                                origiginalPositioning);
index fb23d8433b06f842782aff2fa615ca94bc12c6fc..7bce859119bed8d18525b2c6fb4ae683714581c9 100644 (file)
@@ -62,6 +62,7 @@ public class IPanel extends SimplePanel implements Paintable,
                height = uidl.hasVariable("height") ? uidl.getStringVariable("height")
                                : null;
                setWidth(w != null ? w : "");
+               setHeight(height != null ? height : "");
 
                // TODO optimize: if only the caption has changed, don't re-render whole
                // content
@@ -104,22 +105,35 @@ public class IPanel extends SimplePanel implements Paintable,
        public void iLayout() {
                // In this case we need to fix containers height properly
                if (height != null && height != "") {
-                       // First, calculate needed pixel height
-                       setHeight(height);
-                       int neededHeight = getOffsetHeight();
-                       setHeight("");
-                       // Then calculate the size the content area needs to be
-                       DOM.setStyleAttribute(contentNode, "height", "0");
-                       DOM.setStyleAttribute(contentNode, "overflow", "hidden");
-                       int h = getOffsetHeight();
-                       int total = neededHeight - h;
-                       if (total < 0)
-                               total = 0;
-                       DOM.setStyleAttribute(contentNode, "height", total + "px");
-                       DOM.setStyleAttribute(contentNode, "overflow", "");
-               } else {
+                       // need to fix containers height properly
+
+                       boolean hasChildren = getWidget() != null;
+                       Element contentEl = null;
+                       String origPositioning = null;
+                       if (hasChildren) {
+                               // remove children temporary form normal flow to detect proper
+                               // size
+                               contentEl = getWidget().getElement();
+                               origPositioning = DOM.getStyleAttribute(contentEl, "position");
+                               DOM.setStyleAttribute(contentEl, "position", "absolute");
+                       }
                        DOM.setStyleAttribute(contentNode, "height", "");
-                       // We don't need overflow:auto when height is not set
+                       int availableH = DOM.getElementPropertyInt(getElement(),
+                                       "clientHeight");
+
+                       int usedH = DOM
+                                       .getElementPropertyInt(bottomDecoration, "offsetTop")
+                                       + DOM.getElementPropertyInt(bottomDecoration,
+                                                       "offsetHeight");
+                       int contentH = availableH - usedH;
+                       if (contentH < 0)
+                               contentH = 0;
+                       DOM.setStyleAttribute(contentNode, "height", contentH + "px");
+                       if (hasChildren) {
+                               DOM.setStyleAttribute(contentEl, "position", origPositioning);
+                       }
+                       DOM.setStyleAttribute(contentNode, "overflow", "auto");
+               } else {
                        DOM.setStyleAttribute(contentNode, "overflow", "hidden");
                }
                Util.runAnchestorsLayout(this);
index 268cc6d530bf220dba80790a8d132493a99791a4..5898a158182e428d9c195f7d8ccc996f5cd207bb 100644 (file)
@@ -336,8 +336,6 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
                HeaderCell cell = tHead.getHeaderCell(colIndex);
                cell.setWidth(w);
                tBody.setColWidth(colIndex, w);
-               String cid = cell.getColKey();
-               ;
        }
 
        private int getColWidth(String colKey) {
@@ -355,10 +353,6 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
                return null;
        }
 
-       private int getRenderedRowCount() {
-               return tBody.getLastRendered() - tBody.getFirstRendered();
-       }
-
        private void reOrderColumn(String columnKey, int newIndex) {
 
                int oldIndex = getColIndexByKey(columnKey);
@@ -564,6 +558,12 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
 
        public void iLayout() {
                if (height != null) {
+                       
+                       if(height.equals("100%")) {
+                               // we define height in pixels with 100% not to include borders
+                               setHeight(height);
+                       }
+                       
                        int contentH = (DOM.getElementPropertyInt(getElement(),
                                        "clientHeight") - tHead.getOffsetHeight());
                        if (contentH < 0)
@@ -1886,4 +1886,30 @@ public class IScrollTable extends Composite implements Table, ScrollListener,
                return panel.remove(w);
        }
 
+       public void setHeight(String height) {
+               // workaround very common 100% height problem - extract borders
+               if(height.equals("100%")) {
+                       final int borders = getBorderSpace();
+                       Element elem = getElement();
+                       Element parentElem = DOM.getParent(elem);
+
+                       // put table away from flow for a moment
+                       DOM.setStyleAttribute(getElement(), "position", "absolute");
+                       // get containers natural space for table
+                       int availPixels = DOM.getElementPropertyInt(parentElem, "clientHeight");
+                       // put table back to flow
+                       DOM.setStyleAttribute(getElement(), "position", "static");
+                       // set 100% height with borders
+                       super.setHeight((availPixels - borders) + "px");
+               } else {
+                       // normally height don't include borders
+                       super.setHeight(height);
+               }
+       }
+
+       private int getBorderSpace() {
+               Element el = getElement();
+               return DOM.getElementPropertyInt(el, "offsetHeight") - DOM.getElementPropertyInt(el, "clientHeight");
+       }
+
 }
index f78d586787b4fad82315312e6b2678dd75266680..0963e9de91f3f4b458886e52e5f77084fb0d30fc 100644 (file)
@@ -18,11 +18,9 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
        public static final int ORIENTATION_HORIZONTAL = 0;
        public static final int ORIENTATION_VERTICAL = 1;
 
-       private static final int SPLITTER_SIZE = 10;
+       private static final int MIN_SIZE = 30;
 
-       private static final String MIN_SIZE = (3 * SPLITTER_SIZE) + "px";
-
-       private int orientation;
+       private int orientation = ORIENTATION_HORIZONTAL;
        private Widget firstChild;
        private Widget secondChild;
 
@@ -58,16 +56,16 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                }
                // size below will be overridden in update from uidl, initial size
                // needed to keep IE alive
-               setWidth(MIN_SIZE);
-               setHeight(MIN_SIZE);
+               setWidth(MIN_SIZE + "px");
+               setHeight(MIN_SIZE + "px");
                constructDom();
                setOrientation(orientation);
-               setSplitPosition("50%");
                DOM.sinkEvents(splitter, (Event.MOUSEEVENTS));
                DOM.sinkEvents(getElement(), (Event.MOUSEEVENTS));
        }
 
        protected void constructDom() {
+               DOM.appendChild(splitter, DOM.createDiv()); // for styling
                DOM.appendChild(getElement(), wrapper);
                DOM.setStyleAttribute(wrapper, "position", "relative");
                DOM.setStyleAttribute(wrapper, "width", "100%");
@@ -90,12 +88,10 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                this.orientation = orientation;
                if (orientation == ORIENTATION_HORIZONTAL) {
                        DOM.setStyleAttribute(splitter, "height", "100%");
-                       DOM.setStyleAttribute(splitter, "width", SPLITTER_SIZE + "px");
                        DOM.setStyleAttribute(firstContainer, "height", "100%");
                        DOM.setStyleAttribute(secondContainer, "height", "100%");
                } else {
                        DOM.setStyleAttribute(splitter, "width", "100%");
-                       DOM.setStyleAttribute(splitter, "height", SPLITTER_SIZE + "px");
                        DOM.setStyleAttribute(firstContainer, "width", "100%");
                        DOM.setStyleAttribute(secondContainer, "width", "100%");
                }
@@ -147,7 +143,6 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                }
                int wholeSize;
                int pixelPosition;
-               ApplicationConnection.getConsole().log("splitterpaneeeli");
 
                switch (orientation) {
                case ORIENTATION_HORIZONTAL:
@@ -155,8 +150,10 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                        pixelPosition = DOM.getElementPropertyInt(splitter, "offsetLeft");
 
                        // reposition splitter in case it is out of box
-                       if (pixelPosition + SPLITTER_SIZE > wholeSize) {
-                               pixelPosition = wholeSize - SPLITTER_SIZE;
+                       if (pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize) {
+                               pixelPosition = wholeSize - getSplitterSize();
+                               if (pixelPosition < 0)
+                                       pixelPosition = 0;
                                setSplitPosition(pixelPosition + "px");
                                return;
                        }
@@ -164,13 +161,13 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                        DOM
                                        .setStyleAttribute(firstContainer, "width", pixelPosition
                                                        + "px");
-                       int secondContainerWidth = (wholeSize - pixelPosition - SPLITTER_SIZE);
+                       int secondContainerWidth = (wholeSize - pixelPosition - getSplitterSize());
                        if (secondContainerWidth < 0)
                                secondContainerWidth = 0;
                        DOM.setStyleAttribute(secondContainer, "width",
                                        secondContainerWidth + "px");
                        DOM.setStyleAttribute(secondContainer, "left",
-                                       (pixelPosition + SPLITTER_SIZE) + "px");
+                                       (pixelPosition + getSplitterSize()) + "px");
 
                        break;
                case ORIENTATION_VERTICAL:
@@ -178,21 +175,24 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                        pixelPosition = DOM.getElementPropertyInt(splitter, "offsetTop");
 
                        // reposition splitter in case it is out of box
-                       if (pixelPosition + SPLITTER_SIZE > wholeSize) {
-                               pixelPosition = wholeSize - SPLITTER_SIZE;
+                       if (pixelPosition > 0 && pixelPosition + getSplitterSize() > wholeSize) {
+                               pixelPosition = wholeSize - getSplitterSize();
+                               if (pixelPosition < 0)
+                                       pixelPosition = 0;
                                setSplitPosition(pixelPosition + "px");
                                return;
                        }
 
                        DOM.setStyleAttribute(firstContainer, "height", pixelPosition
                                        + "px");
-                       int secondContainerHeight = (wholeSize - pixelPosition - SPLITTER_SIZE);
+                       int secondContainerHeight = (wholeSize - pixelPosition - getSplitterSize());
                        if (secondContainerHeight < 0)
                                secondContainerHeight = 0;
                        DOM.setStyleAttribute(secondContainer, "height",
                                        secondContainerHeight + "px");
                        DOM.setStyleAttribute(secondContainer, "top",
-                                       (pixelPosition + SPLITTER_SIZE) + "px");
+                                       (pixelPosition + getSplitterSize()) + "px");
+                       break;
                default:
                        ApplicationConnection.getConsole().log("???");
 
@@ -222,16 +222,16 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                super.setHeight(height);
                // give sane height
                getOffsetHeight(); // shake IE
-               if (getOffsetHeight() < SPLITTER_SIZE)
-                       super.setHeight((SPLITTER_SIZE * 3) + "px");
+               if (getOffsetHeight() < MIN_SIZE)
+                       super.setHeight(MIN_SIZE + "px");
        }
 
        public void setWidth(String width) {
                super.setWidth(width);
                // give sane width
                getOffsetWidth(); // shake IE
-               if (getOffsetWidth() < SPLITTER_SIZE)
-                       super.setWidth((SPLITTER_SIZE * 3) + "px");
+               if (getOffsetWidth() < MIN_SIZE)
+                       super.setWidth(MIN_SIZE + "px");
        }
 
        public void onBrowserEvent(Event event) {
@@ -286,8 +286,8 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                int newX = origX + x - origMouseX;
                if (newX < 0)
                        newX = 0;
-               if (newX + SPLITTER_SIZE > getOffsetWidth())
-                       newX = getOffsetWidth() - SPLITTER_SIZE;
+               if (newX + getSplitterSize() > getOffsetWidth())
+                       newX = getOffsetWidth() - getSplitterSize();
                DOM.setStyleAttribute(splitter, "left", newX + "px");
        }
 
@@ -296,8 +296,8 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                if (newY < 0)
                        newY = 0;
 
-               if (newY + SPLITTER_SIZE > getOffsetHeight())
-                       newY = getOffsetHeight() - SPLITTER_SIZE;
+               if (newY + getSplitterSize() > getOffsetHeight())
+                       newY = getOffsetHeight() - getSplitterSize();
                DOM.setStyleAttribute(splitter, "top", newY + "px");
        }
 
@@ -307,4 +307,15 @@ public class ISplitPanel extends ComplexPanel implements Paintable,
                onMouseMove(event);
        }
 
+       private static int splitterSize = -1;
+
+       private int getSplitterSize() {
+               if (splitterSize < 0) {
+                       if (isAttached()) {
+                               splitterSize = DOM.getElementPropertyInt(splitter, "offsetWidth");
+                       }
+               }
+               return splitterSize;
+       }
+
 }