//>>built define("dojo/_base/kernel dojo/_base/declare dojo/_base/connect dojo/_base/array dojo/_base/lang dojo/_base/html dojo/_base/json dojo/_base/window dojo/query dojo/keys dojo/dnd/Source dojo/dnd/Avatar ../_Plugin ../../EnhancedGrid dojo/dnd/Manager ./Selector ./Rearrange".split(" "),function(y,x,B,k,r,f,C,p,z,A,D,E,F,G,H){var I=function(a){a.sort(function(a,b){return a-b});for(var c=[[a[0]]],b=1,e=0;bc.y+c.h||bc.x+c.w},_onMouseMove:function(a){if(!this._dndRegion||this._dnding||this._externalDnd){this._isMouseDown&& !this._dndRegion&&(delete this._isMouseDown,this._oldCursor=f.style(p.body(),"cursor"),f.style(p.body(),"cursor","not-allowed"));var c=this._isOutOfGrid(a);!this._alreadyOut&&c?(this._alreadyOut=!0,this._dnding&&this._destroyDnDUI(!0,!1),this._moveEvent=a,this._source.onOutEvent()):this._alreadyOut&&!c&&(this._alreadyOut=!1,this._dnding&&this._createDnDUI(a,!0),this._moveEvent=a,this._source.onOverEvent())}else this._dnding=!0,this._startDnd(a)},_onMouseUp:function(){if(!this._extDnding&&!this._isSource){var a= this._dnding&&!this._alreadyOut;a&&this._config[this._dndRegion.type].within&&this._rearrange();this._endDnd(a)}f.style(p.body(),"cursor",this._oldCursor||"");delete this._isMouseDown},_initEvents:function(){var a=this.grid,c=this.selector;this.connect(p.doc,"onmousemove","_onMouseMove");this.connect(p.doc,"onmouseup","_onMouseUp");this.connect(a,"onCellMouseOver",function(a){this._dnding||c.isSelecting()||a.ctrlKey||(this._dndReady=c.isSelected("cell",a.rowIndex,a.cell.index),c.selectEnabled(!this._dndReady))}); this.connect(a,"onHeaderCellMouseOver",function(a){this._dndReady&&c.selectEnabled(!0)});this.connect(a,"onRowMouseOver",function(a){this._dndReady&&!a.cell&&c.selectEnabled(!0)});this.connect(a,"onCellMouseDown",function(a){!a.ctrlKey&&this._dndReady&&(this._dndRegion=this._getDnDRegion(a.rowIndex,a.cell.index),this._isMouseDown=!0)});this.connect(a,"onCellMouseUp",function(a){this._dndReady||c.isSelecting()||!a.cell||(this._dndReady=c.isSelected("cell",a.rowIndex,a.cell.index),c.selectEnabled(!this._dndReady))}); this.connect(a,"onCellClick",function(a){!this._dndReady||a.ctrlKey||a.shiftKey||c.select("cell",a.rowIndex,a.cell.index)});this.connect(a,"onEndAutoScroll",function(a,c,d,f,g){this._dnding&&this._markTargetAnchor(g)});this.connect(p.doc,"onkeydown",function(a){a.keyCode==A.ESCAPE?this._endDnd(!1):a.keyCode==A.CTRL&&(c.selectEnabled(!0),this._isCopy=!0)});this.connect(p.doc,"onkeyup",function(a){a.keyCode==A.CTRL&&(c.selectEnabled(!this._dndReady),this._isCopy=!1)})},_clear:function(){this._moveEvent= this._target=this._dndRegion=null;this._targetAnchor={};this._extDnding=this._alreadyOut=this._isSource=this._externalDnd=this._dnding=!1},_getDnDRegion:function(a,c){var b=this.selector,e=b._selected,d=!!e.cell.length|!!e.row.length<<1|!!e.col.length<<2,f;switch(d){case 1:f="cell";if(!this._config[f].within&&!this._config[f].out)break;var g=this.grid.layout.cells,d=function(a){for(var b=0,c=a.min.col;c<=a.max.col;++c)g[c].hidden&&++b;return(a.max.row-a.min.row+1)*(a.max.col-a.min.col+1-b)},h={max:{row:-1, col:-1},min:{row:Infinity,col:Infinity}};k.forEach(e[f],function(a){a.rowh.max.row&&(h.max.row=a.row);a.colh.max.col&&(h.max.col=a.col)});if(k.some(e[f],function(b){return b.row==a&&b.col==c})&&d(h)==e[f].length&&k.every(e[f],function(a){return a.row>=h.min.row&&a.row<=h.max.row&&a.col>=h.min.col&&a.col<=h.max.col}))return{type:f,selected:[h],handle:{row:a,col:c}};break;case 2:case 4:if(f=2==d?"row":"col",this._config[f].within|| this._config[f].out)if(e=b.getSelected(f),e.length)return{type:f,selected:I(e),handle:2==d?a:c}}return null},_startDnd:function(a){this._createDnDUI(a)},_endDnd:function(a){this._destroyDnDUI(!1,a);this._clear()},_createDnDUI:function(a,c){var b=f.position(this.grid.views.views[0].domNode);f.style(this._container,"height",b.h+"px");try{c||this._createSource(a),this._createMoveable(a),this._oldCursor=f.style(p.body(),"cursor"),f.style(p.body(),"cursor","default")}catch(e){console.warn("DnD._createDnDUI() error:", e)}},_destroyDnDUI:function(a,c){try{c&&this._destroySource(),this._unmarkTargetAnchor(),a||this._destroyMoveable(),f.style(p.body(),"cursor",this._oldCursor)}catch(b){console.warn("DnD._destroyDnDUI() error:",this.grid.id,b)}},_createSource:function(a){this._elem.createDnDNodes(this._dndRegion);var c=H.manager(),b=c.makeAvatar;c._dndPlugin=this;c.makeAvatar=function(){var a=new L(c);delete c._dndPlugin;return a};c.startDrag(this._source,this._elem.getDnDNodes(),a.ctrlKey);c.makeAvatar=b;c.onMouseMove(a)}, _destroySource:function(){B.publish("/dnd/cancel")},_createMoveable:function(a){this._markTagetAnchorHandler||(this._markTagetAnchorHandler=this.connect(p.doc,"onmousemove","_markTargetAnchor"))},_destroyMoveable:function(){this.disconnect(this._markTagetAnchorHandler);delete this._markTagetAnchorHandler},_calcColTargetAnchorPos:function(a,c){var b,e,d;d=a.clientX;var l=this.grid.layout.cells,g=f._isBodyLtr(),h=this._getVisibleHeaders();for(a=0;a=b.x)&&d=b.x){e=b.x+(g?0:b.w);break}else if(g?a===h.length-1&&d>=b.x+b.w:a===h.length-1&&d=b.rowCount);)g=f.position(l.getNode(d));if(d=k.x&&a.clientX=k.x+k.w)||n==p.length-q-1&&(g?a.clientX>=k.x+k.w:a=d.row-e.min.row?m-d.row+e.min.row:0;a=d+e.max.row-e.min.row;a>=l.rowCount&&(a=l.rowCount-1,d=a-e.max.row+e.min.row);m=f.position(g.getNode(d));q=f.position(g.getNode(a));e=m.y;l=q.y+q.h-m.y;this._target={min:{row:d,col:t},max:{row:a,col:v}};g=(f.marginBox(w).w-f.contentBox(w).w)/2;t=f.position(h[t].getNode(d));f.style(w,{width:t.w-g+"px",height:t.h-g+"px"});h=f.position(h[v].getNode(a));f.style(b,{width:h.w-g+"px",height:h.h-g+"px"});return{h:l,w:r,l:u-c.x,t:e-c.y}},_markTargetAnchor:function(a){try{var c= this._dndRegion.type;if(!(this._alreadyOut||this._dnding&&!this._config[c].within||this._extDnding&&!this._config[c]["in"])){var b,e,d,l,g=this._targetAnchor[c],h=f.position(this._container);g||(g=this._targetAnchor[c]=f.create("div",{"class":"cell"==c?"dojoxGridCellBorderDIV":"dojoxGridBorderDIV"}),f.style(g,"display","none"),this._container.appendChild(g));switch(c){case "col":b=h.h;e=this._targetAnchorBorderWidth;d=this._calcColTargetAnchorPos(a,h);l=0;break;case "row":b=this._targetAnchorBorderWidth; e=h.w;d=0;l=this._calcRowTargetAnchorPos(a,h);break;case "cell":var k=this._calcCellTargetAnchorPos(a,h,g);b=k.h;e=k.w;d=k.l;l=k.t}"number"==typeof b&&"number"==typeof e&&"number"==typeof d&&"number"==typeof l?(f.style(g,{height:b+"px",width:e+"px",left:d+"px",top:l+"px"}),f.style(g,"display","")):this._target=null}}catch(m){console.warn("DnD._markTargetAnchor() error:",m)}},_unmarkTargetAnchor:function(){this._dndRegion&&this._targetAnchor[this._dndRegion.type]&&f.style(this._targetAnchor[this._dndRegion.type], "display","none")},_getVisibleHeaders:function(){return k.map(k.filter(this.grid.layout.cells,function(a){return!a.hidden}),function(a){return{node:a.getHeaderNode(),cell:a}})},_rearrange:function(){if(null!==this._target){var a=this._dndRegion.type,c=this._dndRegion.selected;if("cell"===a)this.rearranger[this._isCopy||this._copyOnly?"copyCells":"moveCells"](c[0],-1===this._target?null:this._target);else this.rearranger["col"==a?"moveColumns":"moveRows"](u(c),-1===this._target?null:this._target); this._target=null}},onDraggingOver:function(a){!this._dnding&&a&&(this._extDnding=a._isSource=!0,this._externalDnd||(this._externalDnd=!0,this._dndRegion=this._mapRegion(a.grid,a._dndRegion)),this._createDnDUI(this._moveEvent,!0),this.grid.pluginMgr.getPlugin("autoScroll").readyForAutoScroll=!0)},_mapRegion:function(a,c){if("cell"===c.type){var b=c.selected[0],e=this.grid.layout.cells;a=a.layout.cells;var d,f=0;for(d=b.min.col;d<=b.max.col;++d)a[d].hidden||++f;for(d=0;0=d.min.col&&a.index<=d.max.col&&!a.hidden}).length<=c;case "row":if(a._allDnDItemsLoaded())return g}return!1},_allDnDItemsLoaded:function(){if(this._dndRegion){var a=this._dndRegion.selected,c=[];switch(this._dndRegion.type){case "cell":for(var b=a[0].min.row,a=a[0].max.row;b<=a;++b)c.push(b);break;case "row":c=u(a);break;default:return!1}var e= this.grid._by_idx;return k.every(c,function(a){return!!e[a]})}return!1}});G.registerPlugin(y,{dependency:["selector","rearrange"]});return y});