Upgrade to ExtJS 4.0.7 - Released 10/19/2011
[extjs.git] / src / layout / container / Container.js
1 /*
2
3 This file is part of Ext JS 4
4
5 Copyright (c) 2011 Sencha Inc
6
7 Contact:  http://www.sencha.com/contact
8
9 GNU General Public License Usage
10 This file may be used under the terms of the GNU General Public License version 3.0 as published by the Free Software Foundation and appearing in the file LICENSE included in the packaging of this file.  Please review the following information to ensure the GNU General Public License version 3.0 requirements will be met: http://www.gnu.org/copyleft/gpl.html.
11
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
13
14 */
15 /**
16 * @class Ext.layout.container.Container
17 * @extends Ext.layout.container.AbstractContainer
18 * <p>This class is intended to be extended or created via the {@link Ext.container.Container#layout layout}
19 * configuration property.  See {@link Ext.container.Container#layout} for additional details.</p>
20 */
21 Ext.define('Ext.layout.container.Container', {
22
23     /* Begin Definitions */
24
25     extend: 'Ext.layout.container.AbstractContainer',
26     alternateClassName: 'Ext.layout.ContainerLayout',
27
28     /* End Definitions */
29
30     layoutItem: function(item, box) {
31         if (box) {
32             item.doComponentLayout(box.width, box.height);
33         } else {
34             item.doComponentLayout();
35         }
36     },
37
38     getLayoutTargetSize : function() {
39         var target = this.getTarget(),
40             ret;
41
42         if (target) {
43             ret = target.getViewSize();
44
45             // IE in will sometimes return a width of 0 on the 1st pass of getViewSize.
46             // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
47             // with getViewSize
48             if (Ext.isIE && ret.width == 0){
49                 ret = target.getStyleSize();
50             }
51
52             ret.width -= target.getPadding('lr');
53             ret.height -= target.getPadding('tb');
54         }
55         return ret;
56     },
57
58     beforeLayout: function() {
59         if (this.owner.beforeLayout(arguments) !== false) {
60             return this.callParent(arguments);
61         }
62         else {
63             return false;
64         }
65     },
66
67     /**
68      * @protected
69      * Returns all items that are rendered
70      * @return {Array} All matching items
71      */
72     getRenderedItems: function() {
73         var me = this,
74             target = me.getTarget(),
75             items = me.getLayoutItems(),
76             ln = items.length,
77             renderedItems = [],
78             i, item;
79
80         for (i = 0; i < ln; i++) {
81             item = items[i];
82             if (item.rendered && me.isValidParent(item, target, i)) {
83                 renderedItems.push(item);
84             }
85         }
86
87         return renderedItems;
88     },
89
90     /**
91      * @protected
92      * Returns all items that are both rendered and visible
93      * @return {Array} All matching items
94      */
95     getVisibleItems: function() {
96         var target   = this.getTarget(),
97             items = this.getLayoutItems(),
98             ln = items.length,
99             visibleItems = [],
100             i, item;
101
102         for (i = 0; i < ln; i++) {
103             item = items[i];
104             if (item.rendered && this.isValidParent(item, target, i) && item.hidden !== true) {
105                 visibleItems.push(item);
106             }
107         }
108
109         return visibleItems;
110     }
111 });