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;
private boolean modal = false;
+ private boolean resizable = true;
+
private Element modalityCurtain;
private Element draggingCurtain;
setModal(!modal);
}
+ if (uidl.getBooleanAttribute("resizable") != resizable) {
+ setResizable(!resizable);
+ }
+
// Initialize the position form UIDL
try {
final int positionx = uidl.getIntVariable("positionx");
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() {
}
+ 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) {
}
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;
}
}
getElement(),
"width",
(Integer.parseInt(width.substring(0,
- width.length() - 2)) + BORDER_WIDTH_HORIZONTAL)
+ width.length() - 2)) + borderWidthHorizontal)
+ "px");
}
}
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;
+ }
+
}
private boolean modal = false;
+ private boolean resizable = true;
+
+ private boolean centerRequested = false;
+
/* ********************************************************************* */
/**
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()) {
/**
* Sets sub-window modal, so that widgets behind it cannot be accessed.
+ * <b>Note:</b> 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.
+ * <b>Note:</b> 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.
+ * <b>Note:</b> affects sub-windows only.
+ */
+ public void center() {
+ centerRequested = true;
}
/**