//>>built
define("dojox/drawing/ui/Toolbar",["dojo","../library/icons","../util/common","../Drawing","../manager/_registry"],function(c,s,t,v,h){return c.declare("dojox.drawing.ui.Toolbar",[],{constructor:function(b,a){if(b.drawing)this.drawing=this.toolDrawing=b.drawing,this.width=this.toolDrawing.width,this.height=this.toolDrawing.height,this.strSelected=b.selected,this.strTools=b.tools,this.strPlugs=b.plugs,this._mixprops(["padding","margin","size","radius"],b),this.addBack(),this.orient=b.orient?b.orient:
!1;else{var l=c.marginBox(a);this.width=l.w;this.height=l.h;this.strSelected=c.attr(a,"selected");this.strTools=c.attr(a,"tools");this.strPlugs=c.attr(a,"plugs");this._mixprops(["padding","margin","size","radius"],a);this.toolDrawing=new v({mode:"ui"},a);this.orient=c.attr(a,"orient")}this.horizontal=this.orient?"H"==this.orient:this.width>this.height;this.toolDrawing.ready?(this.makeButtons(),!this.strSelected&&this.drawing.defaults.clickMode&&this.drawing.mouse.setCursor("default")):c.connect(this.toolDrawing,
"onSurfaceReady",this,function(){c.disconnect(b);this.drawing=h.getRegistered("drawing",c.attr(a,"drawingId"));this.makeButtons();if(!this.strSelected&&this.drawing.defaults.clickMode)var b=c.connect(this.drawing,"onSurfaceReady",this,function(){c.disconnect(b);this.drawing.mouse.setCursor("default")})})},padding:10,margin:5,size:30,radius:3,toolPlugGap:20,strSelected:"",strTools:"",strPlugs:"",makeButtons:function(){this.buttons=[];this.plugins=[];var b=this.padding,a=this.padding,l=this.size,i=
this.size,o=this.radius,m=this.margin,p={place:"BR",size:2,mult:4};if(this.strTools){var n=[],g=h.getRegistered("tool"),q={},k;for(k in g){var j=t.abbr(k);q[j]=g[k];"all"==this.strTools&&(n.push(j),j=h.getRegistered("tool",k),j.secondary&&n.push(j.secondary.name))}"all"!=this.strTools&&(g=this.strTools.split(","),c.forEach(g,function(a){a=c.trim(a);n.push(a);a=h.getRegistered("tool",q[a].name);a.secondary&&n.push(a.secondary.name)},this));c.forEach(n,function(e){var e=c.trim(e),d=!1;if(-1<e.indexOf("Secondary")){var d=
e.substring(0,e.indexOf("Secondary")),d=h.getRegistered("tool",q[d].name).secondary,f=d.label;this[e]=d.funct;d.setup&&c.hitch(this,d.setup)();f=this.toolDrawing.addUI("button",{data:{x:b,y:a,width:l,height:i/2,r:o},toolType:e,secondary:!0,text:f,shadow:p,scope:this,callback:this[e]});d.postSetup&&c.hitch(this,d.postSetup,f)();d=!0}else f=this.toolDrawing.addUI("button",{data:{x:b,y:a,width:l,height:i,r:o},toolType:e,icon:s[e],shadow:p,scope:this,callback:"onToolClick"});h.register(f,"button");this.buttons.push(f);
if(this.strSelected==e)f.select(),this.selected=f,this.drawing.setTool(f.toolType);this.horizontal?b+=i+m:a+=d?i/2+m:i+m},this)}this.horizontal?b+=this.toolPlugGap:a+=this.toolPlugGap;if(this.strPlugs){var g=[],j=h.getRegistered("plugin"),r={};for(k in j){var u=t.abbr(k);r[u]=j[k];"all"==this.strPlugs&&g.push(u)}"all"!=this.strPlugs&&(g=this.strPlugs.split(","),c.map(g,function(a){return c.trim(a)}));c.forEach(g,function(e){var d=c.trim(e);if(!1!=r[e].button){var f=this.toolDrawing.addUI("button",
{data:{x:b,y:a,width:l,height:i,r:o},toolType:d,icon:s[d],shadow:p,scope:this,callback:"onPlugClick"});h.register(f,"button");this.plugins.push(f);this.horizontal?b+=i+m:a+=i+m}d={};!1==r[e].button?d={name:this.drawing.stencilTypeMap[e]}:d={name:this.drawing.stencilTypeMap[e],options:{button:f}};this.drawing.addPlugin(d)},this)}c.connect(this.drawing,"onRenderStencil",this,"onRenderStencil")},onRenderStencil:function(){if(this.drawing.defaults.clickMode)this.drawing.mouse.setCursor("default"),this.selected&&
this.selected.deselect(),this.selected=null},addTool:function(){},addPlugin:function(){},addBack:function(){this.toolDrawing.addUI("rect",{data:{x:0,y:0,width:this.width,height:this.size+2*this.padding,fill:"#ffffff",borderWidth:0}})},onToolClick:function(b){this.drawing.defaults.clickMode&&this.drawing.mouse.setCursor("crosshair");c.forEach(this.buttons,function(a){a.id==b.id?(a.select(),this.selected=a,this.drawing.setTool(b.toolType)):a.secondary||a.deselect()},this)},onPlugClick:function(){},
_mixprops:function(b,a){c.forEach(b,function(b){this[b]=a.tagName?null===c.attr(a,b)?this[b]:c.attr(a,b):void 0===a[b]?this[b]:a[b]},this)}})});