summaryrefslogtreecommitdiff
path: root/swat/style/qooxdoo/widgets/widgets/QxWindow.js
blob: e4732f5666d1b4493c9a9c478ac88a40cfa2f44d (plain)
1
2
3
4
5
/* Copyright (c): 2002-2005 (Germany): United Internet, 1&1, GMX, Schlund+Partner, Alturo */
function QxWindow(vCaption,vIcon){QxPopup.call(this);this.setBorder(QxBorder.presets.outset);this.setMinWidth(200);this.setMinHeight(100);this.addEventListener("mousedown",this._onwindowmousedown,this);this.addEventListener("mouseup",this._onwindowmouseup,this);this.addEventListener("mousemove",this._onwindowmousemove,this);var c=this._frame=new QxWidget();c.set({timerCreate:false,border:QxBorder.presets.shadow});c=this._captionbar=new QxWidget;c.set({cssClassName:"QxWindowCaptionBar",top:0,left:0,right:0,height:18});c.addEventListener("mousedown",this._oncaptionmousedown,this);c.addEventListener("mouseup",this._oncaptionmouseup,this);c.addEventListener("mousemove",this._oncaptionmousemove,this);this.addToWindow(c);c=this._pane=new QxWidget;c.set({cssClassName:"QxWindowPane",top:18,bottom:0,left:0,right:0});this.addToWindow(c);if(isValidString(vIcon)){this.setIcon(vIcon);};if(isValidString(vCaption)){this.setCaption(vCaption);};};QxWindow.extend(QxPopup,"QxWindow");QxWindow.addProperty({name:"active",type:Boolean,defaultValue:false});QxWindow.addProperty({name:"modal",type:Boolean,defaultValue:false});QxWindow.addProperty({name:"opener",type:Object});QxWindow.addProperty({name:"caption",type:String});QxWindow.addProperty({name:"status",type:String,defaultValue:"Ready"});QxWindow.addProperty({name:"showClose",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"showMaximize",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"showMinimize",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"showStatusbar",type:Boolean,defaultValue:false});QxWindow.addProperty({name:"allowClose",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"allowMaximize",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"allowMinimize",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"showCaption",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"showIcon",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"resizeable",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"moveable",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"resizeMethod",type:String,defaultValue:"frame"});QxWindow.addProperty({name:"moveMethod",type:String,defaultValue:"opaque"});QxWindow.addProperty({name:"usePreferredWidthAsMin",type:Boolean,defaultValue:true});QxWindow.addProperty({name:"usePreferredHeightAsMin",type:Boolean,defaultValue:true});proto._windowManager=new QxWindowManager();proto.getPane=function(){return this._pane;};proto.getCaptionbar=function(){return this._captionbar;};proto.getStatusbar=function(){return this._statusbar;};proto.addToWindow=proto.add;proto.addToPane=function(){this._pane.add.apply(this._pane,arguments);};proto.addToCaptionbar=function(){this._captionbar.add.apply(this._captionbar,arguments);};proto.add=proto.addToPane;proto._beforeShow=function(_b4){QxAtom.prototype._beforeShow.call(this,_b4);(new QxPopupManager).update();this._windowManager.add(this);this._makeActive();this._layoutCommands();};proto._beforeHide=function(_b4){QxAtom.prototype._beforeHide.call(this,_b4);this._windowManager.remove(this);this._makeInactive();};proto.bringToFront=proto.sendToBack=function(){throw new Error("Warning:bringToFront()and sendToBack()are not supported by QxWindow!");};proto._d1=function(){return true;};proto._d2=function(){return true;};proto._d5Width=function(){return this._pane.getAnyWidth();};proto._d5Height=function(){var h=this.getShowStatusbar()&&this._statusbar?this._statusbar.getAnyHeight():0;h+=this._pane.getAnyHeight()+this._captionbar.getAnyHeight();return h;};proto._modifyElement=function(_b1,_b2,_b3,_b4){if(_b1){this._addCssClassName("QxAtomBase");if(this._c1&&!this._icon){this._e3Icon();};if(this._displayCaption&&!this._caption){this._e3Caption();};if(this.getShowMinimize()&&!this._minimizeButton&&!this.getModal()){this._e3MinimizeButton();};if(this.getShowMaximize()&&!this.getModal()){if(!this._restoreButton){this._e3RestoreButton();};if(!this._maximizeButton){this._e3MaximizeButton();};};if(this.getShowStatusbar()){this._e3Statusbar();};if(this.getShowClose()&&!this._closeButton){this._e3CloseButton();};};return QxWidget.prototype._modifyElement.call(this,_b1,_b2,_b3,_b4);};proto._setChildrenDependWidth=QxWidget.prototype._setChildrenDependWidth;proto._setChildrenDependHeight=QxWidget.prototype._setChildrenDependHeight;proto._childOuterWidthChanged=QxWidget.prototype._childOuterWidthChanged;proto._childOuterHeightChanged=QxWidget.prototype._childOuterHeightChanged;proto._d5Helper=QxWidget.prototype._d5Helper;proto._c1=false;proto._displayCaption=false;proto._modifyActive=function(_b1,_b2,_b3,_b4){if(_b1){this.addCssClassNameDetail("active");this._windowManager.setActiveWindow(this,_b4);}else {this.removeCssClassNameDetail("active");};return true;};proto._checkState=function(_b1,_b2,_b3,_b4){if(!this.getResizeable()&&(_b2!="minimized"||this._previousState!=_b1)){throw new Error("This state is not allowed:"+_b1+"!");};return _b1;};proto._modifyState=function(_b1,_b2,_b3,_b4){switch(_b1){case "minimized":this._minimize();break;case "maximized":this._maximize();break;default:this._restore();};this._previousState=_b2;return QxPopup.prototype._modifyState.call(this,_b1,_b2,_b3,_b4);};proto._modifyShowClose=function(_b1,_b2,_b3,_b4){if(_b1&&!this._closeButton){this._e3CloseButton();};this._layoutCommands();return true;};proto._modifyShowMaximize=function(_b1,_b2,_b3,_b4){if(_b1){if(!this._maximizeButton){this._e3MaximizeButton();};if(!this._restoreButton){this._e3RestoreButton();};};this._layoutCommands();return true;};proto._modifyShowMinimize=function(_b1,_b2,_b3,_b4){if(_b1&&!this._minimizeButton){this._e3MinimizeButton();};this._layoutCommands();return true;};proto._modifyResizeable=function(_b1,_b2,_b3,_b4){return this._applyAllowMaximize();};proto._modifyAllowMinimize=function(_b1,_b2,_b3,_b4){return this._applyAllowMinimize();};proto._modifyModal=function(_b1,_b2,_b3,_b4){this._applyAllowMinimize();this._applyAllowMaximize();this._layoutCommands();if(this.getActive()){this.forceModal(true);this.setVisible(false);this.forceModal(_b1);this.setVisible(true);};return true;};proto._applyAllowMinimize=function(){if(this._minimizeButton){this._minimizeButton.setEnabled(this.getAllowMinimize()&&!this.getModal());};return true;};proto._modifyAllowMaximize=function(_b1,_b2,_b3,_b4){return this._applyAllowMaximize();};proto._applyAllowMaximize=function(){var e=this.getAllowMaximize()&&this.getResizeable()&&(this.getMaxWidth()==null||this.getMaxWidth()==Infinity)&&(this.getMaxHeight()==null||this.getMaxHeight()==Infinity);if(this._maximizeButton){this._maximizeButton.setEnabled(e);};if(this._restoreButton){this._restoreButton.setEnabled(e);};return true;};proto._modifyAllowClose=function(_b1,_b2,_b3,_b4){return this._applyAllowClose();};proto._applyAllowClose=function(){if(this._closeButton){this._closeButton.setEnabled(this.getAllowClose());};return true;};proto._layoutCommands=function(){var s=0;if(this._closeButton){if(this.getShowClose()){this._closeButton.setRight(s);if(this._captionbar._wasVisible){this._closeButton.setVisible(true);};s+=this._closeButton.getWidth()+2;}else {this._closeButton.setVisible(false);};};if(this._maximizeButton&&this._restoreButton){if(this.getShowMaximize()){if(this.getState()=="maximized"){this._maximizeButton.setVisible(false);this._restoreButton.setRight(s);if(this._captionbar._wasVisible){this._restoreButton.setVisible(true);};s+=this._restoreButton.getWidth();}else {this._restoreButton.setVisible(false);this._maximizeButton.setRight(s);if(this._captionbar._wasVisible){this._maximizeButton.setVisible(true);};s+=this._maximizeButton.getWidth();};}else {this._maximizeButton.setVisible(false);this._restoreButton.setVisible(false);};};if(this._minimizeButton){if(this.getShowMinimize()){this._minimizeButton.setRight(s);if(this._captionbar._wasVisible){this._minimizeButton.setVisible(true);};}else {this._minimizeButton.setVisible(false);};};};proto._e3CloseButton=function(){var ob = this._closeButton = new QxButton(null, "widgets/window/close.gif");ob.set({top:0,height:15,width:16,tabIndex:-1});ob.addEventListener("click",this._onclosebuttonclick,this);ob.addEventListener("mousedown",this._onbuttonmousedown,this);this._applyAllowClose();this.addToCaptionbar(ob);};proto._e3MinimizeButton=function(){var ob = this._minimizeButton = new QxButton(null, "widgets/window/minimize.gif");ob.set({top:0,height:15,width:16,tabIndex:-1});ob.addEventListener("click",this._onminimizebuttonclick,this);ob.addEventListener("mousedown",this._onbuttonmousedown,this);this._applyAllowMinimize();this.addToCaptionbar(ob);};proto._e3RestoreButton=function(){var ob = this._restoreButton = new QxButton(null, "widgets/window/restore.gif");ob.set({top:0,height:15,width:16,tabIndex:-1});ob.addEventListener("click",this._onrestorebuttonclick,this);ob.addEventListener("mousedown",this._onbuttonmousedown,this);this._applyAllowMaximize();ob._shouldBecomeCreated=function(){return this.getParent().getParent().getState()=="maximized";};this.addToCaptionbar(ob);};proto._e3MaximizeButton=function(){var ob = this._maximizeButton = new QxButton(null, "widgets/window/maximize.gif");ob.set({top:0,height:15,width:16,tabIndex:-1});ob.addEventListener("click",this._onmaximizebuttonclick,this);ob.addEventListener("mousedown",this._onbuttonmousedown,this);this._applyAllowMaximize();ob._shouldBecomeCreated=function(){return this.getParent().getParent().getState()!="maximized";};this.addToCaptionbar(ob);};proto._e3Statusbar=function(){c=this._statusbar=new QxAtom;c.set({cssClassName:"QxWindowStatusBar",width:null,bottom:0,left:0,right:0,height:18,border:QxBorder.presets.thinInset,text:this.getStatus()});this.addToWindow(c);};proto._modifyStatus=function(_b1,_b2,_b3,_b4){if(this._statusbar){this._statusbar.setText(_b1,_b4);};return true;};proto._modifyShowStatusbar=function(_b1,_b2,_b3,_b4){if(_b1){this._statusbar?this.addToWindow(this._statusbar):this._e3Statusbar();this._pane.setBottom(18);}else {if(this._statusbar){this.remove(this._statusbar);};this._pane.setBottom(0);};return true;};proto._modifyCaption=function(_b1,_b2,_b3,_b4){var o=this._caption;if(this._updateUseCaption()){if(o){o.setHtml(_b1);o.setParent(this._captionbar);}else {this._e3Caption();};}else if(o){o.setParent(null);o.setHtml(_b1);};return true;};proto._updateUseCaption=function(){return this._displayCaption=this.getCaption()&&this.getShowCaption();};proto._e3Caption=function(){var o=this._caption=new QxContainer(this.getCaption());o.setTop(1);this._layoutCaption();o.setParent(this._captionbar);};proto._modifyShowCaption=function(_b1,_b2,_b3,_b4){var o=this._caption;if(this._updateUseCaption()){if(o){o.setParent(this._captionbar);}else {this._e3Caption();};}else if(o){o.setParent(null);};return true;};proto._layoutCaption=function(){if(!this._icon||!this._icon.isCreated()){return;};if(this._caption){this._caption.setLeft(this._c1?this._icon.getAnyWidth()+3:0)};};proto._modifyIcon=function(_b1,_b2,_b3,_b4){var o=this._icon;if(this._updateUseIcon()){if(o){o.setSource(_b1);o.setParent(this._captionbar);}else {this._e3Icon();};}else if(o){o.setParent(null);o.setSource(_b1);};return true;};proto._updateUseIcon=function(){return this._c1=this.getIcon()&&this.getShowIcon();};proto._e3Icon=function(){var o=this._icon=new QxImage(this.getIcon(),this.getIconWidth(),this.getIconHeight());o.setLocation(1,0);o.addEventListener("mousedown",this._oniconmousedown,this);o.addEventListener("load",this._oniconload,this);o.setParent(this._captionbar);};proto._modifyShowIcon=function(_b1,_b2,_b3,_b4){var o=this._icon;if(this._updateUseIcon()){if(o){o.setParent(this._captionbar);}else {this._e3Icon();};}else if(o){o.setParent(null);};this._layoutCaption();return true;};proto.close=function(){this.setVisible(false);};proto.open=function(vOpener){if(isValid(vOpener)){this.setOpener(vOpener);};this.setVisible(true);};proto.focus=function(){this.setActive(true);};proto.blur=function(){this.setActive(false);};proto.maximize=function(){this.setState("maximized");};proto.minimize=function(){this.setState("minimized");};proto.restore=function(){this.setState(null);};proto._previousState=null;proto._minimize=function(){this.blur();this.setVisible(false);};proto._restore=function(){if(this.getVisible()){this._omitRendering();};this.setLeft(this._previousLeft?this._previousLeft:null);this.setRight(this._previousRight?this._previousRight:null);this.setTop(this._previousTop?this._previousTop:null);this.setBottom(this._previousBottom?this._previousBottom:null);this.setWidth(this._previousWidth?this._previousWidth:null);this.setHeight(this._previousHeight?this._previousHeight:null);this.getVisible()?this._activateRendering():this.setVisible(true);this._layoutCommands();this.focus();};proto._maximize=function(){if(this.getVisible()){this._omitRendering();};this._previousLeft=this.getLeft();this._previousWidth=this.getWidth();this._previousRight=this.getRight();this._previousTop=this.getTop();this._previousHeight=this.getHeight();this._previousBottom=this.getBottom();this.setWidth(null);this.setLeft(0);this.setRight(0);this.setHeight(null);this.setTop(0);this.setBottom(0);this.getVisible()?this._activateRendering():this.setVisible(true);this._layoutCommands();this.focus();};proto._onwindowmousedown=function(e){this.focus();if(this._resizeMode){this.setCapture(true);this.getTopLevelWidget().setGlobalCursor(this.getCursor());var pa=this.getParent();var l=pa.getComputedPageAreaLeft();var t=pa.getComputedPageAreaTop();var r=pa.getComputedPageAreaRight();var b=pa.getComputedPageAreaBottom();switch(this.getResizeMethod()){case "translucent":this.setOpacity(0.5);break;case "frame":var f=this._frame;f._d3Horizontal(this.getComputedPageBoxLeft()-l);f._d3Vertical(this.getComputedPageBoxTop()-t);f._applySizeHorizontal(this.getComputedBoxWidth());f._applySizeVertical(this.getComputedBoxHeight());f.setZIndex(this.getZIndex()+1);f.setParent(this.getParent());break;};var s=this._resizeSession={};switch(this._resizeMode){case "nw":case "sw":case "w":s.boxWidth=this.getComputedBoxWidth();s.boxRight=this.getComputedPageBoxRight();case "ne":case "se":case "e":s.boxLeft=this.getComputedPageBoxLeft();s.parentAreaOffsetLeft=l;s.parentAreaOffsetRight=r;s.minWidth=this.getUsePreferredWidthAsMin()?Math.max(this.getMinWidth(),this.getPreferredWidth()):this.getMinWidth();s.maxWidth=this.getMaxWidth();};switch(this._resizeMode){case "nw":case "ne":case "n":s.boxHeight=this.getComputedBoxHeight();s.boxBottom=this.getComputedPageBoxBottom();case "sw":case "se":case "s":s.boxTop=this.getComputedPageBoxTop();s.parentAreaOffsetTop=t;s.parentAreaOffsetBottom=b;s.minHeight=this.getUsePreferredHeightAsMin()?Math.max(this.getMinHeight(),this.getPreferredHeight()):this.getMinHeight();s.maxHeight=this.getMaxHeight();};}else {delete this._resizeSession;};};proto._onwindowmouseup=function(e){var s=this._resizeSession;if(s){this.setCapture(false);this.getTopLevelWidget().setGlobalCursor(null);switch(this.getResizeMethod()){case "frame":var o=this._frame;if(!(o&&o.getParent())){break;};case "lazyopaque":if(isValidNumber(s.lastLeft)){this.setLeft(s.lastLeft);};if(isValidNumber(s.lastTop)){this.setTop(s.lastTop);};if(isValidNumber(s.lastWidth)){this.setWidth(s.lastWidth);};if(isValidNumber(s.lastHeight)){this.setHeight(s.lastHeight);};if(this.getResizeMethod()=="frame"){this._frame.setParent(null);};break;case "translucent":this.setOpacity(null);break;};delete this._resizeMode;delete this._resizeSession;};};proto._near=function(p,e){return e>(p-5)&&e<(p+5);};proto._onwindowmousemove=function(e){if(!this.getResizeable()||this.getState()!=null){return;};var s=this._resizeSession;if(s){switch(this._resizeMode){case "nw":case "sw":case "w":s.lastWidth=(s.boxWidth+s.boxLeft-Math.max(e.getPageX(),s.parentAreaOffsetLeft)).limit(s.minWidth,s.maxWidth);s.lastLeft=s.boxRight-s.lastWidth-s.parentAreaOffsetLeft;break;case "ne":case "se":case "e":s.lastWidth=(Math.min(e.getPageX(),s.parentAreaOffsetRight)-s.boxLeft).limit(s.minWidth,s.maxWidth);break;};switch(this._resizeMode){case "nw":case "ne":case "n":s.lastHeight=(s.boxHeight+s.boxTop-Math.max(e.getPageY(),s.parentAreaOffsetTop)).limit(s.minHeight,s.maxHeight);s.lastTop=s.boxBottom-s.lastHeight-s.parentAreaOffsetTop;break;case "sw":case "se":case "s":s.lastHeight=(Math.min(e.getPageY(),s.parentAreaOffsetBottom)-s.boxTop).limit(s.minHeight,s.maxHeight);break;};switch(this.getResizeMethod()){case "opaque":case "translucent":switch(this._resizeMode){case "nw":case "sw":case "w":this.setLeft(s.lastLeft);case "ne":case "se":case "e":this.setWidth(s.lastWidth);};switch(this._resizeMode){case "nw":case "ne":case "n":this.setTop(s.lastTop);case "sw":case "se":case "s":this.setHeight(s.lastHeight);};break;default:var o=this.getResizeMethod()=="frame"?this._frame:this;switch(this._resizeMode){case "nw":case "sw":case "w":o._d3Horizontal(s.lastLeft);case "ne":case "se":case "e":o._applySizeHorizontal(s.lastWidth);};switch(this._resizeMode){case "nw":case "ne":case "n":o._d3Vertical(s.lastTop);case "sw":case "se":case "s":o._applySizeVertical(s.lastHeight);};};}else {var resizeMode="";if(this._near(this.getComputedPageBoxTop(),e.getPageY())){resizeMode="n";}else if(this._near(this.getComputedPageBoxBottom(),e.getPageY())){resizeMode="s";};if(this._near(this.getComputedPageBoxLeft(),e.getPageX())){resizeMode+="w";}else if(this._near(this.getComputedPageBoxRight(),e.getPageX())){resizeMode+="e";};if(resizeMode!=""){this._resizeMode=resizeMode;this.setCursor(resizeMode+"-resize");}else {delete this._resizeMode;this.setCursor(null);};};};proto._oniconmousedown=function(e){e.stopPropagation();};proto._onbuttonmousedown=function(e){e.stopPropagation();};proto._oniconload=function(e){this._layoutCaption();};proto._oncaptionmousedown=function(e){if(e.isNotLeftButton()||!this.getMoveable()||this.getState()!=null){return;};this._captionbar.setCapture(true);var pa=this.getParent();var l=pa.getComputedPageAreaLeft();var t=pa.getComputedPageAreaTop();var r=pa.getComputedPageAreaRight();var b=pa.getComputedPageAreaBottom();this._dragSession=
{offsetX:e.getPageX()-this.getComputedPageBoxLeft()+l,offsetY:e.getPageY()-this.getComputedPageBoxTop()+t,parentAvailableAreaLeft:l+5,parentAvailableAreaTop:t+5,parentAvailableAreaRight:r-5,parentAvailableAreaBottom:b-5
};switch(this.getMoveMethod()){case "translucent":this.setOpacity(0.5);break;case "frame":var f=this._frame;f._d3Horizontal(this.getComputedPageBoxLeft()-l);f._d3Vertical(this.getComputedPageBoxTop()-t);f._applySizeHorizontal(this.getComputedBoxWidth());f._applySizeVertical(this.getComputedBoxHeight());f.setZIndex(this.getZIndex()+1);f.setParent(this.getParent());break;};};proto._oncaptionmouseup=function(e){var s=this._dragSession;if(!s){return;};this._captionbar.setCapture(false);if(isValidNumber(s.lastX)){this.setLeft(s.lastX);};if(isValidNumber(s.lastY)){this.setTop(s.lastY);};switch(this.getMoveMethod()){case "translucent":this.setOpacity(null);break;case "frame":this._frame.setParent(null);break;};delete this._dragSession;};proto._oncaptionmousemove=function(e){var s=this._dragSession;if(!s||!this._captionbar.getCapture()){return;};if(!e.getPageX().inrange(s.parentAvailableAreaLeft,s.parentAvailableAreaRight)||!e.getPageY().inrange(s.parentAvailableAreaTop,s.parentAvailableAreaBottom)){return;};var o=this.getMoveMethod()=="frame"?this._frame:this;o._d3Horizontal(s.lastX=e.getPageX()-s.offsetX);o._d3Vertical(s.lastY=e.getPageY()-s.offsetY);};proto._onminimizebuttonclick=function(e){this.minimize();e.stopPropagation();};proto._onrestorebuttonclick=function(e){this.restore();e.stopPropagation();};proto._onmaximizebuttonclick=function(e){this.maximize();e.stopPropagation();};proto._onclosebuttonclick=function(e){this.close();e.stopPropagation();};proto.dispose=function(){if(this.getDisposed()){return;};this.removeEventListener("mousedown",this._onwindowmousedown,this);this.removeEventListener("mouseup",this._onwindowmouseup,this);this.removeEventListener("mousemove",this._onwindowmousemove,this);var w=this._caption;if(w){w.dispose();this._caption=null;};w=this._icon;if(w){w.removeEventListener("mousedown",this._oniconmousedown,this);w.dispose();this._icon=null;};w=this._closeButton;if(w){w.removeEventListener("click",this._onclosebuttonclick,this);w.removeEventListener("mousedown",this._onbuttonmousedown,this);w.dispose();this._closeButton=null;};w=this._restoreButton;if(w){w.removeEventListener("click",this._onrestorebuttonclick,this);w.removeEventListener("mousedown",this._onbuttonmousedown,this);w.dispose();this._restoreButton=null;};w=this._maximizeButton;if(w){w.removeEventListener("click",this._onmaximizebuttonclick,this);w.removeEventListener("mousedown",this._onbuttonmousedown,this);w.dispose();this._maximizeButton=null;};w=this._minimizeButton;if(w){w.removeEventListener("click",this._onminimizebuttonclick,this);w.removeEventListener("mousedown",this._onbuttonmousedown,this);w.dispose();this._minimizeButton=null;};w=this._captionbar;if(w){w.removeEventListener("mousedown",this._oncaptionmousedown,this);w.removeEventListener("mouseup",this._oncaptionmouseup,this);w.removeEventListener("mousemove",this._oncaptionmousemove,this);w.dispose();this._captionbar=null;};w=this._pane;if(w){w.dispose();this._pane=null;};w=this._statusbar;if(w){w.dispose();this._statusbar=null
};};