Upgrade to ExtJS 3.2.2 - Released 06/02/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.2.2
11  * Copyright(c) 2006-2010 Ext JS, Inc.
12  * licensing@extjs.com
13  * http://www.extjs.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     // inherited docs, same default
191     collapsible : false,
192
193     <div id="cfg-Ext.Window-initHidden"></div>/**
194      * @cfg {Boolean} initHidden
195      * True to hide the window until show() is explicitly called (defaults to true).
196      * @deprecated
197      */
198     initHidden : undefined,
199
200     <div id="cfg-Ext.Window-hidden"></div>/**
201      * @cfg {Boolean} hidden
202      * Render this component hidden (default is <tt>true</tt>). If <tt>true</tt>, the
203      * {@link #hide} method will be called internally.
204      */
205     hidden : 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                 handleCls: 'x-window-handle'
318             });
319             this.resizer.window = this;
320             this.mon(this.resizer, 'beforeresize', this.beforeResize, this);
321         }
322
323         if(this.draggable){
324             this.header.addClass('x-window-draggable');
325         }
326         this.mon(this.el, 'mousedown', this.toFront, this);
327         this.manager = this.manager || Ext.WindowMgr;
328         this.manager.register(this);
329         if(this.maximized){
330             this.maximized = false;
331             this.maximize();
332         }
333         if(this.closable){
334             var km = this.getKeyMap();
335             km.on(27, this.onEsc, this);
336             km.disable();
337         }
338     },
339
340     initDraggable : function(){
341         <div id="prop-Ext.Window-dd"></div>/**
342          * <p>If this Window is configured {@link #draggable}, this property will contain
343          * an instance of {@link Ext.dd.DD} which handles dragging the Window's DOM Element.</p>
344          * <p>This has implementations of <code>startDrag</code>, <code>onDrag</code> and <code>endDrag</code>
345          * which perform the dragging action. If extra logic is needed at these points, use
346          * {@link Function#createInterceptor createInterceptor} or {@link Function#createSequence createSequence} to
347          * augment the existing implementations.</p>
348          * @type Ext.dd.DD
349          * @property dd
350          */
351         this.dd = new Ext.Window.DD(this);
352     },
353
354    // private
355     onEsc : function(k, e){
356         e.stopEvent();
357         this[this.closeAction]();
358     },
359
360     // private
361     beforeDestroy : function(){
362         if(this.rendered){
363             this.hide();
364             this.clearAnchor();
365             Ext.destroy(
366                 this.focusEl,
367                 this.resizer,
368                 this.dd,
369                 this.proxy,
370                 this.mask
371             );
372         }
373         Ext.Window.superclass.beforeDestroy.call(this);
374     },
375
376     // private
377     onDestroy : function(){
378         if(this.manager){
379             this.manager.unregister(this);
380         }
381         Ext.Window.superclass.onDestroy.call(this);
382     },
383
384     // private
385     initTools : function(){
386         if(this.minimizable){
387             this.addTool({
388                 id: 'minimize',
389                 handler: this.minimize.createDelegate(this, [])
390             });
391         }
392         if(this.maximizable){
393             this.addTool({
394                 id: 'maximize',
395                 handler: this.maximize.createDelegate(this, [])
396             });
397             this.addTool({
398                 id: 'restore',
399                 handler: this.restore.createDelegate(this, []),
400                 hidden:true
401             });
402         }
403         if(this.closable){
404             this.addTool({
405                 id: 'close',
406                 handler: this[this.closeAction].createDelegate(this, [])
407             });
408         }
409     },
410
411     // private
412     resizerAction : function(){
413         var box = this.proxy.getBox();
414         this.proxy.hide();
415         this.window.handleResize(box);
416         return box;
417     },
418
419     // private
420     beforeResize : function(){
421         this.resizer.minHeight = Math.max(this.minHeight, this.getFrameHeight() + 40); // 40 is a magic minimum content size?
422         this.resizer.minWidth = Math.max(this.minWidth, this.getFrameWidth() + 40);
423         this.resizeBox = this.el.getBox();
424     },
425
426     // private
427     updateHandles : function(){
428         if(Ext.isIE && this.resizer){
429             this.resizer.syncHandleHeight();
430             this.el.repaint();
431         }
432     },
433
434     // private
435     handleResize : function(box){
436         var rz = this.resizeBox;
437         if(rz.x != box.x || rz.y != box.y){
438             this.updateBox(box);
439         }else{
440             this.setSize(box);
441             if (Ext.isIE6 && Ext.isStrict) {
442                 this.doLayout();
443             }
444         }
445         this.focus();
446         this.updateHandles();
447         this.saveState();
448     },
449
450     <div id="method-Ext.Window-focus"></div>/**
451      * Focuses the window.  If a defaultButton is set, it will receive focus, otherwise the
452      * window itself will receive focus.
453      */
454     focus : function(){
455         var f = this.focusEl,
456             db = this.defaultButton,
457             t = typeof db,
458             el,
459             ct;
460         if(Ext.isDefined(db)){
461             if(Ext.isNumber(db) && this.fbar){
462                 f = this.fbar.items.get(db);
463             }else if(Ext.isString(db)){
464                 f = Ext.getCmp(db);
465             }else{
466                 f = db;
467             }
468             el = f.getEl();
469             ct = Ext.getDom(this.container);
470             if (el && ct) {
471                 if (!Ext.lib.Region.getRegion(ct).contains(Ext.lib.Region.getRegion(el.dom))){
472                     return;
473                 }
474             }
475         }
476         f = f || this.focusEl;
477         f.focus.defer(10, f);
478     },
479
480     <div id="method-Ext.Window-setAnimateTarget"></div>/**
481      * Sets the target element from which the window should animate while opening.
482      * @param {String/Element} el The target element or id
483      */
484     setAnimateTarget : function(el){
485         el = Ext.get(el);
486         this.animateTarget = el;
487     },
488
489     // private
490     beforeShow : function(){
491         delete this.el.lastXY;
492         delete this.el.lastLT;
493         if(this.x === undefined || this.y === undefined){
494             var xy = this.el.getAlignToXY(this.container, 'c-c');
495             var pos = this.el.translatePoints(xy[0], xy[1]);
496             this.x = this.x === undefined? pos.left : this.x;
497             this.y = this.y === undefined? pos.top : this.y;
498         }
499         this.el.setLeftTop(this.x, this.y);
500
501         if(this.expandOnShow){
502             this.expand(false);
503         }
504
505         if(this.modal){
506             Ext.getBody().addClass('x-body-masked');
507             this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
508             this.mask.show();
509         }
510     },
511
512     <div id="method-Ext.Window-show"></div>/**
513      * Shows the window, rendering it first if necessary, or activates it and brings it to front if hidden.
514      * @param {String/Element} animateTarget (optional) The target element or id from which the window should
515      * animate while opening (defaults to null with no animation)
516      * @param {Function} callback (optional) A callback function to call after the window is displayed
517      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
518      * @return {Ext.Window} this
519      */
520     show : function(animateTarget, cb, scope){
521         if(!this.rendered){
522             this.render(Ext.getBody());
523         }
524         if(this.hidden === false){
525             this.toFront();
526             return this;
527         }
528         if(this.fireEvent('beforeshow', this) === false){
529             return this;
530         }
531         if(cb){
532             this.on('show', cb, scope, {single:true});
533         }
534         this.hidden = false;
535         if(Ext.isDefined(animateTarget)){
536             this.setAnimateTarget(animateTarget);
537         }
538         this.beforeShow();
539         if(this.animateTarget){
540             this.animShow();
541         }else{
542             this.afterShow();
543         }
544         return this;
545     },
546
547     // private
548     afterShow : function(isAnim){
549         if (this.isDestroyed){
550             return false;
551         }
552         this.proxy.hide();
553         this.el.setStyle('display', 'block');
554         this.el.show();
555         if(this.maximized){
556             this.fitContainer();
557         }
558         if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
559             this.cascade(this.setAutoScroll);
560         }
561
562         if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
563             Ext.EventManager.onWindowResize(this.onWindowResize, this);
564         }
565         this.doConstrain();
566         this.doLayout();
567         if(this.keyMap){
568             this.keyMap.enable();
569         }
570         this.toFront();
571         this.updateHandles();
572         if(isAnim && (Ext.isIE || Ext.isWebKit)){
573             var sz = this.getSize();
574             this.onResize(sz.width, sz.height);
575         }
576         this.onShow();
577         this.fireEvent('show', this);
578     },
579
580     // private
581     animShow : function(){
582         this.proxy.show();
583         this.proxy.setBox(this.animateTarget.getBox());
584         this.proxy.setOpacity(0);
585         var b = this.getBox();
586         this.el.setStyle('display', 'none');
587         this.proxy.shift(Ext.apply(b, {
588             callback: this.afterShow.createDelegate(this, [true], false),
589             scope: this,
590             easing: 'easeNone',
591             duration: 0.25,
592             opacity: 0.5
593         }));
594     },
595
596     <div id="method-Ext.Window-hide"></div>/**
597      * Hides the window, setting it to invisible and applying negative offsets.
598      * @param {String/Element} animateTarget (optional) The target element or id to which the window should
599      * animate while hiding (defaults to null with no animation)
600      * @param {Function} callback (optional) A callback function to call after the window is hidden
601      * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the callback is executed. Defaults to this Window.
602      * @return {Ext.Window} this
603      */
604     hide : function(animateTarget, cb, scope){
605         if(this.hidden || this.fireEvent('beforehide', this) === false){
606             return this;
607         }
608         if(cb){
609             this.on('hide', cb, scope, {single:true});
610         }
611         this.hidden = true;
612         if(animateTarget !== undefined){
613             this.setAnimateTarget(animateTarget);
614         }
615         if(this.modal){
616             this.mask.hide();
617             Ext.getBody().removeClass('x-body-masked');
618         }
619         if(this.animateTarget){
620             this.animHide();
621         }else{
622             this.el.hide();
623             this.afterHide();
624         }
625         return this;
626     },
627
628     // private
629     afterHide : function(){
630         this.proxy.hide();
631         if(this.monitorResize || this.modal || this.constrain || this.constrainHeader){
632             Ext.EventManager.removeResizeListener(this.onWindowResize, this);
633         }
634         if(this.keyMap){
635             this.keyMap.disable();
636         }
637         this.onHide();
638         this.fireEvent('hide', this);
639     },
640
641     // private
642     animHide : function(){
643         this.proxy.setOpacity(0.5);
644         this.proxy.show();
645         var tb = this.getBox(false);
646         this.proxy.setBox(tb);
647         this.el.hide();
648         this.proxy.shift(Ext.apply(this.animateTarget.getBox(), {
649             callback: this.afterHide,
650             scope: this,
651             duration: 0.25,
652             easing: 'easeNone',
653             opacity: 0
654         }));
655     },
656
657     <div id="prop-Ext.Window-onShow"></div>/**
658      * Method that is called immediately before the <code>show</code> event is fired.
659      * Defaults to <code>Ext.emptyFn</code>.
660      */
661     onShow : Ext.emptyFn,
662
663     <div id="prop-Ext.Window-onHide"></div>/**
664      * Method that is called immediately before the <code>hide</code> event is fired.
665      * Defaults to <code>Ext.emptyFn</code>.
666      */
667     onHide : Ext.emptyFn,
668
669     // private
670     onWindowResize : function(){
671         if(this.maximized){
672             this.fitContainer();
673         }
674         if(this.modal){
675             this.mask.setSize('100%', '100%');
676             var force = this.mask.dom.offsetHeight;
677             this.mask.setSize(Ext.lib.Dom.getViewWidth(true), Ext.lib.Dom.getViewHeight(true));
678         }
679         this.doConstrain();
680     },
681
682     // private
683     doConstrain : function(){
684         if(this.constrain || this.constrainHeader){
685             var offsets;
686             if(this.constrain){
687                 offsets = {
688                     right:this.el.shadowOffset,
689                     left:this.el.shadowOffset,
690                     bottom:this.el.shadowOffset
691                 };
692             }else {
693                 var s = this.getSize();
694                 offsets = {
695                     right:-(s.width - 100),
696                     bottom:-(s.height - 25)
697                 };
698             }
699
700             var xy = this.el.getConstrainToXY(this.container, true, offsets);
701             if(xy){
702                 this.setPosition(xy[0], xy[1]);
703             }
704         }
705     },
706
707     // private - used for dragging
708     ghost : function(cls){
709         var ghost = this.createGhost(cls);
710         var box = this.getBox(true);
711         ghost.setLeftTop(box.x, box.y);
712         ghost.setWidth(box.width);
713         this.el.hide();
714         this.activeGhost = ghost;
715         return ghost;
716     },
717
718     // private
719     unghost : function(show, matchPosition){
720         if(!this.activeGhost) {
721             return;
722         }
723         if(show !== false){
724             this.el.show();
725             this.focus.defer(10, this);
726             if(Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
727                 this.cascade(this.setAutoScroll);
728             }
729         }
730         if(matchPosition !== false){
731             this.setPosition(this.activeGhost.getLeft(true), this.activeGhost.getTop(true));
732         }
733         this.activeGhost.hide();
734         this.activeGhost.remove();
735         delete this.activeGhost;
736     },
737
738     <div id="method-Ext.Window-minimize"></div>/**
739      * Placeholder method for minimizing the window.  By default, this method simply fires the {@link #minimize} event
740      * since the behavior of minimizing a window is application-specific.  To implement custom minimize behavior,
741      * either the minimize event can be handled or this method can be overridden.
742      * @return {Ext.Window} this
743      */
744     minimize : function(){
745         this.fireEvent('minimize', this);
746         return this;
747     },
748
749     <div id="method-Ext.Window-close"></div>/**
750      * <p>Closes the Window, removes it from the DOM, {@link Ext.Component#destroy destroy}s
751      * the Window object and all its descendant Components. The {@link Ext.Panel#beforeclose beforeclose}
752      * event is fired before the close happens and will cancel the close action if it returns false.<p>
753      * <p><b>Note:</b> This method is not affected by the {@link #closeAction} setting which
754      * only affects the action triggered when clicking the {@link #closable 'close' tool in the header}.
755      * To hide the Window without destroying it, call {@link #hide}.</p>
756      */
757     close : function(){
758         if(this.fireEvent('beforeclose', this) !== false){
759             if(this.hidden){
760                 this.doClose();
761             }else{
762                 this.hide(null, this.doClose, this);
763             }
764         }
765     },
766
767     // private
768     doClose : function(){
769         this.fireEvent('close', this);
770         this.destroy();
771     },
772
773     <div id="method-Ext.Window-maximize"></div>/**
774      * Fits the window within its current container and automatically replaces
775      * the {@link #maximizable 'maximize' tool button} with the 'restore' tool button.
776      * Also see {@link #toggleMaximize}.
777      * @return {Ext.Window} this
778      */
779     maximize : function(){
780         if(!this.maximized){
781             this.expand(false);
782             this.restoreSize = this.getSize();
783             this.restorePos = this.getPosition(true);
784             if (this.maximizable){
785                 this.tools.maximize.hide();
786                 this.tools.restore.show();
787             }
788             this.maximized = true;
789             this.el.disableShadow();
790
791             if(this.dd){
792                 this.dd.lock();
793             }
794             if(this.collapsible){
795                 this.tools.toggle.hide();
796             }
797             this.el.addClass('x-window-maximized');
798             this.container.addClass('x-window-maximized-ct');
799
800             this.setPosition(0, 0);
801             this.fitContainer();
802             this.fireEvent('maximize', this);
803         }
804         return this;
805     },
806
807     <div id="method-Ext.Window-restore"></div>/**
808      * Restores a {@link #maximizable maximized}  window back to its original
809      * size and position prior to being maximized and also replaces
810      * the 'restore' tool button with the 'maximize' tool button.
811      * Also see {@link #toggleMaximize}.
812      * @return {Ext.Window} this
813      */
814     restore : function(){
815         if(this.maximized){
816             var t = this.tools;
817             this.el.removeClass('x-window-maximized');
818             if(t.restore){
819                 t.restore.hide();
820             }
821             if(t.maximize){
822                 t.maximize.show();
823             }
824             this.setPosition(this.restorePos[0], this.restorePos[1]);
825             this.setSize(this.restoreSize.width, this.restoreSize.height);
826             delete this.restorePos;
827             delete this.restoreSize;
828             this.maximized = false;
829             this.el.enableShadow(true);
830
831             if(this.dd){
832                 this.dd.unlock();
833             }
834             if(this.collapsible && t.toggle){
835                 t.toggle.show();
836             }
837             this.container.removeClass('x-window-maximized-ct');
838
839             this.doConstrain();
840             this.fireEvent('restore', this);
841         }
842         return this;
843     },
844
845     <div id="method-Ext.Window-toggleMaximize"></div>/**
846      * A shortcut method for toggling between {@link #maximize} and {@link #restore} based on the current maximized
847      * state of the window.
848      * @return {Ext.Window} this
849      */
850     toggleMaximize : function(){
851         return this[this.maximized ? 'restore' : 'maximize']();
852     },
853
854     // private
855     fitContainer : function(){
856         var vs = this.container.getViewSize(false);
857         this.setSize(vs.width, vs.height);
858     },
859
860     // private
861     // z-index is managed by the WindowManager and may be overwritten at any time
862     setZIndex : function(index){
863         if(this.modal){
864             this.mask.setStyle('z-index', index);
865         }
866         this.el.setZIndex(++index);
867         index += 5;
868
869         if(this.resizer){
870             this.resizer.proxy.setStyle('z-index', ++index);
871         }
872
873         this.lastZIndex = index;
874     },
875
876     <div id="method-Ext.Window-alignTo"></div>/**
877      * Aligns the window to the specified element
878      * @param {Mixed} element The element to align to.
879      * @param {String} position (optional, defaults to "tl-bl?") The position to align to (see {@link Ext.Element#alignTo} for more details).
880      * @param {Array} offsets (optional) Offset the positioning by [x, y]
881      * @return {Ext.Window} this
882      */
883     alignTo : function(element, position, offsets){
884         var xy = this.el.getAlignToXY(element, position, offsets);
885         this.setPagePosition(xy[0], xy[1]);
886         return this;
887     },
888
889     <div id="method-Ext.Window-anchorTo"></div>/**
890      * Anchors this window to another element and realigns it when the window is resized or scrolled.
891      * @param {Mixed} element The element to align to.
892      * @param {String} position The position to align to (see {@link Ext.Element#alignTo} for more details)
893      * @param {Array} offsets (optional) Offset the positioning by [x, y]
894      * @param {Boolean/Number} monitorScroll (optional) true to monitor body scroll and reposition. If this parameter
895      * is a number, it is used as the buffer delay (defaults to 50ms).
896      * @return {Ext.Window} this
897      */
898     anchorTo : function(el, alignment, offsets, monitorScroll){
899         this.clearAnchor();
900         this.anchorTarget = {
901             el: el,
902             alignment: alignment,
903             offsets: offsets
904         };
905
906         Ext.EventManager.onWindowResize(this.doAnchor, this);
907         var tm = typeof monitorScroll;
908         if(tm != 'undefined'){
909             Ext.EventManager.on(window, 'scroll', this.doAnchor, this,
910                 {buffer: tm == 'number' ? monitorScroll : 50});
911         }
912         return this.doAnchor();
913     },
914
915     /**
916      * Performs the anchor, using the saved anchorTarget property.
917      * @return {Ext.Window} this
918      * @private
919      */
920     doAnchor : function(){
921         var o = this.anchorTarget;
922         this.alignTo(o.el, o.alignment, o.offsets);
923         return this;
924     },
925
926     <div id="method-Ext.Window-clearAnchor"></div>/**
927      * Removes any existing anchor from this window. See {@link #anchorTo}.
928      * @return {Ext.Window} this
929      */
930     clearAnchor : function(){
931         if(this.anchorTarget){
932             Ext.EventManager.removeResizeListener(this.doAnchor, this);
933             Ext.EventManager.un(window, 'scroll', this.doAnchor, this);
934             delete this.anchorTarget;
935         }
936         return this;
937     },
938
939     <div id="method-Ext.Window-toFront"></div>/**
940      * Brings this window to the front of any other visible windows
941      * @param {Boolean} e (optional) Specify <tt>false</tt> to prevent the window from being focused.
942      * @return {Ext.Window} this
943      */
944     toFront : function(e){
945         if(this.manager.bringToFront(this)){
946             if(!e || !e.getTarget().focus){
947                 this.focus();
948             }
949         }
950         return this;
951     },
952
953     <div id="method-Ext.Window-setActive"></div>/**
954      * Makes this the active window by showing its shadow, or deactivates it by hiding its shadow.  This method also
955      * fires the {@link #activate} or {@link #deactivate} event depending on which action occurred. This method is
956      * called internally by {@link Ext.WindowMgr}.
957      * @param {Boolean} active True to activate the window, false to deactivate it (defaults to false)
958      */
959     setActive : function(active){
960         if(active){
961             if(!this.maximized){
962                 this.el.enableShadow(true);
963             }
964             this.fireEvent('activate', this);
965         }else{
966             this.el.disableShadow();
967             this.fireEvent('deactivate', this);
968         }
969     },
970
971     <div id="method-Ext.Window-toBack"></div>/**
972      * Sends this window to the back of (lower z-index than) any other visible windows
973      * @return {Ext.Window} this
974      */
975     toBack : function(){
976         this.manager.sendToBack(this);
977         return this;
978     },
979
980     <div id="method-Ext.Window-center"></div>/**
981      * Centers this window in the viewport
982      * @return {Ext.Window} this
983      */
984     center : function(){
985         var xy = this.el.getAlignToXY(this.container, 'c-c');
986         this.setPagePosition(xy[0], xy[1]);
987         return this;
988     }
989
990     <div id="cfg-Ext.Window-autoWidth"></div>/**
991      * @cfg {Boolean} autoWidth @hide
992      **/
993 });
994 Ext.reg('window', Ext.Window);
995
996 // private - custom Window DD implementation
997 Ext.Window.DD = function(win){
998     this.win = win;
999     Ext.Window.DD.superclass.constructor.call(this, win.el.id, 'WindowDD-'+win.id);
1000     this.setHandleElId(win.header.id);
1001     this.scroll = false;
1002 };
1003
1004 Ext.extend(Ext.Window.DD, Ext.dd.DD, {
1005     moveOnly:true,
1006     headerOffsets:[100, 25],
1007     startDrag : function(){
1008         var w = this.win;
1009         this.proxy = w.ghost();
1010         if(w.constrain !== false){
1011             var so = w.el.shadowOffset;
1012             this.constrainTo(w.container, {right: so, left: so, bottom: so});
1013         }else if(w.constrainHeader !== false){
1014             var s = this.proxy.getSize();
1015             this.constrainTo(w.container, {right: -(s.width-this.headerOffsets[0]), bottom: -(s.height-this.headerOffsets[1])});
1016         }
1017     },
1018     b4Drag : Ext.emptyFn,
1019
1020     onDrag : function(e){
1021         this.alignElWithMouse(this.proxy, e.getPageX(), e.getPageY());
1022     },
1023
1024     endDrag : function(e){
1025         this.win.unghost();
1026         this.win.saveState();
1027     }
1028 });
1029 </pre>    
1030 </body>
1031 </html>