//>>built
define("dojox/drawing/manager/Mouse",["dojo","../util/oo","../defaults"],function(e,p,l){return p.declare(function(a){this.util=a.util;this.keys=a.keys;this.id=a.id||this.util.uid("mouse");this.currentNodeId="";this.registered={}},{doublClickSpeed:400,_lastx:0,_lasty:0,__reg:0,_downOnCanvas:!1,init:function(a){this.container=a;this.setCanvas();var b,d=!1;e.connect(this.container,"rightclick",this,function(c){});e.connect(document.body,"mousedown",this,function(c){});e.connect(this.container,"mousedown",
this,function(c){this.down(c);c.button!=e.mouseButtons.RIGHT&&(d=!0,b=e.connect(document,"mousemove",this,"drag"))});e.connect(document,"mouseup",this,function(c){e.disconnect(b);d=!1;this.up(c)});e.connect(document,"mousemove",this,function(c){d||this.move(c)});e.connect(this.keys,"onEsc",this,function(c){this._dragged=!1})},setCanvas:function(){var a=e.position(this.container.parentNode);this.origin=e.clone(a)},scrollOffset:function(){return{top:this.container.parentNode.scrollTop,left:this.container.parentNode.scrollLeft}},
resize:function(a,b){this.origin&&(this.origin.w=a,this.origin.h=b)},register:function(a){var b=a.id||"reg_"+this.__reg++;this.registered[b]||(this.registered[b]=a);return b},unregister:function(a){this.registered[a]&&delete this.registered[a]},_broadcastEvent:function(a,b){for(var d in this.registered)if(this.registered[d][a])this.registered[d][a](b)},onDown:function(a){this._broadcastEvent(this.eventName("down"),a)},onDrag:function(a){var b=this.eventName("drag");this._selected&&"onDrag"==b&&(b=
"onStencilDrag");this._broadcastEvent(b,a)},onMove:function(a){this._broadcastEvent("onMove",a)},overName:function(a,b){var d=a.id.split(".");b=b.charAt(0).toUpperCase()+b.substring(1);return"dojox"!=d[0]||!l.clickable&&l.clickMode?"on"+b:"onStencil"+b},onOver:function(a){this._broadcastEvent(this.overName(a,"over"),a)},onOut:function(a){this._broadcastEvent(this.overName(a,"out"),a)},onUp:function(a){var b=this.eventName("up");"onStencilUp"==b?this._selected=!0:this._selected&&"onUp"==b&&(b="onStencilUp",
this._selected=!1);this._broadcastEvent(b,a);"silverlight"!=dojox.gfx.renderer&&(this._clickTime=(new Date).getTime(),this._lastClickTime&&this._clickTime-this._lastClickTime<this.doublClickSpeed&&(b=this.eventName("doubleClick"),this._broadcastEvent(b,a)),this._lastClickTime=this._clickTime)},zoom:1,setZoom:function(a){this.zoom=1/a},setEventMode:function(a){this.mode=a?"on"+a.charAt(0).toUpperCase()+a.substring(1):""},eventName:function(a){a=a.charAt(0).toUpperCase()+a.substring(1);if(this.mode)return"onPathEdit"==
this.mode?"on"+a:this.mode+a;if(!l.clickable&&l.clickMode)return"on"+a;var b=this.drawingType&&"surface"!=this.drawingType&&"canvas"!=this.drawingType?this.drawingType:"";return"on"+(b?b.charAt(0).toUpperCase()+b.substring(1):"")+a},up:function(a){this.onUp(this.create(a))},down:function(a){this._downOnCanvas=!0;var b=this.scrollOffset(),d=this._getXY(a);this._lastpagex=d.x;this._lastpagey=d.y;var c=this.origin,f=d.x-c.x+b.left;b=d.y-c.y+b.top;var m=0<=f&&0<=b&&f<=c.w&&b<=c.h;f*=this.zoom;b*=this.zoom;
c.startx=f;c.starty=b;this._lastx=f;this._lasty=b;this.drawingType=this.util.attr(a,"drawingType")||"";c=this._getId(a);if(a.button!=e.mouseButtons.RIGHT||"mse"!=this.id)a.preventDefault(),e.stopEvent(a);this.onDown({mid:this.id,x:f,y:b,pageX:d.x,pageY:d.y,withinCanvas:m,id:c})},over:function(a){this.onOver(a)},out:function(a){this.onOut(a)},move:function(a){a=this.create(a);if(a.id!=this.currentNodeId){var b={},d;for(d in a)b[d]=a[d];(b.id=this.currentNodeId)&&this.out(b);a.id&&this.over(a);this.currentNodeId=
a.id}this.onMove(a)},drag:function(a){this.onDrag(this.create(a,!0))},create:function(a,b){var d=this.scrollOffset(),c=this._getXY(a),f=c.x,m=c.y,g=this.origin,h=c.x-g.x+d.left,k=c.y-g.y+d.top,n=0<=h&&0<=k&&h<=g.w&&k<=g.h;h*=this.zoom;k*=this.zoom;var q=n?this._getId(a,b):"";d={mid:this.id,x:h,y:k,pageX:c.x,pageY:c.y,page:{x:c.x,y:c.y},orgX:g.x,orgY:g.y,last:{x:this._lastx,y:this._lasty},start:{x:this.origin.startx,y:this.origin.starty},move:{x:f-this._lastpagex,y:m-this._lastpagey},scroll:d,id:q,
withinCanvas:n};this._lastx=h;this._lasty=k;this._lastpagex=f;this._lastpagey=m;e.stopEvent(a);return d},_getId:function(a,b){return this.util.attr(a,"id",null,b)},_getXY:function(a){return{x:a.pageX,y:a.pageY}},setCursor:function(a,b){b?e.style(b,"cursor",a):e.style(this.container,"cursor",a)}})});