Subversion Repositories Applications.papyrus

Rev

Rev 1372 | Go to most recent revision | 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.FloatingPane");
14
dojo.require("dojo.widget.*");
15
dojo.require("dojo.widget.Manager");
16
dojo.require("dojo.html.*");
17
dojo.require("dojo.html.layout");
18
dojo.require("dojo.html.iframe");
19
dojo.require("dojo.html.selection");
20
dojo.require("dojo.lfx.shadow");
21
dojo.require("dojo.widget.html.layout");
22
dojo.require("dojo.widget.ContentPane");
23
dojo.require("dojo.dnd.HtmlDragMove");
24
dojo.require("dojo.widget.Dialog");
25
dojo.require("dojo.widget.ResizeHandle");
26
dojo.declare("dojo.widget.FloatingPaneBase", null, {title:"", iconSrc:"", hasShadow:false, constrainToContainer:false, taskBarId:"", resizable:true, titleBarDisplay:true, windowState:"normal", displayCloseAction:false, displayMinimizeAction:false, displayMaximizeAction:false, _max_taskBarConnectAttempts:5, _taskBarConnectAttempts:0, templateString:"<div id=\"${this.widgetId}\" dojoAttachEvent=\"onMouseDown\" class=\"dojoFloatingPane\">\n\t<div dojoAttachPoint=\"titleBar\" class=\"dojoFloatingPaneTitleBar\"  style=\"display:none\">\n\t  \t<img dojoAttachPoint=\"titleBarIcon\"  class=\"dojoFloatingPaneTitleBarIcon\">\n\t\t<div dojoAttachPoint=\"closeAction\" dojoAttachEvent=\"onClick:closeWindow\"\n   \t  \t\tclass=\"dojoFloatingPaneCloseIcon\"></div>\n\t\t<div dojoAttachPoint=\"restoreAction\" dojoAttachEvent=\"onClick:restoreWindow\"\n   \t  \t\tclass=\"dojoFloatingPaneRestoreIcon\"></div>\n\t\t<div dojoAttachPoint=\"maximizeAction\" dojoAttachEvent=\"onClick:maximizeWindow\"\n   \t  \t\tclass=\"dojoFloatingPaneMaximizeIcon\"></div>\n\t\t<div dojoAttachPoint=\"minimizeAction\" dojoAttachEvent=\"onClick:minimizeWindow\"\n   \t  \t\tclass=\"dojoFloatingPaneMinimizeIcon\"></div>\n\t  \t<div dojoAttachPoint=\"titleBarText\" class=\"dojoFloatingPaneTitleText\">${this.title}</div>\n\t</div>\n\n\t<div id=\"${this.widgetId}_container\" dojoAttachPoint=\"containerNode\" class=\"dojoFloatingPaneClient\"></div>\n\n\t<div dojoAttachPoint=\"resizeBar\" class=\"dojoFloatingPaneResizebar\" style=\"display:none\"></div>\n</div>\n", templateCssString:"\n/********** Outer Window ***************/\n\n.dojoFloatingPane {\n\t/* essential css */\n\tposition: absolute;\n\toverflow: visible;\t\t/* so drop shadow is displayed */\n\tz-index: 10;\n\n\t/* styling css */\n\tborder: 1px solid;\n\tborder-color: ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight;\n\tbackground-color: ThreeDFace;\n}\n\n\n/********** Title Bar ****************/\n\n.dojoFloatingPaneTitleBar {\n\tvertical-align: top;\n\tmargin: 2px 2px 2px 2px;\n\tz-index: 10;\n\tbackground-color: #7596c6;\n\tcursor: default;\n\toverflow: hidden;\n\tborder-color: ThreeDHighlight ThreeDShadow ThreeDShadow ThreeDHighlight;\n\tvertical-align: middle;\n}\n\n.dojoFloatingPaneTitleText {\n\tfloat: left;\n\tpadding: 2px 4px 2px 2px;\n\twhite-space: nowrap;\n\tcolor: CaptionText;\n\tfont: small-caption;\n}\n\n.dojoTitleBarIcon {\n\tfloat: left;\n\theight: 22px;\n\twidth: 22px;\n\tvertical-align: middle;\n\tmargin-right: 5px;\n\tmargin-left: 5px;\n}\n\n.dojoFloatingPaneActions{\n\tfloat: right;\n\tposition: absolute;\n\tright: 2px;\n\ttop: 2px;\n\tvertical-align: middle;\n}\n\n\n.dojoFloatingPaneActionItem {\n\tvertical-align: middle;\n\tmargin-right: 1px;\n\theight: 22px;\n\twidth: 22px;\n}\n\n\n.dojoFloatingPaneTitleBarIcon {\n\t/* essential css */\n\tfloat: left;\n\n\t/* styling css */\n\tmargin-left: 2px;\n\tmargin-right: 4px;\n\theight: 22px;\n}\n\n/* minimize/maximize icons are specified by CSS only */\n.dojoFloatingPaneMinimizeIcon,\n.dojoFloatingPaneMaximizeIcon,\n.dojoFloatingPaneRestoreIcon,\n.dojoFloatingPaneCloseIcon {\n\tvertical-align: middle;\n\theight: 22px;\n\twidth: 22px;\n\tfloat: right;\n}\n.dojoFloatingPaneMinimizeIcon {\n\tbackground-image: url(images/floatingPaneMinimize.gif);\n}\n.dojoFloatingPaneMaximizeIcon {\n\tbackground-image: url(images/floatingPaneMaximize.gif);\n}\n.dojoFloatingPaneRestoreIcon {\n\tbackground-image: url(images/floatingPaneRestore.gif);\n}\n.dojoFloatingPaneCloseIcon {\n\tbackground-image: url(images/floatingPaneClose.gif);\n}\n\n/* bar at bottom of window that holds resize handle */\n.dojoFloatingPaneResizebar {\n\tz-index: 10;\n\theight: 13px;\n\tbackground-color: ThreeDFace;\n}\n\n/************* Client Area ***************/\n\n.dojoFloatingPaneClient {\n\tposition: relative;\n\tz-index: 10;\n\tborder: 1px solid;\n\tborder-color: ThreeDShadow ThreeDHighlight ThreeDHighlight ThreeDShadow;\n\tmargin: 2px;\n\tbackground-color: ThreeDFace;\n\tpadding: 8px;\n\tfont-family: Verdana, Helvetica, Garamond, sans-serif;\n\tfont-size: 12px;\n\toverflow: auto;\n}\n\n", templateCssPath:dojo.uri.moduleUri("dojo.widget", "templates/FloatingPane.css"), fillInFloatingPaneTemplate:function (args, frag) {
27
	var source = this.getFragNodeRef(frag);
28
	dojo.html.copyStyle(this.domNode, source);
29
	dojo.body().appendChild(this.domNode);
30
	if (!this.isShowing()) {
31
		this.windowState = "minimized";
32
	}
33
	if (this.iconSrc == "") {
34
		dojo.html.removeNode(this.titleBarIcon);
35
	} else {
36
		this.titleBarIcon.src = this.iconSrc.toString();
37
	}
38
	if (this.titleBarDisplay) {
39
		this.titleBar.style.display = "";
40
		dojo.html.disableSelection(this.titleBar);
41
		this.titleBarIcon.style.display = (this.iconSrc == "" ? "none" : "");
42
		this.minimizeAction.style.display = (this.displayMinimizeAction ? "" : "none");
43
		this.maximizeAction.style.display = (this.displayMaximizeAction && this.windowState != "maximized" ? "" : "none");
44
		this.restoreAction.style.display = (this.displayMaximizeAction && this.windowState == "maximized" ? "" : "none");
45
		this.closeAction.style.display = (this.displayCloseAction ? "" : "none");
46
		this.drag = new dojo.dnd.HtmlDragMoveSource(this.domNode);
47
		if (this.constrainToContainer) {
48
			this.drag.constrainTo();
49
		}
50
		this.drag.setDragHandle(this.titleBar);
51
		var self = this;
52
		dojo.event.topic.subscribe("dragMove", function (info) {
53
			if (info.source.domNode == self.domNode) {
54
				dojo.event.topic.publish("floatingPaneMove", {source:self});
55
			}
56
		});
57
	}
58
	if (this.resizable) {
59
		this.resizeBar.style.display = "";
60
		this.resizeHandle = dojo.widget.createWidget("ResizeHandle", {targetElmId:this.widgetId, id:this.widgetId + "_resize"});
61
		this.resizeBar.appendChild(this.resizeHandle.domNode);
62
	}
63
	if (this.hasShadow) {
64
		this.shadow = new dojo.lfx.shadow(this.domNode);
65
	}
66
	this.bgIframe = new dojo.html.BackgroundIframe(this.domNode);
67
	if (this.taskBarId) {
68
		this._taskBarSetup();
69
	}
70
	dojo.body().removeChild(this.domNode);
71
}, postCreate:function () {
72
	if (dojo.hostenv.post_load_) {
73
		this._setInitialWindowState();
74
	} else {
75
		dojo.addOnLoad(this, "_setInitialWindowState");
76
	}
77
}, maximizeWindow:function (evt) {
78
	var mb = dojo.html.getMarginBox(this.domNode);
79
	this.previous = {width:mb.width || this.width, height:mb.height || this.height, left:this.domNode.style.left, top:this.domNode.style.top, bottom:this.domNode.style.bottom, right:this.domNode.style.right};
80
	if (this.domNode.parentNode.style.overflow.toLowerCase() != "hidden") {
81
		this.parentPrevious = {overflow:this.domNode.parentNode.style.overflow};
82
		dojo.debug(this.domNode.parentNode.style.overflow);
83
		this.domNode.parentNode.style.overflow = "hidden";
84
	}
85
	this.domNode.style.left = dojo.html.getPixelValue(this.domNode.parentNode, "padding-left", true) + "px";
86
	this.domNode.style.top = dojo.html.getPixelValue(this.domNode.parentNode, "padding-top", true) + "px";
87
	if ((this.domNode.parentNode.nodeName.toLowerCase() == "body")) {
88
		var viewport = dojo.html.getViewport();
89
		var padding = dojo.html.getPadding(dojo.body());
90
		this.resizeTo(viewport.width - padding.width, viewport.height - padding.height);
91
	} else {
92
		var content = dojo.html.getContentBox(this.domNode.parentNode);
93
		this.resizeTo(content.width, content.height);
94
	}
95
	this.maximizeAction.style.display = "none";
96
	this.restoreAction.style.display = "";
97
	if (this.resizeHandle) {
98
		this.resizeHandle.domNode.style.display = "none";
99
	}
100
	this.drag.setDragHandle(null);
101
	this.windowState = "maximized";
102
}, minimizeWindow:function (evt) {
103
	this.hide();
104
	for (var attr in this.parentPrevious) {
105
		this.domNode.parentNode.style[attr] = this.parentPrevious[attr];
106
	}
107
	this.lastWindowState = this.windowState;
108
	this.windowState = "minimized";
109
}, restoreWindow:function (evt) {
110
	if (this.windowState == "minimized") {
111
		this.show();
112
		if (this.lastWindowState == "maximized") {
113
			this.domNode.parentNode.style.overflow = "hidden";
114
			this.windowState = "maximized";
115
		} else {
116
			this.windowState = "normal";
117
		}
118
	} else {
119
		if (this.windowState == "maximized") {
120
			for (var attr in this.previous) {
121
				this.domNode.style[attr] = this.previous[attr];
122
			}
123
			for (var attr in this.parentPrevious) {
124
				this.domNode.parentNode.style[attr] = this.parentPrevious[attr];
125
			}
126
			this.resizeTo(this.previous.width, this.previous.height);
127
			this.previous = null;
128
			this.parentPrevious = null;
129
			this.restoreAction.style.display = "none";
130
			this.maximizeAction.style.display = this.displayMaximizeAction ? "" : "none";
131
			if (this.resizeHandle) {
132
				this.resizeHandle.domNode.style.display = "";
133
			}
134
			this.drag.setDragHandle(this.titleBar);
135
			this.windowState = "normal";
136
		} else {
137
		}
138
	}
139
}, toggleDisplay:function () {
140
	if (this.windowState == "minimized") {
141
		this.restoreWindow();
142
	} else {
143
		this.minimizeWindow();
144
	}
145
}, closeWindow:function (evt) {
146
	dojo.html.removeNode(this.domNode);
147
	this.destroy();
148
}, onMouseDown:function (evt) {
149
	this.bringToTop();
150
}, bringToTop:function () {
151
	var floatingPanes = dojo.widget.manager.getWidgetsByType(this.widgetType);
152
	var windows = [];
153
	for (var x = 0; x < floatingPanes.length; x++) {
154
		if (this.widgetId != floatingPanes[x].widgetId) {
155
			windows.push(floatingPanes[x]);
156
		}
157
	}
158
	windows.sort(function (a, b) {
159
		return a.domNode.style.zIndex - b.domNode.style.zIndex;
160
	});
161
	windows.push(this);
162
	var floatingPaneStartingZ = 100;
163
	for (x = 0; x < windows.length; x++) {
164
		windows[x].domNode.style.zIndex = floatingPaneStartingZ + x * 2;
165
	}
166
}, _setInitialWindowState:function () {
167
	if (this.isShowing()) {
168
		this.width = -1;
169
		var mb = dojo.html.getMarginBox(this.domNode);
170
		this.resizeTo(mb.width, mb.height);
171
	}
172
	if (this.windowState == "maximized") {
173
		this.maximizeWindow();
174
		this.show();
175
		return;
176
	}
177
	if (this.windowState == "normal") {
178
		this.show();
179
		return;
180
	}
181
	if (this.windowState == "minimized") {
182
		this.hide();
183
		return;
184
	}
185
	this.windowState = "minimized";
186
}, _taskBarSetup:function () {
187
	var taskbar = dojo.widget.getWidgetById(this.taskBarId);
188
	if (!taskbar) {
189
		if (this._taskBarConnectAttempts < this._max_taskBarConnectAttempts) {
190
			dojo.lang.setTimeout(this, this._taskBarSetup, 50);
191
			this._taskBarConnectAttempts++;
192
		} else {
193
			dojo.debug("Unable to connect to the taskBar");
194
		}
195
		return;
196
	}
197
	taskbar.addChild(this);
198
}, showFloatingPane:function () {
199
	this.bringToTop();
200
}, onFloatingPaneShow:function () {
201
	var mb = dojo.html.getMarginBox(this.domNode);
202
	this.resizeTo(mb.width, mb.height);
203
}, resizeTo:function (width, height) {
204
	dojo.html.setMarginBox(this.domNode, {width:width, height:height});
205
	dojo.widget.html.layout(this.domNode, [{domNode:this.titleBar, layoutAlign:"top"}, {domNode:this.resizeBar, layoutAlign:"bottom"}, {domNode:this.containerNode, layoutAlign:"client"}]);
206
	dojo.widget.html.layout(this.containerNode, this.children, "top-bottom");
207
	this.bgIframe.onResized();
208
	if (this.shadow) {
209
		this.shadow.size(width, height);
210
	}
211
	this.onResized();
212
}, checkSize:function () {
213
}, destroyFloatingPane:function () {
214
	if (this.resizeHandle) {
215
		this.resizeHandle.destroy();
216
		this.resizeHandle = null;
217
	}
218
}});
219
dojo.widget.defineWidget("dojo.widget.FloatingPane", [dojo.widget.ContentPane, dojo.widget.FloatingPaneBase], {fillInTemplate:function (args, frag) {
220
	this.fillInFloatingPaneTemplate(args, frag);
221
	dojo.widget.FloatingPane.superclass.fillInTemplate.call(this, args, frag);
222
}, postCreate:function () {
223
	dojo.widget.FloatingPaneBase.prototype.postCreate.apply(this, arguments);
224
	dojo.widget.FloatingPane.superclass.postCreate.apply(this, arguments);
225
}, show:function () {
226
	dojo.widget.FloatingPane.superclass.show.apply(this, arguments);
227
	this.showFloatingPane();
228
}, onShow:function () {
229
	dojo.widget.FloatingPane.superclass.onShow.call(this);
230
	this.onFloatingPaneShow();
231
}, destroy:function () {
232
	this.destroyFloatingPane();
233
	dojo.widget.FloatingPane.superclass.destroy.apply(this, arguments);
234
}});
235
dojo.widget.defineWidget("dojo.widget.ModalFloatingPane", [dojo.widget.FloatingPane, dojo.widget.ModalDialogBase], {windowState:"minimized", displayCloseAction:true, postCreate:function () {
236
	dojo.widget.ModalDialogBase.prototype.postCreate.call(this);
237
	dojo.widget.ModalFloatingPane.superclass.postCreate.call(this);
238
}, show:function () {
239
	this.showModalDialog();
240
	dojo.widget.ModalFloatingPane.superclass.show.apply(this, arguments);
241
	this.bg.style.zIndex = this.domNode.style.zIndex - 1;
242
}, hide:function () {
243
	this.hideModalDialog();
244
	dojo.widget.ModalFloatingPane.superclass.hide.apply(this, arguments);
245
}, closeWindow:function () {
246
	this.hide();
247
	dojo.widget.ModalFloatingPane.superclass.closeWindow.apply(this, arguments);
248
}});
249