Upgrade to ExtJS 4.0.2 - Released 06/09/2011
[extjs.git] / src / layout / container / Fit.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.Fit
17  * @extends Ext.layout.container.AbstractFit
18  * <p>This is a base class for layouts that contain <b>a single item</b> that automatically expands to fill the layout's
19  * container.  This class is intended to be extended or created via the <tt>layout:'fit'</tt> {@link Ext.container.Container#layout}
20  * config, and should generally not need to be created directly via the new keyword.</p>
21  * <p>FitLayout does not have any direct config options (other than inherited ones).  To fit a panel to a container
22  * using FitLayout, simply set layout:'fit' on the container and add a single panel to it.  If the container has
23  * multiple panels, only the first one will be displayed.  
24  * {@img Ext.layout.container.Fit/Ext.layout.container.Fit.png Ext.layout.container.Fit container layout}
25  * Example usage:</p>
26  * <pre><code>
27     Ext.create('Ext.panel.Panel', {
28         title: 'Fit Layout',
29         width: 300,
30         height: 150,
31         layout:'fit',
32         items: {
33             title: 'Inner Panel',
34             html: 'This is the inner panel content',
35             bodyPadding: 20,
36             border: false
37         },
38         renderTo: Ext.getBody()
39     });  
40 </code></pre>
41  */
42 Ext.define('Ext.layout.container.Fit', {
43
44     /* Begin Definitions */
45
46     extend: 'Ext.layout.container.AbstractFit',
47     alias: 'layout.fit',
48     alternateClassName: 'Ext.layout.FitLayout',
49
50     /* End Definitions */
51    
52     // @private
53     onLayout : function() {
54         var me = this;
55         me.callParent();
56
57         if (me.owner.items.length) {
58             me.setItemBox(me.owner.items.get(0), me.getLayoutTargetSize());
59         }
60     },
61
62     getTargetBox : function() {
63         return this.getLayoutTargetSize();
64     },
65
66     setItemBox : function(item, box) {
67         var me = this;
68         if (item && box.height > 0) {
69             if (!me.owner.isFixedWidth()) {
70                box.width = undefined;
71             }
72             if (!me.owner.isFixedHeight()) {
73                box.height = undefined;
74             }
75             me.setItemSize(item, box.width, box.height);
76         }
77     },
78
79     configureItem: function(item) {
80
81         // Card layout only controls dimensions which IT has controlled.
82         // That calculation has to be determined at run time by examining the ownerCt's isFixedWidth()/isFixedHeight() methods
83         item.layoutManagedHeight = 0;
84         item.layoutManagedWidth = 0;
85
86         this.callParent(arguments);
87     }
88 });