summaryrefslogtreecommitdiff
path: root/swat/style/qooxdoo/widgets/managers/QxFocusManager.js
blob: 13a2c524dca96c4f89a7966ce7e2baa5fce7d81c (plain)
1
2
/* Copyright (c): 2002-2005 (Germany): United Internet, 1&1, GMX, Schlund+Partner, Alturo */
function QxFocusManager(vClientWindow){QxObject.call(this);if(isValid(vClientWindow)){this._attachedClientWindow=vClientWindow;};};QxFocusManager.extend(QxManager,"QxFocusManager");QxFocusManager.addProperty({name:"focusedWidget"});proto._attachedClientWindow=null;proto._modifyFocusedWidget=function(_b1,_b2,_b3,_b4){var cIn=typeof _b1=="object"&&_b1!=null;var cOut=typeof _b2=="object"&&_b2!=null;if(cIn&&typeof QxPopupManager=="function"){(new QxPopupManager).update(_b1);};if(cOut){var s=new QxFocusEvent("focusout",false);if(cIn){s.setRelatedTarget(_b1);};_b2.dispatchEvent(s);s.dispose();};if(cIn){var s=new QxFocusEvent("focusin",false);if(cOut){s.setRelatedTarget(_b2);};_b1.dispatchEvent(s);s.dispose();};if(cOut){_b2.setFocused(false,_b4);var s=new QxFocusEvent("blur",false);if(cIn){s.setRelatedTarget(_b1);};_b2.dispatchEvent(s);if(typeof QxToolTipManager=="function"){(new QxToolTipManager).handleBlur(s);};s.dispose();(new QxApplication).setActiveWidget(null);};if(cIn){_b1.setFocused(true,_b4);var s=new QxFocusEvent("focus",false);if(cOut){s.setRelatedTarget(_b2);};_b1.dispatchEvent(s);if(typeof QxToolTipManager=="function"){(new QxToolTipManager).handleFocus(s);};s.dispose();(new QxApplication).setActiveWidget(_b1);};return true;};proto._ontabeventname=(new QxClient).isMshtml()?"keydown":"keypress";proto._ontabevent=function(e){if(e.type!=this._ontabeventname||!this._attachedClientWindow){return;};var cd=this._attachedClientWindow.getDocument();var current=this.getFocusedWidget();if(!e.shiftKey){var next=current?this.getWidgetAfter(cd,current):this.getFirstWidget(cd);}else {var next=current?this.getWidgetBefore(cd,current):this.getLastWidget(cd);};if(next){next.setFocused(true);next._ontabfocus();};};proto.compareTabOrder=function(c1,c2){if(c1==c2){return 0;};var t1=c1.getTabIndex();var t2=c2.getTabIndex();if(t1!=t2){return t1-t2;};var y1=c1.getComputedPageBoxTop();var y2=c2.getComputedPageBoxTop();if(y1!=y2){return y1-y2;};var x1=c1.getComputedPageBoxLeft();var x2=c2.getComputedPageBoxLeft();if(x1!=x2){return x1-x2;};var z1=c1.getZIndex();var z2=c2.getZIndex();if(z1!=z2){return z1-z2;};return 0;};proto.getFirstWidget=function(oContainer){return this._getFirst(oContainer,null);};proto.getLastWidget=function(oContainer){return this._getLast(oContainer,null);};proto.getWidgetAfter=function(oContainer,oWidget){if(oContainer==oWidget){return this.getFirstWidget(oContainer);};if(oWidget.getAnonymous()){oWidget=oWidget.getParent();};if(oWidget==null){return[];};var all=[];this._getAllAfter(oContainer,oWidget,all);all.sort(this.compareTabOrder);return all.length>0?all[0]:this.getFirstWidget(oContainer);};proto.getWidgetBefore=function(oContainer,oWidget){if(oContainer==oWidget){return this.getLastWidget(oContainer);};if(oWidget.getAnonymous()){oWidget=oWidget.getParent();};if(oWidget==null){return[];};var all=[];this._getAllBefore(oContainer,oWidget,all);all.sort(this.compareTabOrder);var l=all.length;return l>0?all[l-1]:this.getLastWidget(oContainer);};proto._getAllAfter=function(oCont,oComp,oArray){var cs=oCont.getChildren();var l=cs.length;for(var i=0;i<l;i++){if(!(cs[i]instanceof QxWidget)){continue;};if(cs[i].canGetFocus()&&cs[i].getTabIndex()>0&&this.compareTabOrder(oComp,cs[i])<0){oArray.push(cs[i]);};if(!cs[i].isFocusRoot()){this._getAllAfter(cs[i],oComp,oArray);};};};proto._getAllBefore=function(oCont,oComp,oArray){var cs=oCont.getChildren();var l=cs.length;for(var i=0;i<l;i++){if(!(cs[i]instanceof QxWidget)){continue;};if(cs[i].canGetFocus()&&cs[i].getTabIndex()>0&&this.compareTabOrder(oComp,cs[i])>0){oArray.push(cs[i]);};if(!cs[i].isFocusRoot()){this._getAllBefore(cs[i],oComp,oArray);};};};proto._getFirst=function(oCont,oFirst){var cs=oCont.getChildren();var l=cs.length;for(var i=0;i<l;i++){if(!(cs[i]instanceof QxWidget)){continue;};if(cs[i].canGetFocus()&&cs[i].getTabIndex()>0){if(oFirst==null||this.compareTabOrder(cs[i],oFirst)<0){oFirst=cs[i];};};if(!cs[i].isFocusRoot()){oFirst=this._getFirst(cs[i],oFirst);};};return oFirst;};proto._getLast=function(oCont,oLast){var cs=oCont.getChildren();var l=cs.length;for(var i=0;i<l;i++){if(!(cs[i]instanceof QxWidget)){continue;};if(cs[i].canGetFocus()&&cs[i].getTabIndex()>0){if(oLast==null||this.compareTabOrder(cs[i],oLast)>0){oLast=cs[i];};};if(! cs[i].isFocusRoot()){oLast=this._getLast(cs[i],oLast);};};return oLast;};proto.dispose=function(){if(this.getDisposed()){return;};this._attachedClientWindow=null;QxObject.prototype.dispose.call(this);};