3 * Copyright(c) 2006-2010 Ext JS, Inc.
5 * http://www.extjs.com/license
8 * @class Ext.WindowGroup
9 * An object that manages a group of {@link Ext.Window} instances and provides z-order management
10 * and window activation behavior.
13 Ext.WindowGroup = function(){
19 var sortWindows = function(d1, d2){
20 return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
24 var orderWindows = function(){
25 var a = accessList, len = a.length;
28 var seed = a[0].manager.zseed;
29 for(var i = 0; i < len; i++){
31 if(win && !win.hidden){
32 win.setZIndex(seed + (i*10));
40 var setActiveWin = function(win){
43 front.setActive(false);
53 var activateLast = function(){
54 for(var i = accessList.length-1; i >=0; --i) {
55 if(!accessList[i].hidden){
56 setActiveWin(accessList[i]);
66 * The starting z-index for windows in this WindowGroup (defaults to 9000)
67 * @type Number The z-index value
72 * <p>Registers a {@link Ext.Window Window} with this WindowManager. This should not
73 * need to be called under normal circumstances. Windows are automatically registered
74 * with a {@link Ext.Window#manager manager} at construction time.</p>
75 * <p>Where this may be useful is moving Windows between two WindowManagers. For example,
76 * to bring the Ext.MessageBox dialog under the same manager as the Desktop's
77 * WindowManager in the desktop sample app:</p><code><pre>
78 var msgWin = Ext.MessageBox.getDialog();
79 MyDesktop.getDesktop().getManager().register(msgWin);
81 * @param {Window} win The Window to register.
83 register : function(win){
85 win.manager.unregister(win);
91 win.on('hide', activateLast);
95 * <p>Unregisters a {@link Ext.Window Window} from this WindowManager. This should not
96 * need to be called. Windows are automatically unregistered upon destruction.
97 * See {@link #register}.</p>
98 * @param {Window} win The Window to unregister.
100 unregister : function(win){
103 win.un('hide', activateLast);
104 accessList.remove(win);
108 * Gets a registered window by id.
109 * @param {String/Object} id The id of the window or a {@link Ext.Window} instance
110 * @return {Ext.Window}
113 return typeof id == "object" ? id : list[id];
117 * Brings the specified window to the front of any other active windows in this WindowGroup.
118 * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
119 * @return {Boolean} True if the dialog was brought to the front, else false
120 * if it was already in front
122 bringToFront : function(win){
125 win._lastAccess = new Date().getTime();
133 * Sends the specified window to the back of other active windows in this WindowGroup.
134 * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
135 * @return {Ext.Window} The window
137 sendToBack : function(win){
139 win._lastAccess = -(new Date().getTime());
145 * Hides all windows in this WindowGroup.
147 hideAll : function(){
149 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
156 * Gets the currently-active window in this WindowGroup.
157 * @return {Ext.Window} The active window
159 getActive : function(){
164 * Returns zero or more windows in this WindowGroup using the custom search function passed to this method.
165 * The function should accept a single {@link Ext.Window} reference as its only argument and should
166 * return true if the window matches the search criteria, otherwise it should return false.
167 * @param {Function} fn The search function
168 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Window being tested.
169 * that gets passed to the function if not specified)
170 * @return {Array} An array of zero or more matching windows
172 getBy : function(fn, scope){
174 for(var i = accessList.length-1; i >=0; --i) {
175 var win = accessList[i];
176 if(fn.call(scope||win, win) !== false){
184 * Executes the specified function once for every window in this WindowGroup, passing each
185 * window as the only parameter. Returning false from the function will stop the iteration.
186 * @param {Function} fn The function to execute for each item
187 * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Window in the iteration.
189 each : function(fn, scope){
191 if(list[id] && typeof list[id] != "function"){
192 if(fn.call(scope || list[id], list[id]) === false){
203 * @class Ext.WindowMgr
204 * @extends Ext.WindowGroup
205 * The default global window group that is available automatically. To have more than one group of windows
206 * with separate z-order stacks, create additional instances of {@link Ext.WindowGroup} as needed.
209 Ext.WindowMgr = new Ext.WindowGroup();