3 <title>The source code</title>
\r
4 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
5 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
7 <body onload="prettyPrint();">
\r
8 <pre class="prettyprint lang-js"><div id="cls-Ext.Container"></div>/**
10 * @extends Ext.BoxComponent
11 * <p>Base class for any {@link Ext.BoxComponent} that may contain other Components. Containers handle the
12 * basic behavior of containing items, namely adding, inserting and removing items.</p>
14 * <p>The most commonly used Container classes are {@link Ext.Panel}, {@link Ext.Window} and {@link Ext.TabPanel}.
15 * If you do not need the capabilities offered by the aforementioned classes you can create a lightweight
16 * Container to be encapsulated by an HTML element to your specifications by using the
17 * <tt><b>{@link Ext.Component#autoEl autoEl}</b></tt> config option. This is a useful technique when creating
18 * embedded {@link Ext.layout.ColumnLayout column} layouts inside {@link Ext.form.FormPanel FormPanels}
21 * <p>The code below illustrates both how to explicitly create a Container, and how to implicitly
22 * create one using the <b><tt>'container'</tt></b> xtype:<pre><code>
23 // explicitly create a Container
24 var embeddedColumns = new Ext.Container({
25 autoEl: 'div', // This is the default
28 // implicitly create Container by specifying xtype
30 autoEl: 'div', // This is the default.
37 // The two items below will be Ext.Containers, each encapsulated by a <DIV> element.
42 fieldLabel: 'Start date'
48 fieldLabel: 'End date'
53 * <p><u><b>Layout</b></u></p>
54 * <p>Container classes delegate the rendering of child Components to a layout
55 * manager class which must be configured into the Container using the
56 * <code><b>{@link #layout}</b></code> configuration property.</p>
57 * <p>When either specifying child <code>{@link #items}</code> of a Container,
58 * or dynamically {@link #add adding} Components to a Container, remember to
59 * consider how you wish the Container to arrange those child elements, and
60 * whether those child elements need to be sized using one of Ext's built-in
61 * <b><code>{@link #layout}</code></b> schemes. By default, Containers use the
62 * {@link Ext.layout.ContainerLayout ContainerLayout} scheme which only
63 * renders child components, appending them one after the other inside the
64 * Container, and <b>does not apply any sizing</b> at all.</p>
65 * <p>A common mistake is when a developer neglects to specify a
66 * <b><code>{@link #layout}</code></b> (e.g. widgets like GridPanels or
67 * TreePanels are added to Containers for which no <tt><b>{@link #layout}</b></tt>
68 * has been specified). If a Container is left to use the default
69 * {@link Ext.layout.ContainerLayout ContainerLayout} scheme, none of its
70 * child components will be resized, or changed in any way when the Container
72 * <p>Certain layout managers allow dynamic addition of child components.
73 * Those that do include {@link Ext.layout.CardLayout},
74 * {@link Ext.layout.AnchorLayout}, {@link Ext.layout.FormLayout}, and
75 * {@link Ext.layout.TableLayout}. For example:<pre><code>
76 // Create the GridPanel.
77 var myNewGrid = new Ext.grid.GridPanel({
79 columns: myColumnModel,
80 title: 'Results', // the title becomes the title of the tab
83 myTabPanel.add(myNewGrid); // {@link Ext.TabPanel} implicitly uses {@link Ext.layout.CardLayout CardLayout}
84 myTabPanel.{@link Ext.TabPanel#setActiveTab setActiveTab}(myNewGrid);
86 * <p>The example above adds a newly created GridPanel to a TabPanel. Note that
87 * a TabPanel uses {@link Ext.layout.CardLayout} as its layout manager which
88 * means all its child items are sized to {@link Ext.layout.FitLayout fit}
89 * exactly into its client area.
90 * <p><b><u>Overnesting is a common problem</u></b>.
91 * An example of overnesting occurs when a GridPanel is added to a TabPanel
92 * by wrapping the GridPanel <i>inside</i> a wrapping Panel (that has no
93 * <tt><b>{@link #layout}</b></tt> specified) and then add that wrapping Panel
94 * to the TabPanel. The point to realize is that a GridPanel <b>is</b> a
95 * Component which can be added directly to a Container. If the wrapping Panel
96 * has no <tt><b>{@link #layout}</b></tt> configuration, then the overnested
97 * GridPanel will not be sized as expected.<p>
99 * <p><u><b>Adding via remote configuration</b></u></p>
101 * <p>A server side script can be used to add Components which are generated dynamically on the server.
102 * An example of adding a GridPanel to a TabPanel where the GridPanel is generated by the server
103 * based on certain parameters:
105 // execute an Ajax request to invoke server side script:
107 url: 'gen-invoice-grid.php',
108 // send additional parameters to instruct server script
110 startDate: Ext.getCmp('start-date').getValue(),
111 endDate: Ext.getCmp('end-date').getValue()
113 // process the response object to add it to the TabPanel:
114 success: function(xhr) {
115 var newComponent = eval(xhr.responseText); // see discussion below
116 myTabPanel.add(newComponent); // add the component to the TabPanel
117 myTabPanel.setActiveTab(newComponent);
119 failure: function() {
120 Ext.Msg.alert("Grid create failed", "Server communication failure");
124 * <p>The server script needs to return an executable Javascript statement which, when processed
125 * using <tt>eval()</tt>, will return either a config object with an {@link Ext.Component#xtype xtype},
126 * or an instantiated Component. The server might return this for example:</p><pre><code>
128 function formatDate(value){
129 return value ? value.dateFormat('M d, Y') : '';
132 var store = new Ext.data.Store({
133 url: 'get-invoice-data.php',
135 startDate: '01/01/2008',
136 endDate: '01/31/2008'
138 reader: new Ext.data.JsonReader({
139 record: 'transaction',
141 totalRecords: 'total'
145 {name: 'date', type: 'date', dateFormat: 'm/d/Y'},
146 {name: 'value', type: 'float'}
150 var grid = new Ext.grid.GridPanel({
151 title: 'Invoice Report',
152 bbar: new Ext.PagingToolbar(store),
155 {header: "Customer", width: 250, dataIndex: 'customer', sortable: true},
156 {header: "Invoice Number", width: 120, dataIndex: 'invNo', sortable: true},
157 {header: "Invoice Date", width: 100, dataIndex: 'date', renderer: formatDate, sortable: true},
158 {header: "Value", width: 120, dataIndex: 'value', renderer: 'usMoney', sortable: true}
162 return grid; // return instantiated component
165 * <p>When the above code fragment is passed through the <tt>eval</tt> function in the success handler
166 * of the Ajax request, the code is executed by the Javascript processor, and the anonymous function
167 * runs, and returns the instantiated grid component.</p>
168 * <p>Note: since the code above is <i>generated</i> by a server script, the <tt>baseParams</tt> for
169 * the Store, the metadata to allow generation of the Record layout, and the ColumnModel
170 * can all be generated into the code since these are all known on the server.</p>
174 Ext.Container = Ext.extend(Ext.BoxComponent, {
175 <div id="cfg-Ext.Container-monitorResize"></div>/**
176 * @cfg {Boolean} monitorResize
177 * True to automatically monitor window resize events to handle anything that is sensitive to the current size
178 * of the viewport. This value is typically managed by the chosen <code>{@link #layout}</code> and should not need
179 * to be set manually.
181 <div id="cfg-Ext.Container-layout"></div>/**
182 * @cfg {String/Object} layout
183 * <p><b>*Important</b>: In order for child items to be correctly sized and
184 * positioned, typically a layout manager <b>must</b> be specified through
185 * the <code>layout</code> configuration option.</p>
186 * <br><p>The sizing and positioning of child {@link items} is the responsibility of
187 * the Container's layout manager which creates and manages the type of layout
188 * you have in mind. For example:</p><pre><code>
190 width:300, height: 300,
191 layout: 'fit', // explicitly set layout manager: override the default (layout:'auto')
193 title: 'Panel inside a Window'
197 * <p>If the {@link #layout} configuration is not explicitly specified for
198 * a general purpose container (e.g. Container or Panel) the
199 * {@link Ext.layout.ContainerLayout default layout manager} will be used
200 * which does nothing but render child components sequentially into the
201 * Container (no sizing or positioning will be performed in this situation).
202 * Some container classes implicitly specify a default layout
203 * (e.g. FormPanel specifies <code>layout:'form'</code>). Other specific
204 * purpose classes internally specify/manage their internal layout (e.g.
205 * GridPanel, TabPanel, TreePanel, Toolbar, Menu, etc.).</p>
206 * <br><p><b><code>layout</code></b> may be specified as either as an Object or
207 * as a String:</p><div><ul class="mdetail-params">
209 * <li><u>Specify as an Object</u></li>
210 * <div><ul class="mdetail-params">
211 * <li>Example usage:</li>
220 * <li><tt><b>type</b></tt></li>
221 * <br/><p>The layout type to be used for this container. If not specified,
222 * a default {@link Ext.layout.ContainerLayout} will be created and used.</p>
223 * <br/><p>Valid layout <tt>type</tt> values are:</p>
224 * <div class="sub-desc"><ul class="mdetail-params">
225 * <li><tt><b>{@link Ext.layout.AbsoluteLayout absolute}</b></tt></li>
226 * <li><tt><b>{@link Ext.layout.AccordionLayout accordion}</b></tt></li>
227 * <li><tt><b>{@link Ext.layout.AnchorLayout anchor}</b></tt></li>
228 * <li><tt><b>{@link Ext.layout.ContainerLayout auto}</b></tt> <b>Default</b></li>
229 * <li><tt><b>{@link Ext.layout.BorderLayout border}</b></tt></li>
230 * <li><tt><b>{@link Ext.layout.CardLayout card}</b></tt></li>
231 * <li><tt><b>{@link Ext.layout.ColumnLayout column}</b></tt></li>
232 * <li><tt><b>{@link Ext.layout.FitLayout fit}</b></tt></li>
233 * <li><tt><b>{@link Ext.layout.FormLayout form}</b></tt></li>
234 * <li><tt><b>{@link Ext.layout.HBoxLayout hbox}</b></tt></li>
235 * <li><tt><b>{@link Ext.layout.MenuLayout menu}</b></tt></li>
236 * <li><tt><b>{@link Ext.layout.TableLayout table}</b></tt></li>
237 * <li><tt><b>{@link Ext.layout.ToolbarLayout toolbar}</b></tt></li>
238 * <li><tt><b>{@link Ext.layout.VBoxLayout vbox}</b></tt></li>
241 * <li>Layout specific configuration properties</li>
242 * <br/><p>Additional layout specific configuration properties may also be
243 * specified. For complete details regarding the valid config options for
244 * each layout type, see the layout class corresponding to the <tt>type</tt>
249 * <li><u>Specify as a String</u></li>
250 * <div><ul class="mdetail-params">
251 * <li>Example usage:</li>
259 * <li><tt><b>layout</b></tt></li>
260 * <br/><p>The layout <tt>type</tt> to be used for this container (see list
261 * of valid layout type values above).</p><br/>
262 * <li><tt><b>{@link #layoutConfig}</b></tt></li>
263 * <br/><p>Additional layout specific configuration properties. For complete
264 * details regarding the valid config options for each layout type, see the
265 * layout class corresponding to the <tt>layout</tt> specified.</p>
266 * </ul></div></ul></div>
268 <div id="cfg-Ext.Container-layoutConfig"></div>/**
269 * @cfg {Object} layoutConfig
270 * This is a config object containing properties specific to the chosen
271 * <b><code>{@link #layout}</code></b> if <b><code>{@link #layout}</code></b>
272 * has been specified as a <i>string</i>.</p>
274 <div id="cfg-Ext.Container-bufferResize"></div>/**
275 * @cfg {Boolean/Number} bufferResize
276 * When set to true (100 milliseconds) or a number of milliseconds, the layout assigned for this container will buffer
277 * the frequency it calculates and does a re-layout of components. This is useful for heavy containers or containers
278 * with a large quantity of sub-components for which frequent layout calls would be expensive.
282 <div id="cfg-Ext.Container-activeItem"></div>/**
283 * @cfg {String/Number} activeItem
284 * A string component id or the numeric index of the component that should be initially activated within the
285 * container's layout on render. For example, activeItem: 'item-1' or activeItem: 0 (index 0 = the first
286 * item in the container's collection). activeItem only applies to layout styles that can display
287 * items one at a time (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout} and
288 * {@link Ext.layout.FitLayout}). Related to {@link Ext.layout.ContainerLayout#activeItem}.
290 <div id="cfg-Ext.Container-items"></div>/**
291 * @cfg {Object/Array} items
292 * <pre><b>** IMPORTANT</b>: be sure to <b>{@link #layout specify a <code>layout</code>} if needed ! **</b></pre>
293 * <p>A single item, or an array of child Components to be added to this container,
296 // specifying a single item
298 layout: 'fit', // specify a layout!
300 // specifying multiple items
301 items: [{...}, {...}],
302 layout: 'anchor', // specify a layout!
304 * <p>Each item may be:</p>
305 * <div><ul class="mdetail-params">
306 * <li>any type of object based on {@link Ext.Component}</li>
307 * <li>a fully instanciated object or</li>
308 * <li>an object literal that:</li>
309 * <div><ul class="mdetail-params">
310 * <li>has a specified <code>{@link Ext.Component#xtype xtype}</code></li>
311 * <li>the {@link Ext.Component#xtype} specified is associated with the Component
312 * desired and should be chosen from one of the available xtypes as listed
313 * in {@link Ext.Component}.</li>
314 * <li>If an <code>{@link Ext.Component#xtype xtype}</code> is not explicitly
315 * specified, the {@link #defaultType} for that Container is used.</li>
316 * <li>will be "lazily instanciated", avoiding the overhead of constructing a fully
317 * instanciated Component object</li>
318 * </ul></div></ul></div>
319 * <p><b>Notes</b>:</p>
320 * <div><ul class="mdetail-params">
321 * <li>Ext uses lazy rendering. Child Components will only be rendered
322 * should it become necessary. Items are automatically laid out when they are first
323 * shown (no sizing is done while hidden), or in response to a {@link #doLayout} call.</li>
324 * <li>Do not specify <code>{@link Ext.Panel#contentEl contentEl}</code>/
325 * <code>{@link Ext.Panel#html html}</code> with <code>items</code>.</li>
328 <div id="cfg-Ext.Container-defaults"></div>/**
329 * @cfg {Object} defaults
330 * <p>A config object that will be applied to all components added to this container either via the {@link #items}
331 * config or via the {@link #add} or {@link #insert} methods. The <tt>defaults</tt> config can contain any
332 * number of name/value property pairs to be added to each item, and should be valid for the types of items
333 * being added to the container. For example, to automatically apply padding to the body of each of a set of
334 * contained {@link Ext.Panel} items, you could pass: <tt>defaults: {bodyStyle:'padding:15px'}</tt>.</p><br/>
335 * <p><b>Note</b>: <tt>defaults</tt> will not be applied to config objects if the option is already specified.
336 * For example:</p><pre><code>
337 defaults: { // defaults are applied to items, not the container
342 xtype: 'panel', // defaults <b>do not</b> have precedence over
343 id: 'panel1', // options in config objects, so the defaults
344 autoScroll: false // will not be applied here, panel1 will be autoScroll:false
346 new Ext.Panel({ // defaults <b>do</b> have precedence over options
347 id: 'panel2', // options in components, so the defaults
348 autoScroll: false // will be applied here, panel2 will be autoScroll:true.
355 <div id="cfg-Ext.Container-autoDestroy"></div>/** @cfg {Boolean} autoDestroy
356 * If true the container will automatically destroy any contained component that is removed from it, else
357 * destruction must be handled manually (defaults to true).
361 <div id="cfg-Ext.Container-forceLayout"></div>/** @cfg {Boolean} forceLayout
362 * If true the container will force a layout initially even if hidden or collapsed. This option
363 * is useful for forcing forms to render in collapsed or hidden containers. (defaults to false).
367 <div id="cfg-Ext.Container-hideBorders"></div>/** @cfg {Boolean} hideBorders
368 * True to hide the borders of each contained component, false to defer to the component's existing
369 * border settings (defaults to false).
371 <div id="cfg-Ext.Container-defaultType"></div>/** @cfg {String} defaultType
372 * <p>The default {@link Ext.Component xtype} of child Components to create in this Container when
373 * a child item is specified as a raw configuration object, rather than as an instantiated Component.</p>
374 * <p>Defaults to <tt>'panel'</tt>, except {@link Ext.menu.Menu} which defaults to <tt>'menuitem'</tt>,
375 * and {@link Ext.Toolbar} and {@link Ext.ButtonGroup} which default to <tt>'button'</tt>.</p>
377 defaultType : 'panel',
380 initComponent : function(){
381 Ext.Container.superclass.initComponent.call(this);
384 <div id="event-Ext.Container-afterlayout"></div>/**
386 * Fires when the components in this container are arranged by the associated layout manager.
387 * @param {Ext.Container} this
388 * @param {ContainerLayout} layout The ContainerLayout implementation for this container
391 <div id="event-Ext.Container-beforeadd"></div>/**
393 * Fires before any {@link Ext.Component} is added or inserted into the container.
394 * A handler can return false to cancel the add.
395 * @param {Ext.Container} this
396 * @param {Ext.Component} component The component being added
397 * @param {Number} index The index at which the component will be added to the container's items collection
400 <div id="event-Ext.Container-beforeremove"></div>/**
401 * @event beforeremove
402 * Fires before any {@link Ext.Component} is removed from the container. A handler can return
403 * false to cancel the remove.
404 * @param {Ext.Container} this
405 * @param {Ext.Component} component The component being removed
408 <div id="event-Ext.Container-add"></div>/**
411 * Fires after any {@link Ext.Component} is added or inserted into the container.
412 * @param {Ext.Container} this
413 * @param {Ext.Component} component The component that was added
414 * @param {Number} index The index at which the component was added to the container's items collection
417 <div id="event-Ext.Container-remove"></div>/**
420 * Fires after any {@link Ext.Component} is removed from the container.
421 * @param {Ext.Container} this
422 * @param {Ext.Component} component The component that was removed
427 this.enableBubble('add', 'remove');
429 <div id="prop-Ext.Container-items"></div>/**
430 * The collection of components in this container as a {@link Ext.util.MixedCollection}
431 * @type MixedCollection
434 var items = this.items;
437 if(Ext.isArray(items) && items.length > 0){
438 this.add.apply(this, items);
446 initItems : function(){
448 this.items = new Ext.util.MixedCollection(false, this.getComponentId);
449 this.getLayout(); // initialize the layout
454 setLayout : function(layout){
455 if(this.layout && this.layout != layout){
456 this.layout.setContainer(null);
459 this.layout = layout;
460 layout.setContainer(this);
465 Ext.Container.superclass.render.apply(this, arguments);
467 if(Ext.isObject(this.layout) && !this.layout.layout){
468 this.layoutConfig = this.layout;
469 this.layout = this.layoutConfig.type;
471 if(typeof this.layout == 'string'){
472 this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);
474 this.setLayout(this.layout);
476 if(this.activeItem !== undefined){
477 var item = this.activeItem;
478 delete this.activeItem;
479 this.layout.setActiveItem(item);
483 // force a layout if no ownerCt is set
484 this.doLayout(false, true);
486 if(this.monitorResize === true){
487 Ext.EventManager.onWindowResize(this.doLayout, this, [false]);
491 <div id="method-Ext.Container-getLayoutTarget"></div>/**
492 * <p>Returns the Element to be used to contain the child Components of this Container.</p>
493 * <p>An implementation is provided which returns the Container's {@link #getEl Element}, but
494 * if there is a more complex structure to a Container, this may be overridden to return
495 * the element into which the {@link #layout layout} renders child Components.</p>
496 * @return {Ext.Element} The Element to render child Components into.
498 getLayoutTarget : function(){
502 // private - used as the key lookup function for the items collection
503 getComponentId : function(comp){
504 return comp.getItemId();
507 <div id="method-Ext.Container-add"></div>/**
508 * <p>Adds {@link Ext.Component Component}(s) to this Container.</p>
509 * <br><p><b>Description</b></u> :
510 * <div><ul class="mdetail-params">
511 * <li>Fires the {@link #beforeadd} event before adding</li>
512 * <li>The Container's {@link #defaults default config values} will be applied
513 * accordingly (see <code>{@link #defaults}</code> for details).</li>
514 * <li>Fires the {@link #add} event after the component has been added.</li>
516 * <br><p><b>Notes</b></u> :
517 * <div><ul class="mdetail-params">
518 * <li>If the Container is <i>already rendered</i> when <tt>add</tt>
519 * is called, you may need to call {@link #doLayout} to refresh the view which causes
520 * any unrendered child Components to be rendered. This is required so that you can
521 * <tt>add</tt> multiple child components if needed while only refreshing the layout
522 * once. For example:<pre><code>
523 var tb = new {@link Ext.Toolbar}();
524 tb.render(document.body); // toolbar is rendered
525 tb.add({text:'Button 1'}); // add multiple items ({@link #defaultType} for {@link Ext.Toolbar Toolbar} is 'button')
526 tb.add({text:'Button 2'});
527 tb.{@link #doLayout}(); // refresh the layout
529 * <li><i>Warning:</i> Containers directly managed by the BorderLayout layout manager
530 * may not be removed or added. See the Notes for {@link Ext.layout.BorderLayout BorderLayout}
531 * for more details.</li>
533 * @param {Object/Array} component
534 * <p>Either a single component or an Array of components to add. See
535 * <code>{@link #items}</code> for additional information.</p>
536 * @param {Object} (Optional) component_2
537 * @param {Object} (Optional) component_n
538 * @return {Ext.Component} component The Component (or config object) that was added.
540 add : function(comp){
542 var args = arguments.length > 1;
543 if(args || Ext.isArray(comp)){
544 Ext.each(args ? arguments : comp, function(c){
549 var c = this.lookupComponent(this.applyDefaults(comp));
550 var pos = this.items.length;
551 if(this.fireEvent('beforeadd', this, c, pos) !== false && this.onBeforeAdd(c) !== false){
554 this.fireEvent('add', this, c, pos);
559 <div id="method-Ext.Container-insert"></div>/**
560 * Inserts a Component into this Container at a specified index. Fires the
561 * {@link #beforeadd} event before inserting, then fires the {@link #add} event after the
562 * Component has been inserted.
563 * @param {Number} index The index at which the Component will be inserted
564 * into the Container's items collection
565 * @param {Ext.Component} component The child Component to insert.<br><br>
566 * Ext uses lazy rendering, and will only render the inserted Component should
567 * it become necessary.<br><br>
568 * A Component config object may be passed in order to avoid the overhead of
569 * constructing a real Component object if lazy rendering might mean that the
570 * inserted Component will not be rendered immediately. To take advantage of
571 * this 'lazy instantiation', set the {@link Ext.Component#xtype} config
572 * property to the registered type of the Component wanted.<br><br>
573 * For a list of all available xtypes, see {@link Ext.Component}.
574 * @return {Ext.Component} component The Component (or config object) that was
575 * inserted with the Container's default config values applied.
577 insert : function(index, comp){
579 var a = arguments, len = a.length;
581 for(var i = len-1; i >= 1; --i) {
582 this.insert(index, a[i]);
586 var c = this.lookupComponent(this.applyDefaults(comp));
588 if(c.ownerCt == this && this.items.indexOf(c) < index){
592 if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
593 this.items.insert(index, c);
595 this.fireEvent('add', this, c, index);
601 applyDefaults : function(c){
603 if(typeof c == 'string'){
604 c = Ext.ComponentMgr.get(c);
605 Ext.apply(c, this.defaults);
607 Ext.applyIf(c, this.defaults);
609 Ext.apply(c, this.defaults);
616 onBeforeAdd : function(item){
618 item.ownerCt.remove(item, false);
620 if(this.hideBorders === true){
621 item.border = (item.border === true);
625 <div id="method-Ext.Container-remove"></div>/**
626 * Removes a component from this container. Fires the {@link #beforeremove} event before removing, then fires
627 * the {@link #remove} event after the component has been removed.
628 * @param {Component/String} component The component reference or id to remove.
629 * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
630 * Defaults to the value of this Container's {@link #autoDestroy} config.
631 * @return {Ext.Component} component The Component that was removed.
633 remove : function(comp, autoDestroy){
635 var c = this.getComponent(comp);
636 if(c && this.fireEvent('beforeremove', this, c) !== false){
637 this.items.remove(c);
639 if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){
642 if(this.layout && this.layout.activeItem == c){
643 delete this.layout.activeItem;
645 this.fireEvent('remove', this, c);
650 <div id="method-Ext.Container-removeAll"></div>/**
651 * Removes all components from this container.
652 * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
653 * Defaults to the value of this Container's {@link #autoDestroy} config.
654 * @return {Array} Array of the destroyed components
656 removeAll: function(autoDestroy){
658 var item, rem = [], items = [];
659 this.items.each(function(i){
662 for (var i = 0, len = rem.length; i < len; ++i){
664 this.remove(item, autoDestroy);
665 if(item.ownerCt !== this){
672 <div id="method-Ext.Container-getComponent"></div>/**
673 * Examines this container's <code>{@link #items}</code> <b>property</b>
674 * and gets a direct child component of this container.
675 * @param {String/Number} comp This parameter may be any of the following:
676 * <div><ul class="mdetail-params">
677 * <li>a <b><tt>String</tt></b> : representing the <code>{@link Ext.Component#itemId itemId}</code>
678 * or <code>{@link Ext.Component#id id}</code> of the child component </li>
679 * <li>a <b><tt>Number</tt></b> : representing the position of the child component
680 * within the <code>{@link #items}</code> <b>property</b></li>
682 * <p>For additional information see {@link Ext.util.MixedCollection#get}.
683 * @return Ext.Component The component (if found).
685 getComponent : function(comp){
686 if(Ext.isObject(comp)){
689 return this.items.get(comp);
693 lookupComponent : function(comp){
694 if(typeof comp == 'string'){
695 return Ext.ComponentMgr.get(comp);
696 }else if(!comp.events){
697 return this.createComponent(comp);
703 createComponent : function(config){
704 return Ext.create(config, this.defaultType);
707 <div id="method-Ext.Container-doLayout"></div>/**
708 * Force this container's layout to be recalculated. A call to this function is required after adding a new component
709 * to an already rendered container, or possibly after changing sizing/position properties of child components.
710 * @param {Boolean} shallow (optional) True to only calc the layout of this component, and let child components auto
711 * calc layouts as required (defaults to false, which calls doLayout recursively for each subcontainer)
712 * @param {Boolean} force (optional) True to force a layout to occur, even if the item is hidden.
713 * @return {Ext.Container} this
715 doLayout: function(shallow, force){
716 var rendered = this.rendered,
717 forceLayout = this.forceLayout;
719 if(!this.isVisible() || this.collapsed){
720 this.deferLayout = this.deferLayout || !shallow;
721 if(!(force || forceLayout)){
724 shallow = shallow && !this.deferLayout;
726 delete this.deferLayout;
728 if(rendered && this.layout){
729 this.layout.layout();
731 if(shallow !== true && this.items){
732 var cs = this.items.items;
733 for(var i = 0, len = cs.length; i < len; i++){
736 c.forceLayout = forceLayout;
742 this.onLayout(shallow, force);
744 delete this.forceLayout;
748 onLayout : Ext.emptyFn,
751 Ext.Container.superclass.onShow.call(this);
752 if(this.deferLayout !== undefined){
757 <div id="method-Ext.Container-getLayout"></div>/**
758 * Returns the layout currently in use by the container. If the container does not currently have a layout
759 * set, a default {@link Ext.layout.ContainerLayout} will be created and set as the container's layout.
760 * @return {ContainerLayout} layout The container's layout
762 getLayout : function(){
764 var layout = new Ext.layout.ContainerLayout(this.layoutConfig);
765 this.setLayout(layout);
771 beforeDestroy : function(){
773 Ext.destroy.apply(Ext, this.items.items);
775 if(this.monitorResize){
776 Ext.EventManager.removeResizeListener(this.doLayout, this);
778 Ext.destroy(this.layout);
779 Ext.Container.superclass.beforeDestroy.call(this);
782 <div id="method-Ext.Container-bubble"></div>/**
783 * Bubbles up the component/container heirarchy, calling the specified function with each component. The scope (<i>this</i>) of
784 * function call will be the scope provided or the current component. The arguments to the function
785 * will be the args provided or the current component. If the function returns false at any point,
786 * the bubble is stopped.
787 * @param {Function} fn The function to call
788 * @param {Object} scope (optional) The scope of the function (defaults to current node)
789 * @param {Array} args (optional) The args to call the function with (default to passing the current component)
790 * @return {Ext.Container} this
792 bubble : function(fn, scope, args){
795 if(fn.apply(scope || p, args || [p]) === false){
803 <div id="method-Ext.Container-cascade"></div>/**
804 * Cascades down the component/container heirarchy from this component (called first), calling the specified function with
805 * each component. The scope (<i>this</i>) of
806 * function call will be the scope provided or the current component. The arguments to the function
807 * will be the args provided or the current component. If the function returns false at any point,
808 * the cascade is stopped on that branch.
809 * @param {Function} fn The function to call
810 * @param {Object} scope (optional) The scope of the function (defaults to current component)
811 * @param {Array} args (optional) The args to call the function with (defaults to passing the current component)
812 * @return {Ext.Container} this
814 cascade : function(fn, scope, args){
815 if(fn.apply(scope || this, args || [this]) !== false){
817 var cs = this.items.items;
818 for(var i = 0, len = cs.length; i < len; i++){
820 cs[i].cascade(fn, scope, args);
822 fn.apply(scope || cs[i], args || [cs[i]]);
830 <div id="method-Ext.Container-findById"></div>/**
831 * Find a component under this container at any level by id
833 * @return Ext.Component
835 findById : function(id){
837 this.cascade(function(c){
838 if(ct != c && c.id === id){
846 <div id="method-Ext.Container-findByType"></div>/**
847 * Find a component under this container at any level by xtype or class
848 * @param {String/Class} xtype The xtype string for a component, or the class of the component directly
849 * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
850 * the default), or true to check whether this Component is directly of the specified xtype.
851 * @return {Array} Array of Ext.Components
853 findByType : function(xtype, shallow){
854 return this.findBy(function(c){
855 return c.isXType(xtype, shallow);
859 <div id="method-Ext.Container-find"></div>/**
860 * Find a component under this container at any level by property
861 * @param {String} prop
862 * @param {String} value
863 * @return {Array} Array of Ext.Components
865 find : function(prop, value){
866 return this.findBy(function(c){
867 return c[prop] === value;
871 <div id="method-Ext.Container-findBy"></div>/**
872 * Find a component under this container at any level by a custom function. If the passed function returns
873 * true, the component will be included in the results. The passed function is called with the arguments (component, this container).
874 * @param {Function} fn The function to call
875 * @param {Object} scope (optional)
876 * @return {Array} Array of Ext.Components
878 findBy : function(fn, scope){
879 var m = [], ct = this;
880 this.cascade(function(c){
881 if(ct != c && fn.call(scope || c, c, ct) === true){
888 <div id="method-Ext.Container-get"></div>/**
889 * Get a component contained by this container (alias for items.get(key))
890 * @param {String/Number} key The index or id of the component
891 * @return {Ext.Component} Ext.Component
894 return this.items.get(key);
898 Ext.Container.LAYOUTS = {};
899 Ext.reg('container', Ext.Container);