ExtJs_ExtContainer解说

来源:互联网 发布:软件安全性需求分析 编辑:程序博客网 时间:2024/04/27 14:31


/*
 * Ext JS Library 3.3.0
 */
/**
 * @class Ext.Container
 * @extends Ext.BoxComponent
 *
 * Base class for any {Ext.BoxComponent} that may contain other Components. Containers handle the
 * basic behavior of containing items, namely adding(添加), inserting(插入) and removing(移除) items.
 *
 *
 * The most commonly(通常地) used Container classes are {Ext.Panel}, {Ext.Window} and {Ext.TabPanel}.
 * If you do not need the capabilities(特性、能力) offered by the aforementioned(上述提到的) classes you can create a
 * lightweight(轻量级的) Container to be encapsulated(被包围的) by an HTML element to your specifications by using the
 * {Ext.Component#autoEl autoEl} config option. This is a useful technique(技巧) when creating
 * embedded(嵌入式的) {Ext.layout.ColumnLayout column} layouts inside {Ext.form.FormPanel FormPanels}
 *
 * for example(Ext.layout.ColumnLayout)
 * The code below(下面) illustrates(举例说明) both how to explicitly(明白地) create a Container, and how to implicitly(绝对地)
 * create one using the 'container' xtype:
        // explicitly create a Container
        var embeddedColumns = new Ext.Container({    //embedded嵌入式
            autoEl: 'div',  // This is the default
            layout: 'column',
            defaults: {
                // implicitly(毫无疑问地) create Container by specifying(指定) xtype
                xtype: 'container',
                autoEl: 'div', // This is the default.
                layout: 'form',
                columnWidth: 0.5,
                style: {
                    padding: '10px'
                }
            },
        //  The two items below will be Ext.Containers, each encapsulated(被包围) by a <DIV> element.
            items: [{
                items: {
                    xtype: 'datefield',
                    name: 'startDate',
                    fieldLabel: 'Start date'
                }
            }, {
                items: {
                    xtype: 'datefield',
                    name: 'endDate',
                    fieldLabel: 'End date'
                }
            }]
        });
 *
 *
 * Layout(布局)
 *
 * Container classes delegate(委托) the rendering of child Components to a layout
 * manager class which must be configured into the Container using the
 * layout configuration property.
 *
 * When either specifying(指定) child items of a Container,
 * or dynamically adding Components to a Container, remember to
 * consider(考虑) how you wish the Container to arrange(安排) those child elements, and
 * whether those child elements need to be sized using one of Ext's built-in
 * {layout} schemes. By default, Containers use the
 * {Ext.layout.ContainerLayout ContainerLayout} scheme which only
 * renders child components, appending them one after the other inside the
 * Container(它们一个接一个附加在容器里边 ), and does not apply any sizing at all.
 *
 * A common mistake(错误) is when a developer neglects(忽略) to specify(指定) a
 * layout (e.g. widgets like GridPanels or
 * TreePanels are added to Containers for which no layout
 * has been specified). If a Container is left to use the default
 * {Ext.layout.ContainerLayout ContainerLayout} scheme, none of its
 * child components will be resized, or changed in any way when the Container
 * is resized.
 *
 * Certain(毫无疑问的) layout managers allow dynamic addition of child components.
 * Those that do include {Ext.layout.CardLayout},
 * {Ext.layout.AnchorLayout}, {Ext.layout.FormLayout}, and
 * {Ext.layout.TableLayout}.
 *
 * For example:
        //  Create the GridPanel.
        var myNewGrid = new Ext.grid.GridPanel({
            store: myStore,
            columns: myColumnModel,
            title: 'Results', // the title becomes the title of the tab
        });
    
    myTabPanel.add(myNewGrid); // {Ext.TabPanel} implicitly(绝对) uses {Ext.layout.CardLayout CardLayout}
    myTabPanel.{Ext.TabPanel#setActiveTab setActiveTab}(myNewGrid);
 *
 * The example above adds a newly created GridPanel to a TabPanel. Note that
 * a TabPanel uses {Ext.layout.CardLayout} as its layout manager which
 * means all its child items are sized to {Ext.layout.FitLayout fit}
 * exactly(确切地说) into its client area.
 *
 * An example of overnesting occurs when a GridPanel is added to a TabPanel
 * by wrapping(包装) the GridPanel inside a wrapping Panel (that has no
 * {layout} specified) and then add that wrapping Panel
 * to the TabPanel. The point to realize is that a GridPanel is a
 * Component which can be added directly to a Container. If the wrapping Panel
 * has no {@link #layout} configuration, then the overnested
 * GridPanel will not be sized as expected.
 *
 * A server side script can be used to add Components which are generated dynamically on the server.
 * An example of adding a GridPanel to a TabPanel where the GridPanel is generated by the server
 * based on certain parameters:
        
        // execute an Ajax request to invoke server side script:
        Ext.Ajax.request({
            url: 'grid.php',
            // send additional parameters to instruct(委托) server script
            params: {
                startDate: Ext.getCmp('start-date').getValue(),
                endDate: Ext.getCmp('end-date').getValue()
            },
            // process the response object to add it to the TabPanel:
            success: function(data) {
                var newComponent = eval(data.responseText); // see discussion below
                myTabPanel.add(newComponent); // add the component to the TabPanel
                myTabPanel.setActiveTab(newComponent);
            },
            failure: function() {
                Ext.Msg.alert("Grid create failed", "Server communication failure");
            }
        });
 *
 * The server script needs to return an executable(执行的) Javascript statement which, when processed
 * using eval(), will return either a config object with an {Ext.Component#xtype xtype},
 * or an instantiated(例示) Component. The server might return this for example:
        
        (function() {
            function formatDate(value){
                return value ? value.dateFormat('M d, Y') : '';
            };
        
            var store = new Ext.data.Store({
                url: 'get-data.php',
                baseParams: {
                    startDate: '01/01/2008',
                    endDate: '01/31/2008'
                },
                reader: new Ext.data.JsonReader({
                    record: 'transaction',
                    idProperty: 'id',
                    totalRecords: 'total'
                }, [
                   'customer',
                   'invNo',
                   {name: 'date', type: 'date', dateFormat: 'm/d/Y'},
                   {name: 'value', type: 'float'}
                ])
            });
        
            var grid = new Ext.grid.GridPanel({
                title: 'Invoice(清单) Report',
                bbar: new Ext.PagingToolbar(store),
                store: store,
                columns: [
                    {header: "Customer", width: 250, dataIndex: 'customer', sortable: true},
                    {header: "Invoice Number", width: 120, dataIndex: 'invNo', sortable: true},
                    {header: "Invoice Date", width: 100, dataIndex: 'date', renderer: formatDate, sortable: true},
                    {header: "Value", width: 120, dataIndex: 'value', renderer: 'usMoney', sortable: true}
                ],
            });
            store.load();
            return grid;  // return instantiated(声明的) component
        })();

 *
 * When the above code fragment(片段) is passed through the eval function in the success handler
 * of the Ajax request, the code is executed by the Javascript processor, and the anonymous(匿名的) function
 * runs, and returns the instantiated grid component.

 *
 * Note: since the code above is generated by a server script, the baseParams for
 * the Store, the metadata to allow generation of the Record layout, and the ColumnModel
 * can all be generated into the code since these are all known on the server.

 *
 * @xtype container
 */
Ext.Container = Ext.extend(Ext.BoxComponent, {
    
/**
     * @cfg {Boolean} => monitorResize    //Ture表示为自动监视window resize的事件
     * True to automatically monitor window resize events to handle anything that is sensitive to the current size
     * of the viewport.  This value is typically(典型的) managed by the chosen layout and should not need
     * to be set manually(手工的).
     */
    
/**
     * @cfg {String/Object} => layout
     *
*Important: In order for child items to be correctly sized and
     * positioned, typically a layout manager must be specified through
     * the layout configuration option.
     *
The sizing and positioning of child items is the responsibility(责任) of
     * the Container's layout manager which creates and manages the type of layout
     * you have in mind.  
     * For example:
        new Ext.Window({
            width:300,
            height: 300,
            layout: 'fit', // explicitly(明确地) set layout manager: override the default (layout:'auto')
            items: [{
                title: 'Panel inside a Window'
            }]
        }).show();
     *
     *
If the layout configuration is not explicitly(明确地) specified(指定) for
     * a general purpose container (e.g. Container or Panel) the
     * {Ext.layout.ContainerLayout default layout manager} will be used
     * which does nothing but render child components sequentially(从而) into the
     * Container (no sizing or positioning will be performed(已履行的) in this situation).
     * Some container classes implicitly specify a default layout
     * (e.g. FormPanel specifies layout:'form'). Other specific
     * purpose classes internally specify/manage their internal layout (e.g.
     * GridPanel, TabPanel, TreePanel, Toolbar, Menu, etc.).

     *
layout may be specified as either as an Object or
     * as a String:
     * (1)Specify as an Object
     * Example usage:
        layout: {
            type: 'vbox',
            padding: '5',
            align: 'left'
        }
     * (2)type
     * The layout type to be used for this container.  If not specified,
     * a default {Ext.layout.ContainerLayout} will be created and used.
     *
     * Valid layout type values are:
            {Ext.layout.AbsoluteLayout absolute}    //绝对布局
            {Ext.layout.AccordionLayout accordion}    //伸缩布局
            {Ext.layout.AnchorLayout anchor}    //相对布局
            {Ext.layout.ContainerLayout auto}     Default
            {Ext.layout.BorderLayout border}    //border布局(东西南北中)
            {Ext.layout.CardLayout card}    //卡片布局
            {Ext.layout.ColumnLayout column}    //列布局
            {Ext.layout.FitLayout fit}    //合适布局
            {Ext.layout.FormLayout form}    //表单布局
            {Ext.layout.HBoxLayout hbox}
            {Ext.layout.MenuLayout menu}
            {Ext.layout.TableLayout table}    //表单布局
            {xt.layout.ToolbarLayout toolbar}
            {Ext.layout.VBoxLayout vbox}
     *
Layout specific configuration properties
     *
Additional layout specific configuration properties may also be
     * specified. For complete details regarding the valid config options for
     * each layout type, see the layout class corresponding(相关的) to the type
     * specified.
     *
     * Specify as a String
     * Example usage:
            layout: 'vbox',
            layoutConfig: {
                padding: '5',
                align: 'left'
            }
     */
    
/**
     * @cfg {Object} => layoutConfig
     * This is a config object containing properties specific to the chosen
     * {layout} if layout has been specified as a string.

     */
    
/**
     * @cfg {Boolean/Number} => bufferResize
     * When set to true (50 milliseconds) or a number of milliseconds, the layout assigned for this container will buffer
     * the frequency(频率) it calculates(估算) and does a re-layout of components. This is useful for heavy containers
     * or containers with a large quantity(数量) of sub-components for which frequent layout calls would be expensive.
     *  Defaults to 50.
     */
    bufferResize: 50,

    
/**
     * @cfg {String/Number} => activeItem
     * A string component id or the numeric index of the component that should be initially activated within the
     * container's layout on render.  For example, activeItem: 'item-1' or activeItem: 0 (index 0 = the first
     * item in the container's collection).  activeItem only applies to layout styles that can display
     * items one at a time (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout} and
     * {@link Ext.layout.FitLayout}).  Related to {@link Ext.layout.ContainerLayout#activeItem}.
     */
    
/**
     * @cfg {Object/Array} => items
     *
** IMPORTANT: be sure to {specify a layout} if needed ! **
     *
     * A single item, or an array of child Components to be added to this container,
     * for example:
        // specifying a single item
        items: {...},
        layout: 'fit',    // specify a layout!
        
        // specifying multiple items
        items: [{...}, {...}],
        layout: 'anchor', // specify a layout!
     *
     * Each item may be:
     * (1)any type of object based on {Ext.Component}
     * (2)a fully instantiated(实例) object or an object literal(原义的) that: has a specified
          {Ext.Component#xtype xtype}
     *
the {Ext.Component#xtype} specified is associated with(联系) the Component
     * desired and should be chosen from one of the available xtypes as listed
     * in {Ext.Component}.
     *
If an {Ext.Component#xtype xtype} is not explicitly
     * specified, the {defaultType} for that Container is used.
     *
Notes:
     *
     * Ext uses lazy rendering. Child Components will only be rendered
     * should it become necessary. Items are automatically laid out when they are first
     * shown (no sizing is done while hidden), or in response to a {doLayout} call.
     *
     * Do not specify {Ext.Panel#contentEl contentEl}/
     * {Ext.Panel#html html} with items.
     */
    
/**
     * @cfg {Object|Function} => defaults
     *
This option is a means of applying default settings to all added items whether added through the {items}
     * config or via the {add} or {insert} methods.
     *
If an added item is a config object, and not an instantiated(实例) Component, then the default properties are
     * unconditionally applied. If the added item is an instantiated Component, then the default properties are
     * applied conditionally so as not to override existing properties in the item.
     *
If the defaults option is specified as a function, then the function will be called using this Container as the
     * scope (this reference) and passing the added item as the first parameter. Any resulting object
     * from that call is then applied to the item as default properties.
     *
For example, to automatically apply padding(填充) to the body of each of a set of
     * contained {Ext.Panel} items, you could pass: defaults: {bodyStyle:'padding:15px'}.
     * Usage(示例):
            defaults: {               // defaults are applied to items, not the container
                autoScroll:true
            },
            items: [
                {
                    xtype: 'panel',   // defaults do not have precedence(优先权) over
                    id: 'panel1',     // options in config objects, so the defaults
                    autoScroll: false // 覆盖掉defaults配置 will not be applied here, panel1 will be autoScroll:false
                },
                new Ext.Panel({       // defaults do have precedence over options
                    id: 'panel2',     // defaults中的配置优先配置,故下边同名配置无效,不会被覆盖 options in components, so
                                      // the defaults
                    autoScroll: false // will be applied here, panel2 will be autoScroll:true.
                })
            ]
     *

     */


    
/** @cfg {Boolean} => autoDestroy    //自动摧毁
     * If true the container will automatically destroy any contained component that is removed from it, else
     * destruction(摧毁) must be handled manually(手工地) (defaults to true).
     */
    autoDestroy : true,

    
/** @cfg {Boolean} => forceLayout
     * If true the container will force a layout initially(起初) even if(即使) hidden or collapsed. This option
     * is useful for forcing forms to render in collapsed or hidden containers. (defaults to false).
     */
    forceLayout: false,

    
/** @cfg {Boolean} => hideBorders
     * True to hide the borders of each contained component, false to defer to(顺从) the component's existing
     * border settings (defaults to false).
     */
    
/** @cfg {String} => defaultType
     *
The default {Ext.Component xtype} of child Components to create in this Container when
     * a child item is specified as a raw(原始的) configuration object, rather than as an instantiated Component.


     *
Defaults to 'panel', except(但是) {Ext.menu.Menu} which defaults to 'menuitem',
     * and {Ext.Toolbar} and {Ext.ButtonGroup} which default to 'button'.
     */
    defaultType : 'panel',

    
/** @cfg {String} => resizeEvent
     * The event to listen to for resizing in layouts. Defaults to 'resize'.
     */
    resizeEvent: 'resize',

    
/**
     * @cfg {Array} => bubbleEvents
     *
An array of events that, when fired, should be bubbled to any parent container.
     * See {Ext.util.Observable#enableBubble}.
     * Defaults to ['add', 'remove'].
     */
    bubbleEvents: ['add', 'remove'],

    // private
    initComponent : function(){
        Ext.Container.superclass.initComponent.call(this);

        //注册事件(添加事件)
        this.addEvents(
            

/**
             * @event afterlayout
             * Fires when the components in this container are arranged(准备、安排) by the associated(相关的) layout manager.
             * @param {Ext.Container} this
             * @param {ContainerLayout} layout_The ContainerLayout implementation for this container
             */
            'afterlayout',
            
/**
             * @event beforeadd
             * Fires before any {Ext.Component} is added or inserted into the container.
             * A handler can return false to cancel the add.
             * @param {Ext.Container} this
             * @param {Ext.Component} component_The component being added
             * @param {Number} index_The index at which the component will be added to the container's items collection
             */
            'beforeadd',
            
/**
             * @event beforeremove
             * Fires before any {Ext.Component} is removed from the container.  A handler can return
             * false to cancel the remove.
             * @param {Ext.Container} this
             * @param {Ext.Component} component_The component being removed
             */
            'beforeremove',
            
/**
             * @event add
             * @bubbles
             * Fires after any {Ext.Component} is added or inserted into the container.
             * @param {Ext.Container} this
             * @param {Ext.Component} component_The component that was added
             * @param {Number} index_The index at which the component was added to the container's items collection
             */
            'add',
            
/**
             * @event remove
             * @bubbles
             * Fires after any {Ext.Component} is removed from the container.
             * @param {Ext.Container} this
             * @param {Ext.Component} component_The component that was removed
             */
            'remove'
        );

        
/**
         * The collection of components in this container as a {Ext.util.MixedCollection}
         * @type MixedCollection
         * @property items
         */
        var items = this.items;
        if(items){
            delete this.items;
            this.add(items);
        }
    },

    // read_private
    initItems : function(){
        if(!this.items){
            this.items = new Ext.util.MixedCollection(false, this.getComponentId);
            this.getLayout(); // initialize the layout
        }
    },

    // private
    setLayout : function(layout){
        if(this.layout && this.layout != layout){
            this.layout.setContainer(null);
        }
        this.layout = layout;
        this.initItems();
        layout.setContainer(this);
    },

    afterRender: function(){
        // Render this Container, this should be done before setLayout is called which
        // will hook(指定) onResize
        Ext.Container.superclass.afterRender.call(this);
        if(!this.layout){
            this.layout = 'auto';
        }
        if(Ext.isObject(this.layout) && !this.layout.layout){
            this.layoutConfig = this.layout;
            this.layout = this.layoutConfig.type;
        }
        if(Ext.isString(this.layout)){
            this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);
        }
        this.setLayout(this.layout);

        // If a CardLayout, the active item set
        if(this.activeItem !== undefined && this.layout.setActiveItem){
            var item = this.activeItem;
            delete this.activeItem;
            this.layout.setActiveItem(item);
        }

        // If we have no ownerCt, render and size all children
        if(!this.ownerCt){
            this.doLayout(false, true);
        }

        // This is a manually(手工地) configured flag set by users in conjunction(结合) with renderTo.
        // Not to be confused(迷糊的) with the flag by the same name used in Layouts.
        if(this.monitorResize === true){
            Ext.EventManager.onWindowResize(this.doLayout, this, [false]);
        }
    },

    
/**
Returns the Element to be used to contain the child Components of this Container.
     *
An implementation(执行) is provided which returns the Container's {getEl Element}, but
     * if there is a more complex(复杂的) structure(结构) to a Container, this may be overridden to return
     * the element(渲染子组件的组件) into which the {layout} renders child Components.
     *
     * @return {Ext.Element} element_The Element to render child Components into.
     */
    getLayoutTarget : function(){
        return this.el;
    },

    // private - used as the key lookup(查找) function for the items collection
    getComponentId : function(comp){
        return comp.getItemId();
    },

    
/**    add事件
*
**Description :
     * Fires the {beforeadd} event before adding
     *
     * The Container's {#defaults default config values} will be applied
     * accordingly(相应的) (see {#defaults} for details).
     *
     * Fires the add event after the component has been added.
     *
**Notes :
     *
     * If the Container is already rendered when add
     * is called, you may need to call {doLayout} to refresh the view(视图界面) which causes
     * any unrendered child Components to be rendered. This is required so that you can
     * add multiple child components if needed while only refreshing the layout once.
     * For example:
            var tb = new Ext.Toolbar();
            tb.render(document.body);  // toolbar is rendered    //渲染金文档中。
            tb.add({text:'Button 1'}); // add multiple items ({defaultType} for {Ext.Toolbar Toolbar} is 'button')
            tb.add({text:'Button 2'});
            tb.doLayout();             // refresh the layout    //操作完成以后调用doLayout()函数进行刷新重新渲染。
**Warning: Containers directly managed by the BorderLayout layout manager
     * may not be removed or added.  See the Notes for {Ext.layout.BorderLayout BorderLayout}
     * for more details.

     * @param {...Object/Array} component
     *
Either one or more Components to add or an Array of Components to add.  See
     * {items} for additional information.

     * @return {Ext.Component/Array} The Components that were added.
     */
    add : function(comp){
        this.initItems();
        var args = arguments.length > 1;
        if(args || Ext.isArray(comp)){
            var result = [];
            Ext.each(args ? arguments : comp, function(c){
                result.push(this.add(c));    //说明:一个一个添加组件。
            }, this);
            return result;
        }
        var c = this.lookupComponent(this.applyDefaults(comp));    // 得到组件。
        var index = this.items.length;
        if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
            this.items.add(c);
            // *onAdded
            c.onAdded(this, index);
            this.onAdd(c);
            this.fireEvent('add', this, c, index);
        }
        return c;
    },

    onAdd : function(c){
        // Empty template method
    },

    // private
    onAdded : function(container, pos) {
        //overridden here so we can cascade down(逐级下报), not worth creating a template method.
        this.ownerCt = container;
        this.initRef();
        //initialize references for child items
        this.cascade(function(c){
            c.initRef();
        });
        this.fireEvent('added', this, container, pos);
    },

    
/**    组件插入事件
     * Inserts a Component into this Container at a specified index. Fires the
     * {beforeadd} event before inserting, then fires the {add} event after the
     * Component has been inserted.组件插入之后才触发add事件。
     *
     * @param {Number} index_The index at which the Component will be inserted
     * into the Container's items collection
     * @param {Ext.Component} component_The child Component to insert.

     * Ext uses lazy rendering(延时渲染), and will only render the inserted Component should
     * it become necessary(需要的时候才渲染).

     * A Component config object may be passed in order to avoid the overhead(开销) of
     * constructing(构建) a real Component object if lazy rendering might mean that the
     * inserted Component will not be rendered immediately. To take advantage of
     * this 'lazy instantiation', set the {Ext.Component#xtype} config
     * property to the registered type of the Component wanted.


     * For a list of all available xtypes, see {Ext.Component}.
     * @return {Ext.Component} component_The Component (or config object) that was
     * inserted with the Container's default config values applied.
     */
    insert : function(index, comp) {
        var args   = arguments,
            length = args.length,
            result = [],
            i, c;
        
        this.initItems();
        
        if (length > 2) {
            for (i = length - 1; i >= 1; --i) {
                result.push(this.insert(index, args[i]));
            }
            return result;
        }
        
        c = this.lookupComponent(this.applyDefaults(comp));
        index = Math.min(index, this.items.length);
        
        if (this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false) {
            if (c.ownerCt == this) {
                this.items.remove(c);
            }
            this.items.insert(index, c);
            c.onAdded(this, index);
            this.onAdd(c);
            this.fireEvent('add', this, c, index);
        }
        
        return c;
    },

    //read_private_把默认配置添加进组件。
    applyDefaults : function(c){
        var d = this.defaults;
        if(d){
            if(Ext.isFunction(d)){    //d不是函数。
                d = d.call(this, c);
            }
            if(Ext.isString(c)){
                c = Ext.ComponentMgr.get(c);
                Ext.apply(c, d);
            }else if(!c.events){
                Ext.applyIf(c, d);
            }else{
                Ext.apply(c, d);
            }
        }
        return c;
    },

    // private
    onBeforeAdd : function(item){
        if(item.ownerCt){
            item.ownerCt.remove(item, false);
        }
        if(this.hideBorders === true){
            item.border = (item.border === true);
        }
    },

    
/** 组件移除事件
     * Removes a component from this container.  Fires the {beforeremove} event before removing, then fires
     * the {remove} event after the component has been removed.
     *
     * @param {Component/String} component_The component reference or id to remove.
     * @param {Boolean} autoDestroy (optional)_True to automatically invoke(调用) the removed
     *           Component's {Ext.Component#destroy} function.
     * Defaults to the value of this Container's {autoDestroy} config.
     * @return {Ext.Component} component_The Component that was removed.
     */
    remove : function(comp, autoDestroy){
        this.initItems();
        var c = this.getComponent(comp);
        if(c && this.fireEvent('beforeremove', this, c) !== false){
            this.doRemove(c, autoDestroy);
            this.fireEvent('remove', this, c);
        }
        return c;
    },

    onRemove: function(c){
        // Empty template method
    },

    // private
    doRemove: function(c, autoDestroy){
        var l = this.layout,
            hasLayout = l && this.rendered;

        if(hasLayout){
            l.onRemove(c);
        }
        this.items.remove(c);
        c.onRemoved();
        this.onRemove(c);
        if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){
            c.destroy();
        }
        if(hasLayout){
            l.afterRemove(c);
        }
    },

    
/**
     * Removes all components from this container.
     * @param {Boolean} autoDestroy (optional)_True to automatically invoke(调用) the removed Component's
     * {Ext.Component#destroy} function.
     * Defaults to the value of this Container's {autoDestroy} config.
     * @return {Array} Array of the destroyed components
     */
    removeAll: function(autoDestroy){
        this.initItems();
        var item, rem = [], items = [];
        this.items.each(function(i){
            rem.push(i);
        });
        for (var i = 0, len = rem.length; i < len; ++i){
            item = rem[i];
            this.remove(item, autoDestroy);
            if(item.ownerCt !== this){
                items.push(item);
            }
        }
        return items;
    },

    
/**
     * Examines(检查) this container's items property
     * and gets a direct child component of this container.
     *
     * @param {String/Number} comp_This parameter may be any of the following:
     * (1)a String : representing(代表) the {Ext.Component#itemId itemId}
     * or {Ext.Component#id id} of the child component
     * (2)a Number : representing the position of the child component
     * within the items property
     *
     * @return Ext.Component_The component (if found).
     */
    getComponent : function(comp){
        if(Ext.isObject(comp)){
            comp = comp.getItemId();
        }
        return this.items.get(comp);
    },

    // read_private_查找组件
    lookupComponent : function(comp){
        if(Ext.isString(comp)){
            return Ext.ComponentMgr.get(comp);
        }else if(!comp.events){
            return this.createComponent(comp);
        }
        return comp;
    },

    // private
    createComponent : function(config, defaultType){
        if (config.render) {
            return config;
        }
        // add in ownerCt at creation time but then immediately
        // remove so that onBeforeAdd can handle it
        var c = Ext.create(Ext.apply({
            ownerCt: this
        }, config), defaultType || this.defaultType);
        delete c.initialConfig.ownerCt;
        delete c.ownerCt;
        return c;
    },

    /**
     * @private
     * We can only lay out if there is a view area in which to layout.
     * display: none on the layout target,or any of its parent elements will mean it has no view area.
     */
    canLayout : function() {
        var el = this.getVisibilityEl();
        return el && el.dom && !el.isStyle("display", "none");
    },

    

/**
     * Force this container's layout to be recalculated(重新计算). A call to this function is required
     * after adding a new component to an already rendered container, or possibly after changing sizing/position
     * properties of child components.
     *
     * @param {Boolean} shallow (optional)_True to only calc(计算) the layout of this component, and let child components
     * auto calc layouts as required (defaults to false, which calls doLayout recursively(递归地) for each subcontainer)
     *
     * @param {Boolean} force (optional)_True to force a layout to occur, even if the item is hidden.
     * @return {Ext.Container} this
     */

    doLayout : function(shallow, force){
        var rendered = this.rendered,
            forceLayout = force || this.forceLayout;

        if(this.collapsed || !this.canLayout()){
            this.deferLayout = this.deferLayout || !shallow;
            if(!forceLayout){
                return;
            }
            shallow = shallow && !this.deferLayout;
        } else {
            delete this.deferLayout;
        }
        if(rendered && this.layout){
            this.layout.layout();
        }
        if(shallow !== true && this.items){
            var cs = this.items.items;
            for(var i = 0, len = cs.length; i < len; i++){
                var c = cs[i];
                if(c.doLayout){
                    c.doLayout(false, forceLayout);
                }
            }
        }
        if(rendered){
            this.onLayout(shallow, forceLayout);
        }
        // Initial layout completed
        this.hasLayout = true;
        delete this.forceLayout;
    },

    onLayout : Ext.emptyFn,

    // private
    shouldBufferLayout: function(){
        /*
         * Returns true if the container should buffer a layout.
         * This is true only if the container has previously been laid out
         * and has a parent container that is pending a layout.
         */
        var hl = this.hasLayout;
        if(this.ownerCt){
            // Only ever buffer if we've laid out the first time and we have one pending.
            return hl ? !this.hasLayoutPending() : false;
        }
        // Never buffer initial layout
        return hl;
    },

    // private
    hasLayoutPending: function(){
        // Traverse(穿越) hierarchy(层次体系) to see if any parent container has a pending layout.
        var pending = false;
        this.ownerCt.bubble(function(c){
            if(c.layoutPending){
                pending = true;
                return false;
            }
        });
        return pending;
    },

    onShow : function(){
        // removes css classes that were added to hide
        Ext.Container.superclass.onShow.call(this);
        // If we were sized during the time we were hidden, layout.
        if(Ext.isDefined(this.deferLayout)){
            delete this.deferLayout;
            this.doLayout(true);
        }
    },

    
/**_read
     * Returns the layout currently in use by the container.  If the container does not currently have a layout
     * set, a default {Ext.layout.ContainerLayout} will be created and set as the container's layout.
     * @return {ContainerLayout} layout_The container's layout
     */
    getLayout : function(){
        if(!this.layout){
            var layout = new Ext.layout.AutoLayout(this.layoutConfig);
            this.setLayout(layout);
        }
        return this.layout;
    },

    // private
    beforeDestroy : function(){
        var c;
        if(this.items){
            while(c = this.items.first()){
                this.doRemove(c, true);
            }
        }
        if(this.monitorResize){
            Ext.EventManager.removeResizeListener(this.doLayout, this);
        }
        Ext.destroy(this.layout);
        Ext.Container.superclass.beforeDestroy.call(this);
    },

    
/**read
     * Cascades down(逐层下报) the component/container hierarchy(层次) from this component (called first),
     * calling the specified function with each component. The scope (this) of
     * function call will be the scope provided or the current component. The arguments to the function
     * will be the args provided or the current component. If the function returns false at any point,
     * the cascade is stopped on that branch(分支).
     * @param {Function} fn_The function to call
     * @param {Object} scope (optional)_The scope of the function (defaults to current component)
     * @param {Array} args (optional)_The args to call the function with (defaults to passing the current component)
     * @return {Ext.Container} this
     */
    cascade : function(fn, scope, args){
        if(fn.apply(scope || this, args || [this]) !== false){
            if(this.items){
                var cs = this.items.items;
                for(var i = 0, len = cs.length; i < len; i++){
                    if(cs[i].cascade){
                        cs[i].cascade(fn, scope, args);
                    }else{
                        fn.apply(scope || cs[i], args || [cs[i]]);
                    }
                }
            }
        }
        return this;
    },

    
/**
     * Find a component under this container at any level by id
     * @param {String} id
     * @deprecated(不赞成) Fairly useless method(完全无用的方法), since you can just use Ext.getCmp.
     * Should be removed for 4.0
     * If you need to test if an id belongs to a container, you can use getCmp and findParent*.
     * @return Ext.Component
     */
    findById : function(id){
        var m = null,
            ct = this;
        this.cascade(function(c){
            if(ct != c && c.id === id){
                m = c;
                return false;
            }
        });
        return m;
    },

    
/**
     * Find a component under this container at any level by xtype or class
     * @param {String/Class} xtype_The xtype string for a component, or the class of the component directly
     * @param {Boolean} shallow (optional)_False to check whether this Component is descended from the xtype (this is
     * the default), or true to check whether this Component is directly of the specified xtype.
     * @return {Array} Array of Ext.Components
     */
    findByType : function(xtype, shallow){
        return this.findBy(function(c){
            return c.isXType(xtype, shallow);
        });
    },

    
/**
     * Find a component under this container at any level by property
     * @param {String} prop
     * @param {String} value
     * @return {Array} Array of Ext.Components
     */
    find : function(prop, value){
        return this.findBy(function(c){
            return c[prop] === value;
        });
    },

    
/**
     * Find a component under this container at any level by a custom function. If the passed function returns
     * true, the component will be included in the results. The passed function is called with the arguments
     * (component, this container).
     * @param {Function} fn The function to call
     * @param {Object} scope (optional)
     * @return {Array} Array of Ext.Components
     */
    findBy : function(fn, scope){
        var m = [], ct = this;
        this.cascade(function(c){
            if(ct != c && fn.call(scope || c, c, ct) === true){
                m.push(c);
            }
        });
        return m;
    },

    
/**
     * Get a component contained by this container (alias(别名) for items.get(key))
     * @param {String/Number} key_The index or id of the component
     * @deprecated Should be removed in 4.0, since getComponent does the same thing.
     * @return {Ext.Component} Ext.Component
     */
    get : function(key){
        return this.getComponent(key);
    }
});

Ext.Container.LAYOUTS = {};
Ext.reg('container', Ext.Container);