//>>built
define("dojox/drawing/Drawing","dojo ./defaults ./manager/_registry ./manager/keys ./manager/Mouse ./manager/Canvas ./manager/Undo ./manager/Anchors ./manager/Stencil ./manager/StencilUI ./util/common".split(" "),function(d,l,k,g,m,n,p,q,r,t,f){return d.declare("dojox.drawing.Drawing",[],{ready:!1,mode:"",width:0,height:0,constructor:function(a,b){var c=d.attr(b,"defaults");this.defaults=c?"string"===typeof c?d.getObject(c):c:l;this.id=b.id||dijit.getUniqueId("dojox_drawing_Drawing");k.register(this,
"drawing");this.mode=(a.mode||d.attr(b,"mode")||"").toLowerCase();c=d.contentBox(b);this.width=a.width||c.w;this.height=a.height||c.h;f.register(this);this.mouse=new m({util:f,keys:g,id:"ui"==this.mode?"MUI":"mse"});this.mouse.setEventMode(this.mode);this.tools={};this.stencilTypes={};this.stencilTypeMap={};this.domNode=this.srcRefNode=b;this.plugins=a.plugins?eval(a.plugins):[];this.widgetId=this.id;d.attr(this.domNode,"widgetId",this.widgetId);dijit&&dijit.registry||(dijit.registry={objs:{},add:function(h){this.objs[h.id]=
h}},dijit.byId=function(h){return dijit.registry.objs[h]});dijit.registry.add(this);c=k.getRegistered("stencil");for(var e in c)this.registerTool(c[e].name);c=k.getRegistered("tool");for(e in c)this.registerTool(c[e].name);c=k.getRegistered("plugin");for(e in c)this.registerTool(c[e].name);this._createCanvas()},_createCanvas:function(){this.canvas=new n({srcRefNode:this.domNode,util:f,mouse:this.mouse,width:this.width,height:this.height,callback:d.hitch(this,"onSurfaceReady")});this.initPlugins()},
resize:function(a){a&&d.style(this.domNode,{width:a.w+"px",height:a.h+"px"});this.canvas?a&&this.canvas.resize(a.w,a.h):this._createCanvas()},startup:function(){},getShapeProps:function(a,b){var c=a.stencilType,e="ui"==this.mode||"ui"==b;return d.mixin({container:e&&!c?this.canvas.overlay.createGroup():this.canvas.surface.createGroup(),util:f,keys:g,mouse:this.mouse,drawing:this,drawingType:e&&!c?"ui":"stencil",style:this.defaults.copy()},a||{})},addPlugin:function(a){this.plugins.push(a);this.canvas.surfaceReady&&
this.initPlugins()},initPlugins:function(){if(this.canvas&&this.canvas.surfaceReady)d.forEach(this.plugins,function(b,c){var e=d.mixin({util:f,keys:g,mouse:this.mouse,drawing:this,stencils:this.stencils,anchors:this.anchors,canvas:this.canvas},b.options||{});this.registerTool(b.name,d.getObject(b.name));try{this.plugins[c]=new this.tools[b.name](e)}catch(h){}},this),this.plugins=[],this.mouse.setCanvas();else var a=d.connect(this,"onSurfaceReady",this,function(){d.disconnect(a);this.initPlugins()})},
onSurfaceReady:function(){this.ready=!0;this.mouse.init(this.canvas.domNode);this.undo=new p({keys:g});this.anchors=new q({drawing:this,mouse:this.mouse,undo:this.undo,util:f});"ui"!=this.mode&&(this.stencils=new r({canvas:this.canvas,surface:this.canvas.surface,mouse:this.mouse,undo:this.undo,keys:g,anchors:this.anchors}));this.uiStencils=new t({canvas:this.canvas,surface:this.canvas.surface,mouse:this.mouse,keys:g});if("silverlight"==dojox.gfx.renderer)try{new dojox.drawing.plugins.drawing.Silverlight({util:f,
mouse:this.mouse,stencils:this.stencils,anchors:this.anchors,canvas:this.canvas})}catch(a){throw Error("Attempted to install the Silverlight plugin, but it was not found.");}d.forEach(this.plugins,function(a){a.onSurfaceReady&&a.onSurfaceReady()})},addUI:function(a,b){if(!this.ready){var c=d.connect(this,"onSurfaceReady",this,function(){d.disconnect(c);this.addUI(a,b)});return!1}!b||b.data||b.points||(b={data:b});return this.stencilTypes[a]?this.uiStencils.register(new this.stencilTypes[a](this.getShapeProps(b,
"ui"))):null},addStencil:function(a,b){if(!this.ready){var c=d.connect(this,"onSurfaceReady",this,function(){d.disconnect(c);this.addStencil(a,b)});return!1}!b||b.data||b.points||(b={data:b});var e=this.stencils.register(new this.stencilTypes[a](this.getShapeProps(b)));this.currentStencil&&this.currentStencil.moveToFront();return e},removeStencil:function(a){this.stencils.unregister(a);a.destroy()},removeAll:function(){this.stencils.removeAll()},selectAll:function(){this.stencils.selectAll()},toSelected:function(a){this.stencils.toSelected.apply(this.stencils,
arguments)},exporter:function(){return this.stencils.exporter()},importer:function(a){d.forEach(a,function(b){this.addStencil(b.type,b)},this)},changeDefaults:function(a,b){if(void 0!=b&&b)for(var c in a)this.defaults[c]=a[c];else for(c in a)for(var e in a[c])this.defaults[c][e]=a[c][e];void 0==this.currentStencil||this.currentStencil.created&&!this.defaults.clickMode||(this.unSetTool(),this.setTool(this.currentType))},onRenderStencil:function(a){this.stencils.register(a);this.unSetTool();this.defaults.clickMode?
this.defaults.clickable=!0:this.setTool(this.currentType)},onDeleteStencil:function(a){this.stencils.unregister(a)},registerTool:function(a){if(!this.tools[a]){var b=d.getObject(a);this.tools[a]=b;var c=f.abbr(a);this.stencilTypes[c]=b;this.stencilTypeMap[c]=a}},getConstructor:function(a){return this.stencilTypes[a]},setTool:function(a){if("ui"!=this.mode)if(this.canvas&&this.canvas.surface){this.currentStencil&&this.unSetTool();this.currentType=this.tools[a]?a:this.stencilTypeMap[a];try{this.currentStencil=
new this.tools[this.currentType]({container:this.canvas.surface.createGroup(),util:f,mouse:this.mouse,keys:g}),this.defaults.clickMode&&(this.defaults.clickable=!1),this.currentStencil.connect(this.currentStencil,"onRender",this,"onRenderStencil"),this.currentStencil.connect(this.currentStencil,"destroy",this,"onDeleteStencil")}catch(c){}}else var b=d.connect(this,"onSurfaceReady",this,function(){d.disconnect(b);this.setTool(a)})},set:function(a,b){},get:function(a){},unSetTool:function(){this.currentStencil.created||
this.currentStencil.destroy()}})});