diff options
author | Artur Signell <artur.signell@itmill.com> | 2008-12-15 13:38:14 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2008-12-15 13:38:14 +0000 |
commit | 3626ad212e9f5d3347b45dbea803a34b7e1f412e (patch) | |
tree | c884a3b1d270179dd8293ef089767d30864c9622 | |
parent | 3f82821ef5b50e6701032043c842748a8b202943 (diff) | |
download | vaadin-framework-3626ad212e9f5d3347b45dbea803a34b7e1f412e.tar.gz vaadin-framework-3626ad212e9f5d3347b45dbea803a34b7e1f412e.zip |
Fix for #2325 - SubWindow with relative sized layout broken
svn changeset:6210/svn branch:trunk
-rw-r--r-- | src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java | 45 | ||||
-rw-r--r-- | src/com/itmill/toolkit/tests/tickets/Ticket2325.java | 28 |
2 files changed, 68 insertions, 5 deletions
diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java index 3a51cff709..b9fa80554c 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java @@ -303,13 +303,30 @@ public class IWindow extends IToolkitOverlay implements Container, contentPanel.setWidget((Widget) lo); layout = lo; } + + boolean dynamicWidth = !uidl.hasAttribute("width"); + boolean widthHasBeenFixed = false; + + String layoutWidth = childUidl.getStringAttribute("width"); + if (dynamicWidth) { + if (layoutWidth != null && layoutWidth.contains("%")) { + /* + * Relative layout width, fix window width before rendering + * (width according to caption) + */ + widthHasBeenFixed = true; + setNaturalWidth(); + } + } lo.updateFromUIDL(childUidl, client); - // If no explicit width is specified, calculate natural width for window - // and set it explicitly - if (!uidl.hasAttribute("width")) { - final int naturalWidth = getElement().getOffsetWidth(); - setWidth(naturalWidth + "px"); + /* + * No explicit width is set and the layout does not have relative width + * so fix the size according to the layout. + */ + if (dynamicWidth && !widthHasBeenFixed) { + setNaturalWidth(); + widthHasBeenFixed = true; } // we may have actions and notifications @@ -383,6 +400,24 @@ public class IWindow extends IToolkitOverlay implements Container, } } + private void setNaturalWidth() { + /* + * For some reason IE6 has title DIV set to width 100% which messes this + * up. Also IE6 has a 0 wide element so we use the container element. + */ + int naturalWidth; + if (BrowserInfo.get().isIE6()) { + String headerW = headerText.getStyle().getProperty("width"); + headerText.getStyle().setProperty("width", "auto"); + naturalWidth = getElement().getOffsetWidth(); + headerText.getStyle().setProperty("width", headerW); + } else { + naturalWidth = getElement().getOffsetWidth(); + } + + setWidth(naturalWidth + "px"); + } + private void setReadOnly(boolean readonly) { this.readonly = readonly; if (readonly) { diff --git a/src/com/itmill/toolkit/tests/tickets/Ticket2325.java b/src/com/itmill/toolkit/tests/tickets/Ticket2325.java new file mode 100644 index 0000000000..5fa5eb50b8 --- /dev/null +++ b/src/com/itmill/toolkit/tests/tickets/Ticket2325.java @@ -0,0 +1,28 @@ +package com.itmill.toolkit.tests.tickets; + +import com.itmill.toolkit.Application; +import com.itmill.toolkit.ui.TextField; +import com.itmill.toolkit.ui.VerticalLayout; +import com.itmill.toolkit.ui.Window; + +public class Ticket2325 extends Application { + + public void init() { + Window main = new Window("Testing...."); + setMainWindow(main); + + final VerticalLayout lo = new VerticalLayout(); + lo.setSizeUndefined(); + lo.setWidth("100%"); + TextField tf = new TextField(); + tf.setValue("The textfield should fill the window." + + "\n - Try to resize window\n - Try to push REdo button"); + tf.setRows(10); + tf.setWidth("100%"); + lo.addComponent(tf); + Window subWin = new Window( + "This window should initially be as wide as the caption", lo); + main.addWindow(subWin); + // subWin.setWidth("500px"); + } +} |