3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.Container"></div>/**
16 * @class Ext.Container
17 * @extends Ext.BoxComponent
18 * <p>Base class for any {@link Ext.BoxComponent} that may contain other Components. Containers handle the
19 * basic behavior of containing items, namely adding, inserting and removing items.</p>
21 * <p>The most commonly used Container classes are {@link Ext.Panel}, {@link Ext.Window} and {@link Ext.TabPanel}.
22 * If you do not need the capabilities offered by the aforementioned classes you can create a lightweight
23 * Container to be encapsulated by an HTML element to your specifications by using the
24 * <code><b>{@link Ext.Component#autoEl autoEl}</b></code> config option. This is a useful technique when creating
25 * embedded {@link Ext.layout.ColumnLayout column} layouts inside {@link Ext.form.FormPanel FormPanels}
28 * <p>The code below illustrates both how to explicitly create a Container, and how to implicitly
29 * create one using the <b><code>'container'</code></b> xtype:<pre><code>
30 // explicitly create a Container
31 var embeddedColumns = new Ext.Container({
32 autoEl: 'div', // This is the default
35 // implicitly create Container by specifying xtype
37 autoEl: 'div', // This is the default.
44 // The two items below will be Ext.Containers, each encapsulated by a <DIV> element.
49 fieldLabel: 'Start date'
55 fieldLabel: 'End date'
60 * <p><u><b>Layout</b></u></p>
61 * <p>Container classes delegate the rendering of child Components to a layout
62 * manager class which must be configured into the Container using the
63 * <code><b>{@link #layout}</b></code> configuration property.</p>
64 * <p>When either specifying child <code>{@link #items}</code> of a Container,
65 * or dynamically {@link #add adding} Components to a Container, remember to
66 * consider how you wish the Container to arrange those child elements, and
67 * whether those child elements need to be sized using one of Ext's built-in
68 * <b><code>{@link #layout}</code></b> schemes. By default, Containers use the
69 * {@link Ext.layout.ContainerLayout ContainerLayout} scheme which only
70 * renders child components, appending them one after the other inside the
71 * Container, and <b>does not apply any sizing</b> at all.</p>
72 * <p>A common mistake is when a developer neglects to specify a
73 * <b><code>{@link #layout}</code></b> (e.g. widgets like GridPanels or
74 * TreePanels are added to Containers for which no <code><b>{@link #layout}</b></code>
75 * has been specified). If a Container is left to use the default
76 * {@link Ext.layout.ContainerLayout ContainerLayout} scheme, none of its
77 * child components will be resized, or changed in any way when the Container
79 * <p>Certain layout managers allow dynamic addition of child components.
80 * Those that do include {@link Ext.layout.CardLayout},
81 * {@link Ext.layout.AnchorLayout}, {@link Ext.layout.FormLayout}, and
82 * {@link Ext.layout.TableLayout}. For example:<pre><code>
83 // Create the GridPanel.
84 var myNewGrid = new Ext.grid.GridPanel({
86 columns: myColumnModel,
87 title: 'Results', // the title becomes the title of the tab
90 myTabPanel.add(myNewGrid); // {@link Ext.TabPanel} implicitly uses {@link Ext.layout.CardLayout CardLayout}
91 myTabPanel.{@link Ext.TabPanel#setActiveTab setActiveTab}(myNewGrid);
93 * <p>The example above adds a newly created GridPanel to a TabPanel. Note that
94 * a TabPanel uses {@link Ext.layout.CardLayout} as its layout manager which
95 * means all its child items are sized to {@link Ext.layout.FitLayout fit}
96 * exactly into its client area.
97 * <p><b><u>Overnesting is a common problem</u></b>.
98 * An example of overnesting occurs when a GridPanel is added to a TabPanel
99 * by wrapping the GridPanel <i>inside</i> a wrapping Panel (that has no
100 * <code><b>{@link #layout}</b></code> specified) and then add that wrapping Panel
101 * to the TabPanel. The point to realize is that a GridPanel <b>is</b> a
102 * Component which can be added directly to a Container. If the wrapping Panel
103 * has no <code><b>{@link #layout}</b></code> configuration, then the overnested
104 * GridPanel will not be sized as expected.<p>
106 * <p><u><b>Adding via remote configuration</b></u></p>
108 * <p>A server side script can be used to add Components which are generated dynamically on the server.
109 * An example of adding a GridPanel to a TabPanel where the GridPanel is generated by the server
110 * based on certain parameters:
112 // execute an Ajax request to invoke server side script:
114 url: 'gen-invoice-grid.php',
115 // send additional parameters to instruct server script
117 startDate: Ext.getCmp('start-date').getValue(),
118 endDate: Ext.getCmp('end-date').getValue()
120 // process the response object to add it to the TabPanel:
121 success: function(xhr) {
122 var newComponent = eval(xhr.responseText); // see discussion below
123 myTabPanel.add(newComponent); // add the component to the TabPanel
124 myTabPanel.setActiveTab(newComponent);
126 failure: function() {
127 Ext.Msg.alert("Grid create failed", "Server communication failure");
131 * <p>The server script needs to return an executable Javascript statement which, when processed
132 * using <code>eval()</code>, will return either a config object with an {@link Ext.Component#xtype xtype},
133 * or an instantiated Component. The server might return this for example:</p><pre><code>
135 function formatDate(value){
136 return value ? value.dateFormat('M d, Y') : '';
139 var store = new Ext.data.Store({
140 url: 'get-invoice-data.php',
142 startDate: '01/01/2008',
143 endDate: '01/31/2008'
145 reader: new Ext.data.JsonReader({
146 record: 'transaction',
148 totalRecords: 'total'
152 {name: 'date', type: 'date', dateFormat: 'm/d/Y'},
153 {name: 'value', type: 'float'}
157 var grid = new Ext.grid.GridPanel({
158 title: 'Invoice Report',
159 bbar: new Ext.PagingToolbar(store),
162 {header: "Customer", width: 250, dataIndex: 'customer', sortable: true},
163 {header: "Invoice Number", width: 120, dataIndex: 'invNo', sortable: true},
164 {header: "Invoice Date", width: 100, dataIndex: 'date', renderer: formatDate, sortable: true},
165 {header: "Value", width: 120, dataIndex: 'value', renderer: 'usMoney', sortable: true}
169 return grid; // return instantiated component
172 * <p>When the above code fragment is passed through the <code>eval</code> function in the success handler
173 * of the Ajax request, the code is executed by the Javascript processor, and the anonymous function
174 * runs, and returns the instantiated grid component.</p>
175 * <p>Note: since the code above is <i>generated</i> by a server script, the <code>baseParams</code> for
176 * the Store, the metadata to allow generation of the Record layout, and the ColumnModel
177 * can all be generated into the code since these are all known on the server.</p>
181 Ext.Container = Ext.extend(Ext.BoxComponent, {
182 <div id="cfg-Ext.Container-monitorResize"></div>/**
183 * @cfg {Boolean} monitorResize
184 * True to automatically monitor window resize events to handle anything that is sensitive to the current size
185 * of the viewport. This value is typically managed by the chosen <code>{@link #layout}</code> and should not need
186 * to be set manually.
188 <div id="cfg-Ext.Container-layout"></div>/**
189 * @cfg {String/Object} layout
190 * <p><b>*Important</b>: In order for child items to be correctly sized and
191 * positioned, typically a layout manager <b>must</b> be specified through
192 * the <code>layout</code> configuration option.</p>
193 * <br><p>The sizing and positioning of child {@link items} is the responsibility of
194 * the Container's layout manager which creates and manages the type of layout
195 * you have in mind. For example:</p><pre><code>
197 width:300, height: 300,
198 layout: 'fit', // explicitly set layout manager: override the default (layout:'auto')
200 title: 'Panel inside a Window'
204 * <p>If the {@link #layout} configuration is not explicitly specified for
205 * a general purpose container (e.g. Container or Panel) the
206 * {@link Ext.layout.ContainerLayout default layout manager} will be used
207 * which does nothing but render child components sequentially into the
208 * Container (no sizing or positioning will be performed in this situation).
209 * Some container classes implicitly specify a default layout
210 * (e.g. FormPanel specifies <code>layout:'form'</code>). Other specific
211 * purpose classes internally specify/manage their internal layout (e.g.
212 * GridPanel, TabPanel, TreePanel, Toolbar, Menu, etc.).</p>
213 * <br><p><b><code>layout</code></b> may be specified as either as an Object or
214 * as a String:</p><div><ul class="mdetail-params">
216 * <li><u>Specify as an Object</u></li>
217 * <div><ul class="mdetail-params">
218 * <li>Example usage:</li>
227 * <li><code><b>type</b></code></li>
228 * <br/><p>The layout type to be used for this container. If not specified,
229 * a default {@link Ext.layout.ContainerLayout} will be created and used.</p>
230 * <br/><p>Valid layout <code>type</code> values are:</p>
231 * <div class="sub-desc"><ul class="mdetail-params">
232 * <li><code><b>{@link Ext.layout.AbsoluteLayout absolute}</b></code></li>
233 * <li><code><b>{@link Ext.layout.AccordionLayout accordion}</b></code></li>
234 * <li><code><b>{@link Ext.layout.AnchorLayout anchor}</b></code></li>
235 * <li><code><b>{@link Ext.layout.ContainerLayout auto}</b></code> <b>Default</b></li>
236 * <li><code><b>{@link Ext.layout.BorderLayout border}</b></code></li>
237 * <li><code><b>{@link Ext.layout.CardLayout card}</b></code></li>
238 * <li><code><b>{@link Ext.layout.ColumnLayout column}</b></code></li>
239 * <li><code><b>{@link Ext.layout.FitLayout fit}</b></code></li>
240 * <li><code><b>{@link Ext.layout.FormLayout form}</b></code></li>
241 * <li><code><b>{@link Ext.layout.HBoxLayout hbox}</b></code></li>
242 * <li><code><b>{@link Ext.layout.MenuLayout menu}</b></code></li>
243 * <li><code><b>{@link Ext.layout.TableLayout table}</b></code></li>
244 * <li><code><b>{@link Ext.layout.ToolbarLayout toolbar}</b></code></li>
245 * <li><code><b>{@link Ext.layout.VBoxLayout vbox}</b></code></li>
248 * <li>Layout specific configuration properties</li>
249 * <br/><p>Additional layout specific configuration properties may also be
250 * specified. For complete details regarding the valid config options for
251 * each layout type, see the layout class corresponding to the <code>type</code>
256 * <li><u>Specify as a String</u></li>
257 * <div><ul class="mdetail-params">
258 * <li>Example usage:</li>
266 * <li><code><b>layout</b></code></li>
267 * <br/><p>The layout <code>type</code> to be used for this container (see list
268 * of valid layout type values above).</p><br/>
269 * <li><code><b>{@link #layoutConfig}</b></code></li>
270 * <br/><p>Additional layout specific configuration properties. For complete
271 * details regarding the valid config options for each layout type, see the
272 * layout class corresponding to the <code>layout</code> specified.</p>
273 * </ul></div></ul></div>
275 <div id="cfg-Ext.Container-layoutConfig"></div>/**
276 * @cfg {Object} layoutConfig
277 * This is a config object containing properties specific to the chosen
278 * <b><code>{@link #layout}</code></b> if <b><code>{@link #layout}</code></b>
279 * has been specified as a <i>string</i>.</p>
281 <div id="cfg-Ext.Container-bufferResize"></div>/**
282 * @cfg {Boolean/Number} bufferResize
283 * When set to true (50 milliseconds) or a number of milliseconds, the layout assigned for this container will buffer
284 * the frequency it calculates and does a re-layout of components. This is useful for heavy containers or containers
285 * with a large quantity of sub-components for which frequent layout calls would be expensive. Defaults to <code>50</code>.
289 <div id="cfg-Ext.Container-activeItem"></div>/**
290 * @cfg {String/Number} activeItem
291 * A string component id or the numeric index of the component that should be initially activated within the
292 * container's layout on render. For example, activeItem: 'item-1' or activeItem: 0 (index 0 = the first
293 * item in the container's collection). activeItem only applies to layout styles that can display
294 * items one at a time (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout} and
295 * {@link Ext.layout.FitLayout}). Related to {@link Ext.layout.ContainerLayout#activeItem}.
297 <div id="cfg-Ext.Container-items"></div>/**
298 * @cfg {Object/Array} items
299 * <pre><b>** IMPORTANT</b>: be sure to <b>{@link #layout specify a <code>layout</code>} if needed ! **</b></pre>
300 * <p>A single item, or an array of child Components to be added to this container,
303 // specifying a single item
305 layout: 'fit', // specify a layout!
307 // specifying multiple items
308 items: [{...}, {...}],
309 layout: 'anchor', // specify a layout!
311 * <p>Each item may be:</p>
312 * <div><ul class="mdetail-params">
313 * <li>any type of object based on {@link Ext.Component}</li>
314 * <li>a fully instanciated object or</li>
315 * <li>an object literal that:</li>
316 * <div><ul class="mdetail-params">
317 * <li>has a specified <code>{@link Ext.Component#xtype xtype}</code></li>
318 * <li>the {@link Ext.Component#xtype} specified is associated with the Component
319 * desired and should be chosen from one of the available xtypes as listed
320 * in {@link Ext.Component}.</li>
321 * <li>If an <code>{@link Ext.Component#xtype xtype}</code> is not explicitly
322 * specified, the {@link #defaultType} for that Container is used.</li>
323 * <li>will be "lazily instanciated", avoiding the overhead of constructing a fully
324 * instanciated Component object</li>
325 * </ul></div></ul></div>
326 * <p><b>Notes</b>:</p>
327 * <div><ul class="mdetail-params">
328 * <li>Ext uses lazy rendering. Child Components will only be rendered
329 * should it become necessary. Items are automatically laid out when they are first
330 * shown (no sizing is done while hidden), or in response to a {@link #doLayout} call.</li>
331 * <li>Do not specify <code>{@link Ext.Panel#contentEl contentEl}</code>/
332 * <code>{@link Ext.Panel#html html}</code> with <code>items</code>.</li>
335 <div id="cfg-Ext.Container-defaults"></div>/**
336 * @cfg {Object|Function} defaults
337 * <p>This option is a means of applying default settings to all added items whether added through the {@link #items}
338 * config or via the {@link #add} or {@link #insert} methods.</p>
339 * <p>If an added item is a config object, and <b>not</b> an instantiated Component, then the default properties are
340 * unconditionally applied. If the added item <b>is</b> an instantiated Component, then the default properties are
341 * applied conditionally so as not to override existing properties in the item.</p>
342 * <p>If the defaults option is specified as a function, then the function will be called using this Container as the
343 * scope (<code>this</code> reference) and passing the added item as the first parameter. Any resulting object
344 * from that call is then applied to the item as default properties.</p>
345 * <p>For example, to automatically apply padding to the body of each of a set of
346 * contained {@link Ext.Panel} items, you could pass: <code>defaults: {bodyStyle:'padding:15px'}</code>.</p>
347 * <p>Usage:</p><pre><code>
348 defaults: { // defaults are applied to items, not the container
353 xtype: 'panel', // defaults <b>do not</b> have precedence over
354 id: 'panel1', // options in config objects, so the defaults
355 autoScroll: false // will not be applied here, panel1 will be autoScroll:false
357 new Ext.Panel({ // defaults <b>do</b> have precedence over options
358 id: 'panel2', // options in components, so the defaults
359 autoScroll: false // will be applied here, panel2 will be autoScroll:true.
366 <div id="cfg-Ext.Container-autoDestroy"></div>/** @cfg {Boolean} autoDestroy
367 * If true the container will automatically destroy any contained component that is removed from it, else
368 * destruction must be handled manually (defaults to true).
372 <div id="cfg-Ext.Container-forceLayout"></div>/** @cfg {Boolean} forceLayout
373 * If true the container will force a layout initially even if hidden or collapsed. This option
374 * is useful for forcing forms to render in collapsed or hidden containers. (defaults to false).
378 <div id="cfg-Ext.Container-hideBorders"></div>/** @cfg {Boolean} hideBorders
379 * True to hide the borders of each contained component, false to defer to the component's existing
380 * border settings (defaults to false).
382 <div id="cfg-Ext.Container-defaultType"></div>/** @cfg {String} defaultType
383 * <p>The default {@link Ext.Component xtype} of child Components to create in this Container when
384 * a child item is specified as a raw configuration object, rather than as an instantiated Component.</p>
385 * <p>Defaults to <code>'panel'</code>, except {@link Ext.menu.Menu} which defaults to <code>'menuitem'</code>,
386 * and {@link Ext.Toolbar} and {@link Ext.ButtonGroup} which default to <code>'button'</code>.</p>
388 defaultType : 'panel',
390 <div id="cfg-Ext.Container-resizeEvent"></div>/** @cfg {String} resizeEvent
391 * The event to listen to for resizing in layouts. Defaults to <code>'resize'</code>.
393 resizeEvent: 'resize',
395 <div id="cfg-Ext.Container-bubbleEvents"></div>/**
396 * @cfg {Array} bubbleEvents
397 * <p>An array of events that, when fired, should be bubbled to any parent container.
398 * See {@link Ext.util.Observable#enableBubble}.
399 * Defaults to <code>['add', 'remove']</code>.
401 bubbleEvents: ['add', 'remove'],
404 initComponent : function(){
405 Ext.Container.superclass.initComponent.call(this);
408 <div id="event-Ext.Container-afterlayout"></div>/**
410 * Fires when the components in this container are arranged by the associated layout manager.
411 * @param {Ext.Container} this
412 * @param {ContainerLayout} layout The ContainerLayout implementation for this container
415 <div id="event-Ext.Container-beforeadd"></div>/**
417 * Fires before any {@link Ext.Component} is added or inserted into the container.
418 * A handler can return false to cancel the add.
419 * @param {Ext.Container} this
420 * @param {Ext.Component} component The component being added
421 * @param {Number} index The index at which the component will be added to the container's items collection
424 <div id="event-Ext.Container-beforeremove"></div>/**
425 * @event beforeremove
426 * Fires before any {@link Ext.Component} is removed from the container. A handler can return
427 * false to cancel the remove.
428 * @param {Ext.Container} this
429 * @param {Ext.Component} component The component being removed
432 <div id="event-Ext.Container-add"></div>/**
435 * Fires after any {@link Ext.Component} is added or inserted into the container.
436 * @param {Ext.Container} this
437 * @param {Ext.Component} component The component that was added
438 * @param {Number} index The index at which the component was added to the container's items collection
441 <div id="event-Ext.Container-remove"></div>/**
444 * Fires after any {@link Ext.Component} is removed from the container.
445 * @param {Ext.Container} this
446 * @param {Ext.Component} component The component that was removed
451 <div id="prop-Ext.Container-items"></div>/**
452 * The collection of components in this container as a {@link Ext.util.MixedCollection}
453 * @type MixedCollection
456 var items = this.items;
464 initItems : function(){
466 this.items = new Ext.util.MixedCollection(false, this.getComponentId);
467 this.getLayout(); // initialize the layout
472 setLayout : function(layout){
473 if(this.layout && this.layout != layout){
474 this.layout.setContainer(null);
477 this.layout = layout;
478 layout.setContainer(this);
481 afterRender: function(){
482 // Render this Container, this should be done before setLayout is called which
483 // will hook onResize
484 Ext.Container.superclass.afterRender.call(this);
486 this.layout = 'auto';
488 if(Ext.isObject(this.layout) && !this.layout.layout){
489 this.layoutConfig = this.layout;
490 this.layout = this.layoutConfig.type;
492 if(Ext.isString(this.layout)){
493 this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);
495 this.setLayout(this.layout);
497 // If a CardLayout, the active item set
498 if(this.activeItem !== undefined){
499 var item = this.activeItem;
500 delete this.activeItem;
501 this.layout.setActiveItem(item);
504 // If we have no ownerCt, render and size all children
506 this.doLayout(false, true);
509 // This is a manually configured flag set by users in conjunction with renderTo.
510 // Not to be confused with the flag by the same name used in Layouts.
511 if(this.monitorResize === true){
512 Ext.EventManager.onWindowResize(this.doLayout, this, [false]);
516 <div id="method-Ext.Container-getLayoutTarget"></div>/**
517 * <p>Returns the Element to be used to contain the child Components of this Container.</p>
518 * <p>An implementation is provided which returns the Container's {@link #getEl Element}, but
519 * if there is a more complex structure to a Container, this may be overridden to return
520 * the element into which the {@link #layout layout} renders child Components.</p>
521 * @return {Ext.Element} The Element to render child Components into.
523 getLayoutTarget : function(){
527 // private - used as the key lookup function for the items collection
528 getComponentId : function(comp){
529 return comp.getItemId();
532 <div id="method-Ext.Container-add"></div>/**
533 * <p>Adds {@link Ext.Component Component}(s) to this Container.</p>
534 * <br><p><b>Description</b></u> :
535 * <div><ul class="mdetail-params">
536 * <li>Fires the {@link #beforeadd} event before adding</li>
537 * <li>The Container's {@link #defaults default config values} will be applied
538 * accordingly (see <code>{@link #defaults}</code> for details).</li>
539 * <li>Fires the {@link #add} event after the component has been added.</li>
541 * <br><p><b>Notes</b></u> :
542 * <div><ul class="mdetail-params">
543 * <li>If the Container is <i>already rendered</i> when <code>add</code>
544 * is called, you may need to call {@link #doLayout} to refresh the view which causes
545 * any unrendered child Components to be rendered. This is required so that you can
546 * <code>add</code> multiple child components if needed while only refreshing the layout
547 * once. For example:<pre><code>
548 var tb = new {@link Ext.Toolbar}();
549 tb.render(document.body); // toolbar is rendered
550 tb.add({text:'Button 1'}); // add multiple items ({@link #defaultType} for {@link Ext.Toolbar Toolbar} is 'button')
551 tb.add({text:'Button 2'});
552 tb.{@link #doLayout}(); // refresh the layout
554 * <li><i>Warning:</i> Containers directly managed by the BorderLayout layout manager
555 * may not be removed or added. See the Notes for {@link Ext.layout.BorderLayout BorderLayout}
556 * for more details.</li>
558 * @param {...Object/Array} component
559 * <p>Either one or more Components to add or an Array of Components to add. See
560 * <code>{@link #items}</code> for additional information.</p>
561 * @return {Ext.Component/Array} The Components that were added.
563 add : function(comp){
565 var args = arguments.length > 1;
566 if(args || Ext.isArray(comp)){
568 Ext.each(args ? arguments : comp, function(c){
569 result.push(this.add(c));
573 var c = this.lookupComponent(this.applyDefaults(comp));
574 var index = this.items.length;
575 if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
578 c.onAdded(this, index);
580 this.fireEvent('add', this, c, index);
586 // Empty template method
590 onAdded : function(container, pos) {
591 //overridden here so we can cascade down, not worth creating a template method.
592 this.ownerCt = container;
594 //initialize references for child items
595 this.cascade(function(c){
598 this.fireEvent('added', this, container, pos);
601 <div id="method-Ext.Container-insert"></div>/**
602 * Inserts a Component into this Container at a specified index. Fires the
603 * {@link #beforeadd} event before inserting, then fires the {@link #add} event after the
604 * Component has been inserted.
605 * @param {Number} index The index at which the Component will be inserted
606 * into the Container's items collection
607 * @param {Ext.Component} component The child Component to insert.<br><br>
608 * Ext uses lazy rendering, and will only render the inserted Component should
609 * it become necessary.<br><br>
610 * A Component config object may be passed in order to avoid the overhead of
611 * constructing a real Component object if lazy rendering might mean that the
612 * inserted Component will not be rendered immediately. To take advantage of
613 * this 'lazy instantiation', set the {@link Ext.Component#xtype} config
614 * property to the registered type of the Component wanted.<br><br>
615 * For a list of all available xtypes, see {@link Ext.Component}.
616 * @return {Ext.Component} component The Component (or config object) that was
617 * inserted with the Container's default config values applied.
619 insert : function(index, comp){
621 var a = arguments, len = a.length;
624 for(var i = len-1; i >= 1; --i) {
625 result.push(this.insert(index, a[i]));
629 var c = this.lookupComponent(this.applyDefaults(comp));
630 index = Math.min(index, this.items.length);
631 if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
632 if(c.ownerCt == this){
633 this.items.remove(c);
635 this.items.insert(index, c);
636 c.onAdded(this, index);
638 this.fireEvent('add', this, c, index);
644 applyDefaults : function(c){
645 var d = this.defaults;
647 if(Ext.isFunction(d)){
651 c = Ext.ComponentMgr.get(c);
663 onBeforeAdd : function(item){
665 item.ownerCt.remove(item, false);
667 if(this.hideBorders === true){
668 item.border = (item.border === true);
672 <div id="method-Ext.Container-remove"></div>/**
673 * Removes a component from this container. Fires the {@link #beforeremove} event before removing, then fires
674 * the {@link #remove} event after the component has been removed.
675 * @param {Component/String} component The component reference or id to remove.
676 * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
677 * Defaults to the value of this Container's {@link #autoDestroy} config.
678 * @return {Ext.Component} component The Component that was removed.
680 remove : function(comp, autoDestroy){
682 var c = this.getComponent(comp);
683 if(c && this.fireEvent('beforeremove', this, c) !== false){
684 this.doRemove(c, autoDestroy);
685 this.fireEvent('remove', this, c);
690 onRemove: function(c){
691 // Empty template method
695 doRemove: function(c, autoDestroy){
697 hasLayout = l && this.rendered;
702 this.items.remove(c);
705 if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){
713 <div id="method-Ext.Container-removeAll"></div>/**
714 * Removes all components from this container.
715 * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
716 * Defaults to the value of this Container's {@link #autoDestroy} config.
717 * @return {Array} Array of the destroyed components
719 removeAll: function(autoDestroy){
721 var item, rem = [], items = [];
722 this.items.each(function(i){
725 for (var i = 0, len = rem.length; i < len; ++i){
727 this.remove(item, autoDestroy);
728 if(item.ownerCt !== this){
735 <div id="method-Ext.Container-getComponent"></div>/**
736 * Examines this container's <code>{@link #items}</code> <b>property</b>
737 * and gets a direct child component of this container.
738 * @param {String/Number} comp This parameter may be any of the following:
739 * <div><ul class="mdetail-params">
740 * <li>a <b><code>String</code></b> : representing the <code>{@link Ext.Component#itemId itemId}</code>
741 * or <code>{@link Ext.Component#id id}</code> of the child component </li>
742 * <li>a <b><code>Number</code></b> : representing the position of the child component
743 * within the <code>{@link #items}</code> <b>property</b></li>
745 * <p>For additional information see {@link Ext.util.MixedCollection#get}.
746 * @return Ext.Component The component (if found).
748 getComponent : function(comp){
749 if(Ext.isObject(comp)){
750 comp = comp.getItemId();
752 return this.items.get(comp);
756 lookupComponent : function(comp){
757 if(Ext.isString(comp)){
758 return Ext.ComponentMgr.get(comp);
759 }else if(!comp.events){
760 return this.createComponent(comp);
766 createComponent : function(config, defaultType){
770 // add in ownerCt at creation time but then immediately
771 // remove so that onBeforeAdd can handle it
772 var c = Ext.create(Ext.apply({
774 }, config), defaultType || this.defaultType);
775 delete c.initialConfig.ownerCt;
780 <div id="prop-Ext.Container-private"></div>/**
781 * We can only lay out if there is a view area in which to layout.
782 * display:none on the layout target, *or any of its parent elements* will mean it has no view area.
786 canLayout : function() {
787 var el = this.getVisibilityEl();
788 return el && el.dom && !el.isStyle("display", "none");
791 <div id="method-Ext.Container-doLayout"></div>/**
792 * Force this container's layout to be recalculated. A call to this function is required after adding a new component
793 * to an already rendered container, or possibly after changing sizing/position properties of child components.
794 * @param {Boolean} shallow (optional) True to only calc the layout of this component, and let child components auto
795 * calc layouts as required (defaults to false, which calls doLayout recursively for each subcontainer)
796 * @param {Boolean} force (optional) True to force a layout to occur, even if the item is hidden.
797 * @return {Ext.Container} this
800 doLayout : function(shallow, force){
801 var rendered = this.rendered,
802 forceLayout = force || this.forceLayout;
804 if(this.collapsed || !this.canLayout()){
805 this.deferLayout = this.deferLayout || !shallow;
809 shallow = shallow && !this.deferLayout;
811 delete this.deferLayout;
813 if(rendered && this.layout){
814 this.layout.layout();
816 if(shallow !== true && this.items){
817 var cs = this.items.items;
818 for(var i = 0, len = cs.length; i < len; i++){
821 c.doLayout(false, forceLayout);
826 this.onLayout(shallow, forceLayout);
828 // Initial layout completed
829 this.hasLayout = true;
830 delete this.forceLayout;
833 onLayout : Ext.emptyFn,
836 shouldBufferLayout: function(){
838 * Returns true if the container should buffer a layout.
839 * This is true only if the container has previously been laid out
840 * and has a parent container that is pending a layout.
842 var hl = this.hasLayout;
844 // Only ever buffer if we've laid out the first time and we have one pending.
845 return hl ? !this.hasLayoutPending() : false;
847 // Never buffer initial layout
852 hasLayoutPending: function(){
853 // Traverse hierarchy to see if any parent container has a pending layout.
855 this.ownerCt.bubble(function(c){
865 // removes css classes that were added to hide
866 Ext.Container.superclass.onShow.call(this);
867 // If we were sized during the time we were hidden, layout.
868 if(Ext.isDefined(this.deferLayout)){
869 delete this.deferLayout;
874 <div id="method-Ext.Container-getLayout"></div>/**
875 * Returns the layout currently in use by the container. If the container does not currently have a layout
876 * set, a default {@link Ext.layout.ContainerLayout} will be created and set as the container's layout.
877 * @return {ContainerLayout} layout The container's layout
879 getLayout : function(){
881 var layout = new Ext.layout.AutoLayout(this.layoutConfig);
882 this.setLayout(layout);
888 beforeDestroy : function(){
891 while(c = this.items.first()){
892 this.doRemove(c, true);
895 if(this.monitorResize){
896 Ext.EventManager.removeResizeListener(this.doLayout, this);
898 Ext.destroy(this.layout);
899 Ext.Container.superclass.beforeDestroy.call(this);
902 <div id="method-Ext.Container-bubble"></div>/**
903 * Bubbles up the component/container heirarchy, calling the specified function with each component. The scope (<i>this</i>) of
904 * function call will be the scope provided or the current component. The arguments to the function
905 * will be the args provided or the current component. If the function returns false at any point,
906 * the bubble is stopped.
907 * @param {Function} fn The function to call
908 * @param {Object} scope (optional) The scope of the function (defaults to current node)
909 * @param {Array} args (optional) The args to call the function with (default to passing the current component)
910 * @return {Ext.Container} this
912 bubble : function(fn, scope, args){
915 if(fn.apply(scope || p, args || [p]) === false){
923 <div id="method-Ext.Container-cascade"></div>/**
924 * Cascades down the component/container heirarchy from this component (called first), calling the specified function with
925 * each component. The scope (<i>this</i>) of
926 * function call will be the scope provided or the current component. The arguments to the function
927 * will be the args provided or the current component. If the function returns false at any point,
928 * the cascade is stopped on that branch.
929 * @param {Function} fn The function to call
930 * @param {Object} scope (optional) The scope of the function (defaults to current component)
931 * @param {Array} args (optional) The args to call the function with (defaults to passing the current component)
932 * @return {Ext.Container} this
934 cascade : function(fn, scope, args){
935 if(fn.apply(scope || this, args || [this]) !== false){
937 var cs = this.items.items;
938 for(var i = 0, len = cs.length; i < len; i++){
940 cs[i].cascade(fn, scope, args);
942 fn.apply(scope || cs[i], args || [cs[i]]);
950 <div id="method-Ext.Container-findById"></div>/**
951 * Find a component under this container at any level by id
953 * @return Ext.Component
955 findById : function(id){
957 this.cascade(function(c){
958 if(ct != c && c.id === id){
966 <div id="method-Ext.Container-findByType"></div>/**
967 * Find a component under this container at any level by xtype or class
968 * @param {String/Class} xtype The xtype string for a component, or the class of the component directly
969 * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
970 * the default), or true to check whether this Component is directly of the specified xtype.
971 * @return {Array} Array of Ext.Components
973 findByType : function(xtype, shallow){
974 return this.findBy(function(c){
975 return c.isXType(xtype, shallow);
979 <div id="method-Ext.Container-find"></div>/**
980 * Find a component under this container at any level by property
981 * @param {String} prop
982 * @param {String} value
983 * @return {Array} Array of Ext.Components
985 find : function(prop, value){
986 return this.findBy(function(c){
987 return c[prop] === value;
991 <div id="method-Ext.Container-findBy"></div>/**
992 * Find a component under this container at any level by a custom function. If the passed function returns
993 * true, the component will be included in the results. The passed function is called with the arguments (component, this container).
994 * @param {Function} fn The function to call
995 * @param {Object} scope (optional)
996 * @return {Array} Array of Ext.Components
998 findBy : function(fn, scope){
999 var m = [], ct = this;
1000 this.cascade(function(c){
1001 if(ct != c && fn.call(scope || c, c, ct) === true){
1008 <div id="method-Ext.Container-get"></div>/**
1009 * Get a component contained by this container (alias for items.get(key))
1010 * @param {String/Number} key The index or id of the component
1011 * @return {Ext.Component} Ext.Component
1013 get : function(key){
1014 return this.items.get(key);
1018 Ext.Container.LAYOUTS = {};
1019 Ext.reg('container', Ext.Container);