Upgrade to ExtJS 3.0.3 - Released 10/11/2009
[extjs.git] / docs / source / Window.html
1 <html>
2 <head>
3   <title>The source code</title>
4     <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
5     <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
6 </head>
7 <body  onload="prettyPrint();">
8     <pre class="prettyprint lang-js">/*!
9  * Ext JS Library 3.0.3
10  * Copyright(c) 2006-2009 Ext JS, LLC
11  * licensing@extjs.com
12  * http://www.extjs.com/license
13  */
14 <div id="cls-Ext.Window"></div>/**
15  * @class Ext.Window
16  * @extends Ext.Panel
17  * <p>A specialized panel intended for use as an application window.  Windows are floated, {@link #resizable}, and
18  * {@link #draggable} by default.  Windows can be {@link #maximizable maximized} to fill the viewport,
19  * restored to their prior size, and can be {@link #minimize}d.</p>
20  * <p>Windows can also be linked to a {@link Ext.WindowGroup} or managed by the {@link Ext.WindowMgr} to provide
21  * grouping, activation, to front, to back and other application-specific behavior.</p>
22  * <p>By default, Windows will be rendered to document.body. To {@link #constrain} a Window to another element
23  * specify {@link Ext.Component#renderTo renderTo}.</p>
24  * <p><b>Note:</b> By default, the <code>{@link #closable close}</code> header tool <i>destroys</i> the Window resulting in
25  * destruction of any child Components. This makes the Window object, and all its descendants <b>unusable</b>. To enable
26  * re-use of a Window, use <b><code>{@link #closeAction closeAction: 'hide'}</code></b>.</p>
27  * @constructor
28  * @param {Object} config The config object
29  * @xtype window
30  */
31 Ext.Window = Ext.extend(Ext.Panel, {
32     <div id="cfg-Ext.Window-x"></div>/**
33      * @cfg {Number} x
34      * The X position of the left edge of the window on initial showing. Defaults to centering the Window within
35      * the width of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
36      */
37     <div id="cfg-Ext.Window-y"></div>/**
38      * @cfg {Number} y
39      * The Y position of the top edge of the window on initial showing. Defaults to centering the Window within
40      * the height of the Window's container {@link Ext.Element Element) (The Element that the Window is rendered to).
41      */
42     <div id="cfg-Ext.Window-modal"></div>/**
43      * @cfg {Boolean} modal
44      * True to make the window modal and mask everything behind it when displayed, false to display it without
45      * restricting access to other UI elements (defaults to false).
46      */
47     <div id="cfg-Ext.Window-animateTarget"></div>/**
48      * @cfg {String/Element} animateTarget
49      * Id or element from which the window should animate while opening (defaults to null with no animation).
50      */
51     <div id="cfg-Ext.Window-resizeHandles"></div>/**
52      * @cfg {String} resizeHandles
53      * A valid {@link Ext.Resizable} handles config string (defaults to 'all').  Only applies when resizable = true.
54      */
55     <div id="cfg-Ext.Window-manager"></div>/**
56      * @cfg {Ext.WindowGroup} manager
57      * A reference to the WindowGroup that should manage this window (defaults to {@link Ext.WindowMgr}).
58      */
59     <div id="cfg-Ext.Window-defaultButton"></div>/**
60     * @cfg {String/Number/Button} defaultButton
61     * The id / index of a button or a button instance to focus when this window received the focus.
62     */
63     <div id="cfg-Ext.Window-onEsc"></div>/**
64     * @cfg {Function} onEsc
65     * Allows override of the built-in processing for the escape key. Default action
66     * is to close the Window (performing whatever action is specified in {@link #closeAction}.
67     * To prevent the Window closing when the escape key is pressed, specify this as
68     * Ext.emptyFn (See {@link Ext#emptyFn}).
69     */
70     <div id="cfg-Ext.Window-collapsed"></div>/**
71      * @cfg {Boolean} collapsed
72      * True to render the window collapsed, false to render it expanded (defaults to false). Note that if
73      * {@link #expandOnShow} is true (the default) it will override the <tt>collapsed</tt> config and the window
74      * will always be expanded when shown.
75      */
76     <div id="cfg-Ext.Window-maximized"></div>/**
77      * @cfg {Boolean} maximized
78      * True to initially display the window in a maximized state. (Defaults to false).
79      */
80
81     <div id="cfg-Ext.Window-baseCls"></div>/**
82     * @cfg {String} baseCls
83     * The base CSS class to apply to this panel's element (defaults to 'x-window').
84     */
85     baseCls : 'x-window',
86     <div id="cfg-Ext.Window-resizable"></div>/**
87      * @cfg {Boolean} resizable
88      * True to allow user resizing at each edge and corner of the window, false to disable resizing (defaults to true).
89      */
90     resizable : true,
91     <div id="cfg-Ext.Window-draggable"></div>/**
92      * @cfg {Boolean} draggable
93      * True to allow the window to be dragged by the header bar, false to disable dragging (defaults to true).  Note
94      * that by default the window will be centered in the viewport, so if dragging is disabled the window may need
95      * to be positioned programmatically after render (e.g., myWindow.setPosition(100, 100);).
96      */
97     draggable : true,
98     <div id="cfg-Ext.Window-closable"></div>/**
99      * @cfg {Boolean} closable
100      * <p>True to display the 'close' tool button and allow the user to close the window, false to
101      * hide the button and disallow closing the window (defaults to true).</p>
102      * <p>By default, when close is requested by either clicking the close button in the header
103      * or pressing ESC when the Window has focus, the {@link #close} method will be called. This
104      * will <i>{@link Ext.Component#destroy destroy}</i> the Window and its content meaning that
105      * it may not be reused.</p>
106      * <p>To make closing a Window <i>hide</i> the Window so that it may be reused, set
107      * {@link #closeAction} to 'hide'.
108      */
109     closable : true,
110     <div id="cfg-Ext.Window-closeAction"></div>/**
111      * @cfg {String} closeAction
112      * <p>The action to take when the close header tool is clicked:
113      * <div class="mdetail-params"><ul>
114      * <li><b><code>'{@link #close}'</code></b> : <b>Default</b><div class="sub-desc">
115      * {@link #close remove} the window from the DOM and {@link Ext.Component#destroy destroy}
116      * it and all descendant Components. The window will <b>not</b> be available to be
117      * redisplayed via the {@link #show} method.
118      * </div></li>
119      * <li><b><code>'{@link #hide}'</code></b> : <div class="sub-desc">
120      * {@link #hide} the window by setting visibility to hidden and applying negative offsets.
121      * The window will be available to be redisplayed via the {@link #show} method.
122      * </div></li>
123      * </ul></div>
124      * <p><b>Note:</b> This setting does not affect the {@link #close} method
125      * which will always {@link Ext.Component#destroy destroy} the window. To
126      * programatically <i>hide</i> a window, call {@link #hide}.</p>
127      */
128     closeAction : 'close',
129     <div id="cfg-Ext.Window-constrain"></div>/**
130      * @cfg {Boolean} constrain
131      * True to constrain the window within its containing element, false to allow it to fall outside of its
132      * containing element. By default the window will be rendered to document.body.  To render and constrain the
133      * window within another element specify {@link #renderTo}.
134      * (defaults to false).  Optionally the header only can be constrained using {@link #constrainHeader}.
135      */
136     constrain : false,
137     <div id="cfg-Ext.Window-constrainHeader"></div>/**
138      * @cfg {Boolean} constrainHeader
139      * True to constrain the window header within its containing element (allowing the window body to fall outside
140      * of its containing element) or false to allow the header to fall outside its containing element (defaults to
141      * false). Optionally the entire window can be constrained using {@link #constrain}.
142      */
143     constrainHeader : false,
144     <div id="cfg-Ext.Window-plain"></div>/**
145      * @cfg {Boolean} plain
146      * True to render the window body with a transparent background so that it will blend into the framing
147      * elements, false to add a lighter background color to visually highlight the body element and separate it
148      * more distinctly from the surrounding frame (defaults to false).
149      */
150     plain : false,
151     <div id="cfg-Ext.Window-minimizable"></div>/**
152      * @cfg {Boolean} minimizable
153      * True to display the 'minimize' tool button and allow the user to minimize the window, false to hide the button
154      * and disallow minimizing the window (defaults to false).  Note that this button provides no implementation --
155      * the behavior of minimizing a window is implementation-specific, so the minimize event must be handled and a
156      * custom minimize behavior implemented for this option to be useful.
157      */
158     minimizable : false,
159     <div id="cfg-Ext.Window-maximizable"></div>/**
160      * @cfg {Boolean} maximizable
161      * True to display the 'maximize' tool button and allow the user to maximize the window, false to hide the button
162      * and disallow maximizing the window (defaults to false).  Note that when a window is maximized, the tool button
163      * will automatically change to a 'restore' button with the appropriate behavior already built-in that will
164      * restore the window to its previous size.
165      */
166     maximizable : false,
167     <div id="cfg-Ext.Window-minHeight"></div>/**
168      * @cfg {Number} minHeight
169      * The minimum height in pixels allowed for this window (defaults to 100).  Only applies when resizable = true.
170      */
171     minHeight : 100,
172     <div id="cfg-Ext.Window-minWidth"></div>/**
173      * @cfg {Number} minWidth
174      * The minimum width in pixels allowed for this window (defaults to 200).  Only applies when resizable = true.
175      */
176     minWidth : 200,
177     <div id="cfg-Ext.Window-expandOnShow"></div>/**
178      * @cfg {Boolean} expandOnShow
179      * True to always expand the window when it is displayed, false to keep it in its current state (which may be
180      * {@link #collapsed}) when displayed (defaults to true).
181      */
182     expandOnShow : true,
183
184     // inherited docs, same default
185     collapsible : false,
186
187     <div id="cfg-Ext.Window-initHidden"></div>/**
188      * @cfg {Boolean} initHidden
189      * True to hide the window until show() is explicitly called (defaults to true).
190      * @deprecated
191      */
192     initHidden : undefined,
193     
194     <div id="cfg-Ext.Window-hidden"></div>/**
195      * @cfg {Boolean} hidden
196      * Render this component hidden (default is <tt>true</tt>). If <tt>true</tt>, the
197      * {@link #hide} method will be called internally.
198      */
199     hidden : true,
200     
201     <div id="cfg-Ext.Window-monitorResize"></div>/**
202     * @cfg {Boolean} monitorResize @hide
203     * This is automatically managed based on the value of constrain and constrainToHeader
204     */
205     monitorResize : true,
206
207     // The following configs are set to provide the basic functionality of a window.
208     // Changing them would require additional code to handle correctly and should
209     // usually only be done in subclasses that can provide custom behavior.  Changing them
210     // may have unexpected or undesirable results.
211     <div id="cfg-Ext.Window-elements"></div>/** @cfg {String} elements @hide */
212     elements : 'header,body',
213     <div id="cfg-Ext.Window-frame"></div>/** @cfg {Boolean} frame @hide */
214     frame : true,
215     <div id="cfg-Ext.Window-floating"></div>/** @cfg {Boolean} floating @hide */
216     floating : true,
217
218     // private
219     initComponent : function(){
220         this.initTools();
221         Ext.Window.superclass.initComponent.call(this);
222         this.addEvents(
223             <div id="event-Ext.Window-activate"></div>/**
224              * @event activate
225              * Fires after the window has been visually activated via {@link #setActive}.
226              * @param {Ext.Window} this
227              */
228             <div id="event-Ext.Window-deactivate"></div>/**
229              * @event deactivate
230              * Fires after the window has been visually deactivated via {@link #setActive}.
231              * @param {Ext.Window} this
232              */
233             <div id="event-Ext.Window-resize"></div>/**
234              * @event resize
235              * Fires after the window has been resized.
236              * @param {Ext.Window} this
237              * @param {Number} width The window's new width
238              * @param {Number} height The window's new height
239              */
240             'resize',
241             <div id="event-Ext.Window-maximize"></div>/**
242              * @event maximize
243              * Fires after the window has been maximized.
244              * @param {Ext.Window} this
245              */
246             'maximize',
247             <div id="event-Ext.Window-minimize"></div>/**
248              * @event minimize
249              * Fires after the window has been minimized.
250              * @param {Ext.Window} this
251              */
252             'minimize',
253             <div id="event-Ext.Window-restore"></div>/**
254              * @event restore
255              * Fires after the window has been restored to its original size after being maximized.
256              * @param {Ext.Window} this
257              */
258             'restore'
259         );
260         // for backwards compat, this should be removed at some point
261         if(Ext.isDefined(this.initHidden)){
262             this.hidden = this.initHidden;
263         }
264         if(this.hidden === false){
265             this.hidden = true;
266             this.show();
267         }
268     },
269
270     // private
271     getState : function(){
272         return Ext.apply(Ext.Window.superclass.getState.call(this) || {}, this.getBox(true));
273     },
274
275     // private
276     onRender : function(ct, position){
277         Ext.Window.superclass.onRender.call(this, ct, position);
278
279         if(this.plain){
280             this.el.addClass('x-window-plain');
281         }
282
283         // this element allows the Window to be focused for keyboard events
284         this.focusEl = this.el.createChild({
285                     tag: 'a', href:'#', cls:'x-dlg-focus',
286                     tabIndex:'-1', html: '&#160;'});
287         this.focusEl.swallowEvent('click', true);
288
289         this.proxy = this.el.createProxy('x-window-proxy');
290         this.proxy.enableDisplayMode('block');
291
292         if(this.modal){
293             this.mask = this.container.createChild({cls:'ext-el-mask'}, this.el.dom);
294             this.mask.enableDisplayMode('block');
295             this.mask.hide();
296             this.mon(this.mask, 'click', this.focus, this);
297         }
298         if(this.maximizable){
299             this.mon(this.header, 'dblclick', this.toggleMaximize, this);
300         }
301     },
302
303     // private
304     initEvents : function(){
305         Ext.Window.superclass.initEvents.call(this);
306         if(this.animateTarget){
307             this.setAnimateTarget(this.animateTarget);
308         }
309
310         if(this.resizable){
311             this.resizer = new Ext.Resizable(this.el, {
312                 minWidth: this.minWidth,
313                 minHeight:this.minHeight,
314                 handles: this.resizeHandles || 'all',
315                 pinned: true,
316                 resizeElement : this.resizerAction
317             });
318             this.resizer.window = this;
319             this.mon(this.resizer, 'beforeresize', this.beforeResize, this);
320         }
321
322         if(this.draggable){
323             this.header.addClass('x-window-draggable');
324         }
325         this.mon(this.el, 'mousedown', this.toFront, this);
326         this.manager = this.manager || Ext.WindowMgr;
327         this.manager.register(this);
328         if(this.maximized){
329             this.maximized = false;
330             this.maximize();
331         }
332         if(this.closable){
333             var km = this.getKeyMap();
334             km.on(27, this.onEsc, this);
335             km.disable();
336         }
337     },
338
339     initDraggable : function(){
340         <div id="prop-Ext.Window-dd"></div>/**
341          * If this Window is configured {@link #draggable}, this property will contain
342          * an instance of {@link Ext.dd.DD} which handles dragging the Window's DOM Element.
343          * @type Ext.dd.DD
344          * @property dd
345          */
346         this.dd = new Ext.Window.DD(this);
347     },
348
349    // private
350     onEsc : function(){
351         this[this.closeAction]();
352     },
353
354     // private
355     beforeDestroy : function(){
356         if (this.rendered){
357             this.hide();
358           if(this.doAnchor){
359                 Ext.EventManager.removeResizeListener(this.doAnchor, this);
360               Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
361             }
362             Ext.destroy(
363                 this.focusEl,
364                 this.resizer,
365                 this.dd,
366                 this.proxy,
367                 this.mask
368             );
369         }
370         Ext.Window.superclass.beforeDestroy.call(this);
371     },
372
373     // private
374     onDestroy : function(){
375         if(this.manager){
376             this.manager.unregister(this);
377         }
378         Ext.Window.superclass.onDestroy.call(this);
379     },
380
381     // private
382     initTools : function(){
383         if(this.minimizable){
384             this.addTool({
385                 id: 'minimize',
386                 handler: this.minimize.createDelegate(this, [])
387             });
388         }
389         if(this.maximizable){
390             this.addTool({
391                 id: 'maximize',
392                 handler: this.maximize.createDelegate(this, [])
393             });
394             this.addTool({
395                 id: 'restore',
396                 handler: this.restore.createDelegate(this, []),
397                 hidden:true
398             });
399         }
400         if(this.closable){
401             this.addTool({
402                 id: 'close',
403                 handler: this[this.closeAction].createDelegate(this, [])
404             });
405         }
406     },
407
408     // private
409     resizerAction : function(){
410         var box = this.proxy.getBox();
411         this.proxy.hide();
412         this.window.handleResize(box);
413         return box;
414     },
415
416     // private
417     beforeResize : function(){
418         this.resizer.minHeight = Math.max(this.minHeight, this.getFrameHeight() + 40); // 40 is a magic minimum content size?
419         this.resizer.minWidth = Math.max(this.minWidth, this.getFrameWidth() + 40);
420         this.resizeBox = this.el.getBox();
421     },
422
423     // private
424     updateHandles : function(){
425         if(Ext.isIE && this.resizer){
426             this.resizer.syncHandleHeight();
427             this.el.repaint();
428         }
429     },
430
431     // private
432     handleResize : function(box){
433         var rz = this.resizeBox;
434         if(rz.x != box.x || rz.y != box.y){
435             this.updateBox(box);
436         }else{
437             this.setSize(box);
438         }
439         this.focus();
440         this.updateHandles();
441         this.saveState();
442         this.doLayout();
443     },
444
445     <div id="method-Ext.Window-focus"></div>/**
446      * Focuses the window.  If a defaultButton is set, it will receive focus, otherwise the
447      * window itself will receive focus.
448      */
449     focus : function(){
450         var f = this.focusEl, db = this.defaultButton, t = typeof db;
451         if(Ext.isDefined(db)){
452             if(Ext.isNumber(db) && this.fbar){
453                 f = this.fbar.items.get(db);
454             }else if(Ext.isString(db)){
455                 f = Ext.getCmp(db);
456             }else{
457                 f = db;
458             }
459         }
460         f = f || this.focusEl;
461         f.focus.defer(10, f);
462     },
463
464     <div id="method-Ext.Window-setAnimateTarget"></div>/**
465      * Sets the target element from which the window should animate while opening.
466      * @param {String/Element} el The target element or id
467      */
468     setAnimateTarget : function(el){
469         el = Ext.get(el);
470         this.animateTarget = el;
471     },
472
473     // private
474     beforeShow : function(){
475         delete this.el.lastXY;
476         delete this.el.lastLT;
477         if(this.x === undefined || this.y === undefined){
478             var xy = this.el.getAlignToXY(this.container, 'c-c');
479             var pos = this.el.translatePoints(xy[0], xy[1]);
480             this.x = this.x === undefined? pos.left : this.x;
481             this.y = this.y === undefined? pos.top : this.y;
482         }
483         this.el.setLeftTop(this.x, this.y);
484
485         if(this.expandOnShow){
486             this.expand(false);
487         }
488
489         if(this.modal){
490             Ext.getBody().addClass('x-body-masked');
491             this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
492             this.mask.show();
493         }
494     },
495
496     <div id="method-Ext.Window-show"></div>/**
497      * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
498      * @param {String/Element} animateTarget (optional) The target element or id from which the window should
499      * animate while opening (defaults to null with no animation)
500      * @param {Function} callback (optional) A callback function to call after the window is displayed
501      * @param {Object} scope (optional) The scope in which to execute the callback
502      * @return {Ext.Window} this
503      */
504     show : function(animateTarget, cb, scope){
505         if(!this.rendered){
506             this.render(Ext.getBody());
507         }
508         if(this.hidden === false){
509             this.toFront();
510             return this;
511         }
512         if(this.fireEvent('beforeshow', this) === false){
513             return this;
514         }
515         if(cb){
516             this.on('show', cb, scope, {single:true});
517         }
518         this.hidden = false;
519         if(Ext.isDefined(animateTarget)){
520             this.setAnimateTarget(animateTarget);
521         }
522         this.beforeShow();
523         if(this.animateTarget){
524             this.animShow();
525         }else{
526             this.afterShow();
527         }
528         return this;
529     },
530
531     // private
532     afterShow : function(isAnim){
533         this.proxy.hide();
534         this.el.setStyle('display', 'block');
535         this.el.show();
536         if(this.maximized){
537             this.fitContainer();
538         }
539         if(Ext.isMac && Ext.isGecko){ // work around stupid FF 2.0/Mac scroll bar bug
540             this.cascade(this.setAutoScroll);
541         }
542
543         if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
544             Ext.EventManager.onWindowResize(this.onWindowResize, this);
545         }
546         this.doConstrain();
547         this.doLayout();
548         if(this.keyMap){
549             this.keyMap.enable();
550         }
551         this.toFront();
552         this.updateHandles();
553         if(isAnim && (Ext.isIE || Ext.isWebKit)){
554             var sz = this.getSize();
555             this.onResize(sz.width, sz.height);
556         }
557         this.fireEvent('show', this);
558     },
559
560     // private
561     animShow : function(){
562         this.proxy.show();
563         this.proxy.setBox(this.animateTarget.getBox());
564         this.proxy.setOpacity(0);
565         var b = this.getBox();
566         this.el.setStyle('display', 'none');
567         this.proxy.shift(Ext.apply(b, {
568             callback: this.afterShow.createDelegate(this, [true], false),
569             scope: this,
570             easing: 'easeNone',
571             duration: 0.25,
572             opacity: 0.5
573         }));
574     },
575
576     <div id="method-Ext.Window-hide"></div>/**
577      * Hides the window, setting it to invisible and applying negative offsets.
578      * @param {String/Element} animateTarget (optional) The target element or id to which the window should
579      * animate while hiding (defaults to null with no animation)
580      * @param {Function} callback (optional) A callback function to call after the window is hidden
581      * @param {Object} scope (optional) The scope in which to execute the callback
582      * @return {Ext.Window} this
583      */
584     hide : function(animateTarget, cb, scope){
585         if(this.hidden || this.fireEvent('beforehide', this) === false){
586             return this;
587         }
588         if(cb){
589             this.on('hide', cb, scope, {single:true});
590         }
591         this.hidden = true;
592         if(animateTarget !== undefined){
593             this.setAnimateTarget(animateTarget);
594         }
595         if(this.modal){
596             this.mask.hide();
597             Ext.getBody().removeClass('x-body-masked');
598         }
599         if(this.animateTarget){
600             this.animHide();
601         }else{
602             this.el.hide();
603             this.afterHide();
604         }
605         return this;
606     },
607
608     // private
609     afterHide : function(){
610         this.proxy.hide();
611         if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
612             Ext.EventManager.removeResizeListener(this.onWindowResize, this);
613         }
614         if(this.keyMap){
615             this.keyMap.disable();
616         }
617         this.fireEvent('hide', this);
618     },
619
620     // private
621     animHide : function(){
622         this.proxy.setOpacity(0.5);
623         this.proxy.show();
624         var tb = this.getBox(false);
625         this.proxy.setBox(tb);
626         this.el.hide();
627         this.proxy.shift(Ext.apply(this.animateTarget.getBox(), {
628             callback: this.afterHide,
629             scope: this,
630             duration: 0.25,
631             easing: 'easeNone',
632             opacity: 0
633         }));
634     },
635
636     // private
637     onWindowResize : function(){
638         if(this.maximized){
639             this.fitContainer();
640         }
641         if(this.modal){
642             this.mask.setSize('100%', '100%');
643             var force = this.mask.dom.offsetHeight;
644             this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
645         }
646         this.doConstrain();
647     },
648
649     // private
650     doConstrain : function(){
651         if(this.constrain || this.constrainHeader){
652             var offsets;
653             if(this.constrain){
654                 offsets = {
655                     right:this.el.shadowOffset,
656                     left:this.el.shadowOffset,
657                     bottom:this.el.shadowOffset
658                 };
659             }else {
660                 var s = this.getSize();
661                 offsets = {
662                     right:-(s.width - 100),
663                     bottom:-(s.height - 25)
664                 };
665             }
666
667             var xy = this.el.getConstrainToXY(this.container, true, offsets);
668             if(xy){
669                 this.setPosition(xy[0], xy[1]);
670             }
671         }
672     },
673
674     // private - used for dragging
675     ghost : function(cls){
676         var ghost = this.createGhost(cls);
677         var box = this.getBox(true);
678         ghost.setLeftTop(box.x, box.y);
679         ghost.setWidth(box.width);
680         this.el.hide();
681         this.activeGhost = ghost;
682         return ghost;
683     },
684
685     // private
686     unghost : function(show, matchPosition){
687         if(!this.activeGhost) {
688             return;
689         }
690         if(show !== false){
691             this.el.show();
692             this.focus();
693             if(Ext.isMac && Ext.isGecko){ // work around stupid FF 2.0/Mac scroll bar bug
694                 this.cascade(this.setAutoScroll);
695             }
696         }
697         if(matchPosition !== false){
698             this.setPosition(this.activeGhost.getLeft(true), this.activeGhost.getTop(true));
699         }
700         this.activeGhost.hide();
701         this.activeGhost.remove();
702         delete this.activeGhost;
703     },
704
705     <div id="method-Ext.Window-minimize"></div>/**
706      * Placeholder method for minimizing the window.  By default, this method simply fires the {@link #minimize} event
707      * since the behavior of minimizing a window is application-specific.  To implement custom minimize behavior,
708      * either the minimize event can be handled or this method can be overridden.
709      * @return {Ext.Window} this
710      */
711     minimize : function(){
712         this.fireEvent('minimize', this);
713         return this;
714     },
715
716     <div id="method-Ext.Window-close"></div>/**
717      * <p>Closes the Window, removes it from the DOM, {@link Ext.Component#destroy destroy}s
718      * the Window object and all its descendant Components. The {@link Ext.Panel#beforeclose beforeclose}
719      * event is fired before the close happens and will cancel the close action if it returns false.<p>
720      * <p><b>Note:</b> This method is not affected by the {@link #closeAction} setting which
721      * only affects the action triggered when clicking the {@link #closable 'close' tool in the header}.
722      * To hide the Window without destroying it, call {@link #hide}.</p>
723      */
724     close : function(){
725         if(this.fireEvent('beforeclose', this) !== false){
726             if(this.hidden){
727                 this.doClose();
728             }else{
729                 this.hide(null, this.doClose, this);
730             }
731         }
732     },
733     
734     // private
735     doClose : function(){
736         this.fireEvent('close', this);
737         this.destroy();
738     },
739
740     <div id="method-Ext.Window-maximize"></div>/**
741      * Fits the window within its current container and automatically replaces
742      * the {@link #maximizable 'maximize' tool button} with the 'restore' tool button.
743      * Also see {@link #toggleMaximize}.
744      * @return {Ext.Window} this
745      */
746     maximize : function(){
747         if(!this.maximized){
748             this.expand(false);
749             this.restoreSize = this.getSize();
750             this.restorePos = this.getPosition(true);
751             if (this.maximizable){
752                 this.tools.maximize.hide();
753                 this.tools.restore.show();
754             }
755             this.maximized = true;
756             this.el.disableShadow();
757
758             if(this.dd){
759                 this.dd.lock();
760             }
761             if(this.collapsible){
762                 this.tools.toggle.hide();
763             }
764             this.el.addClass('x-window-maximized');
765             this.container.addClass('x-window-maximized-ct');
766
767             this.setPosition(0, 0);
768             this.fitContainer();
769             this.fireEvent('maximize', this);
770         }
771         return this;
772     },
773
774     <div id="method-Ext.Window-restore"></div>/**
775      * Restores a {@link #maximizable maximized}  window back to its original
776      * size and position prior to being maximized and also replaces
777      * the 'restore' tool button with the 'maximize' tool button.
778      * Also see {@link #toggleMaximize}.
779      * @return {Ext.Window} this
780      */
781     restore : function(){
782         if(this.maximized){
783             this.el.removeClass('x-window-maximized');
784             this.tools.restore.hide();
785             this.tools.maximize.show();
786             this.setPosition(this.restorePos[0], this.restorePos[1]);
787             this.setSize(this.restoreSize.width, this.restoreSize.height);
788             delete this.restorePos;
789             delete this.restoreSize;
790             this.maximized = false;
791             this.el.enableShadow(true);
792
793             if(this.dd){
794                 this.dd.unlock();
795             }
796             if(this.collapsible){
797                 this.tools.toggle.show();
798             }
799             this.container.removeClass('x-window-maximized-ct');
800
801             this.doConstrain();
802             this.fireEvent('restore', this);
803         }
804         return this;
805     },
806
807     <div id="method-Ext.Window-toggleMaximize"></div>/**
808      * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized
809      * state of the window.
810      * @return {Ext.Window} this
811      */
812     toggleMaximize : function(){
813         return this[this.maximized ? 'restore' : 'maximize']();
814     },
815
816     // private
817     fitContainer : function(){
818         var vs = this.container.getViewSize();
819         this.setSize(vs.width, vs.height);
820     },
821
822     // private
823     // z-index is managed by the WindowManager and may be overwritten at any time
824     setZIndex : function(index){
825         if(this.modal){
826             this.mask.setStyle('z-index', index);
827         }
828         this.el.setZIndex(++index);
829         index += 5;
830
831         if(this.resizer){
832             this.resizer.proxy.setStyle('z-index', ++index);
833         }
834
835         this.lastZIndex = index;
836     },
837
838     <div id="method-Ext.Window-alignTo"></div>/**
839      * Aligns the window to the specified element
840      * @param {Mixed} element The element to align to.
841      * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details).
842      * @param {Array} offsets (optional) Offset the positioning by [x, y]
843      * @return {Ext.Window} this
844      */
845     alignTo : function(element, position, offsets){
846         var xy = this.el.getAlignToXY(element, position, offsets);
847         this.setPagePosition(xy[0], xy[1]);
848         return this;
849     },
850
851     <div id="method-Ext.Window-anchorTo"></div>/**
852      * Anchors this window to another element and realigns it when the window is resized or scrolled.
853      * @param {Mixed} element The element to align to.
854      * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details)
855      * @param {Array} offsets (optional) Offset the positioning by [x, y]
856      * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
857      * is a number, it is used as the buffer delay (defaults to 50ms).
858      * @return {Ext.Window} this
859      */
860     anchorTo : function(el, alignment, offsets, monitorScroll){
861       if(this.doAnchor){
862           Ext.EventManager.removeResizeListener(this.doAnchor, this);
863           Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
864       }
865       this.doAnchor = function(){
866           this.alignTo(el, alignment, offsets);
867       };
868       Ext.EventManager.onWindowResize(this.doAnchor, this);
869
870       var tm = typeof monitorScroll;
871       if(tm != 'undefined'){
872           Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
873               {buffer: tm == 'number' ? monitorScroll : 50});
874       }
875       this.doAnchor();
876       return this;
877     },
878
879     <div id="method-Ext.Window-toFront"></div>/**
880      * Brings this window to the front of any other visible windows
881      * @param {Boolean} e (optional) Specify <tt>false</tt> to prevent the window from being focused.
882      * @return {Ext.Window} this
883      */
884     toFront : function(e){
885         if(this.manager.bringToFront(this)){
886             if(!e || !e.getTarget().focus){
887                 this.focus();
888             }
889         }
890         return this;
891     },
892
893     <div id="method-Ext.Window-setActive"></div>/**
894      * Makes this the active window by showing its shadow, or deactivates it by hiding its shadow.  This method also
895      * fires the {@link #activate} or {@link #deactivate} event depending on which action occurred. This method is
896      * called internally by {@link Ext.WindowMgr}.
897      * @param {Boolean} active True to activate the window, false to deactivate it (defaults to false)
898      */
899     setActive : function(active){
900         if(active){
901             if(!this.maximized){
902                 this.el.enableShadow(true);
903             }
904             this.fireEvent('activate', this);
905         }else{
906             this.el.disableShadow();
907             this.fireEvent('deactivate', this);
908         }
909     },
910
911     <div id="method-Ext.Window-toBack"></div>/**
912      * Sends this window to the back of (lower z-index than) any other visible windows
913      * @return {Ext.Window} this
914      */
915     toBack : function(){
916         this.manager.sendToBack(this);
917         return this;
918     },
919
920     <div id="method-Ext.Window-center"></div>/**
921      * Centers this window in the viewport
922      * @return {Ext.Window} this
923      */
924     center : function(){
925         var xy = this.el.getAlignToXY(this.container, 'c-c');
926         this.setPagePosition(xy[0], xy[1]);
927         return this;
928     }
929
930     <div id="cfg-Ext.Window-autoWidth"></div>/**
931      * @cfg {Boolean} autoWidth @hide
932      **/
933 });
934 Ext.reg('window', Ext.Window);
935
936 // private - custom Window DD implementation
937 Ext.Window.DD = function(win){
938     this.win = win;
939     Ext.Window.DD.superclass.constructor.call(this, win.el.id, 'WindowDD-'+win.id);
940     this.setHandleElId(win.header.id);
941     this.scroll = false;
942 };
943
944 Ext.extend(Ext.Window.DD, Ext.dd.DD, {
945     moveOnly:true,
946     headerOffsets:[100, 25],
947     startDrag : function(){
948         var w = this.win;
949         this.proxy = w.ghost();
950         if(w.constrain !== false){
951             var so = w.el.shadowOffset;
952             this.constrainTo(w.container, {right: so, left: so, bottom: so});
953         }else if(w.constrainHeader !== false){
954             var s = this.proxy.getSize();
955             this.constrainTo(w.container, {right: -(s.width-this.headerOffsets[0]), bottom: -(s.height-this.headerOffsets[1])});
956         }
957     },
958     b4Drag : Ext.emptyFn,
959
960     onDrag : function(e){
961         this.alignElWithMouse(this.proxy, e.getPageX(), e.getPageY());
962     },
963
964     endDrag : function(e){
965         this.win.unghost();
966         this.win.saveState();
967     }
968 });
969 </pre>
970 </body>
971 </html>