From 64f06d0f252e2844b3e103f2f5864441381d42ac Mon Sep 17 00:00:00 2001 From: Jouni Koivuviita Date: Thu, 21 Aug 2008 11:59:09 +0000 Subject: [PATCH] API changes: Window.setResizable(boolean resizability) now allows to disable end-user sub-window resizing. Window.center() allows to request a sub-window to be centered on screen. Improved theming capabilities for IWindow: window borders are now calculated dynamically for every sub-window instance, previously only one final static was specified. svn changeset:5238/svn branch:trunk --- WebContent/ITMILL/themes/default/styles.css | 8 ++ .../ITMILL/themes/default/window/window.css | 8 ++ .../terminal/gwt/client/DebugConsole.java | 2 +- .../terminal/gwt/client/ui/IWindow.java | 109 ++++++++++++------ src/com/itmill/toolkit/ui/Window.java | 51 ++++++++ 5 files changed, 141 insertions(+), 37 deletions(-) diff --git a/WebContent/ITMILL/themes/default/styles.css b/WebContent/ITMILL/themes/default/styles.css index fa22d8e52d..fa5c072c9a 100644 --- a/WebContent/ITMILL/themes/default/styles.css +++ b/WebContent/ITMILL/themes/default/styles.css @@ -2280,6 +2280,11 @@ i-orderedlayout-margin-top { background: transparent url(window/img/resize.png); } +.i-window-resizebox-disabled { + cursor: default; + background: transparent; +} + .i-window-closebox { position:absolute; top: 33px; @@ -2355,6 +2360,9 @@ i-orderedlayout-margin-top { height: 12px; background: url(window/img/resize.png); } +* html .i-window-resizebox-disabled { + background: transparent; +} *+html .i-window-resizebox { bottom: 0; background-position: 3px 3px; diff --git a/WebContent/ITMILL/themes/default/window/window.css b/WebContent/ITMILL/themes/default/window/window.css index 4460002a72..cea46271ee 100644 --- a/WebContent/ITMILL/themes/default/window/window.css +++ b/WebContent/ITMILL/themes/default/window/window.css @@ -97,6 +97,11 @@ background: transparent url(img/resize.png); } +.i-window-resizebox-disabled { + cursor: default; + background: transparent; +} + .i-window-closebox { position:absolute; top: 33px; @@ -172,6 +177,9 @@ height: 12px; background: url(img/resize.png); } +* html .i-window-resizebox-disabled { + background: transparent; +} *+html .i-window-resizebox { bottom: 0; background-position: 3px 3px; diff --git a/src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java b/src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java index fb324f2167..6407c25f32 100755 --- a/src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/DebugConsole.java @@ -63,7 +63,7 @@ public final class DebugConsole extends IWindow implements Console { // TODO stack to bottom (create window manager of some sort) setPixelSize(60, 60); setPopupPosition(Window.getClientWidth() - - (100 + IWindow.BORDER_WIDTH_HORIZONTAL), 0); + - 142, 0); } /* 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 8a8ffa2130..95dbebf47f 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java @@ -42,11 +42,11 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { public static final String CLASSNAME = "i-window"; - /** pixels used by inner borders and paddings horizontally */ - protected static final int BORDER_WIDTH_HORIZONTAL = 41; - - /** pixels used by headers, footers, inner borders and paddings vertically */ - protected static final int BORDER_WIDTH_VERTICAL = 58; + /** + * pixels used by inner borders and paddings horizontally (calculated on + * attach) + */ + private int borderWidthHorizontal = 0; private static final int STACKING_OFFSET_PIXELS = 15; @@ -96,6 +96,8 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { private boolean modal = false; + private boolean resizable = true; + private Element modalityCurtain; private Element draggingCurtain; @@ -207,6 +209,10 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { setModal(!modal); } + if (uidl.getBooleanAttribute("resizable") != resizable) { + setResizable(!resizable); + } + // Initialize the position form UIDL try { final int positionx = uidl.getIntVariable("positionx"); @@ -367,6 +373,13 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { contentPanel.setHorizontalScrollPosition(uidl .getIntVariable("scrollLeft")); + // Center this window on screen if requested + // This has to be here because we might not know the content size before + // everything is painted into the window + if (uidl.getBooleanAttribute("center")) { + center(); + } + } public void show() { @@ -490,6 +503,17 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { } + private void setResizable(boolean resizability) { + resizable = resizability; + if (resizability) { + DOM.setElementProperty(resizeBox, "className", CLASSNAME + + "-resizebox"); + } else { + DOM.setElementProperty(resizeBox, "className", CLASSNAME + + "-resizebox " + CLASSNAME + "-resizebox-disabled"); + } + } + public void setPopupPosition(int left, int top) { super.setPopupPosition(left, top); if (left != uidlPositionX && client != null) { @@ -562,38 +586,40 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { } private void onResizeEvent(Event event) { - switch (DOM.eventGetType(event)) { - case Event.ONMOUSEDOWN: - if (!isActive()) { - bringToFront(); - } - showDraggingCurtain(true); - resizing = true; - startX = DOM.eventGetScreenX(event); - startY = DOM.eventGetScreenY(event); - origW = getWidget().getOffsetWidth(); - origH = getWidget().getOffsetHeight(); - DOM.setCapture(getElement()); - DOM.eventPreventDefault(event); - break; - case Event.ONMOUSEUP: - showDraggingCurtain(false); - resizing = false; - DOM.releaseCapture(getElement()); - setSize(event, true); - break; - case Event.ONLOSECAPTURE: - showDraggingCurtain(false); - resizing = false; - case Event.ONMOUSEMOVE: - if (resizing) { - setSize(event, false); + if (resizable) { + switch (DOM.eventGetType(event)) { + case Event.ONMOUSEDOWN: + if (!isActive()) { + bringToFront(); + } + showDraggingCurtain(true); + resizing = true; + startX = DOM.eventGetScreenX(event); + startY = DOM.eventGetScreenY(event); + origW = getWidget().getOffsetWidth(); + origH = getWidget().getOffsetHeight(); + DOM.setCapture(getElement()); + DOM.eventPreventDefault(event); + break; + case Event.ONMOUSEUP: + showDraggingCurtain(false); + resizing = false; + DOM.releaseCapture(getElement()); + setSize(event, true); + break; + case Event.ONLOSECAPTURE: + showDraggingCurtain(false); + resizing = false; + case Event.ONMOUSEMOVE: + if (resizing) { + setSize(event, false); + DOM.eventPreventDefault(event); + } + break; + default: DOM.eventPreventDefault(event); + break; } - break; - default: - DOM.eventPreventDefault(event); - break; } } @@ -624,7 +650,7 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { getElement(), "width", (Integer.parseInt(width.substring(0, - width.length() - 2)) + BORDER_WIDTH_HORIZONTAL) + width.length() - 2)) + borderWidthHorizontal) + "px"); } } @@ -695,4 +721,15 @@ public class IWindow extends PopupPanel implements Paintable, ScrollListener { true); } + protected void onAttach() { + super.onAttach(); + // Calculate space required by window borders, so we can accurately + // calculate space for content + final int contentWidth = DOM.getElementPropertyInt(contentPanel + .getElement(), "offsetWidth"); + final int windowWidth = DOM.getElementPropertyInt(getElement(), + "offsetWidth"); + borderWidthHorizontal = windowWidth - contentWidth; + } + } diff --git a/src/com/itmill/toolkit/ui/Window.java b/src/com/itmill/toolkit/ui/Window.java index a69ac113ca..b1e85f7f2d 100644 --- a/src/com/itmill/toolkit/ui/Window.java +++ b/src/com/itmill/toolkit/ui/Window.java @@ -108,6 +108,10 @@ public class Window extends Panel implements URIHandler, ParameterHandler { private boolean modal = false; + private boolean resizable = true; + + private boolean centerRequested = false; + /* ********************************************************************* */ /** @@ -470,6 +474,15 @@ public class Window extends Panel implements URIHandler, ParameterHandler { target.addAttribute("modal", true); } + if (resizable) { + target.addAttribute("resizable", true); + } + + if(centerRequested) { + target.addAttribute("center", true); + centerRequested = false; + } + // Marks the main window if (getApplication() != null && this == getApplication().getMainWindow()) { @@ -1023,12 +1036,50 @@ public class Window extends Panel implements URIHandler, ParameterHandler { /** * Sets sub-window modal, so that widgets behind it cannot be accessed. + * Note: affects sub-windows only. * * @param modality * true if modality is to be turned on */ public void setModal(boolean modality) { modal = modality; + center(); + requestRepaint(); + } + + /** + * @return true if this window is modal. + */ + public boolean isModal() { + return modal; + } + + /** + * Sets sub-window resizable. + * Note: affects sub-windows only. + * + * @param resizable + * true if resizability is to be turned on + */ + public void setResizable(boolean resizeability) { + resizable = resizeability; + requestRepaint(); + } + + /** + * + * @return true if window is resizable by the end-user, otherwise false. + */ + public boolean isResizable() { + return resizable; + } + + /** + * Request to center this window on the screen. + * Note: affects sub-windows only. + */ + public void center() { + centerRequested = true; } /** -- 2.39.5