3 This file is part of Ext JS 4
5 Copyright (c) 2011 Sencha Inc
7 Contact: http://www.sencha.com/contact
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.
12 If you are unsure which license is appropriate for your use, please contact the sales department at http://www.sencha.com/contact.
16 * @class Ext.grid.ColumnLayout
17 * @extends Ext.layout.container.HBox
20 * <p>This class is used only by the grid's HeaderContainer docked child.</p>
22 * <p>This class adds the ability to shrink the vertical size of the inner container element back if a grouped
23 * column header has all its child columns dragged out, and the whole HeaderContainer needs to shrink back down.</p>
25 * <p>It also enforces the grid's HeaderContainer's forceFit config by, after every calaculateChildBoxes call, converting
26 * all pixel widths into flex values, so that propertions are maintained upon width change of the grid.</p>
28 * <p>Also, after every layout, after all headers have attained their 'stretchmax' height, it goes through and calls
29 * <code>setPadding</code> on the columns so that they lay out correctly. TODO: implement a ColumnHeader component
30 * layout which takes responsibility for this, and will run upon resize.</p>
32 Ext.define('Ext.grid.ColumnLayout', {
33 extend: 'Ext.layout.container.HBox',
34 alias: 'layout.gridcolumn',
39 // Height-stretched innerCt must be able to revert back to unstretched height
40 clearInnerCtOnLayout: false,
42 beforeLayout: function() {
45 items = me.getLayoutItems(),
50 // Scrollbar offset defined by width of any vertical scroller in the owning grid
51 if (!Ext.isDefined(me.availableSpaceOffset)) {
52 s = me.owner.up('tablepanel').verticalScroller;
53 me.availableSpaceOffset = s ? s.width-1 : 0;
56 returnValue = me.callParent(arguments);
58 // Size to a sane minimum height before possibly being stretched to accommodate grouped headers
59 me.innerCt.setHeight(23);
61 // Unstretch child items before the layout which stretches them.
62 if (me.align == 'stretchmax') {
63 for (; i < len; i++) {
68 item.titleContainer.setStyle({
72 if (item.componentLayout && item.componentLayout.lastComponentSize) {
73 item.componentLayout.lastComponentSize.height = item.el.dom.offsetHeight;
80 // Override to enforce the forceFit config.
81 calculateChildBoxes: function(visibleItems, targetSize) {
83 calculations = me.callParent(arguments),
84 boxes = calculations.boxes,
85 metaData = calculations.meta,
86 len = boxes.length, i = 0, box, item;
88 if (targetSize.width && !me.isColumn) {
89 // If configured forceFit then all columns will be flexed
90 if (me.owner.forceFit) {
92 for (; i < len; i++) {
96 // Set a sane minWidth for the Box layout to be able to squeeze flexed Headers down to.
97 item.minWidth = Ext.grid.plugin.HeaderResizer.prototype.minColWidth;
99 // For forceFit, just use allocated width as the flex value, and the proportions
100 // will end up the same whatever HeaderContainer width they are being forced into.
101 item.flex = box.width;
104 // Recalculate based upon all columns now being flexed instead of sized.
105 calculations = me.callParent(arguments);
107 else if (metaData.tooNarrow) {
108 targetSize.width = metaData.desiredSize;
115 afterLayout: function() {
118 items = me.getLayoutItems(),
121 me.callParent(arguments);
123 // Set up padding in items
124 if (!me.owner.hideHeaders && me.align == 'stretchmax') {
125 for (; i < len; i++) {
126 items[i].setPadding();
131 // FIX: when flexing we actually don't have enough space as we would
132 // typically because of the scrollOffset on the GridView, must reserve this
133 updateInnerCtSize: function(tSize, calcs) {
137 // Columns must not account for scroll offset
139 me.tooNarrow = calcs.meta.tooNarrow;
140 extra = (me.reserveOffset ? me.availableSpaceOffset : 0);
142 if (calcs.meta.tooNarrow) {
143 tSize.width = calcs.meta.desiredSize + extra;
145 tSize.width += extra;
149 return me.callParent(arguments);
152 doOwnerCtLayouts: function() {
153 var ownerCt = this.owner.ownerCt;
154 if (!ownerCt.componentLayout.layoutBusy) {
155 ownerCt.doComponentLayout();