Upgrade to ExtJS 4.0.0 - Released 04/26/2011
[extjs.git] / src / layout / component / BoundList.js
1 /**
2  * Component layout for {@link Ext.view.BoundList}. Handles constraining the height to the configured maxHeight.
3  * @class Ext.layout.component.BoundList
4  * @extends Ext.layout.component.Component
5  * @private
6  */
7 Ext.define('Ext.layout.component.BoundList', {
8     extend: 'Ext.layout.component.Component',
9     alias: 'layout.boundlist',
10
11     type: 'component',
12
13     beforeLayout: function() {
14         return this.callParent(arguments) || this.owner.refreshed > 0;
15     },
16
17     onLayout : function(width, height) {
18         var me = this,
19             owner = me.owner,
20             floating = owner.floating,
21             el = owner.el,
22             xy = el.getXY(),
23             isNumber = Ext.isNumber,
24             minWidth, maxWidth, minHeight, maxHeight,
25             naturalWidth, naturalHeight, constrainedWidth, constrainedHeight, undef;
26
27         if (floating) {
28             // Position offscreen so the natural width is not affected by the viewport's right edge
29             el.setXY([-9999,-9999]);
30         }
31
32         // Calculate initial layout
33         me.setTargetSize(width, height);
34
35         // Handle min/maxWidth for auto-width
36         if (!isNumber(width)) {
37             minWidth = owner.minWidth;
38             maxWidth = owner.maxWidth;
39             if (isNumber(minWidth) || isNumber(maxWidth)) {
40                 naturalWidth = el.getWidth();
41                 if (naturalWidth < minWidth) {
42                     constrainedWidth = minWidth;
43                 }
44                 else if (naturalWidth > maxWidth) {
45                     constrainedWidth = maxWidth;
46                 }
47                 if (constrainedWidth) {
48                     me.setTargetSize(constrainedWidth);
49                 }
50             }
51         }
52         // Handle min/maxHeight for auto-height
53         if (!isNumber(height)) {
54             minHeight = owner.minHeight;
55             maxHeight = owner.maxHeight;
56             if (isNumber(minHeight) || isNumber(maxHeight)) {
57                 naturalHeight = el.getHeight();
58                 if (naturalHeight < minHeight) {
59                     constrainedHeight = minHeight;
60                 }
61                 else if (naturalHeight > maxHeight) {
62                     constrainedHeight = maxHeight;
63                 }
64                 if (constrainedHeight) {
65                     me.setTargetSize(undef, constrainedHeight);
66                 }
67             }
68         }
69
70         if (floating) {
71             // Restore position
72             el.setXY(xy);
73         }
74     },
75
76     afterLayout: function() {
77         var me = this,
78             toolbar = me.owner.pagingToolbar;
79         me.callParent();
80         if (toolbar) {
81             toolbar.doComponentLayout();
82         }
83     },
84
85     setTargetSize : function(width, height) {
86         var me = this,
87             owner = me.owner,
88             listHeight = null,
89             toolbar;
90
91         // Size the listEl
92         if (Ext.isNumber(height)) {
93             listHeight = height - owner.el.getFrameWidth('tb');
94             toolbar = owner.pagingToolbar;
95             if (toolbar) {
96                 listHeight -= toolbar.getHeight();
97             }
98         }
99         me.setElementSize(owner.listEl, null, listHeight);
100
101         me.callParent(arguments);
102     }
103
104 });