Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
dojo.provide("dojo.widget.Toolbar");
14
dojo.require("dojo.widget.*");
15
dojo.require("dojo.html.style");
16
dojo.widget.defineWidget("dojo.widget.ToolbarContainer", dojo.widget.HtmlWidget, {isContainer:true, templateString:"<div class=\"toolbarContainer\" dojoAttachPoint=\"containerNode\"></div>", templateCssString:".toolbarContainer {\n\tborder-bottom : 0;\n\tbackground-color : #def;\n\tcolor : ButtonText;\n\tfont : Menu;\n\tbackground-image: url(images/toolbar-bg.gif);\n}\n\n.toolbar {\n\tpadding : 2px 4px;\n\tmin-height : 26px;\n\t_height : 26px;\n}\n\n.toolbarItem {\n\tfloat : left;\n\tpadding : 1px 2px;\n\tmargin : 0 2px 1px 0;\n\tcursor : pointer;\n}\n\n.toolbarItem.selected, .toolbarItem.down {\n\tmargin : 1px 1px 0 1px;\n\tpadding : 0px 1px;\n\tborder : 1px solid #bbf;\n\tbackground-color : #fafaff;\n}\n\n.toolbarButton img {\n\tvertical-align : bottom;\n}\n\n.toolbarButton span {\n\tline-height : 16px;\n\tvertical-align : middle;\n}\n\n.toolbarButton.hover {\n\tpadding : 0px 1px;\n\tborder : 1px solid #99c;\n}\n\n.toolbarItem.disabled {\n\topacity : 0.3;\n\tfilter : alpha(opacity=30);\n\tcursor : default;\n}\n\n.toolbarSeparator {\n\tcursor : default;\n}\n\n.toolbarFlexibleSpace {\n}\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/Toolbar.css"), getItem:function (name) {
17
	if (name instanceof dojo.widget.ToolbarItem) {
18
		return name;
19
	}
20
	for (var i = 0; i < this.children.length; i++) {
21
		var child = this.children[i];
22
		if (child instanceof dojo.widget.Toolbar) {
23
			var item = child.getItem(name);
24
			if (item) {
25
				return item;
26
			}
27
		}
28
	}
29
	return null;
30
}, getItems:function () {
31
	var items = [];
32
	for (var i = 0; i < this.children.length; i++) {
33
		var child = this.children[i];
34
		if (child instanceof dojo.widget.Toolbar) {
35
			items = items.concat(child.getItems());
36
		}
37
	}
38
	return items;
39
}, enable:function () {
40
	for (var i = 0; i < this.children.length; i++) {
41
		var child = this.children[i];
42
		if (child instanceof dojo.widget.Toolbar) {
43
			child.enable.apply(child, arguments);
44
		}
45
	}
46
}, disable:function () {
47
	for (var i = 0; i < this.children.length; i++) {
48
		var child = this.children[i];
49
		if (child instanceof dojo.widget.Toolbar) {
50
			child.disable.apply(child, arguments);
51
		}
52
	}
53
}, select:function (name) {
54
	for (var i = 0; i < this.children.length; i++) {
55
		var child = this.children[i];
56
		if (child instanceof dojo.widget.Toolbar) {
57
			child.select(arguments);
58
		}
59
	}
60
}, deselect:function (name) {
61
	for (var i = 0; i < this.children.length; i++) {
62
		var child = this.children[i];
63
		if (child instanceof dojo.widget.Toolbar) {
64
			child.deselect(arguments);
65
		}
66
	}
67
}, getItemsState:function () {
68
	var values = {};
69
	for (var i = 0; i < this.children.length; i++) {
70
		var child = this.children[i];
71
		if (child instanceof dojo.widget.Toolbar) {
72
			dojo.lang.mixin(values, child.getItemsState());
73
		}
74
	}
75
	return values;
76
}, getItemsActiveState:function () {
77
	var values = {};
78
	for (var i = 0; i < this.children.length; i++) {
79
		var child = this.children[i];
80
		if (child instanceof dojo.widget.Toolbar) {
81
			dojo.lang.mixin(values, child.getItemsActiveState());
82
		}
83
	}
84
	return values;
85
}, getItemsSelectedState:function () {
86
	var values = {};
87
	for (var i = 0; i < this.children.length; i++) {
88
		var child = this.children[i];
89
		if (child instanceof dojo.widget.Toolbar) {
90
			dojo.lang.mixin(values, child.getItemsSelectedState());
91
		}
92
	}
93
	return values;
94
}});
95
dojo.widget.defineWidget("dojo.widget.Toolbar", dojo.widget.HtmlWidget, {isContainer:true, templateString:"<div class=\"toolbar\" dojoAttachPoint=\"containerNode\" unselectable=\"on\" dojoOnMouseover=\"_onmouseover\" dojoOnMouseout=\"_onmouseout\" dojoOnClick=\"_onclick\" dojoOnMousedown=\"_onmousedown\" dojoOnMouseup=\"_onmouseup\"></div>", _getItem:function (node) {
96
	var start = new Date();
97
	var widget = null;
98
	while (node && node != this.domNode) {
99
		if (dojo.html.hasClass(node, "toolbarItem")) {
100
			var widgets = dojo.widget.manager.getWidgetsByFilter(function (w) {
101
				return w.domNode == node;
102
			});
103
			if (widgets.length == 1) {
104
				widget = widgets[0];
105
				break;
106
			} else {
107
				if (widgets.length > 1) {
108
					dojo.raise("Toolbar._getItem: More than one widget matches the node");
109
				}
110
			}
111
		}
112
		node = node.parentNode;
113
	}
114
	return widget;
115
}, _onmouseover:function (e) {
116
	var widget = this._getItem(e.target);
117
	if (widget && widget._onmouseover) {
118
		widget._onmouseover(e);
119
	}
120
}, _onmouseout:function (e) {
121
	var widget = this._getItem(e.target);
122
	if (widget && widget._onmouseout) {
123
		widget._onmouseout(e);
124
	}
125
}, _onclick:function (e) {
126
	var widget = this._getItem(e.target);
127
	if (widget && widget._onclick) {
128
		widget._onclick(e);
129
	}
130
}, _onmousedown:function (e) {
131
	var widget = this._getItem(e.target);
132
	if (widget && widget._onmousedown) {
133
		widget._onmousedown(e);
134
	}
135
}, _onmouseup:function (e) {
136
	var widget = this._getItem(e.target);
137
	if (widget && widget._onmouseup) {
138
		widget._onmouseup(e);
139
	}
140
}, addChild:function (item, pos, props) {
141
	var widget = dojo.widget.ToolbarItem.make(item, null, props);
142
	var ret = dojo.widget.Toolbar.superclass.addChild.call(this, widget, null, pos, null);
143
	return ret;
144
}, push:function () {
145
	for (var i = 0; i < arguments.length; i++) {
146
		this.addChild(arguments[i]);
147
	}
148
}, getItem:function (name) {
149
	if (name instanceof dojo.widget.ToolbarItem) {
150
		return name;
151
	}
152
	for (var i = 0; i < this.children.length; i++) {
153
		var child = this.children[i];
154
		if (child instanceof dojo.widget.ToolbarItem && child._name == name) {
155
			return child;
156
		}
157
	}
158
	return null;
159
}, getItems:function () {
160
	var items = [];
161
	for (var i = 0; i < this.children.length; i++) {
162
		var child = this.children[i];
163
		if (child instanceof dojo.widget.ToolbarItem) {
164
			items.push(child);
165
		}
166
	}
167
	return items;
168
}, getItemsState:function () {
169
	var values = {};
170
	for (var i = 0; i < this.children.length; i++) {
171
		var child = this.children[i];
172
		if (child instanceof dojo.widget.ToolbarItem) {
173
			values[child._name] = {selected:child._selected, enabled:!child.disabled};
174
		}
175
	}
176
	return values;
177
}, getItemsActiveState:function () {
178
	var values = this.getItemsState();
179
	for (var item in values) {
180
		values[item] = values[item].enabled;
181
	}
182
	return values;
183
}, getItemsSelectedState:function () {
184
	var values = this.getItemsState();
185
	for (var item in values) {
186
		values[item] = values[item].selected;
187
	}
188
	return values;
189
}, enable:function () {
190
	var items = arguments.length ? arguments : this.children;
191
	for (var i = 0; i < items.length; i++) {
192
		var child = this.getItem(items[i]);
193
		if (child instanceof dojo.widget.ToolbarItem) {
194
			child.enable(false, true);
195
		}
196
	}
197
}, disable:function () {
198
	var items = arguments.length ? arguments : this.children;
199
	for (var i = 0; i < items.length; i++) {
200
		var child = this.getItem(items[i]);
201
		if (child instanceof dojo.widget.ToolbarItem) {
202
			child.disable();
203
		}
204
	}
205
}, select:function () {
206
	for (var i = 0; i < arguments.length; i++) {
207
		var name = arguments[i];
208
		var item = this.getItem(name);
209
		if (item) {
210
			item.select();
211
		}
212
	}
213
}, deselect:function () {
214
	for (var i = 0; i < arguments.length; i++) {
215
		var name = arguments[i];
216
		var item = this.getItem(name);
217
		if (item) {
218
			item.disable();
219
		}
220
	}
221
}, setValue:function () {
222
	for (var i = 0; i < arguments.length; i += 2) {
223
		var name = arguments[i], value = arguments[i + 1];
224
		var item = this.getItem(name);
225
		if (item) {
226
			if (item instanceof dojo.widget.ToolbarItem) {
227
				item.setValue(value);
228
			}
229
		}
230
	}
231
}});
232
dojo.widget.defineWidget("dojo.widget.ToolbarItem", dojo.widget.HtmlWidget, {templateString:"<span unselectable=\"on\" class=\"toolbarItem\"></span>", _name:null, getName:function () {
233
	return this._name;
234
}, setName:function (value) {
235
	return (this._name = value);
236
}, getValue:function () {
237
	return this.getName();
238
}, setValue:function (value) {
239
	return this.setName(value);
240
}, _selected:false, isSelected:function () {
241
	return this._selected;
242
}, setSelected:function (is, force, preventEvent) {
243
	if (!this._toggleItem && !force) {
244
		return;
245
	}
246
	is = Boolean(is);
247
	if (force || !this.disabled && this._selected != is) {
248
		this._selected = is;
249
		this.update();
250
		if (!preventEvent) {
251
			this._fireEvent(is ? "onSelect" : "onDeselect");
252
			this._fireEvent("onChangeSelect");
253
		}
254
	}
255
}, select:function (force, preventEvent) {
256
	return this.setSelected(true, force, preventEvent);
257
}, deselect:function (force, preventEvent) {
258
	return this.setSelected(false, force, preventEvent);
259
}, _toggleItem:false, isToggleItem:function () {
260
	return this._toggleItem;
261
}, setToggleItem:function (value) {
262
	this._toggleItem = Boolean(value);
263
}, toggleSelected:function (force) {
264
	return this.setSelected(!this._selected, force);
265
}, isEnabled:function () {
266
	return !this.disabled;
267
}, setEnabled:function (is, force, preventEvent) {
268
	is = Boolean(is);
269
	if (force || this.disabled == is) {
270
		this.disabled = !is;
271
		this.update();
272
		if (!preventEvent) {
273
			this._fireEvent(this.disabled ? "onDisable" : "onEnable");
274
			this._fireEvent("onChangeEnabled");
275
		}
276
	}
277
	return !this.disabled;
278
}, enable:function (force, preventEvent) {
279
	return this.setEnabled(true, force, preventEvent);
280
}, disable:function (force, preventEvent) {
281
	return this.setEnabled(false, force, preventEvent);
282
}, toggleEnabled:function (force, preventEvent) {
283
	return this.setEnabled(this.disabled, force, preventEvent);
284
}, _icon:null, getIcon:function () {
285
	return this._icon;
286
}, setIcon:function (value) {
287
	var icon = dojo.widget.Icon.make(value);
288
	if (this._icon) {
289
		this._icon.setIcon(icon);
290
	} else {
291
		this._icon = icon;
292
	}
293
	var iconNode = this._icon.getNode();
294
	if (iconNode.parentNode != this.domNode) {
295
		if (this.domNode.hasChildNodes()) {
296
			this.domNode.insertBefore(iconNode, this.domNode.firstChild);
297
		} else {
298
			this.domNode.appendChild(iconNode);
299
		}
300
	}
301
	return this._icon;
302
}, _label:"", getLabel:function () {
303
	return this._label;
304
}, setLabel:function (value) {
305
	var ret = (this._label = value);
306
	if (!this.labelNode) {
307
		this.labelNode = document.createElement("span");
308
		this.domNode.appendChild(this.labelNode);
309
	}
310
	this.labelNode.innerHTML = "";
311
	this.labelNode.appendChild(document.createTextNode(this._label));
312
	this.update();
313
	return ret;
314
}, update:function () {
315
	if (this.disabled) {
316
		this._selected = false;
317
		dojo.html.addClass(this.domNode, "disabled");
318
		dojo.html.removeClass(this.domNode, "down");
319
		dojo.html.removeClass(this.domNode, "hover");
320
	} else {
321
		dojo.html.removeClass(this.domNode, "disabled");
322
		if (this._selected) {
323
			dojo.html.addClass(this.domNode, "selected");
324
		} else {
325
			dojo.html.removeClass(this.domNode, "selected");
326
		}
327
	}
328
	this._updateIcon();
329
}, _updateIcon:function () {
330
	if (this._icon) {
331
		if (this.disabled) {
332
			this._icon.disable();
333
		} else {
334
			if (this._cssHover) {
335
				this._icon.hover();
336
			} else {
337
				if (this._selected) {
338
					this._icon.select();
339
				} else {
340
					this._icon.enable();
341
				}
342
			}
343
		}
344
	}
345
}, _fireEvent:function (evt) {
346
	if (typeof this[evt] == "function") {
347
		var args = [this];
348
		for (var i = 1; i < arguments.length; i++) {
349
			args.push(arguments[i]);
350
		}
351
		this[evt].apply(this, args);
352
	}
353
}, _onmouseover:function (e) {
354
	if (this.disabled) {
355
		return;
356
	}
357
	dojo.html.addClass(this.domNode, "hover");
358
	this._fireEvent("onMouseOver");
359
}, _onmouseout:function (e) {
360
	dojo.html.removeClass(this.domNode, "hover");
361
	dojo.html.removeClass(this.domNode, "down");
362
	if (!this._selected) {
363
		dojo.html.removeClass(this.domNode, "selected");
364
	}
365
	this._fireEvent("onMouseOut");
366
}, _onclick:function (e) {
367
	if (!this.disabled && !this._toggleItem) {
368
		this._fireEvent("onClick");
369
	}
370
}, _onmousedown:function (e) {
371
	if (e.preventDefault) {
372
		e.preventDefault();
373
	}
374
	if (this.disabled) {
375
		return;
376
	}
377
	dojo.html.addClass(this.domNode, "down");
378
	if (this._toggleItem) {
379
		if (this.parent.preventDeselect && this._selected) {
380
			return;
381
		}
382
		this.toggleSelected();
383
	}
384
	this._fireEvent("onMouseDown");
385
}, _onmouseup:function (e) {
386
	dojo.html.removeClass(this.domNode, "down");
387
	this._fireEvent("onMouseUp");
388
}, onClick:function () {
389
}, onMouseOver:function () {
390
}, onMouseOut:function () {
391
}, onMouseDown:function () {
392
}, onMouseUp:function () {
393
}, fillInTemplate:function (args, frag) {
394
	if (args.name) {
395
		this._name = args.name;
396
	}
397
	if (args.selected) {
398
		this.select();
399
	}
400
	if (args.disabled) {
401
		this.disable();
402
	}
403
	if (args.label) {
404
		this.setLabel(args.label);
405
	}
406
	if (args.icon) {
407
		this.setIcon(args.icon);
408
	}
409
	if (args.toggleitem || args.toggleItem) {
410
		this.setToggleItem(true);
411
	}
412
}});
413
dojo.widget.ToolbarItem.make = function (wh, whIsType, props) {
414
	var item = null;
415
	if (wh instanceof Array) {
416
		item = dojo.widget.createWidget("ToolbarButtonGroup", props);
417
		item.setName(wh[0]);
418
		for (var i = 1; i < wh.length; i++) {
419
			item.addChild(wh[i]);
420
		}
421
	} else {
422
		if (wh instanceof dojo.widget.ToolbarItem) {
423
			item = wh;
424
		} else {
425
			if (wh instanceof dojo.uri.Uri) {
426
				item = dojo.widget.createWidget("ToolbarButton", dojo.lang.mixin(props || {}, {icon:new dojo.widget.Icon(wh.toString())}));
427
			} else {
428
				if (whIsType) {
429
					item = dojo.widget.createWidget(wh, props);
430
				} else {
431
					if (typeof wh == "string" || wh instanceof String) {
432
						switch (wh.charAt(0)) {
433
						  case "|":
434
						  case "-":
435
						  case "/":
436
							item = dojo.widget.createWidget("ToolbarSeparator", props);
437
							break;
438
						  case " ":
439
							if (wh.length == 1) {
440
								item = dojo.widget.createWidget("ToolbarSpace", props);
441
							} else {
442
								item = dojo.widget.createWidget("ToolbarFlexibleSpace", props);
443
							}
444
							break;
445
						  default:
446
							if (/\.(gif|jpg|jpeg|png)$/i.test(wh)) {
447
								item = dojo.widget.createWidget("ToolbarButton", dojo.lang.mixin(props || {}, {icon:new dojo.widget.Icon(wh.toString())}));
448
							} else {
449
								item = dojo.widget.createWidget("ToolbarButton", dojo.lang.mixin(props || {}, {label:wh.toString()}));
450
							}
451
						}
452
					} else {
453
						if (wh && wh.tagName && /^img$/i.test(wh.tagName)) {
454
							item = dojo.widget.createWidget("ToolbarButton", dojo.lang.mixin(props || {}, {icon:wh}));
455
						} else {
456
							item = dojo.widget.createWidget("ToolbarButton", dojo.lang.mixin(props || {}, {label:wh.toString()}));
457
						}
458
					}
459
				}
460
			}
461
		}
462
	}
463
	return item;
464
};
465
dojo.widget.defineWidget("dojo.widget.ToolbarButtonGroup", dojo.widget.ToolbarItem, {isContainer:true, templateString:"<span unselectable=\"on\" class=\"toolbarButtonGroup\" dojoAttachPoint=\"containerNode\"></span>", defaultButton:"", postCreate:function () {
466
	for (var i = 0; i < this.children.length; i++) {
467
		this._injectChild(this.children[i]);
468
	}
469
}, addChild:function (item, pos, props) {
470
	var widget = dojo.widget.ToolbarItem.make(item, null, dojo.lang.mixin(props || {}, {toggleItem:true}));
471
	var ret = dojo.widget.ToolbarButtonGroup.superclass.addChild.call(this, widget, null, pos, null);
472
	this._injectChild(widget);
473
	return ret;
474
}, _injectChild:function (widget) {
475
	dojo.event.connect(widget, "onSelect", this, "onChildSelected");
476
	dojo.event.connect(widget, "onDeselect", this, "onChildDeSelected");
477
	if (widget._name == this.defaultButton || (typeof this.defaultButton == "number" && this.children.length - 1 == this.defaultButton)) {
478
		widget.select(false, true);
479
	}
480
}, getItem:function (name) {
481
	if (name instanceof dojo.widget.ToolbarItem) {
482
		return name;
483
	}
484
	for (var i = 0; i < this.children.length; i++) {
485
		var child = this.children[i];
486
		if (child instanceof dojo.widget.ToolbarItem && child._name == name) {
487
			return child;
488
		}
489
	}
490
	return null;
491
}, getItems:function () {
492
	var items = [];
493
	for (var i = 0; i < this.children.length; i++) {
494
		var child = this.children[i];
495
		if (child instanceof dojo.widget.ToolbarItem) {
496
			items.push(child);
497
		}
498
	}
499
	return items;
500
}, onChildSelected:function (e) {
501
	this.select(e._name);
502
}, onChildDeSelected:function (e) {
503
	this._fireEvent("onChangeSelect", this._value);
504
}, enable:function (force, preventEvent) {
505
	for (var i = 0; i < this.children.length; i++) {
506
		var child = this.children[i];
507
		if (child instanceof dojo.widget.ToolbarItem) {
508
			child.enable(force, preventEvent);
509
			if (child._name == this._value) {
510
				child.select(force, preventEvent);
511
			}
512
		}
513
	}
514
}, disable:function (force, preventEvent) {
515
	for (var i = 0; i < this.children.length; i++) {
516
		var child = this.children[i];
517
		if (child instanceof dojo.widget.ToolbarItem) {
518
			child.disable(force, preventEvent);
519
		}
520
	}
521
}, _value:"", getValue:function () {
522
	return this._value;
523
}, select:function (name, force, preventEvent) {
524
	for (var i = 0; i < this.children.length; i++) {
525
		var child = this.children[i];
526
		if (child instanceof dojo.widget.ToolbarItem) {
527
			if (child._name == name) {
528
				child.select(force, preventEvent);
529
				this._value = name;
530
			} else {
531
				child.deselect(true, true);
532
			}
533
		}
534
	}
535
	if (!preventEvent) {
536
		this._fireEvent("onSelect", this._value);
537
		this._fireEvent("onChangeSelect", this._value);
538
	}
539
}, setValue:this.select, preventDeselect:false});
540
dojo.widget.defineWidget("dojo.widget.ToolbarButton", dojo.widget.ToolbarItem, {fillInTemplate:function (args, frag) {
541
	dojo.widget.ToolbarButton.superclass.fillInTemplate.call(this, args, frag);
542
	dojo.html.addClass(this.domNode, "toolbarButton");
543
	if (this._icon) {
544
		this.setIcon(this._icon);
545
	}
546
	if (this._label) {
547
		this.setLabel(this._label);
548
	}
549
	if (!this._name) {
550
		if (this._label) {
551
			this.setName(this._label);
552
		} else {
553
			if (this._icon) {
554
				var src = this._icon.getSrc("enabled").match(/[\/^]([^\.\/]+)\.(gif|jpg|jpeg|png)$/i);
555
				if (src) {
556
					this.setName(src[1]);
557
				}
558
			} else {
559
				this._name = this._widgetId;
560
			}
561
		}
562
	}
563
}});
564
dojo.widget.defineWidget("dojo.widget.ToolbarDialog", dojo.widget.ToolbarButton, {fillInTemplate:function (args, frag) {
565
	dojo.widget.ToolbarDialog.superclass.fillInTemplate.call(this, args, frag);
566
	dojo.event.connect(this, "onSelect", this, "showDialog");
567
	dojo.event.connect(this, "onDeselect", this, "hideDialog");
568
}, showDialog:function (e) {
569
	dojo.lang.setTimeout(dojo.event.connect, 1, document, "onmousedown", this, "deselect");
570
}, hideDialog:function (e) {
571
	dojo.event.disconnect(document, "onmousedown", this, "deselect");
572
}});
573
dojo.widget.defineWidget("dojo.widget.ToolbarMenu", dojo.widget.ToolbarDialog, {});
574
dojo.widget.ToolbarMenuItem = function () {
575
};
576
dojo.widget.defineWidget("dojo.widget.ToolbarSeparator", dojo.widget.ToolbarItem, {templateString:"<span unselectable=\"on\" class=\"toolbarItem toolbarSeparator\"></span>", defaultIconPath:new dojo.uri.moduleUri("dojo.widget", "templates/buttons/sep.gif"), fillInTemplate:function (args, frag, skip) {
577
	dojo.widget.ToolbarSeparator.superclass.fillInTemplate.call(this, args, frag);
578
	this._name = this.widgetId;
579
	if (!skip) {
580
		if (!this._icon) {
581
			this.setIcon(this.defaultIconPath);
582
		}
583
		this.domNode.appendChild(this._icon.getNode());
584
	}
585
}, _onmouseover:null, _onmouseout:null, _onclick:null, _onmousedown:null, _onmouseup:null});
586
dojo.widget.defineWidget("dojo.widget.ToolbarSpace", dojo.widget.ToolbarSeparator, {fillInTemplate:function (args, frag, skip) {
587
	dojo.widget.ToolbarSpace.superclass.fillInTemplate.call(this, args, frag, true);
588
	if (!skip) {
589
		dojo.html.addClass(this.domNode, "toolbarSpace");
590
	}
591
}});
592
dojo.widget.defineWidget("dojo.widget.ToolbarSelect", dojo.widget.ToolbarItem, {templateString:"<span class=\"toolbarItem toolbarSelect\" unselectable=\"on\"><select dojoAttachPoint=\"selectBox\" dojoOnChange=\"changed\"></select></span>", fillInTemplate:function (args, frag) {
593
	dojo.widget.ToolbarSelect.superclass.fillInTemplate.call(this, args, frag, true);
594
	var keys = args.values;
595
	var i = 0;
596
	for (var val in keys) {
597
		var opt = document.createElement("option");
598
		opt.setAttribute("value", keys[val]);
599
		opt.innerHTML = val;
600
		this.selectBox.appendChild(opt);
601
	}
602
}, changed:function (e) {
603
	this._fireEvent("onSetValue", this.selectBox.value);
604
}, setEnabled:function (is, force, preventEvent) {
605
	var ret = dojo.widget.ToolbarSelect.superclass.setEnabled.call(this, is, force, preventEvent);
606
	this.selectBox.disabled = this.disabled;
607
	return ret;
608
}, _onmouseover:null, _onmouseout:null, _onclick:null, _onmousedown:null, _onmouseup:null});
609
dojo.widget.Icon = function (enabled, disabled, hovered, selected) {
610
	if (!arguments.length) {
611
		throw new Error("Icon must have at least an enabled state");
612
	}
613
	var states = ["enabled", "disabled", "hovered", "selected"];
614
	var currentState = "enabled";
615
	var domNode = document.createElement("img");
616
	this.getState = function () {
617
		return currentState;
618
	};
619
	this.setState = function (value) {
620
		if (dojo.lang.inArray(states, value)) {
621
			if (this[value]) {
622
				currentState = value;
623
				var img = this[currentState];
624
				if ((dojo.render.html.ie55 || dojo.render.html.ie60) && img.src && img.src.match(/[.]png$/i)) {
625
					domNode.width = img.width || img.offsetWidth;
626
					domNode.height = img.height || img.offsetHeight;
627
					domNode.setAttribute("src", dojo.uri.moduleUri("dojo.widget", "templates/images/blank.gif").uri);
628
					domNode.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img.src + "',sizingMethod='image')";
629
				} else {
630
					domNode.setAttribute("src", img.src);
631
				}
632
			}
633
		} else {
634
			throw new Error("Invalid state set on Icon (state: " + value + ")");
635
		}
636
	};
637
	this.setSrc = function (state, value) {
638
		if (/^img$/i.test(value.tagName)) {
639
			this[state] = value;
640
		} else {
641
			if (typeof value == "string" || value instanceof String || value instanceof dojo.uri.Uri) {
642
				this[state] = new Image();
643
				this[state].src = value.toString();
644
			}
645
		}
646
		return this[state];
647
	};
648
	this.setIcon = function (icon) {
649
		for (var i = 0; i < states.length; i++) {
650
			if (icon[states[i]]) {
651
				this.setSrc(states[i], icon[states[i]]);
652
			}
653
		}
654
		this.update();
655
	};
656
	this.enable = function () {
657
		this.setState("enabled");
658
	};
659
	this.disable = function () {
660
		this.setState("disabled");
661
	};
662
	this.hover = function () {
663
		this.setState("hovered");
664
	};
665
	this.select = function () {
666
		this.setState("selected");
667
	};
668
	this.getSize = function () {
669
		return {width:domNode.width || domNode.offsetWidth, height:domNode.height || domNode.offsetHeight};
670
	};
671
	this.setSize = function (w, h) {
672
		domNode.width = w;
673
		domNode.height = h;
674
		return {width:w, height:h};
675
	};
676
	this.getNode = function () {
677
		return domNode;
678
	};
679
	this.getSrc = function (state) {
680
		if (state) {
681
			return this[state].src;
682
		}
683
		return domNode.src || "";
684
	};
685
	this.update = function () {
686
		this.setState(currentState);
687
	};
688
	for (var i = 0; i < states.length; i++) {
689
		var arg = arguments[i];
690
		var state = states[i];
691
		this[state] = null;
692
		if (!arg) {
693
			continue;
694
		}
695
		this.setSrc(state, arg);
696
	}
697
	this.enable();
698
};
699
dojo.widget.Icon.make = function (a, b, c, d) {
700
	for (var i = 0; i < arguments.length; i++) {
701
		if (arguments[i] instanceof dojo.widget.Icon) {
702
			return arguments[i];
703
		}
704
	}
705
	return new dojo.widget.Icon(a, b, c, d);
706
};
707
dojo.widget.defineWidget("dojo.widget.ToolbarColorDialog", dojo.widget.ToolbarDialog, {palette:"7x10", fillInTemplate:function (args, frag) {
708
	dojo.widget.ToolbarColorDialog.superclass.fillInTemplate.call(this, args, frag);
709
	this.dialog = dojo.widget.createWidget("ColorPalette", {palette:this.palette});
710
	this.dialog.domNode.style.position = "absolute";
711
	dojo.event.connect(this.dialog, "onColorSelect", this, "_setValue");
712
}, _setValue:function (color) {
713
	this._value = color;
714
	this._fireEvent("onSetValue", color);
715
}, showDialog:function (e) {
716
	dojo.widget.ToolbarColorDialog.superclass.showDialog.call(this, e);
717
	var abs = dojo.html.getAbsolutePosition(this.domNode, true);
718
	var y = abs.y + dojo.html.getBorderBox(this.domNode).height;
719
	this.dialog.showAt(abs.x, y);
720
}, hideDialog:function (e) {
721
	dojo.widget.ToolbarColorDialog.superclass.hideDialog.call(this, e);
722
	this.dialog.hide();
723
}});
724