Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / layout / container / Container.js
1 /**
2 * @class Ext.layout.container.Container
3 * @extends Ext.layout.container.AbstractContainer
4 * @private
5 * <p>This class is intended to be extended or created via the <tt><b>{@link Ext.container.Container#layout layout}</b></tt>
6 * configuration property.  See <tt><b>{@link Ext.container.Container#layout}</b></tt> for additional details.</p>
7 */
8 Ext.define('Ext.layout.container.Container', {
9
10     /* Begin Definitions */
11
12     extend: 'Ext.layout.container.AbstractContainer',
13     alternateClassName: 'Ext.layout.ContainerLayout',
14     
15     /* End Definitions */
16
17     layoutItem: function(item, box) {
18         box = box || {};
19         if (item.componentLayout.initialized !== true) {
20             this.setItemSize(item, box.width || item.width || undefined, box.height || item.height || undefined);
21             // item.doComponentLayout(box.width || item.width || undefined, box.height || item.height || undefined);
22         }
23     },
24
25     getLayoutTargetSize : function() {
26         var target = this.getTarget(),
27             ret;
28
29         if (target) {
30             ret = target.getViewSize();
31
32             // IE in will sometimes return a width of 0 on the 1st pass of getViewSize.
33             // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
34             // with getViewSize
35             if (Ext.isIE && ret.width == 0){
36                 ret = target.getStyleSize();
37             }
38
39             ret.width -= target.getPadding('lr');
40             ret.height -= target.getPadding('tb');
41         }
42         return ret;
43     },
44
45     beforeLayout: function() {
46         if (this.owner.beforeLayout(arguments) !== false) {
47             return this.callParent(arguments);
48         }
49         else {
50             return false;
51         }
52     },
53
54     afterLayout: function() {
55         this.owner.afterLayout(arguments);
56         this.callParent(arguments);
57     },
58
59     /**
60      * @protected
61      * Returns all items that are rendered
62      * @return {Array} All matching items
63      */
64     getRenderedItems: function() {
65         var me = this,
66             target = me.getTarget(),
67             items = me.getLayoutItems(),
68             ln = items.length,
69             renderedItems = [],
70             i, item;
71
72         for (i = 0; i < ln; i++) {
73             item = items[i];
74             if (item.rendered && me.isValidParent(item, target, i)) {
75                 renderedItems.push(item);
76             }
77         }
78
79         return renderedItems;
80     },
81
82     /**
83      * @protected
84      * Returns all items that are both rendered and visible
85      * @return {Array} All matching items
86      */
87     getVisibleItems: function() {
88         var target   = this.getTarget(),
89             items = this.getLayoutItems(),
90             ln = items.length,
91             visibleItems = [],
92             i, item;
93
94         for (i = 0; i < ln; i++) {
95             item = items[i];
96             if (item.rendered && this.isValidParent(item, target, i) && item.hidden !== true) {
97                 visibleItems.push(item);
98             }
99         }
100
101         return visibleItems;
102     }
103 });