From 2b0eff0e7d10912241ac1d934bd360ed74f010e9 Mon Sep 17 00:00:00 2001 From: Matti Tahvonen Date: Tue, 9 Oct 2007 09:04:04 +0000 Subject: [PATCH] layout changes svn changeset:2462/svn branch:trunk --- .../terminal/gwt/client/ui/IExpandLayout.java | 8 ++- .../terminal/gwt/client/ui/IPanel.java | 44 ++++++++----- .../terminal/gwt/client/ui/IScrollTable.java | 38 +++++++++-- .../terminal/gwt/client/ui/ISplitPanel.java | 63 +++++++++++-------- 4 files changed, 103 insertions(+), 50 deletions(-) diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java index 953b5efd4d..5db1035073 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IExpandLayout.java @@ -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); diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java index fb23d8433b..7bce859119 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IPanel.java @@ -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); diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java index 268cc6d530..5898a15818 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IScrollTable.java @@ -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"); + } + } diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ISplitPanel.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ISplitPanel.java index f78d586787..0963e9de91 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ISplitPanel.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ISplitPanel.java @@ -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; + } + } -- 2.39.5