3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
\r
4 <title>The source code</title>
\r
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
\r
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
\r
8 <body onload="prettyPrint();">
\r
9 <pre class="prettyprint lang-js"><div id="cls-Ext.Container"></div>/**
10 * @class Ext.Container
11 * @extends Ext.BoxComponent
12 * <p>Base class for any {@link Ext.BoxComponent} that may contain other Components. Containers handle the
13 * basic behavior of containing items, namely adding, inserting and removing items.</p>
15 * <p>The most commonly used Container classes are {@link Ext.Panel}, {@link Ext.Window} and {@link Ext.TabPanel}.
16 * If you do not need the capabilities offered by the aforementioned classes you can create a lightweight
17 * Container to be encapsulated by an HTML element to your specifications by using the
18 * <code><b>{@link Ext.Component#autoEl autoEl}</b></code> config option. This is a useful technique when creating
19 * embedded {@link Ext.layout.ColumnLayout column} layouts inside {@link Ext.form.FormPanel FormPanels}
22 * <p>The code below illustrates both how to explicitly create a Container, and how to implicitly
23 * create one using the <b><code>'container'</code></b> xtype:<pre><code>
24 // explicitly create a Container
25 var embeddedColumns = new Ext.Container({
26 autoEl: 'div', // This is the default
29 // implicitly create Container by specifying xtype
31 autoEl: 'div', // This is the default.
38 // The two items below will be Ext.Containers, each encapsulated by a <DIV> element.
43 fieldLabel: 'Start date'
49 fieldLabel: 'End date'
54 * <p><u><b>Layout</b></u></p>
55 * <p>Container classes delegate the rendering of child Components to a layout
56 * manager class which must be configured into the Container using the
57 * <code><b>{@link #layout}</b></code> configuration property.</p>
58 * <p>When either specifying child <code>{@link #items}</code> of a Container,
59 * or dynamically {@link #add adding} Components to a Container, remember to
60 * consider how you wish the Container to arrange those child elements, and
61 * whether those child elements need to be sized using one of Ext's built-in
62 * <b><code>{@link #layout}</code></b> schemes. By default, Containers use the
63 * {@link Ext.layout.ContainerLayout ContainerLayout} scheme which only
64 * renders child components, appending them one after the other inside the
65 * Container, and <b>does not apply any sizing</b> at all.</p>
66 * <p>A common mistake is when a developer neglects to specify a
67 * <b><code>{@link #layout}</code></b> (e.g. widgets like GridPanels or
68 * TreePanels are added to Containers for which no <code><b>{@link #layout}</b></code>
69 * has been specified). If a Container is left to use the default
70 * {@link Ext.layout.ContainerLayout ContainerLayout} scheme, none of its
71 * child components will be resized, or changed in any way when the Container
73 * <p>Certain layout managers allow dynamic addition of child components.
74 * Those that do include {@link Ext.layout.CardLayout},
75 * {@link Ext.layout.AnchorLayout}, {@link Ext.layout.FormLayout}, and
76 * {@link Ext.layout.TableLayout}. For example:<pre><code>
77 // Create the GridPanel.
78 var myNewGrid = new Ext.grid.GridPanel({
80 columns: myColumnModel,
81 title: 'Results', // the title becomes the title of the tab
84 myTabPanel.add(myNewGrid); // {@link Ext.TabPanel} implicitly uses {@link Ext.layout.CardLayout CardLayout}
85 myTabPanel.{@link Ext.TabPanel#setActiveTab setActiveTab}(myNewGrid);
87 * <p>The example above adds a newly created GridPanel to a TabPanel. Note that
88 * a TabPanel uses {@link Ext.layout.CardLayout} as its layout manager which
89 * means all its child items are sized to {@link Ext.layout.FitLayout fit}
90 * exactly into its client area.
91 * <p><b><u>Overnesting is a common problem</u></b>.
92 * An example of overnesting occurs when a GridPanel is added to a TabPanel
93 * by wrapping the GridPanel <i>inside</i> a wrapping Panel (that has no
94 * <code><b>{@link #layout}</b></code> specified) and then add that wrapping Panel
95 * to the TabPanel. The point to realize is that a GridPanel <b>is</b> a
96 * Component which can be added directly to a Container. If the wrapping Panel
97 * has no <code><b>{@link #layout}</b></code> configuration, then the overnested
98 * GridPanel will not be sized as expected.<p>
100 * <p><u><b>Adding via remote configuration</b></u></p>
102 * <p>A server side script can be used to add Components which are generated dynamically on the server.
103 * An example of adding a GridPanel to a TabPanel where the GridPanel is generated by the server
104 * based on certain parameters:
106 // execute an Ajax request to invoke server side script:
108 url: 'gen-invoice-grid.php',
109 // send additional parameters to instruct server script
111 startDate: Ext.getCmp('start-date').getValue(),
112 endDate: Ext.getCmp('end-date').getValue()
114 // process the response object to add it to the TabPanel:
115 success: function(xhr) {
116 var newComponent = eval(xhr.responseText); // see discussion below
117 myTabPanel.add(newComponent); // add the component to the TabPanel
118 myTabPanel.setActiveTab(newComponent);
120 failure: function() {
121 Ext.Msg.alert("Grid create failed", "Server communication failure");
125 * <p>The server script needs to return an executable Javascript statement which, when processed
126 * using <code>eval()</code>, will return either a config object with an {@link Ext.Component#xtype xtype},
127 * or an instantiated Component. The server might return this for example:</p><pre><code>
129 function formatDate(value){
130 return value ? value.dateFormat('M d, Y') : '';
133 var store = new Ext.data.Store({
134 url: 'get-invoice-data.php',
136 startDate: '01/01/2008',
137 endDate: '01/31/2008'
139 reader: new Ext.data.JsonReader({
140 record: 'transaction',
142 totalRecords: 'total'
146 {name: 'date', type: 'date', dateFormat: 'm/d/Y'},
147 {name: 'value', type: 'float'}
151 var grid = new Ext.grid.GridPanel({
152 title: 'Invoice Report',
153 bbar: new Ext.PagingToolbar(store),
156 {header: "Customer", width: 250, dataIndex: 'customer', sortable: true},
157 {header: "Invoice Number", width: 120, dataIndex: 'invNo', sortable: true},
158 {header: "Invoice Date", width: 100, dataIndex: 'date', renderer: formatDate, sortable: true},
159 {header: "Value", width: 120, dataIndex: 'value', renderer: 'usMoney', sortable: true}
163 return grid; // return instantiated component
166 * <p>When the above code fragment is passed through the <code>eval</code> function in the success handler
167 * of the Ajax request, the code is executed by the Javascript processor, and the anonymous function
168 * runs, and returns the instantiated grid component.</p>
169 * <p>Note: since the code above is <i>generated</i> by a server script, the <code>baseParams</code> for
170 * the Store, the metadata to allow generation of the Record layout, and the ColumnModel
171 * can all be generated into the code since these are all known on the server.</p>
175 Ext.Container = Ext.extend(Ext.BoxComponent, {
176 <div id="cfg-Ext.Container-monitorResize"></div>/**
177 * @cfg {Boolean} monitorResize
178 * True to automatically monitor window resize events to handle anything that is sensitive to the current size
179 * of the viewport. This value is typically managed by the chosen <code>{@link #layout}</code> and should not need
180 * to be set manually.
182 <div id="cfg-Ext.Container-layout"></div>/**
183 * @cfg {String/Object} layout
184 * <p><b>*Important</b>: In order for child items to be correctly sized and
185 * positioned, typically a layout manager <b>must</b> be specified through
186 * the <code>layout</code> configuration option.</p>
187 * <br><p>The sizing and positioning of child {@link items} is the responsibility of
188 * the Container's layout manager which creates and manages the type of layout
189 * you have in mind. For example:</p><pre><code>
191 width:300, height: 300,
192 layout: 'fit', // explicitly set layout manager: override the default (layout:'auto')
194 title: 'Panel inside a Window'
198 * <p>If the {@link #layout} configuration is not explicitly specified for
199 * a general purpose container (e.g. Container or Panel) the
200 * {@link Ext.layout.ContainerLayout default layout manager} will be used
201 * which does nothing but render child components sequentially into the
202 * Container (no sizing or positioning will be performed in this situation).
203 * Some container classes implicitly specify a default layout
204 * (e.g. FormPanel specifies <code>layout:'form'</code>). Other specific
205 * purpose classes internally specify/manage their internal layout (e.g.
206 * GridPanel, TabPanel, TreePanel, Toolbar, Menu, etc.).</p>
207 * <br><p><b><code>layout</code></b> may be specified as either as an Object or
208 * as a String:</p><div><ul class="mdetail-params">
210 * <li><u>Specify as an Object</u></li>
211 * <div><ul class="mdetail-params">
212 * <li>Example usage:</li>
221 * <li><code><b>type</b></code></li>
222 * <br/><p>The layout type to be used for this container. If not specified,
223 * a default {@link Ext.layout.ContainerLayout} will be created and used.</p>
224 * <br/><p>Valid layout <code>type</code> values are:</p>
225 * <div class="sub-desc"><ul class="mdetail-params">
226 * <li><code><b>{@link Ext.layout.AbsoluteLayout absolute}</b></code></li>
227 * <li><code><b>{@link Ext.layout.AccordionLayout accordion}</b></code></li>
228 * <li><code><b>{@link Ext.layout.AnchorLayout anchor}</b></code></li>
229 * <li><code><b>{@link Ext.layout.ContainerLayout auto}</b></code> <b>Default</b></li>
230 * <li><code><b>{@link Ext.layout.BorderLayout border}</b></code></li>
231 * <li><code><b>{@link Ext.layout.CardLayout card}</b></code></li>
232 * <li><code><b>{@link Ext.layout.ColumnLayout column}</b></code></li>
233 * <li><code><b>{@link Ext.layout.FitLayout fit}</b></code></li>
234 * <li><code><b>{@link Ext.layout.FormLayout form}</b></code></li>
235 * <li><code><b>{@link Ext.layout.HBoxLayout hbox}</b></code></li>
236 * <li><code><b>{@link Ext.layout.MenuLayout menu}</b></code></li>
237 * <li><code><b>{@link Ext.layout.TableLayout table}</b></code></li>
238 * <li><code><b>{@link Ext.layout.ToolbarLayout toolbar}</b></code></li>
239 * <li><code><b>{@link Ext.layout.VBoxLayout vbox}</b></code></li>
242 * <li>Layout specific configuration properties</li>
243 * <br/><p>Additional layout specific configuration properties may also be
244 * specified. For complete details regarding the valid config options for
245 * each layout type, see the layout class corresponding to the <code>type</code>
250 * <li><u>Specify as a String</u></li>
251 * <div><ul class="mdetail-params">
252 * <li>Example usage:</li>
260 * <li><code><b>layout</b></code></li>
261 * <br/><p>The layout <code>type</code> to be used for this container (see list
262 * of valid layout type values above).</p><br/>
263 * <li><code><b>{@link #layoutConfig}</b></code></li>
264 * <br/><p>Additional layout specific configuration properties. For complete
265 * details regarding the valid config options for each layout type, see the
266 * layout class corresponding to the <code>layout</code> specified.</p>
267 * </ul></div></ul></div>
269 <div id="cfg-Ext.Container-layoutConfig"></div>/**
270 * @cfg {Object} layoutConfig
271 * This is a config object containing properties specific to the chosen
272 * <b><code>{@link #layout}</code></b> if <b><code>{@link #layout}</code></b>
273 * has been specified as a <i>string</i>.</p>
275 <div id="cfg-Ext.Container-bufferResize"></div>/**
276 * @cfg {Boolean/Number} bufferResize
277 * When set to true (50 milliseconds) or a number of milliseconds, the layout assigned for this container will buffer
278 * the frequency it calculates and does a re-layout of components. This is useful for heavy containers or containers
279 * with a large quantity of sub-components for which frequent layout calls would be expensive. Defaults to <code>50</code>.
283 <div id="cfg-Ext.Container-activeItem"></div>/**
284 * @cfg {String/Number} activeItem
285 * A string component id or the numeric index of the component that should be initially activated within the
286 * container's layout on render. For example, activeItem: 'item-1' or activeItem: 0 (index 0 = the first
287 * item in the container's collection). activeItem only applies to layout styles that can display
288 * items one at a time (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout} and
289 * {@link Ext.layout.FitLayout}). Related to {@link Ext.layout.ContainerLayout#activeItem}.
291 <div id="cfg-Ext.Container-items"></div>/**
292 * @cfg {Object/Array} items
293 * <pre><b>** IMPORTANT</b>: be sure to <b>{@link #layout specify a <code>layout</code>} if needed ! **</b></pre>
294 * <p>A single item, or an array of child Components to be added to this container,
297 // specifying a single item
299 layout: 'fit', // specify a layout!
301 // specifying multiple items
302 items: [{...}, {...}],
303 layout: 'anchor', // specify a layout!
305 * <p>Each item may be:</p>
306 * <div><ul class="mdetail-params">
307 * <li>any type of object based on {@link Ext.Component}</li>
308 * <li>a fully instanciated object or</li>
309 * <li>an object literal that:</li>
310 * <div><ul class="mdetail-params">
311 * <li>has a specified <code>{@link Ext.Component#xtype xtype}</code></li>
312 * <li>the {@link Ext.Component#xtype} specified is associated with the Component
313 * desired and should be chosen from one of the available xtypes as listed
314 * in {@link Ext.Component}.</li>
315 * <li>If an <code>{@link Ext.Component#xtype xtype}</code> is not explicitly
316 * specified, the {@link #defaultType} for that Container is used.</li>
317 * <li>will be "lazily instanciated", avoiding the overhead of constructing a fully
318 * instanciated Component object</li>
319 * </ul></div></ul></div>
320 * <p><b>Notes</b>:</p>
321 * <div><ul class="mdetail-params">
322 * <li>Ext uses lazy rendering. Child Components will only be rendered
323 * should it become necessary. Items are automatically laid out when they are first
324 * shown (no sizing is done while hidden), or in response to a {@link #doLayout} call.</li>
325 * <li>Do not specify <code>{@link Ext.Panel#contentEl contentEl}</code>/
326 * <code>{@link Ext.Panel#html html}</code> with <code>items</code>.</li>
329 <div id="cfg-Ext.Container-defaults"></div>/**
330 * @cfg {Object|Function} defaults
331 * <p>This option is a means of applying default settings to all added items whether added through the {@link #items}
332 * config or via the {@link #add} or {@link #insert} methods.</p>
333 * <p>If an added item is a config object, and <b>not</b> an instantiated Component, then the default properties are
334 * unconditionally applied. If the added item <b>is</b> an instantiated Component, then the default properties are
335 * applied conditionally so as not to override existing properties in the item.</p>
336 * <p>If the defaults option is specified as a function, then the function will be called using this Container as the
337 * scope (<code>this</code> reference) and passing the added item as the first parameter. Any resulting object
338 * from that call is then applied to the item as default properties.</p>
339 * <p>For example, to automatically apply padding to the body of each of a set of
340 * contained {@link Ext.Panel} items, you could pass: <code>defaults: {bodyStyle:'padding:15px'}</code>.</p>
341 * <p>Usage:</p><pre><code>
342 defaults: { // defaults are applied to items, not the container
347 xtype: 'panel', // defaults <b>do not</b> have precedence over
348 id: 'panel1', // options in config objects, so the defaults
349 autoScroll: false // will not be applied here, panel1 will be autoScroll:false
351 new Ext.Panel({ // defaults <b>do</b> have precedence over options
352 id: 'panel2', // options in components, so the defaults
353 autoScroll: false // will be applied here, panel2 will be autoScroll:true.
360 <div id="cfg-Ext.Container-autoDestroy"></div>/** @cfg {Boolean} autoDestroy
361 * If true the container will automatically destroy any contained component that is removed from it, else
362 * destruction must be handled manually (defaults to true).
366 <div id="cfg-Ext.Container-forceLayout"></div>/** @cfg {Boolean} forceLayout
367 * If true the container will force a layout initially even if hidden or collapsed. This option
368 * is useful for forcing forms to render in collapsed or hidden containers. (defaults to false).
372 <div id="cfg-Ext.Container-hideBorders"></div>/** @cfg {Boolean} hideBorders
373 * True to hide the borders of each contained component, false to defer to the component's existing
374 * border settings (defaults to false).
376 <div id="cfg-Ext.Container-defaultType"></div>/** @cfg {String} defaultType
377 * <p>The default {@link Ext.Component xtype} of child Components to create in this Container when
378 * a child item is specified as a raw configuration object, rather than as an instantiated Component.</p>
379 * <p>Defaults to <code>'panel'</code>, except {@link Ext.menu.Menu} which defaults to <code>'menuitem'</code>,
380 * and {@link Ext.Toolbar} and {@link Ext.ButtonGroup} which default to <code>'button'</code>.</p>
382 defaultType : 'panel',
384 <div id="cfg-Ext.Container-resizeEvent"></div>/** @cfg {String} resizeEvent
385 * The event to listen to for resizing in layouts. Defaults to <code>'resize'</code>.
387 resizeEvent: 'resize',
389 <div id="cfg-Ext.Container-bubbleEvents"></div>/**
390 * @cfg {Array} bubbleEvents
391 * <p>An array of events that, when fired, should be bubbled to any parent container.
392 * See {@link Ext.util.Observable#enableBubble}.
393 * Defaults to <code>['add', 'remove']</code>.
395 bubbleEvents: ['add', 'remove'],
398 initComponent : function(){
399 Ext.Container.superclass.initComponent.call(this);
402 <div id="event-Ext.Container-afterlayout"></div>/**
404 * Fires when the components in this container are arranged by the associated layout manager.
405 * @param {Ext.Container} this
406 * @param {ContainerLayout} layout The ContainerLayout implementation for this container
409 <div id="event-Ext.Container-beforeadd"></div>/**
411 * Fires before any {@link Ext.Component} is added or inserted into the container.
412 * A handler can return false to cancel the add.
413 * @param {Ext.Container} this
414 * @param {Ext.Component} component The component being added
415 * @param {Number} index The index at which the component will be added to the container's items collection
418 <div id="event-Ext.Container-beforeremove"></div>/**
419 * @event beforeremove
420 * Fires before any {@link Ext.Component} is removed from the container. A handler can return
421 * false to cancel the remove.
422 * @param {Ext.Container} this
423 * @param {Ext.Component} component The component being removed
426 <div id="event-Ext.Container-add"></div>/**
429 * Fires after any {@link Ext.Component} is added or inserted into the container.
430 * @param {Ext.Container} this
431 * @param {Ext.Component} component The component that was added
432 * @param {Number} index The index at which the component was added to the container's items collection
435 <div id="event-Ext.Container-remove"></div>/**
438 * Fires after any {@link Ext.Component} is removed from the container.
439 * @param {Ext.Container} this
440 * @param {Ext.Component} component The component that was removed
445 this.enableBubble(this.bubbleEvents);
447 <div id="prop-Ext.Container-items"></div>/**
448 * The collection of components in this container as a {@link Ext.util.MixedCollection}
449 * @type MixedCollection
452 var items = this.items;
460 initItems : function(){
462 this.items = new Ext.util.MixedCollection(false, this.getComponentId);
463 this.getLayout(); // initialize the layout
468 setLayout : function(layout){
469 if(this.layout && this.layout != layout){
470 this.layout.setContainer(null);
473 this.layout = layout;
474 layout.setContainer(this);
477 afterRender: function(){
478 this.layoutDone = false;
480 this.layout = 'auto';
482 if(Ext.isObject(this.layout) && !this.layout.layout){
483 this.layoutConfig = this.layout;
484 this.layout = this.layoutConfig.type;
486 if(Ext.isString(this.layout)){
487 this.layout = new Ext.Container.LAYOUTS[this.layout.toLowerCase()](this.layoutConfig);
489 this.setLayout(this.layout);
491 // BoxComponent's afterRender will set the size.
492 // This will will trigger a layout if the layout is configured to monitor resize
493 Ext.Container.superclass.afterRender.call(this);
495 if(Ext.isDefined(this.activeItem)){
496 var item = this.activeItem;
497 delete this.activeItem;
498 this.layout.setActiveItem(item);
501 // If we have no ownerCt and the BoxComponent's sizing did not trigger a layout, force a layout
502 if(!this.ownerCt && !this.layoutDone){
503 this.doLayout(false, true);
506 if(this.monitorResize === true){
507 Ext.EventManager.onWindowResize(this.doLayout, this, [false]);
511 <div id="method-Ext.Container-getLayoutTarget"></div>/**
512 * <p>Returns the Element to be used to contain the child Components of this Container.</p>
513 * <p>An implementation is provided which returns the Container's {@link #getEl Element}, but
514 * if there is a more complex structure to a Container, this may be overridden to return
515 * the element into which the {@link #layout layout} renders child Components.</p>
516 * @return {Ext.Element} The Element to render child Components into.
518 getLayoutTarget : function(){
522 // private - used as the key lookup function for the items collection
523 getComponentId : function(comp){
524 return comp.getItemId();
527 <div id="method-Ext.Container-add"></div>/**
528 * <p>Adds {@link Ext.Component Component}(s) to this Container.</p>
529 * <br><p><b>Description</b></u> :
530 * <div><ul class="mdetail-params">
531 * <li>Fires the {@link #beforeadd} event before adding</li>
532 * <li>The Container's {@link #defaults default config values} will be applied
533 * accordingly (see <code>{@link #defaults}</code> for details).</li>
534 * <li>Fires the {@link #add} event after the component has been added.</li>
536 * <br><p><b>Notes</b></u> :
537 * <div><ul class="mdetail-params">
538 * <li>If the Container is <i>already rendered</i> when <code>add</code>
539 * is called, you may need to call {@link #doLayout} to refresh the view which causes
540 * any unrendered child Components to be rendered. This is required so that you can
541 * <code>add</code> multiple child components if needed while only refreshing the layout
542 * once. For example:<pre><code>
543 var tb = new {@link Ext.Toolbar}();
544 tb.render(document.body); // toolbar is rendered
545 tb.add({text:'Button 1'}); // add multiple items ({@link #defaultType} for {@link Ext.Toolbar Toolbar} is 'button')
546 tb.add({text:'Button 2'});
547 tb.{@link #doLayout}(); // refresh the layout
549 * <li><i>Warning:</i> Containers directly managed by the BorderLayout layout manager
550 * may not be removed or added. See the Notes for {@link Ext.layout.BorderLayout BorderLayout}
551 * for more details.</li>
553 * @param {Object/Array} component
554 * <p>Either a single component or an Array of components to add. See
555 * <code>{@link #items}</code> for additional information.</p>
556 * @param {Object} (Optional) component_2
557 * @param {Object} (Optional) component_n
558 * @return {Ext.Component} component The Component (or config object) that was added.
560 add : function(comp){
562 var args = arguments.length > 1;
563 if(args || Ext.isArray(comp)){
565 Ext.each(args ? arguments : comp, function(c){
566 result.push(this.add(c));
570 var c = this.lookupComponent(this.applyDefaults(comp));
571 var index = this.items.length;
572 if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
575 c.onAdded(this, index);
577 this.fireEvent('add', this, c, index);
583 // Empty template method
587 onAdded : function(container, pos) {
588 //overridden here so we can cascade down, not worth creating a template method.
589 this.ownerCt = container;
591 //initialize references for child items
592 this.cascade(function(c){
595 this.fireEvent('added', this, container, pos);
598 <div id="method-Ext.Container-insert"></div>/**
599 * Inserts a Component into this Container at a specified index. Fires the
600 * {@link #beforeadd} event before inserting, then fires the {@link #add} event after the
601 * Component has been inserted.
602 * @param {Number} index The index at which the Component will be inserted
603 * into the Container's items collection
604 * @param {Ext.Component} component The child Component to insert.<br><br>
605 * Ext uses lazy rendering, and will only render the inserted Component should
606 * it become necessary.<br><br>
607 * A Component config object may be passed in order to avoid the overhead of
608 * constructing a real Component object if lazy rendering might mean that the
609 * inserted Component will not be rendered immediately. To take advantage of
610 * this 'lazy instantiation', set the {@link Ext.Component#xtype} config
611 * property to the registered type of the Component wanted.<br><br>
612 * For a list of all available xtypes, see {@link Ext.Component}.
613 * @return {Ext.Component} component The Component (or config object) that was
614 * inserted with the Container's default config values applied.
616 insert : function(index, comp){
618 var a = arguments, len = a.length;
621 for(var i = len-1; i >= 1; --i) {
622 result.push(this.insert(index, a[i]));
626 var c = this.lookupComponent(this.applyDefaults(comp));
627 index = Math.min(index, this.items.length);
628 if(this.fireEvent('beforeadd', this, c, index) !== false && this.onBeforeAdd(c) !== false){
629 if(c.ownerCt == this){
630 this.items.remove(c);
632 this.items.insert(index, c);
633 c.onAdded(this, index);
635 this.fireEvent('add', this, c, index);
641 applyDefaults : function(c){
642 var d = this.defaults;
644 if(Ext.isFunction(d)){
648 c = Ext.ComponentMgr.get(c);
660 onBeforeAdd : function(item){
662 item.ownerCt.remove(item, false);
664 if(this.hideBorders === true){
665 item.border = (item.border === true);
669 <div id="method-Ext.Container-remove"></div>/**
670 * Removes a component from this container. Fires the {@link #beforeremove} event before removing, then fires
671 * the {@link #remove} event after the component has been removed.
672 * @param {Component/String} component The component reference or id to remove.
673 * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
674 * Defaults to the value of this Container's {@link #autoDestroy} config.
675 * @return {Ext.Component} component The Component that was removed.
677 remove : function(comp, autoDestroy){
679 var c = this.getComponent(comp);
680 if(c && this.fireEvent('beforeremove', this, c) !== false){
681 this.doRemove(c, autoDestroy);
682 this.fireEvent('remove', this, c);
687 onRemove: function(c){
688 // Empty template method
692 doRemove: function(c, autoDestroy){
693 if(this.layout && this.rendered){
694 this.layout.onRemove(c);
696 this.items.remove(c);
699 if(autoDestroy === true || (autoDestroy !== false && this.autoDestroy)){
704 <div id="method-Ext.Container-removeAll"></div>/**
705 * Removes all components from this container.
706 * @param {Boolean} autoDestroy (optional) True to automatically invoke the removed Component's {@link Ext.Component#destroy} function.
707 * Defaults to the value of this Container's {@link #autoDestroy} config.
708 * @return {Array} Array of the destroyed components
710 removeAll: function(autoDestroy){
712 var item, rem = [], items = [];
713 this.items.each(function(i){
716 for (var i = 0, len = rem.length; i < len; ++i){
718 this.remove(item, autoDestroy);
719 if(item.ownerCt !== this){
726 <div id="method-Ext.Container-getComponent"></div>/**
727 * Examines this container's <code>{@link #items}</code> <b>property</b>
728 * and gets a direct child component of this container.
729 * @param {String/Number} comp This parameter may be any of the following:
730 * <div><ul class="mdetail-params">
731 * <li>a <b><code>String</code></b> : representing the <code>{@link Ext.Component#itemId itemId}</code>
732 * or <code>{@link Ext.Component#id id}</code> of the child component </li>
733 * <li>a <b><code>Number</code></b> : representing the position of the child component
734 * within the <code>{@link #items}</code> <b>property</b></li>
736 * <p>For additional information see {@link Ext.util.MixedCollection#get}.
737 * @return Ext.Component The component (if found).
739 getComponent : function(comp){
740 if(Ext.isObject(comp)){
741 comp = comp.getItemId();
743 return this.items.get(comp);
747 lookupComponent : function(comp){
748 if(Ext.isString(comp)){
749 return Ext.ComponentMgr.get(comp);
750 }else if(!comp.events){
751 return this.createComponent(comp);
757 createComponent : function(config, defaultType){
758 // add in ownerCt at creation time but then immediately
759 // remove so that onBeforeAdd can handle it
760 var c = config.render ? config : Ext.create(Ext.apply({
762 }, config), defaultType || this.defaultType);
767 <div id="method-Ext.Container-canLayout"></div>/**
768 * We can only lay out if there is a view area in which to layout.
769 * display:none on the layout target, *or any of its parent elements* will mean it has no view area.
771 canLayout: function() {
772 var el = this.getLayoutTarget(), vs;
773 return !!(el && (vs = el.dom.offsetWidth || el.dom.offsetHeight));
776 <div id="method-Ext.Container-doLayout"></div>/**
777 * Force this container's layout to be recalculated. A call to this function is required after adding a new component
778 * to an already rendered container, or possibly after changing sizing/position properties of child components.
779 * @param {Boolean} shallow (optional) True to only calc the layout of this component, and let child components auto
780 * calc layouts as required (defaults to false, which calls doLayout recursively for each subcontainer)
781 * @param {Boolean} force (optional) True to force a layout to occur, even if the item is hidden.
782 * @return {Ext.Container} this
784 doLayout: function(shallow, force){
785 var rendered = this.rendered,
786 forceLayout = force || this.forceLayout,
789 this.layoutDone = true;
790 if(!this.canLayout() || this.collapsed){
791 this.deferLayout = this.deferLayout || !shallow;
795 shallow = shallow && !this.deferLayout;
797 delete this.deferLayout;
800 cs = (shallow !== true && this.items) ? this.items.items : [];
802 // Inhibit child Containers from relaying on resize since we are about to to explicitly call doLayout on them all!
803 for(i = 0, len = cs.length; i < len; i++){
804 if ((c = cs[i]).layout) {
805 c.suspendLayoutResize = true;
809 // Tell the layout manager to ensure all child items are rendered, and sized according to their rules.
810 // Will not cause the child items to relayout.
811 if(rendered && this.layout){
812 this.layout.layout();
815 // Explicitly lay out all child items
816 for(i = 0; i < len; i++){
817 if((c = cs[i]).doLayout){
818 c.doLayout(false, forceLayout);
822 this.onLayout(shallow, forceLayout);
824 // Initial layout completed
825 this.hasLayout = true;
826 delete this.forceLayout;
828 // Re-enable child layouts relaying on resize.
829 for(i = 0; i < len; i++){
830 if ((c = cs[i]).layout) {
831 delete c.suspendLayoutResize;
837 onLayout : Ext.emptyFn,
839 onResize: function(adjWidth, adjHeight, rawWidth, rawHeight){
840 Ext.Container.superclass.onResize.apply(this, arguments);
841 if ((this.rendered && this.layout && this.layout.monitorResize) && !this.suspendLayoutResize) {
842 this.layout.onResize();
847 hasLayoutPending: function(){
848 // Traverse hierarchy to see if any parent container has a pending layout.
849 var pending = this.layoutPending;
850 this.ownerCt.bubble(function(c){
851 return !(pending = c.layoutPending);
858 Ext.Container.superclass.onShow.call(this);
859 if(Ext.isDefined(this.deferLayout)){
864 <div id="method-Ext.Container-getLayout"></div>/**
865 * Returns the layout currently in use by the container. If the container does not currently have a layout
866 * set, a default {@link Ext.layout.ContainerLayout} will be created and set as the container's layout.
867 * @return {ContainerLayout} layout The container's layout
869 getLayout : function(){
871 var layout = new Ext.layout.ContainerLayout(this.layoutConfig);
872 this.setLayout(layout);
878 beforeDestroy : function(){
881 while(c = this.items.first()){
882 this.doRemove(c, true);
885 if(this.monitorResize){
886 Ext.EventManager.removeResizeListener(this.doLayout, this);
888 Ext.destroy(this.layout);
889 Ext.Container.superclass.beforeDestroy.call(this);
892 <div id="method-Ext.Container-bubble"></div>/**
893 * Bubbles up the component/container heirarchy, calling the specified function with each component. The scope (<i>this</i>) of
894 * function call will be the scope provided or the current component. The arguments to the function
895 * will be the args provided or the current component. If the function returns false at any point,
896 * the bubble is stopped.
897 * @param {Function} fn The function to call
898 * @param {Object} scope (optional) The scope of the function (defaults to current node)
899 * @param {Array} args (optional) The args to call the function with (default to passing the current component)
900 * @return {Ext.Container} this
902 bubble : function(fn, scope, args){
905 if(fn.apply(scope || p, args || [p]) === false){
913 <div id="method-Ext.Container-cascade"></div>/**
914 * Cascades down the component/container heirarchy from this component (called first), calling the specified function with
915 * each component. The scope (<i>this</i>) of
916 * function call will be the scope provided or the current component. The arguments to the function
917 * will be the args provided or the current component. If the function returns false at any point,
918 * the cascade is stopped on that branch.
919 * @param {Function} fn The function to call
920 * @param {Object} scope (optional) The scope of the function (defaults to current component)
921 * @param {Array} args (optional) The args to call the function with (defaults to passing the current component)
922 * @return {Ext.Container} this
924 cascade : function(fn, scope, args){
925 if(fn.apply(scope || this, args || [this]) !== false){
927 var cs = this.items.items;
928 for(var i = 0, len = cs.length; i < len; i++){
930 cs[i].cascade(fn, scope, args);
932 fn.apply(scope || cs[i], args || [cs[i]]);
940 <div id="method-Ext.Container-findById"></div>/**
941 * Find a component under this container at any level by id
943 * @return Ext.Component
945 findById : function(id){
947 this.cascade(function(c){
948 if(ct != c && c.id === id){
956 <div id="method-Ext.Container-findByType"></div>/**
957 * Find a component under this container at any level by xtype or class
958 * @param {String/Class} xtype The xtype string for a component, or the class of the component directly
959 * @param {Boolean} shallow (optional) False to check whether this Component is descended from the xtype (this is
960 * the default), or true to check whether this Component is directly of the specified xtype.
961 * @return {Array} Array of Ext.Components
963 findByType : function(xtype, shallow){
964 return this.findBy(function(c){
965 return c.isXType(xtype, shallow);
969 <div id="method-Ext.Container-find"></div>/**
970 * Find a component under this container at any level by property
971 * @param {String} prop
972 * @param {String} value
973 * @return {Array} Array of Ext.Components
975 find : function(prop, value){
976 return this.findBy(function(c){
977 return c[prop] === value;
981 <div id="method-Ext.Container-findBy"></div>/**
982 * Find a component under this container at any level by a custom function. If the passed function returns
983 * true, the component will be included in the results. The passed function is called with the arguments (component, this container).
984 * @param {Function} fn The function to call
985 * @param {Object} scope (optional)
986 * @return {Array} Array of Ext.Components
988 findBy : function(fn, scope){
989 var m = [], ct = this;
990 this.cascade(function(c){
991 if(ct != c && fn.call(scope || c, c, ct) === true){
998 <div id="method-Ext.Container-get"></div>/**
999 * Get a component contained by this container (alias for items.get(key))
1000 * @param {String/Number} key The index or id of the component
1001 * @return {Ext.Component} Ext.Component
1003 get : function(key){
1004 return this.items.get(key);
1008 Ext.Container.LAYOUTS = {};
1009 Ext.reg('container', Ext.Container);