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