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.layout.container.CheckboxGroup
17 * @extends Ext.layout.container.Container
18 * <p>This layout implements the column arrangement for {@link Ext.form.CheckboxGroup} and {@link Ext.form.RadioGroup}.
19 * It groups the component's sub-items into columns based on the component's
20 * {@link Ext.form.CheckboxGroup#columns columns} and {@link Ext.form.CheckboxGroup#vertical} config properties.</p>
23 Ext.define('Ext.layout.container.CheckboxGroup', {
24 extend: 'Ext.layout.container.Container',
25 alias: ['layout.checkboxgroup'],
28 onLayout: function() {
29 var numCols = this.getColCount(),
30 shadowCt = this.getShadowCt(),
33 shadowItems = shadowCt.items,
34 numItems = items.length,
38 // Distribute the items into the appropriate column containers. We add directly to the
39 // containers' items collection rather than calling container.add(), because we need the
40 // checkboxes to maintain their original ownerCt. The distribution is done on each layout
41 // in case items have been added, removed, or reordered.
43 shadowItems.each(function(col) {
47 // If columns="auto", then the number of required columns may change as checkboxes are added/removed
48 // from the CheckboxGroup; adjust to match.
49 while (shadowItems.length > numCols) {
50 shadowCt.remove(shadowItems.last());
52 while (shadowItems.length < numCols) {
61 numRows = Math.ceil(numItems / numCols);
62 for (i = 0; i < numItems; i++) {
63 if (i > 0 && i % numRows === 0) {
66 shadowItems.getAt(colIndex).items.add(items.getAt(i));
69 for (i = 0; i < numItems; i++) {
70 colIndex = i % numCols;
71 shadowItems.getAt(colIndex).items.add(items.getAt(i));
75 if (!shadowCt.rendered) {
76 shadowCt.render(this.getRenderTarget());
78 // Ensure all items are rendered in the correct place in the correct column - this won't
79 // get done by the column containers themselves if their dimensions are not changing.
80 shadowItems.each(function(col) {
81 var layout = col.getLayout();
82 layout.renderItems(layout.getLayoutItems(), layout.getRenderTarget());
86 shadowCt.doComponentLayout();
90 // We don't want to render any items to the owner directly, that gets handled by each column's own layout
91 renderItems: Ext.emptyFn,
96 * Creates and returns the shadow hbox container that will be used to arrange the owner's items
99 getShadowCt: function() {
101 shadowCt = me.shadowCt,
102 owner, items, item, columns, columnsIsArray, numCols, i;
105 // Create the column containers based on the owner's 'columns' config
107 columns = owner.columns;
108 columnsIsArray = Ext.isArray(columns);
109 numCols = me.getColCount();
111 for(i = 0; i < numCols; i++) {
116 if (columnsIsArray) {
117 // Array can contain mixture of whole numbers, used as fixed pixel widths, and fractional
118 // numbers, used as relative flex values.
119 if (columns[i] < 1) {
120 item.flex = columns[i];
122 item.width = columns[i];
126 // All columns the same width
132 // Create the shadow container; delay rendering until after items are added to the columns
133 shadowCt = me.shadowCt = Ext.createWidget('container', {
145 * @private Get the number of columns in the checkbox group
147 getColCount: function() {
148 var owner = this.owner,
149 colsCfg = owner.columns;
150 return Ext.isArray(colsCfg) ? colsCfg.length : (Ext.isNumber(colsCfg) ? colsCfg : owner.items.length);