Upgrade to ExtJS 3.2.2 - Released 06/02/2010
[extjs.git] / pkgs / window-debug.js
1 /*!
2  * Ext JS Library 3.2.2
3  * Copyright(c) 2006-2010 Ext JS, Inc.
4  * licensing@extjs.com
5  * http://www.extjs.com/license
6  */
7 /**
8  * @class Ext.Window
9  * @extends Ext.Panel
10  * <p>A specialized panel intended for use as an application window.  Windows are floated, {@link #resizable}, and
11  * {@link #draggable} by default.  Windows can be {@link #maximizable maximized} to fill the viewport,
12  * restored to their prior size, and can be {@link #minimize}d.</p>
13  * <p>Windows can also be linked to a {@link Ext.WindowGroup} or managed by the {@link Ext.WindowMgr} to provide
14  * grouping, activation, to front, to back and other application-specific behavior.</p>
15  * <p>By default, Windows will be rendered to document.body. To {@link #constrain} a Window to another element
16  * specify {@link Ext.Component#renderTo renderTo}.</p>
17  * <p><b>Note:</b> By default, the <code>{@link #closable close}</code> header tool <i>destroys</i> the Window resulting in
18  * destruction of any child Components. This makes the Window object, and all its descendants <b>unusable</b>. To enable
19  * re-use of a Window, use <b><code>{@link #closeAction closeAction: 'hide'}</code></b>.</p>
20  * @constructor
21  * @param {Object} config The config object
22  * @xtype window
23  */
24 Ext.Window = Ext.extend(Ext.Panel, {
25     /**
26      * @cfg {Number} x
27      * The X position of the left edge of the window on initial showing. Defaults to centering the Window within
28      * the width of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
29      */
30     /**
31      * @cfg {Number} y
32      * The Y position of the top edge of the window on initial showing. Defaults to centering the Window within
33      * the height of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
34      */
35     /**
36      * @cfg {Boolean} modal
37      * True to make the window modal and mask everything behind it when displayed, false to display it without
38      * restricting access to other UI elements (defaults to false).
39      */
40     /**
41      * @cfg {String/Element} animateTarget
42      * Id or element from which the window should animate while opening (defaults to null with no animation).
43      */
44     /**
45      * @cfg {String} resizeHandles
46      * A valid {@link Ext.Resizable} handles config string (defaults to 'all').  Only applies when resizable = true.
47      */
48     /**
49      * @cfg {Ext.WindowGroup} manager
50      * A reference to the WindowGroup that should manage this window (defaults to {@link Ext.WindowMgr}).
51      */
52     /**
53     * @cfg {String/Number/Component} defaultButton
54     * <p>Specifies a Component to receive focus when this Window is focussed.</p>
55     * <p>This may be one of:</p><div class="mdetail-params"><ul>
56     * <li>The index of a footer Button.</li>
57     * <li>The id of a Component.</li>
58     * <li>A Component.</li>
59     * </ul></div>
60     */
61     /**
62     * @cfg {Function} onEsc
63     * Allows override of the built-in processing for the escape key. Default action
64     * is to close the Window (performing whatever action is specified in {@link #closeAction}.
65     * To prevent the Window closing when the escape key is pressed, specify this as
66     * Ext.emptyFn (See {@link Ext#emptyFn}).
67     */
68     /**
69      * @cfg {Boolean} collapsed
70      * True to render the window collapsed, false to render it expanded (defaults to false). Note that if
71      * {@link #expandOnShow} is true (the default) it will override the <tt>collapsed</tt> config and the window
72      * will always be expanded when shown.
73      */
74     /**
75      * @cfg {Boolean} maximized
76      * True to initially display the window in a maximized state. (Defaults to false).
77      */
78
79     /**
80     * @cfg {String} baseCls
81     * The base CSS class to apply to this panel's element (defaults to 'x-window').
82     */
83     baseCls : 'x-window',
84     /**
85      * @cfg {Boolean} resizable
86      * True to allow user resizing at each edge and corner of the window, false to disable resizing (defaults to true).
87      */
88     resizable : true,
89     /**
90      * @cfg {Boolean} draggable
91      * True to allow the window to be dragged by the header bar, false to disable dragging (defaults to true).  Note
92      * that by default the window will be centered in the viewport, so if dragging is disabled the window may need
93      * to be positioned programmatically after render (e.g., myWindow.setPosition(100, 100);).
94      */
95     draggable : true,
96     /**
97      * @cfg {Boolean} closable
98      * <p>True to display the 'close' tool button and allow the user to close the window, false to
99      * hide the button and disallow closing the window (defaults to true).</p>
100      * <p>By default, when close is requested by either clicking the close button in the header
101      * or pressing ESC when the Window has focus, the {@link #close} method will be called. This
102      * will <i>{@link Ext.Component#destroy destroy}</i> the Window and its content meaning that
103      * it may not be reused.</p>
104      * <p>To make closing a Window <i>hide</i> the Window so that it may be reused, set
105      * {@link #closeAction} to 'hide'.
106      */
107     closable : true,
108     /**
109      * @cfg {String} closeAction
110      * <p>The action to take when the close header tool is clicked:
111      * <div class="mdetail-params"><ul>
112      * <li><b><code>'{@link #close}'</code></b> : <b>Default</b><div class="sub-desc">
113      * {@link #close remove} the window from the DOM and {@link Ext.Component#destroy destroy}
114      * it and all descendant Components. The window will <b>not</b> be available to be
115      * redisplayed via the {@link #show} method.
116      * </div></li>
117      * <li><b><code>'{@link #hide}'</code></b> : <div class="sub-desc">
118      * {@link #hide} the window by setting visibility to hidden and applying negative offsets.
119      * The window will be available to be redisplayed via the {@link #show} method.
120      * </div></li>
121      * </ul></div>
122      * <p><b>Note:</b> This setting does not affect the {@link #close} method
123      * which will always {@link Ext.Component#destroy destroy} the window. To
124      * programatically <i>hide</i> a window, call {@link #hide}.</p>
125      */
126     closeAction : 'close',
127     /**
128      * @cfg {Boolean} constrain
129      * True to constrain the window within its containing element, false to allow it to fall outside of its
130      * containing element. By default the window will be rendered to document.body.  To render and constrain the
131      * window within another element specify {@link #renderTo}.
132      * (defaults to false).  Optionally the header only can be constrained using {@link #constrainHeader}.
133      */
134     constrain : false,
135     /**
136      * @cfg {Boolean} constrainHeader
137      * True to constrain the window header within its containing element (allowing the window body to fall outside
138      * of its containing element) or false to allow the header to fall outside its containing element (defaults to
139      * false). Optionally the entire window can be constrained using {@link #constrain}.
140      */
141     constrainHeader : false,
142     /**
143      * @cfg {Boolean} plain
144      * True to render the window body with a transparent background so that it will blend into the framing
145      * elements, false to add a lighter background color to visually highlight the body element and separate it
146      * more distinctly from the surrounding frame (defaults to false).
147      */
148     plain : false,
149     /**
150      * @cfg {Boolean} minimizable
151      * True to display the 'minimize' tool button and allow the user to minimize the window, false to hide the button
152      * and disallow minimizing the window (defaults to false).  Note that this button provides no implementation --
153      * the behavior of minimizing a window is implementation-specific, so the minimize event must be handled and a
154      * custom minimize behavior implemented for this option to be useful.
155      */
156     minimizable : false,
157     /**
158      * @cfg {Boolean} maximizable
159      * True to display the 'maximize' tool button and allow the user to maximize the window, false to hide the button
160      * and disallow maximizing the window (defaults to false).  Note that when a window is maximized, the tool button
161      * will automatically change to a 'restore' button with the appropriate behavior already built-in that will
162      * restore the window to its previous size.
163      */
164     maximizable : false,
165     /**
166      * @cfg {Number} minHeight
167      * The minimum height in pixels allowed for this window (defaults to 100).  Only applies when resizable = true.
168      */
169     minHeight : 100,
170     /**
171      * @cfg {Number} minWidth
172      * The minimum width in pixels allowed for this window (defaults to 200).  Only applies when resizable = true.
173      */
174     minWidth : 200,
175     /**
176      * @cfg {Boolean} expandOnShow
177      * True to always expand the window when it is displayed, false to keep it in its current state (which may be
178      * {@link #collapsed}) when displayed (defaults to true).
179      */
180     expandOnShow : true,
181
182     // inherited docs, same default
183     collapsible : false,
184
185     /**
186      * @cfg {Boolean} initHidden
187      * True to hide the window until show() is explicitly called (defaults to true).
188      * @deprecated
189      */
190     initHidden : undefined,
191
192     /**
193      * @cfg {Boolean} hidden
194      * Render this component hidden (default is <tt>true</tt>). If <tt>true</tt>, the
195      * {@link #hide} method will be called internally.
196      */
197     hidden : true,
198
199     // The following configs are set to provide the basic functionality of a window.
200     // Changing them would require additional code to handle correctly and should
201     // usually only be done in subclasses that can provide custom behavior.  Changing them
202     // may have unexpected or undesirable results.
203     /** @cfg {String} elements @hide */
204     elements : 'header,body',
205     /** @cfg {Boolean} frame @hide */
206     frame : true,
207     /** @cfg {Boolean} floating @hide */
208     floating : true,
209
210     // private
211     initComponent : function(){
212         this.initTools();
213         Ext.Window.superclass.initComponent.call(this);
214         this.addEvents(
215             /**
216              * @event activate
217              * Fires after the window has been visually activated via {@link #setActive}.
218              * @param {Ext.Window} this
219              */
220             /**
221              * @event deactivate
222              * Fires after the window has been visually deactivated via {@link #setActive}.
223              * @param {Ext.Window} this
224              */
225             /**
226              * @event resize
227              * Fires after the window has been resized.
228              * @param {Ext.Window} this
229              * @param {Number} width The window's new width
230              * @param {Number} height The window's new height
231              */
232             'resize',
233             /**
234              * @event maximize
235              * Fires after the window has been maximized.
236              * @param {Ext.Window} this
237              */
238             'maximize',
239             /**
240              * @event minimize
241              * Fires after the window has been minimized.
242              * @param {Ext.Window} this
243              */
244             'minimize',
245             /**
246              * @event restore
247              * Fires after the window has been restored to its original size after being maximized.
248              * @param {Ext.Window} this
249              */
250             'restore'
251         );
252         // for backwards compat, this should be removed at some point
253         if(Ext.isDefined(this.initHidden)){
254             this.hidden = this.initHidden;
255         }
256         if(this.hidden === false){
257             this.hidden = true;
258             this.show();
259         }
260     },
261
262     // private
263     getState : function(){
264         return Ext.apply(Ext.Window.superclass.getState.call(this) || {}, this.getBox(true));
265     },
266
267     // private
268     onRender : function(ct, position){
269         Ext.Window.superclass.onRender.call(this, ct, position);
270
271         if(this.plain){
272             this.el.addClass('x-window-plain');
273         }
274
275         // this element allows the Window to be focused for keyboard events
276         this.focusEl = this.el.createChild({
277                     tag: 'a', href:'#', cls:'x-dlg-focus',
278                     tabIndex:'-1', html: '&#160;'});
279         this.focusEl.swallowEvent('click', true);
280
281         this.proxy = this.el.createProxy('x-window-proxy');
282         this.proxy.enableDisplayMode('block');
283
284         if(this.modal){
285             this.mask = this.container.createChild({cls:'ext-el-mask'}, this.el.dom);
286             this.mask.enableDisplayMode('block');
287             this.mask.hide();
288             this.mon(this.mask, 'click', this.focus, this);
289         }
290         if(this.maximizable){
291             this.mon(this.header, 'dblclick', this.toggleMaximize, this);
292         }
293     },
294
295     // private
296     initEvents : function(){
297         Ext.Window.superclass.initEvents.call(this);
298         if(this.animateTarget){
299             this.setAnimateTarget(this.animateTarget);
300         }
301
302         if(this.resizable){
303             this.resizer = new Ext.Resizable(this.el, {
304                 minWidth: this.minWidth,
305                 minHeight:this.minHeight,
306                 handles: this.resizeHandles || 'all',
307                 pinned: true,
308                 resizeElement : this.resizerAction,
309                 handleCls: 'x-window-handle'
310             });
311             this.resizer.window = this;
312             this.mon(this.resizer, 'beforeresize', this.beforeResize, this);
313         }
314
315         if(this.draggable){
316             this.header.addClass('x-window-draggable');
317         }
318         this.mon(this.el, 'mousedown', this.toFront, this);
319         this.manager = this.manager || Ext.WindowMgr;
320         this.manager.register(this);
321         if(this.maximized){
322             this.maximized = false;
323             this.maximize();
324         }
325         if(this.closable){
326             var km = this.getKeyMap();
327             km.on(27, this.onEsc, this);
328             km.disable();
329         }
330     },
331
332     initDraggable : function(){
333         /**
334          * <p>If this Window is configured {@link #draggable}, this property will contain
335          * an instance of {@link Ext.dd.DD} which handles dragging the Window's DOM Element.</p>
336          * <p>This has implementations of <code>startDrag</code>, <code>onDrag</code> and <code>endDrag</code>
337          * which perform the dragging action. If extra logic is needed at these points, use
338          * {@link Function#createInterceptor createInterceptor} or {@link Function#createSequence createSequence} to
339          * augment the existing implementations.</p>
340          * @type Ext.dd.DD
341          * @property dd
342          */
343         this.dd = new Ext.Window.DD(this);
344     },
345
346    // private
347     onEsc : function(k, e){
348         e.stopEvent();
349         this[this.closeAction]();
350     },
351
352     // private
353     beforeDestroy : function(){
354         if(this.rendered){
355             this.hide();
356             this.clearAnchor();
357             Ext.destroy(
358                 this.focusEl,
359                 this.resizer,
360                 this.dd,
361                 this.proxy,
362                 this.mask
363             );
364         }
365         Ext.Window.superclass.beforeDestroy.call(this);
366     },
367
368     // private
369     onDestroy : function(){
370         if(this.manager){
371             this.manager.unregister(this);
372         }
373         Ext.Window.superclass.onDestroy.call(this);
374     },
375
376     // private
377     initTools : function(){
378         if(this.minimizable){
379             this.addTool({
380                 id: 'minimize',
381                 handler: this.minimize.createDelegate(this, [])
382             });
383         }
384         if(this.maximizable){
385             this.addTool({
386                 id: 'maximize',
387                 handler: this.maximize.createDelegate(this, [])
388             });
389             this.addTool({
390                 id: 'restore',
391                 handler: this.restore.createDelegate(this, []),
392                 hidden:true
393             });
394         }
395         if(this.closable){
396             this.addTool({
397                 id: 'close',
398                 handler: this[this.closeAction].createDelegate(this, [])
399             });
400         }
401     },
402
403     // private
404     resizerAction : function(){
405         var box = this.proxy.getBox();
406         this.proxy.hide();
407         this.window.handleResize(box);
408         return box;
409     },
410
411     // private
412     beforeResize : function(){
413         this.resizer.minHeight = Math.max(this.minHeight, this.getFrameHeight() + 40); // 40 is a magic minimum content size?
414         this.resizer.minWidth = Math.max(this.minWidth, this.getFrameWidth() + 40);
415         this.resizeBox = this.el.getBox();
416     },
417
418     // private
419     updateHandles : function(){
420         if(Ext.isIE && this.resizer){
421             this.resizer.syncHandleHeight();
422             this.el.repaint();
423         }
424     },
425
426     // private
427     handleResize : function(box){
428         var rz = this.resizeBox;
429         if(rz.x != box.x || rz.y != box.y){
430             this.updateBox(box);
431         }else{
432             this.setSize(box);
433             if (Ext.isIE6 && Ext.isStrict) {
434                 this.doLayout();
435             }
436         }
437         this.focus();
438         this.updateHandles();
439         this.saveState();
440     },
441
442     /**
443      * Focuses the window.  If a defaultButton is set, it will receive focus, otherwise the
444      * window itself will receive focus.
445      */
446     focus : function(){
447         var f = this.focusEl,
448             db = this.defaultButton,
449             t = typeof db,
450             el,
451             ct;
452         if(Ext.isDefined(db)){
453             if(Ext.isNumber(db) && this.fbar){
454                 f = this.fbar.items.get(db);
455             }else if(Ext.isString(db)){
456                 f = Ext.getCmp(db);
457             }else{
458                 f = db;
459             }
460             el = f.getEl();
461             ct = Ext.getDom(this.container);
462             if (el && ct) {
463                 if (!Ext.lib.Region.getRegion(ct).contains(Ext.lib.Region.getRegion(el.dom))){
464                     return;
465                 }
466             }
467         }
468         f = f || this.focusEl;
469         f.focus.defer(10, f);
470     },
471
472     /**
473      * Sets the target element from which the window should animate while opening.
474      * @param {String/Element} el The target element or id
475      */
476     setAnimateTarget : function(el){
477         el = Ext.get(el);
478         this.animateTarget = el;
479     },
480
481     // private
482     beforeShow : function(){
483         delete this.el.lastXY;
484         delete this.el.lastLT;
485         if(this.x === undefined || this.y === undefined){
486             var xy = this.el.getAlignToXY(this.container, 'c-c');
487             var pos = this.el.translatePoints(xy[0], xy[1]);
488             this.x = this.x === undefined? pos.left : this.x;
489             this.y = this.y === undefined? pos.top : this.y;
490         }
491         this.el.setLeftTop(this.x, this.y);
492
493         if(this.expandOnShow){
494             this.expand(false);
495         }
496
497         if(this.modal){
498             Ext.getBody().addClass('x-body-masked');
499             this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
500             this.mask.show();
501         }
502     },
503
504     /**
505      * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
506      * @param {String/Element} animateTarget (optional) The target element or id from which the window should
507      * animate while opening (defaults to null with no animation)
508      * @param {Function} callback (optional) A callback function to call after the window is displayed
509      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
510      * @return {Ext.Window} this
511      */
512     show : function(animateTarget, cb, scope){
513         if(!this.rendered){
514             this.render(Ext.getBody());
515         }
516         if(this.hidden === false){
517             this.toFront();
518             return this;
519         }
520         if(this.fireEvent('beforeshow', this) === false){
521             return this;
522         }
523         if(cb){
524             this.on('show', cb, scope, {single:true});
525         }
526         this.hidden = false;
527         if(Ext.isDefined(animateTarget)){
528             this.setAnimateTarget(animateTarget);
529         }
530         this.beforeShow();
531         if(this.animateTarget){
532             this.animShow();
533         }else{
534             this.afterShow();
535         }
536         return this;
537     },
538
539     // private
540     afterShow : function(isAnim){
541         if (this.isDestroyed){
542             return false;
543         }
544         this.proxy.hide();
545         this.el.setStyle('display', 'block');
546         this.el.show();
547         if(this.maximized){
548             this.fitContainer();
549         }
550         if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
551             this.cascade(this.setAutoScroll);
552         }
553
554         if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
555             Ext.EventManager.onWindowResize(this.onWindowResize, this);
556         }
557         this.doConstrain();
558         this.doLayout();
559         if(this.keyMap){
560             this.keyMap.enable();
561         }
562         this.toFront();
563         this.updateHandles();
564         if(isAnim && (Ext.isIE || Ext.isWebKit)){
565             var sz = this.getSize();
566             this.onResize(sz.width, sz.height);
567         }
568         this.onShow();
569         this.fireEvent('show', this);
570     },
571
572     // private
573     animShow : function(){
574         this.proxy.show();
575         this.proxy.setBox(this.animateTarget.getBox());
576         this.proxy.setOpacity(0);
577         var b = this.getBox();
578         this.el.setStyle('display', 'none');
579         this.proxy.shift(Ext.apply(b, {
580             callback: this.afterShow.createDelegate(this, [true], false),
581             scope: this,
582             easing: 'easeNone',
583             duration: 0.25,
584             opacity: 0.5
585         }));
586     },
587
588     /**
589      * Hides the window, setting it to invisible and applying negative offsets.
590      * @param {String/Element} animateTarget (optional) The target element or id to which the window should
591      * animate while hiding (defaults to null with no animation)
592      * @param {Function} callback (optional) A callback function to call after the window is hidden
593      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
594      * @return {Ext.Window} this
595      */
596     hide : function(animateTarget, cb, scope){
597         if(this.hidden || this.fireEvent('beforehide', this) === false){
598             return this;
599         }
600         if(cb){
601             this.on('hide', cb, scope, {single:true});
602         }
603         this.hidden = true;
604         if(animateTarget !== undefined){
605             this.setAnimateTarget(animateTarget);
606         }
607         if(this.modal){
608             this.mask.hide();
609             Ext.getBody().removeClass('x-body-masked');
610         }
611         if(this.animateTarget){
612             this.animHide();
613         }else{
614             this.el.hide();
615             this.afterHide();
616         }
617         return this;
618     },
619
620     // private
621     afterHide : function(){
622         this.proxy.hide();
623         if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
624             Ext.EventManager.removeResizeListener(this.onWindowResize, this);
625         }
626         if(this.keyMap){
627             this.keyMap.disable();
628         }
629         this.onHide();
630         this.fireEvent('hide', this);
631     },
632
633     // private
634     animHide : function(){
635         this.proxy.setOpacity(0.5);
636         this.proxy.show();
637         var tb = this.getBox(false);
638         this.proxy.setBox(tb);
639         this.el.hide();
640         this.proxy.shift(Ext.apply(this.animateTarget.getBox(), {
641             callback: this.afterHide,
642             scope: this,
643             duration: 0.25,
644             easing: 'easeNone',
645             opacity: 0
646         }));
647     },
648
649     /**
650      * Method that is called immediately before the <code>show</code> event is fired.
651      * Defaults to <code>Ext.emptyFn</code>.
652      */
653     onShow : Ext.emptyFn,
654
655     /**
656      * Method that is called immediately before the <code>hide</code> event is fired.
657      * Defaults to <code>Ext.emptyFn</code>.
658      */
659     onHide : Ext.emptyFn,
660
661     // private
662     onWindowResize : function(){
663         if(this.maximized){
664             this.fitContainer();
665         }
666         if(this.modal){
667             this.mask.setSize('100%', '100%');
668             var force = this.mask.dom.offsetHeight;
669             this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
670         }
671         this.doConstrain();
672     },
673
674     // private
675     doConstrain : function(){
676         if(this.constrain || this.constrainHeader){
677             var offsets;
678             if(this.constrain){
679                 offsets = {
680                     right:this.el.shadowOffset,
681                     left:this.el.shadowOffset,
682                     bottom:this.el.shadowOffset
683                 };
684             }else {
685                 var s = this.getSize();
686                 offsets = {
687                     right:-(s.width - 100),
688                     bottom:-(s.height - 25)
689                 };
690             }
691
692             var xy = this.el.getConstrainToXY(this.container, true, offsets);
693             if(xy){
694                 this.setPosition(xy[0], xy[1]);
695             }
696         }
697     },
698
699     // private - used for dragging
700     ghost : function(cls){
701         var ghost = this.createGhost(cls);
702         var box = this.getBox(true);
703         ghost.setLeftTop(box.x, box.y);
704         ghost.setWidth(box.width);
705         this.el.hide();
706         this.activeGhost = ghost;
707         return ghost;
708     },
709
710     // private
711     unghost : function(show, matchPosition){
712         if(!this.activeGhost) {
713             return;
714         }
715         if(show !== false){
716             this.el.show();
717             this.focus.defer(10, this);
718             if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
719                 this.cascade(this.setAutoScroll);
720             }
721         }
722         if(matchPosition !== false){
723             this.setPosition(this.activeGhost.getLeft(true), this.activeGhost.getTop(true));
724         }
725         this.activeGhost.hide();
726         this.activeGhost.remove();
727         delete this.activeGhost;
728     },
729
730     /**
731      * Placeholder method for minimizing the window.  By default, this method simply fires the {@link #minimize} event
732      * since the behavior of minimizing a window is application-specific.  To implement custom minimize behavior,
733      * either the minimize event can be handled or this method can be overridden.
734      * @return {Ext.Window} this
735      */
736     minimize : function(){
737         this.fireEvent('minimize', this);
738         return this;
739     },
740
741     /**
742      * <p>Closes the Window, removes it from the DOM, {@link Ext.Component#destroy destroy}s
743      * the Window object and all its descendant Components. The {@link Ext.Panel#beforeclose beforeclose}
744      * event is fired before the close happens and will cancel the close action if it returns false.<p>
745      * <p><b>Note:</b> This method is not affected by the {@link #closeAction} setting which
746      * only affects the action triggered when clicking the {@link #closable 'close' tool in the header}.
747      * To hide the Window without destroying it, call {@link #hide}.</p>
748      */
749     close : function(){
750         if(this.fireEvent('beforeclose', this) !== false){
751             if(this.hidden){
752                 this.doClose();
753             }else{
754                 this.hide(null, this.doClose, this);
755             }
756         }
757     },
758
759     // private
760     doClose : function(){
761         this.fireEvent('close', this);
762         this.destroy();
763     },
764
765     /**
766      * Fits the window within its current container and automatically replaces
767      * the {@link #maximizable 'maximize' tool button} with the 'restore' tool button.
768      * Also see {@link #toggleMaximize}.
769      * @return {Ext.Window} this
770      */
771     maximize : function(){
772         if(!this.maximized){
773             this.expand(false);
774             this.restoreSize = this.getSize();
775             this.restorePos = this.getPosition(true);
776             if (this.maximizable){
777                 this.tools.maximize.hide();
778                 this.tools.restore.show();
779             }
780             this.maximized = true;
781             this.el.disableShadow();
782
783             if(this.dd){
784                 this.dd.lock();
785             }
786             if(this.collapsible){
787                 this.tools.toggle.hide();
788             }
789             this.el.addClass('x-window-maximized');
790             this.container.addClass('x-window-maximized-ct');
791
792             this.setPosition(0, 0);
793             this.fitContainer();
794             this.fireEvent('maximize', this);
795         }
796         return this;
797     },
798
799     /**
800      * Restores a {@link #maximizable maximized}  window back to its original
801      * size and position prior to being maximized and also replaces
802      * the 'restore' tool button with the 'maximize' tool button.
803      * Also see {@link #toggleMaximize}.
804      * @return {Ext.Window} this
805      */
806     restore : function(){
807         if(this.maximized){
808             var t = this.tools;
809             this.el.removeClass('x-window-maximized');
810             if(t.restore){
811                 t.restore.hide();
812             }
813             if(t.maximize){
814                 t.maximize.show();
815             }
816             this.setPosition(this.restorePos[0], this.restorePos[1]);
817             this.setSize(this.restoreSize.width, this.restoreSize.height);
818             delete this.restorePos;
819             delete this.restoreSize;
820             this.maximized = false;
821             this.el.enableShadow(true);
822
823             if(this.dd){
824                 this.dd.unlock();
825             }
826             if(this.collapsible && t.toggle){
827                 t.toggle.show();
828             }
829             this.container.removeClass('x-window-maximized-ct');
830
831             this.doConstrain();
832             this.fireEvent('restore', this);
833         }
834         return this;
835     },
836
837     /**
838      * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized
839      * state of the window.
840      * @return {Ext.Window} this
841      */
842     toggleMaximize : function(){
843         return this[this.maximized ? 'restore' : 'maximize']();
844     },
845
846     // private
847     fitContainer : function(){
848         var vs = this.container.getViewSize(false);
849         this.setSize(vs.width, vs.height);
850     },
851
852     // private
853     // z-index is managed by the WindowManager and may be overwritten at any time
854     setZIndex : function(index){
855         if(this.modal){
856             this.mask.setStyle('z-index', index);
857         }
858         this.el.setZIndex(++index);
859         index += 5;
860
861         if(this.resizer){
862             this.resizer.proxy.setStyle('z-index', ++index);
863         }
864
865         this.lastZIndex = index;
866     },
867
868     /**
869      * Aligns the window to the specified element
870      * @param {Mixed} element The element to align to.
871      * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.Element#alignTo} for more details).
872      * @param {Array} offsets (optional) Offset the positioning by [x, y]
873      * @return {Ext.Window} this
874      */
875     alignTo : function(element, position, offsets){
876         var xy = this.el.getAlignToXY(element, position, offsets);
877         this.setPagePosition(xy[0], xy[1]);
878         return this;
879     },
880
881     /**
882      * Anchors this window to another element and realigns it when the window is resized or scrolled.
883      * @param {Mixed} element The element to align to.
884      * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details)
885      * @param {Array} offsets (optional) Offset the positioning by [x, y]
886      * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
887      * is a number, it is used as the buffer delay (defaults to 50ms).
888      * @return {Ext.Window} this
889      */
890     anchorTo : function(el, alignment, offsets, monitorScroll){
891         this.clearAnchor();
892         this.anchorTarget = {
893             el: el,
894             alignment: alignment,
895             offsets: offsets
896         };
897
898         Ext.EventManager.onWindowResize(this.doAnchor, this);
899         var tm = typeof monitorScroll;
900         if(tm != 'undefined'){
901             Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
902                 {buffer: tm == 'number' ? monitorScroll : 50});
903         }
904         return this.doAnchor();
905     },
906
907     /**
908      * Performs the anchor, using the saved anchorTarget property.
909      * @return {Ext.Window} this
910      * @private
911      */
912     doAnchor : function(){
913         var o = this.anchorTarget;
914         this.alignTo(o.el, o.alignment, o.offsets);
915         return this;
916     },
917
918     /**
919      * Removes any existing anchor from this window. See {@link #anchorTo}.
920      * @return {Ext.Window} this
921      */
922     clearAnchor : function(){
923         if(this.anchorTarget){
924             Ext.EventManager.removeResizeListener(this.doAnchor, this);
925             Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
926             delete this.anchorTarget;
927         }
928         return this;
929     },
930
931     /**
932      * Brings this window to the front of any other visible windows
933      * @param {Boolean} e (optional) Specify <tt>false</tt> to prevent the window from being focused.
934      * @return {Ext.Window} this
935      */
936     toFront : function(e){
937         if(this.manager.bringToFront(this)){
938             if(!e || !e.getTarget().focus){
939                 this.focus();
940             }
941         }
942         return this;
943     },
944
945     /**
946      * Makes this the active window by showing its shadow, or deactivates it by hiding its shadow.  This method also
947      * fires the {@link #activate} or {@link #deactivate} event depending on which action occurred. This method is
948      * called internally by {@link Ext.WindowMgr}.
949      * @param {Boolean} active True to activate the window, false to deactivate it (defaults to false)
950      */
951     setActive : function(active){
952         if(active){
953             if(!this.maximized){
954                 this.el.enableShadow(true);
955             }
956             this.fireEvent('activate', this);
957         }else{
958             this.el.disableShadow();
959             this.fireEvent('deactivate', this);
960         }
961     },
962
963     /**
964      * Sends this window to the back of (lower z-index than) any other visible windows
965      * @return {Ext.Window} this
966      */
967     toBack : function(){
968         this.manager.sendToBack(this);
969         return this;
970     },
971
972     /**
973      * Centers this window in the viewport
974      * @return {Ext.Window} this
975      */
976     center : function(){
977         var xy = this.el.getAlignToXY(this.container, 'c-c');
978         this.setPagePosition(xy[0], xy[1]);
979         return this;
980     }
981
982     /**
983      * @cfg {Boolean} autoWidth @hide
984      **/
985 });
986 Ext.reg('window', Ext.Window);
987
988 // private - custom Window DD implementation
989 Ext.Window.DD = function(win){
990     this.win = win;
991     Ext.Window.DD.superclass.constructor.call(this, win.el.id, 'WindowDD-'+win.id);
992     this.setHandleElId(win.header.id);
993     this.scroll = false;
994 };
995
996 Ext.extend(Ext.Window.DD, Ext.dd.DD, {
997     moveOnly:true,
998     headerOffsets:[100, 25],
999     startDrag : function(){
1000         var w = this.win;
1001         this.proxy = w.ghost();
1002         if(w.constrain !== false){
1003             var so = w.el.shadowOffset;
1004             this.constrainTo(w.container, {right: so, left: so, bottom: so});
1005         }else if(w.constrainHeader !== false){
1006             var s = this.proxy.getSize();
1007             this.constrainTo(w.container, {right: -(s.width-this.headerOffsets[0]), bottom: -(s.height-this.headerOffsets[1])});
1008         }
1009     },
1010     b4Drag : Ext.emptyFn,
1011
1012     onDrag : function(e){
1013         this.alignElWithMouse(this.proxy, e.getPageX(), e.getPageY());
1014     },
1015
1016     endDrag : function(e){
1017         this.win.unghost();
1018         this.win.saveState();
1019     }
1020 });
1021 /**
1022  * @class Ext.WindowGroup
1023  * An object that manages a group of {@link Ext.Window} instances and provides z-order management
1024  * and window activation behavior.
1025  * @constructor
1026  */
1027 Ext.WindowGroup = function(){
1028     var list = {};
1029     var accessList = [];
1030     var front = null;
1031
1032     // private
1033     var sortWindows = function(d1, d2){
1034         return (!d1._lastAccess || d1._lastAccess < d2._lastAccess) ? -1 : 1;
1035     };
1036
1037     // private
1038     var orderWindows = function(){
1039         var a = accessList, len = a.length;
1040         if(len > 0){
1041             a.sort(sortWindows);
1042             var seed = a[0].manager.zseed;
1043             for(var i = 0; i < len; i++){
1044                 var win = a[i];
1045                 if(win && !win.hidden){
1046                     win.setZIndex(seed + (i*10));
1047                 }
1048             }
1049         }
1050         activateLast();
1051     };
1052
1053     // private
1054     var setActiveWin = function(win){
1055         if(win != front){
1056             if(front){
1057                 front.setActive(false);
1058             }
1059             front = win;
1060             if(win){
1061                 win.setActive(true);
1062             }
1063         }
1064     };
1065
1066     // private
1067     var activateLast = function(){
1068         for(var i = accessList.length-1; i >=0; --i) {
1069             if(!accessList[i].hidden){
1070                 setActiveWin(accessList[i]);
1071                 return;
1072             }
1073         }
1074         // none to activate
1075         setActiveWin(null);
1076     };
1077
1078     return {
1079         /**
1080          * The starting z-index for windows in this WindowGroup (defaults to 9000)
1081          * @type Number The z-index value
1082          */
1083         zseed : 9000,
1084
1085         /**
1086          * <p>Registers a {@link Ext.Window Window} with this WindowManager. This should not
1087          * need to be called under normal circumstances. Windows are automatically registered
1088          * with a {@link Ext.Window#manager manager} at construction time.</p>
1089          * <p>Where this may be useful is moving Windows between two WindowManagers. For example,
1090          * to bring the Ext.MessageBox dialog under the same manager as the Desktop's
1091          * WindowManager in the desktop sample app:</p><code><pre>
1092 var msgWin = Ext.MessageBox.getDialog();
1093 MyDesktop.getDesktop().getManager().register(msgWin);
1094 </pre></code>
1095          * @param {Window} win The Window to register.
1096          */
1097         register : function(win){
1098             if(win.manager){
1099                 win.manager.unregister(win);
1100             }
1101             win.manager = this;
1102
1103             list[win.id] = win;
1104             accessList.push(win);
1105             win.on('hide', activateLast);
1106         },
1107
1108         /**
1109          * <p>Unregisters a {@link Ext.Window Window} from this WindowManager. This should not
1110          * need to be called. Windows are automatically unregistered upon destruction.
1111          * See {@link #register}.</p>
1112          * @param {Window} win The Window to unregister.
1113          */
1114         unregister : function(win){
1115             delete win.manager;
1116             delete list[win.id];
1117             win.un('hide', activateLast);
1118             accessList.remove(win);
1119         },
1120
1121         /**
1122          * Gets a registered window by id.
1123          * @param {String/Object} id The id of the window or a {@link Ext.Window} instance
1124          * @return {Ext.Window}
1125          */
1126         get : function(id){
1127             return typeof id == "object" ? id : list[id];
1128         },
1129
1130         /**
1131          * Brings the specified window to the front of any other active windows in this WindowGroup.
1132          * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
1133          * @return {Boolean} True if the dialog was brought to the front, else false
1134          * if it was already in front
1135          */
1136         bringToFront : function(win){
1137             win = this.get(win);
1138             if(win != front){
1139                 win._lastAccess = new Date().getTime();
1140                 orderWindows();
1141                 return true;
1142             }
1143             return false;
1144         },
1145
1146         /**
1147          * Sends the specified window to the back of other active windows in this WindowGroup.
1148          * @param {String/Object} win The id of the window or a {@link Ext.Window} instance
1149          * @return {Ext.Window} The window
1150          */
1151         sendToBack : function(win){
1152             win = this.get(win);
1153             win._lastAccess = -(new Date().getTime());
1154             orderWindows();
1155             return win;
1156         },
1157
1158         /**
1159          * Hides all windows in this WindowGroup.
1160          */
1161         hideAll : function(){
1162             for(var id in list){
1163                 if(list[id] && typeof list[id] != "function" && list[id].isVisible()){
1164                     list[id].hide();
1165                 }
1166             }
1167         },
1168
1169         /**
1170          * Gets the currently-active window in this WindowGroup.
1171          * @return {Ext.Window} The active window
1172          */
1173         getActive : function(){
1174             return front;
1175         },
1176
1177         /**
1178          * Returns zero or more windows in this WindowGroup using the custom search function passed to this method.
1179          * The function should accept a single {@link Ext.Window} reference as its only argument and should
1180          * return true if the window matches the search criteria, otherwise it should return false.
1181          * @param {Function} fn The search function
1182          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Window being tested.
1183          * that gets passed to the function if not specified)
1184          * @return {Array} An array of zero or more matching windows
1185          */
1186         getBy : function(fn, scope){
1187             var r = [];
1188             for(var i = accessList.length-1; i >=0; --i) {
1189                 var win = accessList[i];
1190                 if(fn.call(scope||win, win) !== false){
1191                     r.push(win);
1192                 }
1193             }
1194             return r;
1195         },
1196
1197         /**
1198          * Executes the specified function once for every window in this WindowGroup, passing each
1199          * window as the only parameter. Returning false from the function will stop the iteration.
1200          * @param {Function} fn The function to execute for each item
1201          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current Window in the iteration.
1202          */
1203         each : function(fn, scope){
1204             for(var id in list){
1205                 if(list[id] && typeof list[id] != "function"){
1206                     if(fn.call(scope || list[id], list[id]) === false){
1207                         return;
1208                     }
1209                 }
1210             }
1211         }
1212     };
1213 };
1214
1215
1216 /**
1217  * @class Ext.WindowMgr
1218  * @extends Ext.WindowGroup
1219  * The default global window group that is available automatically.  To have more than one group of windows
1220  * with separate z-order stacks, create additional instances of {@link Ext.WindowGroup} as needed.
1221  * @singleton
1222  */
1223 Ext.WindowMgr = new Ext.WindowGroup();/**
1224  * @class Ext.MessageBox
1225  * <p>Utility class for generating different styles of message boxes.  The alias Ext.Msg can also be used.<p/>
1226  * <p>Note that the MessageBox is asynchronous.  Unlike a regular JavaScript <code>alert</code> (which will halt
1227  * browser execution), showing a MessageBox will not cause the code to stop.  For this reason, if you have code
1228  * that should only run <em>after</em> some user feedback from the MessageBox, you must use a callback function
1229  * (see the <code>function</code> parameter for {@link #show} for more details).</p>
1230  * <p>Example usage:</p>
1231  *<pre><code>
1232 // Basic alert:
1233 Ext.Msg.alert('Status', 'Changes saved successfully.');
1234
1235 // Prompt for user data and process the result using a callback:
1236 Ext.Msg.prompt('Name', 'Please enter your name:', function(btn, text){
1237     if (btn == 'ok'){
1238         // process text value and close...
1239     }
1240 });
1241
1242 // Show a dialog using config options:
1243 Ext.Msg.show({
1244    title:'Save Changes?',
1245    msg: 'You are closing a tab that has unsaved changes. Would you like to save your changes?',
1246    buttons: Ext.Msg.YESNOCANCEL,
1247    fn: processResult,
1248    animEl: 'elId',
1249    icon: Ext.MessageBox.QUESTION
1250 });
1251 </code></pre>
1252  * @singleton
1253  */
1254 Ext.MessageBox = function(){
1255     var dlg, opt, mask, waitTimer,
1256         bodyEl, msgEl, textboxEl, textareaEl, progressBar, pp, iconEl, spacerEl,
1257         buttons, activeTextEl, bwidth, bufferIcon = '', iconCls = '',
1258         buttonNames = ['ok', 'yes', 'no', 'cancel'];
1259
1260     // private
1261     var handleButton = function(button){
1262         buttons[button].blur();
1263         if(dlg.isVisible()){
1264             dlg.hide();
1265             handleHide();
1266             Ext.callback(opt.fn, opt.scope||window, [button, activeTextEl.dom.value, opt], 1);
1267         }
1268     };
1269
1270     // private
1271     var handleHide = function(){
1272         if(opt && opt.cls){
1273             dlg.el.removeClass(opt.cls);
1274         }
1275         progressBar.reset();        
1276     };
1277
1278     // private
1279     var handleEsc = function(d, k, e){
1280         if(opt && opt.closable !== false){
1281             dlg.hide();
1282             handleHide();
1283         }
1284         if(e){
1285             e.stopEvent();
1286         }
1287     };
1288
1289     // private
1290     var updateButtons = function(b){
1291         var width = 0,
1292             cfg;
1293         if(!b){
1294             Ext.each(buttonNames, function(name){
1295                 buttons[name].hide();
1296             });
1297             return width;
1298         }
1299         dlg.footer.dom.style.display = '';
1300         Ext.iterate(buttons, function(name, btn){
1301             cfg = b[name];
1302             if(cfg){
1303                 btn.show();
1304                 btn.setText(Ext.isString(cfg) ? cfg : Ext.MessageBox.buttonText[name]);
1305                 width += btn.getEl().getWidth() + 15;
1306             }else{
1307                 btn.hide();
1308             }
1309         });
1310         return width;
1311     };
1312
1313     return {
1314         /**
1315          * Returns a reference to the underlying {@link Ext.Window} element
1316          * @return {Ext.Window} The window
1317          */
1318         getDialog : function(titleText){
1319            if(!dlg){
1320                 var btns = [];
1321                 
1322                 buttons = {};
1323                 Ext.each(buttonNames, function(name){
1324                     btns.push(buttons[name] = new Ext.Button({
1325                         text: this.buttonText[name],
1326                         handler: handleButton.createCallback(name),
1327                         hideMode: 'offsets'
1328                     }));
1329                 }, this);
1330                 dlg = new Ext.Window({
1331                     autoCreate : true,
1332                     title:titleText,
1333                     resizable:false,
1334                     constrain:true,
1335                     constrainHeader:true,
1336                     minimizable : false,
1337                     maximizable : false,
1338                     stateful: false,
1339                     modal: true,
1340                     shim:true,
1341                     buttonAlign:"center",
1342                     width:400,
1343                     height:100,
1344                     minHeight: 80,
1345                     plain:true,
1346                     footer:true,
1347                     closable:true,
1348                     close : function(){
1349                         if(opt && opt.buttons && opt.buttons.no && !opt.buttons.cancel){
1350                             handleButton("no");
1351                         }else{
1352                             handleButton("cancel");
1353                         }
1354                     },
1355                     fbar: new Ext.Toolbar({
1356                         items: btns,
1357                         enableOverflow: false
1358                     })
1359                 });
1360                 dlg.render(document.body);
1361                 dlg.getEl().addClass('x-window-dlg');
1362                 mask = dlg.mask;
1363                 bodyEl = dlg.body.createChild({
1364                     html:'<div class="ext-mb-icon"></div><div class="ext-mb-content"><span class="ext-mb-text"></span><br /><div class="ext-mb-fix-cursor"><input type="text" class="ext-mb-input" /><textarea class="ext-mb-textarea"></textarea></div></div>'
1365                 });
1366                 iconEl = Ext.get(bodyEl.dom.firstChild);
1367                 var contentEl = bodyEl.dom.childNodes[1];
1368                 msgEl = Ext.get(contentEl.firstChild);
1369                 textboxEl = Ext.get(contentEl.childNodes[2].firstChild);
1370                 textboxEl.enableDisplayMode();
1371                 textboxEl.addKeyListener([10,13], function(){
1372                     if(dlg.isVisible() && opt && opt.buttons){
1373                         if(opt.buttons.ok){
1374                             handleButton("ok");
1375                         }else if(opt.buttons.yes){
1376                             handleButton("yes");
1377                         }
1378                     }
1379                 });
1380                 textareaEl = Ext.get(contentEl.childNodes[2].childNodes[1]);
1381                 textareaEl.enableDisplayMode();
1382                 progressBar = new Ext.ProgressBar({
1383                     renderTo:bodyEl
1384                 });
1385                bodyEl.createChild({cls:'x-clear'});
1386             }
1387             return dlg;
1388         },
1389
1390         /**
1391          * Updates the message box body text
1392          * @param {String} text (optional) Replaces the message box element's innerHTML with the specified string (defaults to
1393          * the XHTML-compliant non-breaking space character '&amp;#160;')
1394          * @return {Ext.MessageBox} this
1395          */
1396         updateText : function(text){
1397             if(!dlg.isVisible() && !opt.width){
1398                 dlg.setSize(this.maxWidth, 100); // resize first so content is never clipped from previous shows
1399             }
1400             msgEl.update(text || '&#160;');
1401
1402             var iw = iconCls != '' ? (iconEl.getWidth() + iconEl.getMargins('lr')) : 0,
1403                 mw = msgEl.getWidth() + msgEl.getMargins('lr'),
1404                 fw = dlg.getFrameWidth('lr'),
1405                 bw = dlg.body.getFrameWidth('lr'),
1406                 w;
1407                 
1408             if (Ext.isIE && iw > 0){
1409                 //3 pixels get subtracted in the icon CSS for an IE margin issue,
1410                 //so we have to add it back here for the overall width to be consistent
1411                 iw += 3;
1412             }
1413             w = Math.max(Math.min(opt.width || iw+mw+fw+bw, opt.maxWidth || this.maxWidth),
1414                     Math.max(opt.minWidth || this.minWidth, bwidth || 0));
1415
1416             if(opt.prompt === true){
1417                 activeTextEl.setWidth(w-iw-fw-bw);
1418             }
1419             if(opt.progress === true || opt.wait === true){
1420                 progressBar.setSize(w-iw-fw-bw);
1421             }
1422             if(Ext.isIE && w == bwidth){
1423                 w += 4; //Add offset when the content width is smaller than the buttons.    
1424             }
1425             dlg.setSize(w, 'auto').center();
1426             return this;
1427         },
1428
1429         /**
1430          * Updates a progress-style message box's text and progress bar. Only relevant on message boxes
1431          * initiated via {@link Ext.MessageBox#progress} or {@link Ext.MessageBox#wait},
1432          * or by calling {@link Ext.MessageBox#show} with progress: true.
1433          * @param {Number} value Any number between 0 and 1 (e.g., .5, defaults to 0)
1434          * @param {String} progressText The progress text to display inside the progress bar (defaults to '')
1435          * @param {String} msg The message box's body text is replaced with the specified string (defaults to undefined
1436          * so that any existing body text will not get overwritten by default unless a new value is passed in)
1437          * @return {Ext.MessageBox} this
1438          */
1439         updateProgress : function(value, progressText, msg){
1440             progressBar.updateProgress(value, progressText);
1441             if(msg){
1442                 this.updateText(msg);
1443             }
1444             return this;
1445         },
1446
1447         /**
1448          * Returns true if the message box is currently displayed
1449          * @return {Boolean} True if the message box is visible, else false
1450          */
1451         isVisible : function(){
1452             return dlg && dlg.isVisible();
1453         },
1454
1455         /**
1456          * Hides the message box if it is displayed
1457          * @return {Ext.MessageBox} this
1458          */
1459         hide : function(){
1460             var proxy = dlg ? dlg.activeGhost : null;
1461             if(this.isVisible() || proxy){
1462                 dlg.hide();
1463                 handleHide();
1464                 if (proxy){
1465                     // unghost is a private function, but i saw no better solution
1466                     // to fix the locking problem when dragging while it closes
1467                     dlg.unghost(false, false);
1468                 } 
1469             }
1470             return this;
1471         },
1472
1473         /**
1474          * Displays a new message box, or reinitializes an existing message box, based on the config options
1475          * passed in. All display functions (e.g. prompt, alert, etc.) on MessageBox call this function internally,
1476          * although those calls are basic shortcuts and do not support all of the config options allowed here.
1477          * @param {Object} config The following config options are supported: <ul>
1478          * <li><b>animEl</b> : String/Element<div class="sub-desc">An id or Element from which the message box should animate as it
1479          * opens and closes (defaults to undefined)</div></li>
1480          * <li><b>buttons</b> : Object/Boolean<div class="sub-desc">A button config object (e.g., Ext.MessageBox.OKCANCEL or {ok:'Foo',
1481          * cancel:'Bar'}), or false to not show any buttons (defaults to false)</div></li>
1482          * <li><b>closable</b> : Boolean<div class="sub-desc">False to hide the top-right close button (defaults to true). Note that
1483          * progress and wait dialogs will ignore this property and always hide the close button as they can only
1484          * be closed programmatically.</div></li>
1485          * <li><b>cls</b> : String<div class="sub-desc">A custom CSS class to apply to the message box's container element</div></li>
1486          * <li><b>defaultTextHeight</b> : Number<div class="sub-desc">The default height in pixels of the message box's multiline textarea
1487          * if displayed (defaults to 75)</div></li>
1488          * <li><b>fn</b> : Function<div class="sub-desc">A callback function which is called when the dialog is dismissed either
1489          * by clicking on the configured buttons, or on the dialog close button, or by pressing
1490          * the return button to enter input.
1491          * <p>Progress and wait dialogs will ignore this option since they do not respond to user
1492          * actions and can only be closed programmatically, so any required function should be called
1493          * by the same code after it closes the dialog. Parameters passed:<ul>
1494          * <li><b>buttonId</b> : String<div class="sub-desc">The ID of the button pressed, one of:<div class="sub-desc"><ul>
1495          * <li><tt>ok</tt></li>
1496          * <li><tt>yes</tt></li>
1497          * <li><tt>no</tt></li>
1498          * <li><tt>cancel</tt></li>
1499          * </ul></div></div></li>
1500          * <li><b>text</b> : String<div class="sub-desc">Value of the input field if either <tt><a href="#show-option-prompt" ext:member="show-option-prompt" ext:cls="Ext.MessageBox">prompt</a></tt>
1501          * or <tt><a href="#show-option-multiline" ext:member="show-option-multiline" ext:cls="Ext.MessageBox">multiline</a></tt> is true</div></li>
1502          * <li><b>opt</b> : Object<div class="sub-desc">The config object passed to show.</div></li>
1503          * </ul></p></div></li>
1504          * <li><b>scope</b> : Object<div class="sub-desc">The scope of the callback function</div></li>
1505          * <li><b>icon</b> : String<div class="sub-desc">A CSS class that provides a background image to be used as the body icon for the
1506          * dialog (e.g. Ext.MessageBox.WARNING or 'custom-class') (defaults to '')</div></li>
1507          * <li><b>iconCls</b> : String<div class="sub-desc">The standard {@link Ext.Window#iconCls} to
1508          * add an optional header icon (defaults to '')</div></li>
1509          * <li><b>maxWidth</b> : Number<div class="sub-desc">The maximum width in pixels of the message box (defaults to 600)</div></li>
1510          * <li><b>minWidth</b> : Number<div class="sub-desc">The minimum width in pixels of the message box (defaults to 100)</div></li>
1511          * <li><b>modal</b> : Boolean<div class="sub-desc">False to allow user interaction with the page while the message box is
1512          * displayed (defaults to true)</div></li>
1513          * <li><b>msg</b> : String<div class="sub-desc">A string that will replace the existing message box body text (defaults to the
1514          * XHTML-compliant non-breaking space character '&amp;#160;')</div></li>
1515          * <li><a id="show-option-multiline"></a><b>multiline</b> : Boolean<div class="sub-desc">
1516          * True to prompt the user to enter multi-line text (defaults to false)</div></li>
1517          * <li><b>progress</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
1518          * <li><b>progressText</b> : String<div class="sub-desc">The text to display inside the progress bar if progress = true (defaults to '')</div></li>
1519          * <li><a id="show-option-prompt"></a><b>prompt</b> : Boolean<div class="sub-desc">True to prompt the user to enter single-line text (defaults to false)</div></li>
1520          * <li><b>proxyDrag</b> : Boolean<div class="sub-desc">True to display a lightweight proxy while dragging (defaults to false)</div></li>
1521          * <li><b>title</b> : String<div class="sub-desc">The title text</div></li>
1522          * <li><b>value</b> : String<div class="sub-desc">The string value to set into the active textbox element if displayed</div></li>
1523          * <li><b>wait</b> : Boolean<div class="sub-desc">True to display a progress bar (defaults to false)</div></li>
1524          * <li><b>waitConfig</b> : Object<div class="sub-desc">A {@link Ext.ProgressBar#waitConfig} object (applies only if wait = true)</div></li>
1525          * <li><b>width</b> : Number<div class="sub-desc">The width of the dialog in pixels</div></li>
1526          * </ul>
1527          * Example usage:
1528          * <pre><code>
1529 Ext.Msg.show({
1530    title: 'Address',
1531    msg: 'Please enter your address:',
1532    width: 300,
1533    buttons: Ext.MessageBox.OKCANCEL,
1534    multiline: true,
1535    fn: saveAddress,
1536    animEl: 'addAddressBtn',
1537    icon: Ext.MessageBox.INFO
1538 });
1539 </code></pre>
1540          * @return {Ext.MessageBox} this
1541          */
1542         show : function(options){
1543             if(this.isVisible()){
1544                 this.hide();
1545             }
1546             opt = options;
1547             var d = this.getDialog(opt.title || "&#160;");
1548
1549             d.setTitle(opt.title || "&#160;");
1550             var allowClose = (opt.closable !== false && opt.progress !== true && opt.wait !== true);
1551             d.tools.close.setDisplayed(allowClose);
1552             activeTextEl = textboxEl;
1553             opt.prompt = opt.prompt || (opt.multiline ? true : false);
1554             if(opt.prompt){
1555                 if(opt.multiline){
1556                     textboxEl.hide();
1557                     textareaEl.show();
1558                     textareaEl.setHeight(Ext.isNumber(opt.multiline) ? opt.multiline : this.defaultTextHeight);
1559                     activeTextEl = textareaEl;
1560                 }else{
1561                     textboxEl.show();
1562                     textareaEl.hide();
1563                 }
1564             }else{
1565                 textboxEl.hide();
1566                 textareaEl.hide();
1567             }
1568             activeTextEl.dom.value = opt.value || "";
1569             if(opt.prompt){
1570                 d.focusEl = activeTextEl;
1571             }else{
1572                 var bs = opt.buttons;
1573                 var db = null;
1574                 if(bs && bs.ok){
1575                     db = buttons["ok"];
1576                 }else if(bs && bs.yes){
1577                     db = buttons["yes"];
1578                 }
1579                 if (db){
1580                     d.focusEl = db;
1581                 }
1582             }
1583             if(Ext.isDefined(opt.iconCls)){
1584               d.setIconClass(opt.iconCls);
1585             }
1586             this.setIcon(Ext.isDefined(opt.icon) ? opt.icon : bufferIcon);
1587             bwidth = updateButtons(opt.buttons);
1588             progressBar.setVisible(opt.progress === true || opt.wait === true);
1589             this.updateProgress(0, opt.progressText);
1590             this.updateText(opt.msg);
1591             if(opt.cls){
1592                 d.el.addClass(opt.cls);
1593             }
1594             d.proxyDrag = opt.proxyDrag === true;
1595             d.modal = opt.modal !== false;
1596             d.mask = opt.modal !== false ? mask : false;
1597             if(!d.isVisible()){
1598                 // force it to the end of the z-index stack so it gets a cursor in FF
1599                 document.body.appendChild(dlg.el.dom);
1600                 d.setAnimateTarget(opt.animEl);
1601                 //workaround for window internally enabling keymap in afterShow
1602                 d.on('show', function(){
1603                     if(allowClose === true){
1604                         d.keyMap.enable();
1605                     }else{
1606                         d.keyMap.disable();
1607                     }
1608                 }, this, {single:true});
1609                 d.show(opt.animEl);
1610             }
1611             if(opt.wait === true){
1612                 progressBar.wait(opt.waitConfig);
1613             }
1614             return this;
1615         },
1616
1617         /**
1618          * Adds the specified icon to the dialog.  By default, the class 'ext-mb-icon' is applied for default
1619          * styling, and the class passed in is expected to supply the background image url. Pass in empty string ('')
1620          * to clear any existing icon. This method must be called before the MessageBox is shown.
1621          * The following built-in icon classes are supported, but you can also pass in a custom class name:
1622          * <pre>
1623 Ext.MessageBox.INFO
1624 Ext.MessageBox.WARNING
1625 Ext.MessageBox.QUESTION
1626 Ext.MessageBox.ERROR
1627          *</pre>
1628          * @param {String} icon A CSS classname specifying the icon's background image url, or empty string to clear the icon
1629          * @return {Ext.MessageBox} this
1630          */
1631         setIcon : function(icon){
1632             if(!dlg){
1633                 bufferIcon = icon;
1634                 return;
1635             }
1636             bufferIcon = undefined;
1637             if(icon && icon != ''){
1638                 iconEl.removeClass('x-hidden');
1639                 iconEl.replaceClass(iconCls, icon);
1640                 bodyEl.addClass('x-dlg-icon');
1641                 iconCls = icon;
1642             }else{
1643                 iconEl.replaceClass(iconCls, 'x-hidden');
1644                 bodyEl.removeClass('x-dlg-icon');
1645                 iconCls = '';
1646             }
1647             return this;
1648         },
1649
1650         /**
1651          * Displays a message box with a progress bar.  This message box has no buttons and is not closeable by
1652          * the user.  You are responsible for updating the progress bar as needed via {@link Ext.MessageBox#updateProgress}
1653          * and closing the message box when the process is complete.
1654          * @param {String} title The title bar text
1655          * @param {String} msg The message box body text
1656          * @param {String} progressText (optional) The text to display inside the progress bar (defaults to '')
1657          * @return {Ext.MessageBox} this
1658          */
1659         progress : function(title, msg, progressText){
1660             this.show({
1661                 title : title,
1662                 msg : msg,
1663                 buttons: false,
1664                 progress:true,
1665                 closable:false,
1666                 minWidth: this.minProgressWidth,
1667                 progressText: progressText
1668             });
1669             return this;
1670         },
1671
1672         /**
1673          * Displays a message box with an infinitely auto-updating progress bar.  This can be used to block user
1674          * interaction while waiting for a long-running process to complete that does not have defined intervals.
1675          * You are responsible for closing the message box when the process is complete.
1676          * @param {String} msg The message box body text
1677          * @param {String} title (optional) The title bar text
1678          * @param {Object} config (optional) A {@link Ext.ProgressBar#waitConfig} object
1679          * @return {Ext.MessageBox} this
1680          */
1681         wait : function(msg, title, config){
1682             this.show({
1683                 title : title,
1684                 msg : msg,
1685                 buttons: false,
1686                 closable:false,
1687                 wait:true,
1688                 modal:true,
1689                 minWidth: this.minProgressWidth,
1690                 waitConfig: config
1691             });
1692             return this;
1693         },
1694
1695         /**
1696          * Displays a standard read-only message box with an OK button (comparable to the basic JavaScript alert prompt).
1697          * If a callback function is passed it will be called after the user clicks the button, and the
1698          * id of the button that was clicked will be passed as the only parameter to the callback
1699          * (could also be the top-right close button).
1700          * @param {String} title The title bar text
1701          * @param {String} msg The message box body text
1702          * @param {Function} fn (optional) The callback function invoked after the message box is closed
1703          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
1704          * @return {Ext.MessageBox} this
1705          */
1706         alert : function(title, msg, fn, scope){
1707             this.show({
1708                 title : title,
1709                 msg : msg,
1710                 buttons: this.OK,
1711                 fn: fn,
1712                 scope : scope,
1713                 minWidth: this.minWidth
1714             });
1715             return this;
1716         },
1717
1718         /**
1719          * Displays a confirmation message box with Yes and No buttons (comparable to JavaScript's confirm).
1720          * If a callback function is passed it will be called after the user clicks either button,
1721          * and the id of the button that was clicked will be passed as the only parameter to the callback
1722          * (could also be the top-right close button).
1723          * @param {String} title The title bar text
1724          * @param {String} msg The message box body text
1725          * @param {Function} fn (optional) The callback function invoked after the message box is closed
1726          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
1727          * @return {Ext.MessageBox} this
1728          */
1729         confirm : function(title, msg, fn, scope){
1730             this.show({
1731                 title : title,
1732                 msg : msg,
1733                 buttons: this.YESNO,
1734                 fn: fn,
1735                 scope : scope,
1736                 icon: this.QUESTION,
1737                 minWidth: this.minWidth
1738             });
1739             return this;
1740         },
1741
1742         /**
1743          * Displays a message box with OK and Cancel buttons prompting the user to enter some text (comparable to JavaScript's prompt).
1744          * The prompt can be a single-line or multi-line textbox.  If a callback function is passed it will be called after the user
1745          * clicks either button, and the id of the button that was clicked (could also be the top-right
1746          * close button) and the text that was entered will be passed as the two parameters to the callback.
1747          * @param {String} title The title bar text
1748          * @param {String} msg The message box body text
1749          * @param {Function} fn (optional) The callback function invoked after the message box is closed
1750          * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to the browser wnidow.
1751          * @param {Boolean/Number} multiline (optional) True to create a multiline textbox using the defaultTextHeight
1752          * property, or the height in pixels to create the textbox (defaults to false / single-line)
1753          * @param {String} value (optional) Default value of the text input element (defaults to '')
1754          * @return {Ext.MessageBox} this
1755          */
1756         prompt : function(title, msg, fn, scope, multiline, value){
1757             this.show({
1758                 title : title,
1759                 msg : msg,
1760                 buttons: this.OKCANCEL,
1761                 fn: fn,
1762                 minWidth: this.minPromptWidth,
1763                 scope : scope,
1764                 prompt:true,
1765                 multiline: multiline,
1766                 value: value
1767             });
1768             return this;
1769         },
1770
1771         /**
1772          * Button config that displays a single OK button
1773          * @type Object
1774          */
1775         OK : {ok:true},
1776         /**
1777          * Button config that displays a single Cancel button
1778          * @type Object
1779          */
1780         CANCEL : {cancel:true},
1781         /**
1782          * Button config that displays OK and Cancel buttons
1783          * @type Object
1784          */
1785         OKCANCEL : {ok:true, cancel:true},
1786         /**
1787          * Button config that displays Yes and No buttons
1788          * @type Object
1789          */
1790         YESNO : {yes:true, no:true},
1791         /**
1792          * Button config that displays Yes, No and Cancel buttons
1793          * @type Object
1794          */
1795         YESNOCANCEL : {yes:true, no:true, cancel:true},
1796         /**
1797          * The CSS class that provides the INFO icon image
1798          * @type String
1799          */
1800         INFO : 'ext-mb-info',
1801         /**
1802          * The CSS class that provides the WARNING icon image
1803          * @type String
1804          */
1805         WARNING : 'ext-mb-warning',
1806         /**
1807          * The CSS class that provides the QUESTION icon image
1808          * @type String
1809          */
1810         QUESTION : 'ext-mb-question',
1811         /**
1812          * The CSS class that provides the ERROR icon image
1813          * @type String
1814          */
1815         ERROR : 'ext-mb-error',
1816
1817         /**
1818          * The default height in pixels of the message box's multiline textarea if displayed (defaults to 75)
1819          * @type Number
1820          */
1821         defaultTextHeight : 75,
1822         /**
1823          * The maximum width in pixels of the message box (defaults to 600)
1824          * @type Number
1825          */
1826         maxWidth : 600,
1827         /**
1828          * The minimum width in pixels of the message box (defaults to 100)
1829          * @type Number
1830          */
1831         minWidth : 100,
1832         /**
1833          * The minimum width in pixels of the message box if it is a progress-style dialog.  This is useful
1834          * for setting a different minimum width than text-only dialogs may need (defaults to 250).
1835          * @type Number
1836          */
1837         minProgressWidth : 250,
1838         /**
1839          * The minimum width in pixels of the message box if it is a prompt dialog.  This is useful
1840          * for setting a different minimum width than text-only dialogs may need (defaults to 250).
1841          * @type Number
1842          */
1843         minPromptWidth: 250,
1844         /**
1845          * An object containing the default button text strings that can be overriden for localized language support.
1846          * Supported properties are: ok, cancel, yes and no.  Generally you should include a locale-specific
1847          * resource file for handling language support across the framework.
1848          * Customize the default text like so: Ext.MessageBox.buttonText.yes = "oui"; //french
1849          * @type Object
1850          */
1851         buttonText : {
1852             ok : "OK",
1853             cancel : "Cancel",
1854             yes : "Yes",
1855             no : "No"
1856         }
1857     };
1858 }();
1859
1860 /**
1861  * Shorthand for {@link Ext.MessageBox}
1862  */
1863 Ext.Msg = Ext.MessageBox;/**
1864  * @class Ext.dd.PanelProxy
1865  * A custom drag proxy implementation specific to {@link Ext.Panel}s. This class is primarily used internally
1866  * for the Panel's drag drop implementation, and should never need to be created directly.
1867  * @constructor
1868  * @param panel The {@link Ext.Panel} to proxy for
1869  * @param config Configuration options
1870  */
1871 Ext.dd.PanelProxy = function(panel, config){
1872     this.panel = panel;
1873     this.id = this.panel.id +'-ddproxy';
1874     Ext.apply(this, config);
1875 };
1876
1877 Ext.dd.PanelProxy.prototype = {
1878     /**
1879      * @cfg {Boolean} insertProxy True to insert a placeholder proxy element while dragging the panel,
1880      * false to drag with no proxy (defaults to true).
1881      */
1882     insertProxy : true,
1883
1884     // private overrides
1885     setStatus : Ext.emptyFn,
1886     reset : Ext.emptyFn,
1887     update : Ext.emptyFn,
1888     stop : Ext.emptyFn,
1889     sync: Ext.emptyFn,
1890
1891     /**
1892      * Gets the proxy's element
1893      * @return {Element} The proxy's element
1894      */
1895     getEl : function(){
1896         return this.ghost;
1897     },
1898
1899     /**
1900      * Gets the proxy's ghost element
1901      * @return {Element} The proxy's ghost element
1902      */
1903     getGhost : function(){
1904         return this.ghost;
1905     },
1906
1907     /**
1908      * Gets the proxy's element
1909      * @return {Element} The proxy's element
1910      */
1911     getProxy : function(){
1912         return this.proxy;
1913     },
1914
1915     /**
1916      * Hides the proxy
1917      */
1918     hide : function(){
1919         if(this.ghost){
1920             if(this.proxy){
1921                 this.proxy.remove();
1922                 delete this.proxy;
1923             }
1924             this.panel.el.dom.style.display = '';
1925             this.ghost.remove();
1926             delete this.ghost;
1927         }
1928     },
1929
1930     /**
1931      * Shows the proxy
1932      */
1933     show : function(){
1934         if(!this.ghost){
1935             this.ghost = this.panel.createGhost(undefined, undefined, Ext.getBody());
1936             this.ghost.setXY(this.panel.el.getXY());
1937             if(this.insertProxy){
1938                 this.proxy = this.panel.el.insertSibling({cls:'x-panel-dd-spacer'});
1939                 this.proxy.setSize(this.panel.getSize());
1940             }
1941             this.panel.el.dom.style.display = 'none';
1942         }
1943     },
1944
1945     // private
1946     repair : function(xy, callback, scope){
1947         this.hide();
1948         if(typeof callback == "function"){
1949             callback.call(scope || this);
1950         }
1951     },
1952
1953     /**
1954      * Moves the proxy to a different position in the DOM.  This is typically called while dragging the Panel
1955      * to keep the proxy sync'd to the Panel's location.
1956      * @param {HTMLElement} parentNode The proxy's parent DOM node
1957      * @param {HTMLElement} before (optional) The sibling node before which the proxy should be inserted (defaults
1958      * to the parent's last child if not specified)
1959      */
1960     moveProxy : function(parentNode, before){
1961         if(this.proxy){
1962             parentNode.insertBefore(this.proxy.dom, before);
1963         }
1964     }
1965 };
1966
1967 // private - DD implementation for Panels
1968 Ext.Panel.DD = function(panel, cfg){
1969     this.panel = panel;
1970     this.dragData = {panel: panel};
1971     this.proxy = new Ext.dd.PanelProxy(panel, cfg);
1972     Ext.Panel.DD.superclass.constructor.call(this, panel.el, cfg);
1973     var h = panel.header;
1974     if(h){
1975         this.setHandleElId(h.id);
1976     }
1977     (h ? h : this.panel.body).setStyle('cursor', 'move');
1978     this.scroll = false;
1979 };
1980
1981 Ext.extend(Ext.Panel.DD, Ext.dd.DragSource, {
1982     showFrame: Ext.emptyFn,
1983     startDrag: Ext.emptyFn,
1984     b4StartDrag: function(x, y) {
1985         this.proxy.show();
1986     },
1987     b4MouseDown: function(e) {
1988         var x = e.getPageX();
1989         var y = e.getPageY();
1990         this.autoOffset(x, y);
1991     },
1992     onInitDrag : function(x, y){
1993         this.onStartDrag(x, y);
1994         return true;
1995     },
1996     createFrame : Ext.emptyFn,
1997     getDragEl : function(e){
1998         return this.proxy.ghost.dom;
1999     },
2000     endDrag : function(e){
2001         this.proxy.hide();
2002         this.panel.saveState();
2003     },
2004
2005     autoOffset : function(x, y) {
2006         x -= this.startPageX;
2007         y -= this.startPageY;
2008         this.setDelta(x, y);
2009     }
2010 });