summaryrefslogtreecommitdiff
path: root/swat/style/qooxdoo/widgets/managers/QxEventManager.js
blob: 53ef5f26acb35f9c65563d7057beeac1657cf4de (plain)
1
2
/* Copyright (c): 2002-2005 (Germany): United Internet, 1&1, GMX, Schlund+Partner, Alturo */
function QxEventManager(vClientWindow){QxObject.call(this);var o=this;this.__onmouseevent=function(e){return o._onmouseevent(e);};this.__onkeyevent=function(e){return o._onkeyevent(e);};this.__ondragevent=function(e){return o._ondragevent(e);};this.__onwindowblur=function(e){return o._onwindowblur(e);};this.__onwindowfocus=function(e){return o._onwindowfocus(e);};this.__onwindowresize=function(e){return o._onwindowresize(e);};if(isValid(vClientWindow)){this.attachEvents(vClientWindow);};this._commands={};};QxEventManager.extend(QxManager,"QxEventManager");QxEventManager.mouseEventTypes=["mouseover","mousemove","mouseout","mousedown","mouseup","click","dblclick","contextmenu",(new QxClient).isMshtml()?"mousewheel":"DOMMouseScroll"];QxEventManager.keyEventTypes=["keydown","keypress","keyup"];QxEventManager.dragEventTypes=(new QxClient).isGecko()?["dragdrop","dragenter","dragexit","draggesture","dragover"]:[];QxEventManager.addProperty({name:"allowClientContextMenu",type:Boolean,defaultValue:false});QxEventManager.addProperty({name:"captureWidget"});proto._attachedClientWindow=null;proto._lastMouseEventType=null;proto._lastMouseDown=false;proto._lastMouseEventDate=0;proto._modifyCaptureWidget=function(_b1,_b2,_b3,_b4){if(_b2){_b2.setCapture(false,_b4);};if(_b1){_b1.setCapture(true,_b4);};return true;};proto.addCommand=function(vCommand){this._commands[vCommand.toHash()]=vCommand;};proto.removeCommand=function(vCommand){delete this._commands[vCommand.toHash()];};proto._checkKeyEventMatch=function(e){var vCommand;for(var vHash in this._commands){vCommand=this._commands[vHash];if(vCommand.getEnabled()&&vCommand._matchesKeyEvent(e)){if(!vCommand.execute()){e.preventDefault();};};};};proto.attachEvents=function(clientWindow){if(this._attachedClientWindow){return false;};this._attachedClientWindow=clientWindow;this.attachEventTypes(QxEventManager.mouseEventTypes,this.__onmouseevent);this.attachEventTypes(QxEventManager.keyEventTypes,this.__onkeyevent);this.attachEventTypes(QxEventManager.dragEventTypes,this.__ondragevent);this.attachWindowEvents();};if((new QxClient).isMshtml()){proto.attachWindowEvents=function(){var winElem=this._attachedClientWindow.getElement();winElem.attachEvent("onblur",this.__onwindowblur);winElem.attachEvent("onfocus",this.__onwindowfocus);winElem.attachEvent("onresize",this.__onwindowresize);};}else {proto.attachWindowEvents=function(){var winElem=this._attachedClientWindow.getElement();winElem.addEventListener("blur",this.__onwindowblur,false);winElem.addEventListener("focus",this.__onwindowfocus,false);winElem.addEventListener("resize",this.__onwindowresize,false);};};proto.detachEvents=function(){if(!this._attachedClientWindow){return false;};this.detachWindowEvents();this.detachEventTypes(QxEventManager.mouseEventTypes,this.__onmouseevent);this.detachEventTypes(QxEventManager.keyEventTypes,this.__onkeyevent);this.detachEventTypes(QxEventManager.dragEventTypes,this.__ondragevent);this._attachedClientWindow=null;};if((new QxClient).isMshtml()){proto.detachWindowEvents=function(){try{var winElem=this._attachedClientWindow.getElement();winElem.detachEvent("onblur",this.__onwindowblur);winElem.detachEvent("onfocus",this.__onwindowfocus);winElem.detachEvent("onresize",this.__onwindowresize);}catch(ex){};};}else {proto.detachWindowEvents=function(){try{var winElem=this._attachedClientWindow.getElement();winElem.removeEventListener("blur",this.__onwindowblur,false);winElem.removeEventListener("focus",this.__onwindowfocus,false);winElem.removeEventListener("resize",this.__onwindowresize,false);}catch(ex){};};};proto.attachEventTypes=function(eventTypes,functionPointer){try{var d=this._attachedClientWindow.getClientDocument().getElement();if(d.attachEvent){for(var i=0;i<eventTypes.length;i++){d.attachEvent("on"+eventTypes[i],functionPointer);};}else if(d.addEventListener){for(var i=0;i<eventTypes.length;i++){d.addEventListener(eventTypes[i],functionPointer,false);};};}catch(ex){};};proto.detachEventTypes=function(eventTypes,functionPointer){try{var d=this._attachedClientWindow.getClientDocument().getElement();if(d.detachEvent){for(var i=0;i<eventTypes.length;i++){d.detachEvent("on"+eventTypes[i],functionPointer);};}else if(d.removeEventListener){for(var i=0;i<eventTypes.length;i++){d.removeEventListener(eventTypes[i],functionPointer,false);};};}catch(ex){};};QxEventManager.getTargetObject=function(n){while(n!=null&&n._QxWidget==null){try{n=n.parentNode;}catch(e){n=null;};};return n?n._QxWidget:null;};QxEventManager.getTargetObjectFromEvent=function(e){return QxEventManager.getTargetObject(e.target||e.srcElement);};QxEventManager.getRelatedTargetObjectFromEvent=function(e){return QxEventManager.getTargetObject(e.relatedTarget||(e.type=="mouseover"?e.fromElement:e.toElement));};QxEventManager.getActiveTargetObject=function(n,o){if(!o){var o=QxEventManager.getTargetObject(n);if(!o){return null;};};while(o){if(!o.getEnabled()){return;};if(!o.getAnonymous()){break;};o=o.getParent();};return o;};QxEventManager.getActiveTargetObjectFromEvent=function(e){return QxEventManager.getActiveTargetObject(e.target||e.srcElement);};QxEventManager.getRelatedActiveTargetObjectFromEvent=function(e){return QxEventManager.getActiveTargetObject(e.relatedTarget||(e.type=="mouseover"?e.fromElement:e.toElement));};proto._onkeyevent=function(e){if(this.getDisposed()||typeof QxKeyEvent!="function"){return;};if(!e){e=this._attachedClientWindow.getElement().event;};var k=e.keyCode||e.charCode;if(k==QxKeyEvent.keys.tab){if((new QxClient).isNotMshtml()){e.preventDefault();};e.returnValue=false;if(typeof QxMenuManager=="function"){(new QxMenuManager).update();};this._attachedClientWindow.getFocusManager()._ontabevent(e);}else {if(k==QxKeyEvent.keys.esc){if(typeof QxMenuManager=="function"){(new QxMenuManager).update();};};var o=this.getCaptureWidget()||(new QxApplication).getActiveWidget();if(o==null||!o.getEnabled()){return;};var s=new QxKeyEvent(e.type,e,false);if(e.type=="keypress"){this._checkKeyEventMatch(s);};var r=o.dispatchEvent(s);if(typeof QxDragAndDropManager=="function"){(new QxDragAndDropManager).handleKeyEvent(s);};s.dispose();return r;};};if((new QxClient).isMshtml()){proto._onmouseevent=function(e){if(!e){e=this._attachedClientWindow.getElement().event;};var t=e.type;if(t=="mousemove"){if(this._mouseIsDown&&e.button==0){this._onmouseevent_post(e,"mouseup");this._mouseIsDown=false;};}else {if(t=="mousedown"){this._mouseIsDown=true;}else if(t=="mouseup"){this._mouseIsDown=false;};if(t=="mouseup"&&!this._lastMouseDown&&((new Date).valueOf()-this._lastMouseEventDate)<250){this._onmouseevent_post(e,"mousedown");}else if(t=="dblclick"&&this._lastMouseEventType=="mouseup"&&((new Date).valueOf()-this._lastMouseEventDate)<250){this._onmouseevent_post(e,"click");};if(t=="mousedown"||t=="mouseup"||t=="click"||t=="dblclick"||t=="contextmenu"){this._lastMouseEventType=t;this._lastMouseEventDate=(new Date).valueOf();this._lastMouseDown=t=="mousedown";};};this._onmouseevent_post(e,t);};}else {proto._onmouseevent=function(e){var t=e.type;switch(t){case "DOMMouseScroll":t="mousewheel";break;case "click":case "dblclick":if(e.button!=QxMouseEvent.buttons.left){return;};};this._onmouseevent_post(e,t);};};proto._onmouseevent_post=function(e,t){var vEventObject,vDispatchTarget,vTarget,vActiveTarget,vRelatedTarget;switch(t){case "contextmenu":if(!this.getAllowClientContextMenu()){if(!(new QxClient).isMshtml()){e.preventDefault();};e.returnValue=false;};break;case "mousedown":this._onactivateevent(e);break;};vDispatchTarget=this.getCaptureWidget();vTarget=QxEventManager.getTargetObjectFromEvent(e);if(!isValidObject(vDispatchTarget)){vDispatchTarget=vActiveTarget=QxEventManager.getActiveTargetObject(null,vTarget);if(!isValidObject(vDispatchTarget)){return;};}else {vActiveTarget=QxEventManager.getActiveTargetObject(null,vTarget);};switch(t){case "mouseover":case "mouseout":vRelatedTarget=QxEventManager.getRelatedActiveTargetObjectFromEvent(e);if(vRelatedTarget==vActiveTarget){return;};};vEventObject=new QxMouseEvent(t,e,false,vTarget,vActiveTarget,vRelatedTarget);QxMouseEvent._storeEventState(vEventObject);if(t=="mousedown"){if(typeof QxPopupManager=="function"){(new QxPopupManager).update(vActiveTarget);};};vDispatchTarget.dispatchEvent(vEventObject);switch(t){case "mousedown":if(!vEventObject.getPropagationStopped()){if(typeof QxMenuManager=="function"){(new QxMenuManager).update();};};break;case "mouseover":if(typeof QxToolTipManager=="function"){(new QxToolTipManager).handleMouseOver(vEventObject);};break;case "mouseout":if(typeof QxToolTipManager=="function"){(new QxToolTipManager).handleMouseOut(vEventObject);};break;};if(typeof QxDragAndDropManager=="function"){(new QxDragAndDropManager).handleMouseEvent(vEventObject);};vEventObject.dispose();vEventObject=null;};proto._ondragevent=function(e){e.preventDefault();e.returnValue=false;e.preventBubble();};proto._onwindowblur=function(e){if(this._ignoreBlur){delete this._ignoreBlur;return;};this._allowFocus=true;if(typeof QxPopupManager=="function"){(new QxPopupManager).update();};if(typeof QxMenuManager=="function"){(new QxMenuManager).update();};if(typeof QxDragAndDropManager=="function"){(new QxDragAndDropManager).globalCancelDrag();};var vDoc=this._attachedClientWindow.getDocument();if(vDoc.hasEventListeners("blur")){vDoc.dispatchEvent(new QxEvent("blur"),true);};};proto._onwindowfocus=function(e){if(!this._allowFocus){return;};delete this._allowFocus;var vDoc=this._attachedClientWindow.getDocument();if(vDoc.hasEventListeners("focus")){vDoc.dispatchEvent(new QxEvent("focus"),true);};};proto._onwindowresize=function(e){this._attachedClientWindow.getDocument().dispatchEvent(new QxEvent("resize"),true);};proto._onactivateevent=function(e){var n=e.target||e.srcElement;while(n!=null&&n._QxWidget==null){n=n.parentNode;};if(n==null){return;};var o=n._QxWidget;var oactive=o;if(o){while(o!=null&&!o.canGetFocus()){o=o.getParent();};if(o){o.setFocused(true);};if(oactive!=o){(new QxApplication).setActiveWidget(oactive);};};this._ignoreBlur=true;};proto.dispose=function(){if(this.getDisposed()){return;};this.detachEvents();this._attachedClientWindow=null;this._lastMouseEventType=null;this._lastMouseDown=null;this._lastMouseEventDate=null;if(this._commands){for(var vHash in this._commands){this._commands[vHash].dispose();delete this._commands[vHash];};this._commands=null;};QxObject.prototype.dispose.call(this);};