Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/web/ext/src/widgets/Window.js @ 76

Revision 76, 35.6 KB checked in by djay, 12 years ago (diff)

Ajout du répertoire web

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