root / trunk / web / dojo / dojox / drawing / ui / Toolbar.js @ 9
History | View | Annotate | Download (5.12 KB)
| 1 |
/*
|
|---|---|
| 2 |
Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
| 3 |
Available via Academic Free License >= 2.1 OR the modified BSD license.
|
| 4 |
see: http://dojotoolkit.org/license for details
|
| 5 |
*/
|
| 6 |
|
| 7 |
|
| 8 |
if(!dojo._hasResource["dojox.drawing.ui.Toolbar"]){ |
| 9 |
dojo._hasResource["dojox.drawing.ui.Toolbar"]=true; |
| 10 |
dojo.provide("dojox.drawing.ui.Toolbar");
|
| 11 |
dojo.require("dojox.drawing.library.icons");
|
| 12 |
dojo.declare("dojox.drawing.ui.Toolbar",[],{constructor:function(_1,_2){ |
| 13 |
this.util=dojox.drawing.util.common;
|
| 14 |
if(_1.drawing){
|
| 15 |
this.toolDrawing=_1.drawing;
|
| 16 |
this.drawing=this.toolDrawing; |
| 17 |
this.width=this.toolDrawing.width; |
| 18 |
this.height=this.toolDrawing.height; |
| 19 |
this.strSelected=_1.selected;
|
| 20 |
this.strTools=_1.tools;
|
| 21 |
this.strPlugs=_1.plugs;
|
| 22 |
this._mixprops(["padding","margin","size","radius"],_1); |
| 23 |
this.addBack();
|
| 24 |
}else{
|
| 25 |
var _3=dojo.marginBox(_2);
|
| 26 |
this.width=_3.w;
|
| 27 |
this.height=_3.h;
|
| 28 |
this.strSelected=dojo.attr(_2,"selected"); |
| 29 |
this.strTools=dojo.attr(_2,"tools"); |
| 30 |
this.strPlugs=dojo.attr(_2,"plugs"); |
| 31 |
this._mixprops(["padding","margin","size","radius"],_2); |
| 32 |
this.toolDrawing=new dojox.drawing.Drawing({mode:"ui"},_2); |
| 33 |
} |
| 34 |
this.horizontal=this.width>this.height; |
| 35 |
if(this.toolDrawing.ready){ |
| 36 |
this.makeButtons();
|
| 37 |
if(!this.strSelected&&this.drawing.defaults.clickMode){ |
| 38 |
this.drawing.mouse.setCursor("default"); |
| 39 |
} |
| 40 |
}else{
|
| 41 |
var c=dojo.connect(this.toolDrawing,"onSurfaceReady",this,function(){ |
| 42 |
dojo.disconnect(c); |
| 43 |
this.drawing=dojox.drawing.getRegistered("drawing",dojo.attr(_2,"drawingId")); |
| 44 |
this.makeButtons();
|
| 45 |
if(!this.strSelected&&this.drawing.defaults.clickMode){ |
| 46 |
var c=dojo.connect(this.drawing,"onSurfaceReady",this,function(){ |
| 47 |
dojo.disconnect(c); |
| 48 |
this.drawing.mouse.setCursor("default"); |
| 49 |
}); |
| 50 |
} |
| 51 |
}); |
| 52 |
} |
| 53 |
},padding:10,margin:5,size:30,radius:3,toolPlugGap:20,strSelected:"",strTools:"",strPlugs:"",makeButtons:function(){ |
| 54 |
this.buttons=[];
|
| 55 |
this.plugins=[];
|
| 56 |
var x=this.padding,y=this.padding,w=this.size,h=this.size,r=this.radius,g=this.margin,_4=dojox.drawing.library.icons,s={place:"BR",size:2,mult:4}; |
| 57 |
if(this.strTools){ |
| 58 |
var _5=[];
|
| 59 |
var _6=dojox.drawing.getRegistered("tool"); |
| 60 |
var _7={};
|
| 61 |
for(var nm in _6){ |
| 62 |
var _8=this.util.abbr(nm); |
| 63 |
_7[_8]=_6[nm]; |
| 64 |
if(this.strTools=="all"){ |
| 65 |
_5.push(_8); |
| 66 |
var _9=dojox.drawing.getRegistered("tool",nm); |
| 67 |
if(_9.secondary){
|
| 68 |
_5.push(_9.secondary.name); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
if(this.strTools!="all"){ |
| 73 |
var _a=this.strTools.split(","); |
| 74 |
dojo.forEach(_a,function(_b){
|
| 75 |
_b=dojo.trim(_b); |
| 76 |
_5.push(_b); |
| 77 |
var _c=dojox.drawing.getRegistered("tool",_7[_b].name); |
| 78 |
if(_c.secondary){
|
| 79 |
_5.push(_c.secondary.name); |
| 80 |
} |
| 81 |
},this);
|
| 82 |
} |
| 83 |
dojo.forEach(_5,function(t){
|
| 84 |
t=dojo.trim(t); |
| 85 |
var _d=false; |
| 86 |
if(t.indexOf("Secondary")>-1){ |
| 87 |
var _e=t.substring(0,t.indexOf("Secondary")); |
| 88 |
var _f=dojox.drawing.getRegistered("tool",_7[_e].name).secondary; |
| 89 |
var _10=_f.label;
|
| 90 |
this[t]=_f.funct;
|
| 91 |
if(_f.setup){
|
| 92 |
dojo.hitch(this,_f.setup)();
|
| 93 |
} |
| 94 |
var btn=this.toolDrawing.addUI("button",{data:{x:x,y:y,width:w,height:h/2,r:r},toolType:t,secondary:true,text:_10,shadow:s,scope:this,callback:this[t]}); |
| 95 |
if(_f.postSetup){
|
| 96 |
dojo.hitch(this,_f.postSetup,btn)();
|
| 97 |
} |
| 98 |
_d=true;
|
| 99 |
}else{
|
| 100 |
var btn=this.toolDrawing.addUI("button",{data:{x:x,y:y,width:w,height:h,r:r},toolType:t,icon:_4[t],shadow:s,scope:this,callback:"onToolClick"}); |
| 101 |
} |
| 102 |
dojox.drawing.register(btn,"button");
|
| 103 |
this.buttons.push(btn);
|
| 104 |
if(this.strSelected==t){ |
| 105 |
btn.select(); |
| 106 |
this.selected=btn;
|
| 107 |
this.drawing.setTool(btn.toolType);
|
| 108 |
} |
| 109 |
if(this.horizontal){ |
| 110 |
var _11=_d?h/2+g:h+g; |
| 111 |
y+=_11; |
| 112 |
}else{
|
| 113 |
var _11=_d?h/2+g:h+g; |
| 114 |
y+=_11; |
| 115 |
} |
| 116 |
},this);
|
| 117 |
} |
| 118 |
if(this.horizontal){ |
| 119 |
y+=this.toolPlugGap;
|
| 120 |
}else{
|
| 121 |
y+=this.toolPlugGap;
|
| 122 |
} |
| 123 |
if(this.strPlugs){ |
| 124 |
var _12=[];
|
| 125 |
var _13=dojox.drawing.getRegistered("plugin"); |
| 126 |
var _14={};
|
| 127 |
for(var nm in _13){ |
| 128 |
var _15=this.util.abbr(nm); |
| 129 |
_14[_15]=_13[nm]; |
| 130 |
if(this.strPlugs=="all"){ |
| 131 |
_12.push(_15); |
| 132 |
} |
| 133 |
} |
| 134 |
if(this.strPlugs!="all"){ |
| 135 |
_12=this.strPlugs.split(","); |
| 136 |
dojo.map(_12,function(p){
|
| 137 |
return dojo.trim(p);
|
| 138 |
}); |
| 139 |
} |
| 140 |
dojo.forEach(_12,function(p){
|
| 141 |
var t=dojo.trim(p);
|
| 142 |
if(_14[p].button!=false){ |
| 143 |
var btn=this.toolDrawing.addUI("button",{data:{x:x,y:y,width:w,height:h,r:r},toolType:t,icon:_4[t],shadow:s,scope:this,callback:"onPlugClick"}); |
| 144 |
dojox.drawing.register(btn,"button");
|
| 145 |
this.plugins.push(btn);
|
| 146 |
if(this.horizontal){ |
| 147 |
y+=h+g; |
| 148 |
}else{
|
| 149 |
y+=h+g; |
| 150 |
} |
| 151 |
} |
| 152 |
var _16={};
|
| 153 |
_14[p].button==false?_16={name:this.drawing.stencilTypeMap[p]}:_16={name:this.drawing.stencilTypeMap[p],options:{button:btn}}; |
| 154 |
this.drawing.addPlugin(_16);
|
| 155 |
},this);
|
| 156 |
} |
| 157 |
dojo.connect(this.drawing,"onRenderStencil",this,"onRenderStencil"); |
| 158 |
},onRenderStencil:function(_17){ |
| 159 |
if(this.drawing.defaults.clickMode){ |
| 160 |
this.drawing.mouse.setCursor("default"); |
| 161 |
this.selected&&this.selected.deselect(); |
| 162 |
this.selected=null; |
| 163 |
} |
| 164 |
},addTool:function(){ |
| 165 |
},addPlugin:function(){ |
| 166 |
},addBack:function(){ |
| 167 |
this.toolDrawing.addUI("rect",{data:{x:0,y:0,width:this.width,height:this.size+(this.padding*2),fill:"#ffffff",borderWidth:0}}); |
| 168 |
},onToolClick:function(_18){ |
| 169 |
if(this.drawing.defaults.clickMode){ |
| 170 |
this.drawing.mouse.setCursor("crosshair"); |
| 171 |
} |
| 172 |
dojo.forEach(this.buttons,function(b){ |
| 173 |
if(b.id==_18.id){
|
| 174 |
b.select(); |
| 175 |
this.selected=b;
|
| 176 |
this.drawing.setTool(_18.toolType);
|
| 177 |
}else{
|
| 178 |
if(!b.secondary){
|
| 179 |
b.deselect(); |
| 180 |
} |
| 181 |
} |
| 182 |
},this);
|
| 183 |
},onPlugClick:function(_19){ |
| 184 |
},_mixprops:function(_1a,_1b){ |
| 185 |
dojo.forEach(_1a,function(p){
|
| 186 |
this[p]=_1b.tagName?dojo.attr(_1b,p)===null?this[p]:dojo.attr(_1b,p):_1b[p]===undefined?this[p]:_1b[p]; |
| 187 |
},this);
|
| 188 |
}}); |
| 189 |
} |