rename swat => swat2, so that we don't conflict with samba3
[gd/samba/.git] / swat2 / style / qooxdoo / widgets / managers / QxDragAndDropManager.js
diff --git a/swat2/style/qooxdoo/widgets/managers/QxDragAndDropManager.js b/swat2/style/qooxdoo/widgets/managers/QxDragAndDropManager.js
new file mode 100644 (file)
index 0000000..d1b98ec
--- /dev/null
@@ -0,0 +1,3 @@
+/* Copyright (c): 2002-2005 (Germany): United Internet, 1&1, GMX, Schlund+Partner, Alturo */
+function QxDragAndDropManager(){if(QxDragAndDropManager._instance){return QxDragAndDropManager._instance;};QxTarget.call(this);this._k1={};this._k2={};this._k3={};var d=window.application.getClientWindow().getClientDocument();var a=["move","copy","alias","nodrop"];var c;for(var i=0;i<a.length;i++){c = this._k3[a[i]] = new QxImage("widgets/cursors/" + a[i] + ".gif");c.setTimerCreate(false);c.setStyleProperty("top","-1000px");c.setZIndex(10000);c.setParent(d);};QxDragAndDropManager._instance=this;};QxDragAndDropManager.extend(QxManager,"QxDragAndDropManager");QxDragAndDropManager.addProperty({name:"sourceWidget",type:Object});QxDragAndDropManager.addProperty({name:"destinationWidget",type:Object});QxDragAndDropManager.addProperty({name:"cursor",type:Object});QxDragAndDropManager.addProperty({name:"currentAction",type:String});proto._k5=null;proto._modifyDestinationWidget=function(_b1,_b2,_b3,_b4){if(_b1){_b1.dispatchEvent(new QxDragEvent("dragdrop",this._k5));this._k5=null;};return true;};proto.addData=function(vMimeType,vData){this._k1[vMimeType]=vData;};proto.getData=function(vMimeType){return this._k1[vMimeType];};proto.clearData=function(){this._k1={};};proto.getDropDataTypes=function(){var dw=this.getDestinationWidget();var st=[];if(!dw){return st;};var ddt=dw.getDropDataTypes();var ddtl=ddt.length;for(var i=0;i<ddtl;i++){if(ddt[i]in this._k1){st.push(ddt[i]);};};return st;};proto.startDrag=function(){if(!this._k6){throw new Error("Invalid usage of startDrag. Missing dragInfo!");};this._k6.dragHandlerActive=true;this.setSourceWidget(this._k6.sourceWidget);};proto._fireUserEvents=function(fromWidget,toWidget,e){if(fromWidget&&fromWidget!=toWidget){var outEvent=new QxDragEvent("dragout",e);outEvent._relatedTarget=toWidget;fromWidget.dispatchEvent(outEvent,true);outEvent=null;};if(toWidget){if(fromWidget!=toWidget){var overEvent=new QxDragEvent("dragover",e);overEvent._relatedTarget=fromWidget;toWidget.dispatchEvent(overEvent,true);overEvent=null;};var moveEvent=new QxDragEvent("dragmove",e);toWidget.dispatchEvent(moveEvent,true);moveEvent=null;};};proto.handleMouseEvent=function(e){switch(e.getType()){case "mousedown":return this._handleMouseDown(e);case "mouseup":return this._handleMouseUp(e);case "mousemove":return this._handleMouseMove(e);};};proto._handleMouseDown=function(e){if(e.getDefaultPrevented()){return;};this._k6={startScreenX:e.getScreenX(),startScreenY:e.getScreenY(),pageX:e.getPageX(),pageY:e.getPageY(),sourceWidget:e.getTarget(),dragHandlerActive:false,hasFiredDragStart:false
+};this._k6.sourceTopLevel=this._k6.sourceWidget.getTopLevelWidget();};proto._handleMouseMove=function(e){if(!this._k6){return;};if(this._k6.dragHandlerActive){this._k6.pageX=e.getPageX();this._k6.pageY=e.getPageY();var currentDropTarget=this.getDropTarget(e);this.setCurrentAction(currentDropTarget?this._evalNewAction(e.getShiftKey(),e.getCtrlKey(),e.getAltKey()):null);this._fireUserEvents(this._k6.currentDropWidget,currentDropTarget,e);this._k6.currentDropWidget=currentDropTarget;this._renderCursor();}else if(!this._k6.hasFiredDragStart){if(Math.abs(e.getScreenX()-this._k6.startScreenX)>5||Math.abs(e.getScreenY()-this._k6.startScreenY)>5){this._k6.sourceWidget.dispatchEvent(new QxDragEvent("dragstart",e));this._k6.hasFiredDragStart=true;if(this._k6.dragHandlerActive){this._fireUserEvents(this._k6.currentDropWidget,this._k6.sourceWidget,e);this._k6.currentDropWidget=this._k6.sourceWidget;var clientDocument=window.application.getClientWindow().getClientDocument();clientDocument.setCapture(true);clientDocument.addEventListener("losecapture",this.cancelDrag,this);};};};};proto._handleMouseUp=function(e){if(!this._k6){return;};if(this._k6.dragHandlerActive){this._endDrag(this.getDropTarget(e),e);}else {this._k6=null;};};proto.handleKeyEvent=function(e){if(!this._k6){return;};switch(e.getType()){case "keydown":this._handleKeyDown(e);return;case "keyup":this._handleKeyUp(e);return;};};proto._handleKeyDown=function(e){if(e.getKeyCode()==QxKeyEvent.keys.esc){this.cancelDrag();}else if(this.getCurrentAction()!=null){switch(e.getKeyCode()){case QxKeyEvent.keys.shift:case QxKeyEvent.keys.ctrl:case QxKeyEvent.keys.alt:this.setAction(this._evalNewAction(e.getShiftKey(),e.getCtrlKey(),e.getAltKey()));this._renderCursor();};};};proto._handleKeyUp=function(e){var bShiftPressed=e.getKeyCode()==QxKeyEvent.keys.shift;var bCtrlPressed=e.getKeyCode()==QxKeyEvent.keys.strl;var bAltPressed=e.getKeyCode()==QxKeyEvent.keys.alt;if(bShiftPressed||bCtrlPressed||bAltPressed){if(this.getCurrentAction()!=null){this.setAction(this._evalNewAction(!bShiftPressed&&e.getShiftKey(),! bCtrlPressed&&e.getCtrlKey(),!bAltPressed&&e.getAltKey()));this._renderCursor();};};e.preventDefault();};proto.cancelDrag=function(e){this._endDrag(null,e);};proto.globalCancelDrag=function(){if(this._k6&&this._k6.dragHandlerActive){this._endDragCore();};};proto._endDrag=function(currentDestinationWidget,e){if(currentDestinationWidget){this._k5=e;this.setDestinationWidget(currentDestinationWidget);};this.getSourceWidget().dispatchEvent(new QxDragEvent("dragend",e));this._fireUserEvents(this._k6&&this._k6.currentDropWidget,null,e);this._endDragCore();};proto._endDragCore=function(){this.setCursor(null);var d=window.application.getClientWindow().getClientDocument();d.removeEventListener("losecapture",this.cancelDrag,this);d.setCapture(false);if(this._k6){this._k6.currentDropWidget=null;this._k6=null;};this.clearData();this.clearActions();this.setSourceWidget(null);this.setDestinationWidget(null);};proto._renderCursor=function(){var newCursor;switch(this.getCurrentAction()){case "move":newCursor=this._k3.move;break;case "copy":newCursor=this._k3.copy;break;case "alias":newCursor=this._k3.alias;break;default:newCursor=this._k3.nodrop;};newCursor._d3Horizontal(this._k6.pageX+5);newCursor._d3Vertical(this._k6.pageY+15);this.setCursor(newCursor);};proto._modifyCursor=function(_b1,_b2,_b3,_b4){if(_b2){_b2.setStyleProperty("display","none");};if(_b1){_b1.removeStyleProperty("display");};return true;};proto.supportsDrop=function(vWidget){var types=vWidget.getDropDataTypes();if(!types){return false;};for(var i=0;i<types.length;i++){if(types[i]in this._k1){return true;};};return false;};if((new QxClient).isGecko()){proto.getDropTarget=function(e){var currentWidget=e.getTarget();if(currentWidget==this._k6.sourceWidget){currentWidget=this._k6.sourceTopLevel.getWidgetFromPoint(e.getPageX(),e.getPageY());}else {currentWidget=QxEventManager.getActiveTargetObject(null,currentWidget);};while(currentWidget!=null){if(this.supportsDrop(currentWidget)){return currentWidget;};currentWidget=currentWidget.getParent();};return null;};}else {proto.getDropTarget=function(e){var currentWidget=e.getActiveTarget();while(currentWidget!=null){if(this.supportsDrop(currentWidget)){return currentWidget;};currentWidget=currentWidget.getParent();};return null;};};proto.addAction=function(vAction,vForce){this._k2[vAction]=true;if(vForce||this.getCurrentAction()==null){this.setCurrentAction(vAction);};};proto.clearActions=function(){this._k2={};this.setCurrentAction(null);};proto.removeAction=function(sAction){delete this._k2[sAction];if(this.getCurrentAction()==sAction){this.setCurrentAction(null);};};proto.setAction=function(s){if(s!=null&&!(s in this._k2)){this.addAction(s,true);}else {this.setCurrentAction(s);};};proto._evalNewAction=function(kShift,kCtrl,kAlt){if(kShift&&kCtrl&&this._k4("alias")){return "alias";}else if(kShift&&kAlt&&this._k4("copy")){return "copy";}else if(kShift&&this._k4("move")){return "move";}else if(kAlt&&this._k4("alias")){return "alias";}else if(kCtrl&&this._k4("copy")){return "copy";}else {for(var action in this._k2){return action;};};return null;};proto._k4=function(vAction){return vAction in this._k2;};proto.dispose=function(){if(this.getDisposed()){return;};this._k1=null;this._k2=null;this.setSourceWidget(null);this.setDestinationWidget(null);this._lastdestinationWidgetEvent=null;this._k6=null;if(QxDragAndDropManager._k3){if(QxDragAndDropManager._k3.move){QxDragAndDropManager._k3.move.dispose();QxDragAndDropManager._k3.move=null;};if(QxDragAndDropManager._k3.copy){QxDragAndDropManager._k3.copy.dispose();QxDragAndDropManager._k3.copy=null;};if(QxDragAndDropManager._k3.alias){QxDragAndDropManager._k3.alias.dispose();QxDragAndDropManager._k3.alias=null;};if(QxDragAndDropManager._k3.nodrop){QxDragAndDropManager._k3.nodrop.dispose();QxDragAndDropManager._k3.nodrop=null;};QxDragAndDropManager._k3=null;};QxManager.prototype.dispose.call(this);};
\ No newline at end of file