r9133: a huge import of the qooxdoo infrastructure. I decided to import all the widge...
[jra/samba/.git] / swat / style / qooxdoo / widgets / widgets / QxMenu.js
1 /* Copyright (c): 2002-2005 (Germany): United Internet, 1&1, GMX, Schlund+Partner, Alturo */
2 function QxMenu(){QxPopup.call(this);this.setWidth("auto");this.setHeight(null);this.setTimerCreate(false);this.setMinWidth(120);this._openTimer=new QxTimer(this.getOpenInterval());this._openTimer.addEventListener("interval",this._onopentimer,this);this._closeTimer=new QxTimer(this.getCloseInterval());this._closeTimer.addEventListener("interval",this._onclosetimer,this);this.addEventListener("mouseover",this._onmouseover);this.addEventListener("mousemove",this._onmouseover);this.addEventListener("mouseout",this._onmouseout);this.addEventListener("keydown",this._g4);};QxMenu.extend(QxPopup,"QxMenu");QxMenu.addProperty({name:"iconContentGap",type:Number,defaultValue:4});QxMenu.addProperty({name:"textShortcutGap",type:Number,defaultValue:10});QxMenu.addProperty({name:"contentArrowGap",type:Number,defaultValue:6});QxMenu.addProperty({name:"hoverItem",type:Object});QxMenu.addProperty({name:"openItem",type:Object});QxMenu.addProperty({name:"opener",type:Object});QxMenu.addProperty({name:"parentMenu",type:Object});QxMenu.addProperty({name:"fastReopen",type:Boolean,defaultValue:false});QxMenu.addProperty({name:"openInterval",type:Number,defaultValue:250});QxMenu.addProperty({name:"closeInterval",type:Number,defaultValue:250});QxMenu.addProperty({name:"subMenuHorizontalOffset",type:Number,defaultValue:-3});QxMenu.addProperty({name:"subMenuVerticalOffset",type:Number,defaultValue:-2});QxMenu.addProperty({name:"minIconColumnWidth",type:Number,defaultValue:16});QxMenu.addProperty({name:"showIconColumnWithoutAnyIcon",type:Boolean,defaultValue:true});proto._menuManager=new QxMenuManager();proto._beforeShow=function(_b4){QxAtom.prototype._beforeShow.call(this,_b4);this._menuManager.add(this);this.bringToFront();this._makeActive();};proto._beforeHide=function(_b4){QxAtom.prototype._beforeHide.call(this,_b4);this.sendToBack();this._menuManager.remove(this);this._makeInactive();};proto._modifyHoverItem=function(_b1,_b2,_b3,_b4){if(_b2){_b2.setState(null);};if(_b1){_b1.setState("hover");};return true;};proto._modifyOpenItem=function(_b1,_b2,_b3,_b4){var vMakeActive=false;if(_b2){var vOldSub=_b2.getMenu();if(vOldSub){vOldSub.setParentMenu(null);vOldSub.setOpener(null);vOldSub.setVisible(false);};};if(_b1){var vSub=_b1.getMenu();if(vSub){vSub.setOpener(_b1);vSub.setParentMenu(this);vSub.setTop(_b1.getComputedPageBoxTop()+this.getSubMenuVerticalOffset());vSub.setLeft(this.getComputedPageBoxLeft()+this.getComputedBoxWidth()+this.getSubMenuHorizontalOffset());vSub.setVisible(true);};};return true;};proto._modifyVisible=function(_b1,_b2,_b3,_b4){this.setHoverItem(null);this.setOpenItem(null);if(_b2){var vOpener=this.getOpener();if(vOpener&&vOpener.getState()!="hover"){vOpener.setState(null);};};return QxWidget.prototype._modifyVisible.call(this,_b1,_b2,_b3,_b4);};proto._setChildrenDependWidth=function(_e4,_e5){var vMaxPaddingLeft=0;var vMaxPaddingRight=0;var vMaxIconWidth=0;var vMaxTextWidth=0;var vMaxShortcutWidth=0;var vMaxArrowWidth=0;var vMaxTextWidth=0;var vMaxContentWidth=0;var vIconContentGap=this.getIconContentGap();var vContentArrowGap=this.getContentArrowGap();var vTextShortcutGap=this.getTextShortcutGap();var ch=this.getChildren();var chl=ch.length;var chc;for(var i=0;i<chl;i++){chc=ch[i];if(chc instanceof QxMenuButton){vMaxPaddingLeft=Math.max(vMaxPaddingLeft,chc.getComputedPaddingLeft());vMaxPaddingRight=Math.max(vMaxPaddingRight,chc.getComputedPaddingRight());vMaxIconWidth=Math.max(vMaxIconWidth,chc.getNeededIconWidth());vMaxArrowWidth=Math.max(vMaxArrowWidth,chc.getNeededArrowWidth());if(chc.getNeededShortcutWidth()>0){vMaxTextWidth=Math.max(vMaxTextWidth,chc.getNeededTextWidth());vMaxShortcutWidth=Math.max(vMaxShortcutWidth,chc.getNeededShortcutWidth());}else {vMaxContentWidth=Math.max(vMaxContentWidth,chc.getNeededTextWidth());};};};if(vMaxIconWidth>0||this.getShowIconColumnWithoutAnyIcon()){vMaxIconWidth=Math.max(vMaxIconWidth,this.getMinIconColumnWidth());};vMaxContentWidth=Math.max(vMaxContentWidth,(vMaxTextWidth+vTextShortcutGap+vMaxShortcutWidth));this._childIconPosition=vMaxPaddingLeft;var vUseIconWidth=vMaxIconWidth>0?(vMaxIconWidth+vIconContentGap):0;this._childTextPosition=this._childIconPosition+vUseIconWidth;var vUseEndPos=this._childTextPosition+vMaxContentWidth;var vUseMaxArrow=vMaxArrowWidth>0?vContentArrowGap+vMaxArrowWidth:4;var vUseInnerWidth=vMaxPaddingLeft+vUseEndPos+vUseMaxArrow+vMaxPaddingRight;var vUseOuterFrame=this.getComputedBorderLeft()+this.getComputedPaddingLeft()+this.getComputedPaddingRight()+this.getComputedBorderRight();var vUseOuterWidth=vUseInnerWidth+vUseOuterFrame;var vMinWidth=this.getMinWidth();if(vMinWidth!=null&&vUseOuterWidth<vMinWidth){vUseEndPos=vMinWidth-vUseOuterFrame-vMaxPaddingLeft-vMaxPaddingRight-vUseMaxArrow;};this._childShortcutPosition=vUseEndPos-vMaxShortcutWidth;this._childArrowPosition=vUseEndPos+vContentArrowGap;this.setWidth(vUseOuterWidth,null,true);};proto._onmouseover=function(e){var vParent=this.getParentMenu();if(vParent){vParent._closeTimer.stop();var vOpener=this.getOpener();if(vOpener){vParent.setHoverItem(vOpener);};};var t=e.getActiveTarget();if(t==this){this._openTimer.stop();this._closeTimer.start();this.setHoverItem(null);return;};var vOpen=this.getOpenItem();if(vOpen){this.setHoverItem(t);this._openTimer.stop();if(t.hasMenu()){if(this.getFastReopen()){this.setOpenItem(t);this._closeTimer.stop();}else {this._openTimer.start();};}else {this._closeTimer.start();};}else {this.setHoverItem(t);this._openTimer.stop();if(t.hasMenu()){this._openTimer.start();};};};proto._onmouseout=function(e){this._openTimer.stop();var t=e.getActiveTarget();if(t!=this&&t.hasMenu()){this._closeTimer.start();};this.setHoverItem(null);};proto._onopentimer=function(e){this._openTimer.stop();var vHover=this.getHoverItem();if(vHover&&vHover.hasMenu()){this.setOpenItem(vHover);};};proto._onclosetimer=function(e){this._closeTimer.stop();this.setOpenItem(null);};proto._g4=function(e){switch(e.getKeyCode()){case QxKeyEvent.keys.up:this._g4_up(e);break;case QxKeyEvent.keys.down:this._g4_down(e);break;case QxKeyEvent.keys.left:this._g4_left(e);break;case QxKeyEvent.keys.right:this._g4_right(e);break;case QxKeyEvent.keys.enter:this._g4_enter(e);break;default:return;};e.preventDefault();};proto._g4_up=function(e){var vHover=this.getHoverItem();var vPrev=vHover?vHover.isFirstChild()?this.getLastActiveChild():vHover.getPreviousActiveSibling([QxMenuSeparator]):this.getLastActiveChild();this.setHoverItem(vPrev);};proto._g4_down=function(e){var vHover=this.getHoverItem();var vNext=vHover?vHover.isLastChild()?this.getFirstActiveChild():vHover.getNextActiveSibling([QxMenuSeparator]):this.getFirstActiveChild();this.setHoverItem(vNext);};proto._g4_left=function(e){var vOpener=this.getOpener();if(vOpener instanceof QxMenuButton){var vOpenerParent=this.getOpener().getParent();vOpenerParent.setOpenItem(null);vOpenerParent.setHoverItem(vOpener);vOpenerParent._makeActive();}else if(vOpener instanceof QxMenuBarButton){var vOpenerParent=this.getOpener().getParent();(new QxApplication).setActiveWidget(vOpenerParent);vOpenerParent._g4(e);};};proto._g4_right=function(e){var vHover=this.getHoverItem();if(vHover){var vMenu=vHover.getMenu();if(vMenu){this.setOpenItem(vHover);vMenu.setHoverItem(vMenu.getFirstChild());return;};}else if(!this.getOpenItem()){var vFirst=this.getFirstActiveChild();if(vFirst){vFirst.hasMenu()?this.setOpenItem(vFirst):this.setHoverItem(vFirst);};};var vOpener=this.getOpener();if(vOpener instanceof QxMenuBarButton){var vOpenerParent=this.getOpener().getParent();(new QxApplication).setActiveWidget(vOpenerParent);vOpenerParent._g4(e);}else if(vOpener instanceof QxMenuButton&&vHover){var vOpenerParent=vOpener.getParent();while(vOpenerParent){if(vOpenerParent instanceof QxMenuBar){(new QxApplication).setActiveWidget(vOpenerParent);vOpenerParent._g4(e);break;};try{vOpenerParent=vOpenerParent.getOpener().getParent();}catch(ex){break;};};};};proto._g4_enter=function(e){var vHover=this.getHoverItem();if(vHover){vHover.execute();};(new QxMenuManager()).update();};proto.dispose=function(){if(this.getDisposed()){return;};if(this._openTimer){this._openTimer.dispose();this._openTimer=null;};if(this._closeTimer){this._closeTimer.dispose();this._closeTimer=null;};this.removeEventListener("mouseover",this._onmouseover);this.removeEventListener("mousemove",this._onmouseover);this.removeEventListener("mouseout",this._onmouseout);this.removeEventListener("keydown",this._g4);return QxPopup.prototype.dispose.call(this);};