//>>built
define("dojox/drawing/plugins/tools/Pan",["dojo/_base/lang","../../util/oo","../_Plugin","../../manager/_registry"],function(l,d,u,v){d=d.declare(u,function(a){this.domNode=a.node;var b;this.toolbar=a.scope;this.connect(this.toolbar,"onToolClick",this,function(){this.onSetPan(!1)});this.connect(this.keys,"onKeyUp",this,"onKeyUp");this.connect(this.keys,"onKeyDown",this,"onKeyDown");this.connect(this.keys,"onArrow",this,"onArrow");this.connect(this.anchors,"onAnchorUp",this,"checkBounds");this.connect(this.stencils,
"register",this,"checkBounds");this.connect(this.canvas,"resize",this,"checkBounds");this.connect(this.canvas,"setZoom",this,"checkBounds");this.connect(this.canvas,"onScroll",this,function(){this._blockScroll?this._blockScroll=!1:(b&&clearTimeout(b),b=setTimeout(l.hitch(this,"checkBounds"),200))});this._mouseHandle=this.mouse.register(this)},{selected:!1,keyScroll:!1,type:"dojox.drawing.plugins.tools.Pan",onPanUp:function(a){if(a.id==this.button.id)this.onSetPan(!1)},onKeyUp:function(a){switch(a.keyCode){case 32:this.onSetPan(!1);
break;case 39:case 37:case 38:case 40:clearInterval(this._timer)}},onKeyDown:function(a){if(32==a.keyCode)this.onSetPan(!0)},interval:20,onArrow:function(a){this._timer&&clearInterval(this._timer);this._timer=setInterval(l.hitch(this,function(b){this.canvas.domNode.parentNode.scrollLeft+=10*b.x;this.canvas.domNode.parentNode.scrollTop+=10*b.y},a),this.interval)},onSetPan:function(a){if(!0===a||!1===a)this.selected=!a;this.selected?(this.selected=!1,this.button.deselect()):(this.selected=!0,this.button.select());
this.mouse.setEventMode(this.selected?"pan":"")},onPanDrag:function(a){this.canvas.domNode.parentNode.scrollTop-=a.move.y;this.canvas.domNode.parentNode.scrollLeft-=a.move.x;this.canvas.onScroll()},onUp:function(a){this.keyScroll=a.withinCanvas?!0:!1},onStencilUp:function(a){this.checkBounds()},onStencilDrag:function(a){},checkBounds:function(){var a=-Infinity,b=-1E4,m=0,n=0,p=this.stencils.group?this.stencils.group.getTransform():{dx:0,dy:0},e=this.mouse.scrollOffset(),f=this.canvas.height,g=this.canvas.width,
q=this.canvas.zoom,h=this.canvas.parentHeight,k=this.canvas.parentWidth;this.stencils.withSelected(function(c){c=c.getBounds();a=Math.max(c.x2+p.dx,a);b=Math.max(c.y2+p.dy,b)});this.stencils.withUnselected(function(c){c=c.getBounds();a=Math.max(c.x2,a);b=Math.max(c.y2,b)});b*=q;var r=0,t=0;b>h||e.top?(f=Math.max(b,h+e.top),n=e.top,r+=this.canvas.getScrollWidth()):!n&&f>h&&(f=h);a*=q;a>k||e.left?(g=Math.max(a,k+e.left),m=e.left,t+=this.canvas.getScrollWidth()):!m&&g>k&&(g=k);g+=2*r;f+=2*t;this._blockScroll=
!0;this.stencils.group&&this.stencils.group.applyTransform({dx:0,dy:0});this.stencils.withUnselected(function(c){c.transformPoints({dx:0,dy:0})});this.canvas.setDimensions(g,f,m,n)}});d.setup={name:"dojox.drawing.plugins.tools.Pan",tooltip:"Pan Tool",iconClass:"iconPan",button:!1};l.setObject("dojox.drawing.plugins.tools.Pan",d);v.register(d.setup,"plugin");return d});