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