13693261870
2022-09-16 354b3dbfbffb3df45212a2a44dbbf48b4acc2594
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>The source code</title>
  <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  <style type="text/css">
    .highlight { display: block; background-color: #ddd; }
  </style>
  <script type="text/javascript">
    function highlight() {
      document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
    }
  </script>
</head>
<body onload="prettyPrint(); highlight();">
  <pre class="prettyprint lang-js"><span id='Ext-grid-ColumnLayout'>/**
</span> * @private
 *
 * This class is used only by the grid's HeaderContainer docked child.
 *
 * It adds the ability to shrink the vertical size of the inner container element back if a grouped
 * column header has all its child columns dragged out, and the whole HeaderContainer needs to shrink back down.
 *
 * Also, after every layout, after all headers have attained their 'stretchmax' height, it goes through and calls
 * `setPadding` on the columns so that they lay out correctly.
 */
Ext.define('Ext.grid.ColumnLayout', {
    extend: 'Ext.layout.container.HBox',
    alias: 'layout.gridcolumn',
<span id='Ext-grid-ColumnLayout-property-type'>    type : 'gridcolumn',
</span>
<span id='Ext-grid-ColumnLayout-property-reserveOffset'>    reserveOffset: false,
</span>
<span id='Ext-grid-ColumnLayout-property-firstHeaderCls'>    firstHeaderCls: Ext.baseCSSPrefix + 'column-header-first',
</span><span id='Ext-grid-ColumnLayout-property-lastHeaderCls'>    lastHeaderCls: Ext.baseCSSPrefix + 'column-header-last',
</span>
<span id='Ext-grid-ColumnLayout-method-initLayout'>    initLayout: function() {
</span>        if (!this.scrollbarWidth) {
            this.self.prototype.scrollbarWidth = Ext.getScrollbarSize().width;
        }
        this.grid = this.owner.up('[scrollerOwner]');
        this.callParent();
    },
 
<span id='Ext-grid-ColumnLayout-method-beginLayout'>    // Collect the height of the table of data upon layout begin
</span>    beginLayout: function (ownerContext) {
        var me = this,
            owner = me.owner,
            grid = me.grid,
            view = grid.view,
            items = me.getVisibleItems(),
            len = items.length,
            firstCls = me.firstHeaderCls, 
            lastCls = me.lastHeaderCls,
            i, item;
 
        // If we are one side of a locking grid, then if we are on the &quot;normal&quot; side, we have to grab the normal view
        // for use in determining whether to subtract scrollbar width from available width.
        // The locked side does not have scrollbars, so it should not look at the view.
        if (grid.lockable) {
            if (owner.up('tablepanel') === view.normalGrid) {
                view = view.normalGrid.getView();
            } else {
                view = null;
            }
        }
 
        for (i = 0; i &lt; len; i++) {
            item = items[i];
 
            // Keep the isLast flag correct so that the column's component layout can know whether or not
            // it needs a right border. See ColumnComponentLayout.beginLayoutCycle
            item.isLast = false;
            item.removeCls([firstCls, lastCls]);
            if (i === 0) {
                item.addCls(firstCls);
            }
 
            if (i === len - 1) {
                item.addCls(lastCls);
                item.isLast = true;
            }
        }
 
        me.callParent(arguments);
 
        // If the owner is the grid's HeaderContainer, and the UI displays old fashioned scrollbars and there is a rendered View with data in it,
        // collect the View context to interrogate it for overflow, and possibly invalidate it if there is overflow
        if (!owner.isColumn &amp;&amp; Ext.getScrollbarSize().width &amp;&amp; !grid.collapsed &amp;&amp; view &amp;&amp;
                view.rendered &amp;&amp; (ownerContext.viewTable = view.body.dom)) {
            ownerContext.viewContext = ownerContext.context.getCmp(view);
        }
    },
 
<span id='Ext-grid-ColumnLayout-method-roundFlex'>    roundFlex: function(width) {
</span>        return Math.floor(width);
    },
 
<span id='Ext-grid-ColumnLayout-method-calculate'>    calculate: function(ownerContext) {
</span>        this.callParent(arguments);
 
        // If we have calculated the widths, then if forceFit, and there are no flexes, we cannot tell the
        // TableLayout we are done. We will have to go through the convertWidthsToFlexes stage.
        if (ownerContext.state.parallelDone &amp;&amp; (!this.owner.forceFit || ownerContext.flexedItems.length)) {
            // TODO: auto width columns aren't necessarily done here.
            // see view.TableLayout, there is a work around for that there 
            ownerContext.setProp('columnWidthsDone', true);
        }
 
        // Collect the height of the data table if we need it to determine overflow
        if (ownerContext.viewContext) {
            ownerContext.state.tableHeight = ownerContext.viewTable.offsetHeight;
        }
    },
 
<span id='Ext-grid-ColumnLayout-method-completeLayout'>    completeLayout: function(ownerContext) {
</span>        var me = this,
            owner = me.owner,
            state = ownerContext.state;
 
        me.callParent(arguments);
 
        // If we have not been through this already, and the owning Container is configured
        // forceFit, is not a group column and and there is a valid width, then convert
        // widths to flexes, and loop back.
        if (!ownerContext.flexedItems.length &amp;&amp; !state.flexesCalculated &amp;&amp; owner.forceFit &amp;&amp;
 
            // Recalculate based upon all columns now being flexed instead of sized.
            // Set flag, so that we do not do this infinitely
            me.convertWidthsToFlexes(ownerContext)) {
            me.cacheFlexes(ownerContext);
            ownerContext.invalidate({
                state: {
                    flexesCalculated: true
                }
            });
        } else {
            ownerContext.setProp('columnWidthsDone', true);
        }
    },
 
<span id='Ext-grid-ColumnLayout-method-convertWidthsToFlexes'>    convertWidthsToFlexes: function(ownerContext) {
</span>        var me = this,
            totalWidth = 0,
            calculated = me.sizeModels.calculated,
            childItems, len, i, childContext, item;
 
        childItems = ownerContext.childItems;
        len = childItems.length;
 
        for (i = 0; i &lt; len; i++) {
            childContext = childItems[i];
            item = childContext.target;
 
            totalWidth += childContext.props.width;
 
            // Only allow to be flexed if it's a resizable column
            if (!(item.fixed || item.resizable === false)) {
 
                // For forceFit, just use allocated width as the flex value, and the proportions
                // will end up the same whatever HeaderContainer width they are being forced into.
                item.flex = ownerContext.childItems[i].flex = childContext.props.width;
                item.width = null;
                childContext.widthModel = calculated;
            }
        }
 
        // Only need to loop back if the total column width is not already an exact fit
        return totalWidth !== ownerContext.props.width;
    },
 
<span id='Ext-grid-ColumnLayout-method-getContainerSize'>    /**
</span>     * @private
     * Local getContainerSize implementation accounts for vertical scrollbar in the view.
     */
    getContainerSize: function(ownerContext) {
        var me = this,
            result,
            viewContext = ownerContext.viewContext,
            viewHeight;
 
        // Column, NOT the main grid's HeaderContainer
        if (me.owner.isColumn) {
            result = me.getColumnContainerSize(ownerContext);
        }
 
        // This is the maingrid's HeaderContainer
        else {
            result = me.callParent(arguments);
 
            // If we've collected a viewContext and we're not shrinkwrapping the height
            // then we see if we have to narrow the width slightly to account for scrollbar
            if (viewContext &amp;&amp; !viewContext.heightModel.shrinkWrap &amp;&amp;
                    viewContext.target.componentLayout.ownerContext) { // if (its layout is running)
                viewHeight = viewContext.getProp('height');
                if (isNaN(viewHeight)) {
                    me.done = false;
                } else if (ownerContext.state.tableHeight &gt; viewHeight) {
                    result.width -= Ext.getScrollbarSize().width;
                    ownerContext.state.parallelDone = false;
                    viewContext.invalidate();
                }
            }
        }
 
// TODO - flip the initial assumption to &quot;we have a vscroll&quot; to avoid the invalidate in most
// cases (and the expensive ones to boot)
 
        return result;
    },
 
<span id='Ext-grid-ColumnLayout-method-getColumnContainerSize'>    getColumnContainerSize : function(ownerContext) {
</span>        var padding = ownerContext.paddingContext.getPaddingInfo(),
            got = 0,
            needed = 0,
            gotWidth, gotHeight, width, height;
 
        // In an shrinkWrap width/height case, we must not ask for any of these dimensions
        // because they will be determined by contentWidth/Height which is calculated by
        // this layout...
 
        // Fit/Card layouts are able to set just the width of children, allowing child's
        // resulting height to autosize the Container.
        // See examples/tabs/tabs.html for an example of this.
 
        if (!ownerContext.widthModel.shrinkWrap) {
            ++needed;
            width = ownerContext.getProp('innerWidth');
            gotWidth = (typeof width == 'number');
            if (gotWidth) {
                ++got;
                width -= padding.width;
                if (width &lt; 0) {
                    width = 0;
                }
            }
        }
 
        if (!ownerContext.heightModel.shrinkWrap) {
            ++needed;
            height = ownerContext.getProp('innerHeight');
            gotHeight = (typeof height == 'number');
            if (gotHeight) {
                ++got;
                height -= padding.height;
                if (height &lt; 0) {
                    height = 0;
                }
            }
        }
 
        return {
            width: width,
            height: height,
            needed: needed,
            got: got,
            gotAll: got == needed,
            gotWidth: gotWidth,
            gotHeight: gotHeight
        };
    },
 
<span id='Ext-grid-ColumnLayout-method-publishInnerCtSize'>    // FIX: when flexing we actually don't have enough space as we would
</span>    // typically because of the scrollOffset on the GridView, must reserve this
    publishInnerCtSize: function(ownerContext) {
        var me = this,
            size = ownerContext.state.boxPlan.targetSize,
            cw = ownerContext.peek('contentWidth'),
            view;
 
        // Allow the other co-operating objects to know whether the columns overflow the available width.
        me.owner.tooNarrow = ownerContext.state.boxPlan.tooNarrow;
 
        // InnerCt MUST stretch to accommodate all columns so that left/right scrolling is enabled in the header container.
        if ((cw != null) &amp;&amp; !me.owner.isColumn) {
            size.width = cw;
 
            // innerCt must also encompass any vertical scrollbar width if there may be one
            view = me.owner.ownerCt.view;
            if (view.scrollFlags.y) {
                size.width += Ext.getScrollbarSize().width;
            }
        }
 
        return me.callParent(arguments);
    }
});
</pre>
</body>
</html>