]> source.dussan.org Git - vaadin-framework.git/commitdiff
window: order, size
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 28 Aug 2007 06:01:47 +0000 (06:01 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 28 Aug 2007 06:01:47 +0000 (06:01 +0000)
svn changeset:2137/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IWindow.java
src/com/itmill/toolkit/terminal/gwt/public/component-themes/window/css/window.css

index a7f9b8d201a52ecb3056e09a77a80d989afc6bea..9d56870ffdc0a0c90a97cd058e065bac5ffb802d 100644 (file)
@@ -1,5 +1,7 @@
 package com.itmill.toolkit.terminal.gwt.client.ui;
 
+import java.util.Vector;
+
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.Event;
@@ -10,19 +12,28 @@ import com.itmill.toolkit.terminal.gwt.client.Paintable;
 import com.itmill.toolkit.terminal.gwt.client.UIDL;
 
 /**
+ * "Sub window" component.
+ * 
+ * TODO update position / scrollposition / size to client
  * 
  * @author IT Mill Ltd
  */
 public class IWindow extends PopupPanel implements Paintable {
-
+       
+       private static Vector windowOrder = new Vector();
+       
        public static final String CLASSNAME = "i-window";
 
-       /** pixels used by borders and paddings horizontally */
-       protected static final int BORDER_WIDTH_HORIZONTAL = 2;
+       /** pixels used by inner borders and paddings horizontally */
+       protected static final int BORDER_WIDTH_HORIZONTAL = 0;
 
-       /** pixels used by headers, footers, borders and paddings vertically */
+       /** pixels used by headers, footers, inner borders and paddings vertically */
        protected static final int BORDER_WIDTH_VERTICAL = 22;
 
+       private static final int STACKING_OFFSET_PIXELS = 15;
+       
+       private static final int Z_INDEX_BASE = 10000;
+
        private Paintable layout;
 
        private Element contents;
@@ -57,8 +68,36 @@ public class IWindow extends PopupPanel implements Paintable {
        
        public IWindow() {
                super();
+               int order = windowOrder.size();
+               setWindowOrder(order);
+               windowOrder.add(this);
                setStyleName(CLASSNAME);
                constructDOM();
+               setPopupPosition(order*STACKING_OFFSET_PIXELS, order*STACKING_OFFSET_PIXELS);
+       }
+       
+       private void bringToFront() {
+               int curIndex = windowOrder.indexOf(this);
+               if(curIndex + 1 < windowOrder.size()) {
+                       windowOrder.remove(this);
+                       windowOrder.add(this);
+                       for(;curIndex < windowOrder.size();curIndex++) {
+                               ((IWindow) windowOrder.get(curIndex)).setWindowOrder(curIndex);
+                       }
+               }
+       }
+       
+       /**
+        * Returns true if window is the topmost window 
+        * 
+        * @return
+        */
+       private boolean isActive() {
+               return windowOrder.lastElement().equals(this);
+       }
+       
+       public void setWindowOrder(int order) {
+               DOM.setStyleAttribute(getElement(), "zIndex", "" + (order + Z_INDEX_BASE));
        }
        
        protected void constructDOM() {
@@ -77,6 +116,7 @@ public class IWindow extends PopupPanel implements Paintable {
                DOM.sinkEvents(header, Event.MOUSEEVENTS);
                DOM.sinkEvents(resizeBox, Event.MOUSEEVENTS);
                DOM.sinkEvents(closeBox, Event.ONCLICK);
+               DOM.sinkEvents(contents, Event.ONCLICK);
                
                Element wrapper = getElement();
                DOM.appendChild(wrapper, closeBox);
@@ -89,10 +129,18 @@ public class IWindow extends PopupPanel implements Paintable {
        public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
                this.id = uidl.getId();
                this.client = client;
+               
                if(uidl.hasAttribute("invisible")) {
                        this.hide();
                        return;
                } else {
+                       if(uidl.getIntVariable("width") > 0) {
+                               setPixelWidth(uidl.getIntVariable("width"));
+                       }
+                       if(uidl.getIntVariable("height") > 0) {
+                               setPixelHeight(uidl.getIntVariable("width"));
+                       }
+                       
                        if(!isAttached()) {
                                show();
                        }
@@ -123,11 +171,21 @@ public class IWindow extends PopupPanel implements Paintable {
        }
        
        public void setPixelSize(int width, int height) {
-               // set contents size also due IE's bugs
+               setPixelHeight(height);
+               setPixelWidth(width);
+       }
+       
+       public void setPixelWidth(int width) {
                DOM.setStyleAttribute(contents, "width", (width - BORDER_WIDTH_HORIZONTAL) + "px");
-               DOM.setStyleAttribute(contents, "height", (height - BORDER_WIDTH_VERTICAL) + "px");
                DOM.setStyleAttribute(header, "width", (width - BORDER_WIDTH_HORIZONTAL) + "px");
-               super.setPixelSize(width - BORDER_WIDTH_HORIZONTAL, height - BORDER_WIDTH_VERTICAL);
+               DOM.setStyleAttribute(footer, "width", (width - BORDER_WIDTH_HORIZONTAL) + "px");
+               DOM.setStyleAttribute(getElement(), "width", width + "px");
+               
+       }
+       
+       public void setPixelHeight(int height) {
+               DOM.setStyleAttribute(contents, "height", (height - BORDER_WIDTH_VERTICAL) + "px");
+               DOM.setStyleAttribute(getElement(), "height", height + "px");
        }
 
        protected Element getContainerElement() {
@@ -135,6 +193,9 @@ public class IWindow extends PopupPanel implements Paintable {
        }
 
        public void onBrowserEvent(Event event) {
+               if( !isActive()) {
+                       bringToFront();
+               }
                Element target = DOM.eventGetTarget(event);
                if (dragging || DOM.compare(header, target))
                        onHeaderEvent(event);
index f458f67a2cbf9ac7b3e1b0e0ba6131e654ed9c7a..a5cc9486b34cdb13d5f804d9e2bdc16aa14fd886 100644 (file)
@@ -1,22 +1,25 @@
 .i-window {
        border: 1px solid #999;
+       /* mac FF fix for scrollbar see thru */
+       position: absolute;
 }
 .i-window-header {
        background: yellow;
        height:20px;
+       overflow: hidden;
 }
 
 .i-window-footer {
        background: #0f0;
-       height:0px;
+       height:2px;
 }
 
 .i-window-contents {
-       background: #fff;
        overflow:auto;
+       background: #fff;
 }
 
-.i-window-resizeBox {
+.i-window-resizebox {
        position:absolute;
        bottom:0;
        right:0;
        width: 5px;
        height: 5px;
        float:right;
+       /* IE 6 hack */
+       overflow: auto;
+}
+
+.i-window-closebox {
+       position:absolute;
+       top:0;
+       right:0;
+       background: red;
+       width: 15px;
+       height: 15px;
+       float:right;
 }