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