# HG changeset patch
# User Frank Benoit
+ * There are two ways to create a GridData
is the layout data object associated with
+ * GridLayout
. To set a GridData
object into a
+ * control, you use the Control.setLayoutData(Object)
method.
+ * GridData
object with certain
+ * fields set. The first is to set the fields directly, like this:
+ *
+ * GridData gridData = new GridData();
+ * gridData.horizontalAlignment = GridData.FILL;
+ * gridData.grabExcessHorizontalSpace = true;
+ * button1.setLayoutData(gridData);
+ *
+ * The second is to take advantage of convenience style bits defined
+ * by GridData
:
+ *
+ * button1.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
+ *
+ *
+ * NOTE: Do not reuse GridData
objects. Every control in a
+ * Composite
that is managed by a GridLayout
+ * must have a unique GridData
object. If the layout data
+ * for a control in a GridLayout
is null at layout time,
+ * a unique GridData
object is created for it.
+ *
grabExcessHorizontalSpace specifies whether the width of the cell
+ * changes depending on the size of the parent Composite. If
+ * grabExcessHorizontalSpace is true
, the following rules
+ * apply to the width of the cell:
The default value is false.
+ * + * @see GridData#minimumWidth + * @see GridData#widthHint + */ + public bool grabExcessHorizontalSpace = false; + + /** + *grabExcessVerticalSpace specifies whether the height of the cell
+ * changes depending on the size of the parent Composite. If
+ * grabExcessVerticalSpace is true
, the following rules
+ * apply to the height of the cell:
The default value is false.
+ * + * @see GridData#minimumHeight + * @see GridData#heightHint + */ + public bool grabExcessVerticalSpace = false; + + /** + * minimumWidth specifies the minimum width in pixels. This value + * applies only if grabExcessHorizontalSpace is true. A value of + * SWT.DEFAULT means that the minimum width will be the result + * of Control.computeSize(int, int, bool) where wHint is + * determined by GridData.widthHint. + * + * The default value is 0. + * + * @since 3.1 + * @see Control#computeSize(int, int, bool) + * @see GridData#widthHint + */ + public int minimumWidth = 0; + + /** + * minimumHeight specifies the minimum height in pixels. This value + * applies only if grabExcessVerticalSpace is true. A value of + * SWT.DEFAULT means that the minimum height will be the result + * of Control.computeSize(int, int, bool) where hHint is + * determined by GridData.heightHint. + * + * The default value is 0. + * + * @since 3.1 + * @see Control#computeSize(int, int, bool) + * @see GridData#heightHint + */ + public int minimumHeight = 0; + + /** + * exclude informs the layout to ignore this control when sizing + * and positioning controls. If this value istrue
,
+ * the size and position of the control will not be managed by the
+ * layout. If this value is false
, the size and
+ * position of the control will be computed and assigned.
+ *
+ * The default value is false
.
+ *
+ * @since 3.1
+ */
+ public bool exclude = false;
+
+ /**
+ * Value for horizontalAlignment or verticalAlignment.
+ * Position the control at the top or left of the cell.
+ * Not recommended. Use SWT.BEGINNING, SWT.TOP or SWT.LEFT instead.
+ */
+ public static const int BEGINNING = SWT.BEGINNING;
+
+ /**
+ * Value for horizontalAlignment or verticalAlignment.
+ * Position the control in the vertical or horizontal center of the cell
+ * Not recommended. Use SWT.CENTER instead.
+ */
+ public static const int CENTER = 2;
+
+ /**
+ * Value for horizontalAlignment or verticalAlignment.
+ * Position the control at the bottom or right of the cell
+ * Not recommended. Use SWT.END, SWT.BOTTOM or SWT.RIGHT instead.
+ */
+ public static const int END = 3;
+
+ /**
+ * Value for horizontalAlignment or verticalAlignment.
+ * Resize the control to fill the cell horizontally or vertically.
+ * Not recommended. Use SWT.FILL instead.
+ */
+ public static const int FILL = SWT.FILL;
+
+ /**
+ * Style bit for new GridData(int)
.
+ * Position the control at the top of the cell.
+ * Not recommended. Use
+ * new GridData(int, SWT.BEGINNING, bool, bool)
+ * instead.
+ */
+ public static const int VERTICAL_ALIGN_BEGINNING = 1 << 1;
+
+ /**
+ * Style bit for new GridData(int)
to position the
+ * control in the vertical center of the cell.
+ * Not recommended. Use
+ * new GridData(int, SWT.CENTER, bool, bool)
+ * instead.
+ */
+ public static const int VERTICAL_ALIGN_CENTER = 1 << 2;
+
+ /**
+ * Style bit for new GridData(int)
to position the
+ * control at the bottom of the cell.
+ * Not recommended. Use
+ * new GridData(int, SWT.END, bool, bool)
+ * instead.
+ */
+ public static const int VERTICAL_ALIGN_END = 1 << 3;
+
+ /**
+ * Style bit for new GridData(int)
to resize the
+ * control to fill the cell vertically.
+ * Not recommended. Use
+ * new GridData(int, SWT.FILL, bool, bool)
+ * instead
+ */
+ public static const int VERTICAL_ALIGN_FILL = 1 << 4;
+
+ /**
+ * Style bit for new GridData(int)
to position the
+ * control at the left of the cell.
+ * Not recommended. Use
+ * new GridData(SWT.BEGINNING, int, bool, bool)
+ * instead.
+ */
+ public static const int HORIZONTAL_ALIGN_BEGINNING = 1 << 5;
+
+ /**
+ * Style bit for new GridData(int)
to position the
+ * control in the horizontal center of the cell.
+ * Not recommended. Use
+ * new GridData(SWT.CENTER, int, bool, bool)
+ * instead.
+ */
+ public static const int HORIZONTAL_ALIGN_CENTER = 1 << 6;
+
+ /**
+ * Style bit for new GridData(int)
to position the
+ * control at the right of the cell.
+ * Not recommended. Use
+ * new GridData(SWT.END, int, bool, bool)
+ * instead.
+ */
+ public static const int HORIZONTAL_ALIGN_END = 1 << 7;
+
+ /**
+ * Style bit for new GridData(int)
to resize the
+ * control to fill the cell horizontally.
+ * Not recommended. Use
+ * new GridData(SWT.FILL, int, bool, bool)
+ * instead.
+ */
+ public static const int HORIZONTAL_ALIGN_FILL = 1 << 8;
+
+ /**
+ * Style bit for new GridData(int)
to resize the
+ * control to fit the remaining horizontal space.
+ * Not recommended. Use
+ * new GridData(int, int, true, bool)
+ * instead.
+ */
+ public static const int GRAB_HORIZONTAL = 1 << 9;
+
+ /**
+ * Style bit for new GridData(int)
to resize the
+ * control to fit the remaining vertical space.
+ * Not recommended. Use
+ * new GridData(int, int, bool, true)
+ * instead.
+ */
+ public static const int GRAB_VERTICAL = 1 << 10;
+
+ /**
+ * Style bit for new GridData(int)
to resize the
+ * control to fill the cell vertically and to fit the remaining
+ * vertical space.
+ * FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL
+ * Not recommended. Use
+ * new GridData(int, SWT.FILL, bool, true)
+ * instead.
+ */
+ public static const int FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL;
+
+ /**
+ * Style bit for new GridData(int)
to resize the
+ * control to fill the cell horizontally and to fit the remaining
+ * horizontal space.
+ * FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL
+ * Not recommended. Use
+ * new GridData(SWT.FILL, int, true, bool)
+ * instead.
+ */
+ public static const int FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL;
+
+ /**
+ * Style bit for new GridData(int)
to resize the
+ * control to fill the cell horizontally and vertically and
+ * to fit the remaining horizontal and vertical space.
+ * FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL
+ * Not recommended. Use
+ * new GridData(SWT.FILL, SWT.FILL, true, true)
+ * instead.
+ */
+ public static const int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL;
+
+ int cacheWidth = -1, cacheHeight = -1;
+ int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1;
+ int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
+
+/**
+ * Constructs a new instance of GridData using
+ * default values.
+ */
+public this () {
+}
+
+/**
+ * Constructs a new instance based on the GridData style.
+ * This constructor is not recommended.
+ *
+ * @param style the GridData style
+ */
+public this (int style) {
+ if ((style & VERTICAL_ALIGN_BEGINNING) !is 0) verticalAlignment = BEGINNING;
+ if ((style & VERTICAL_ALIGN_CENTER) !is 0) verticalAlignment = CENTER;
+ if ((style & VERTICAL_ALIGN_FILL) !is 0) verticalAlignment = FILL;
+ if ((style & VERTICAL_ALIGN_END) !is 0) verticalAlignment = END;
+ if ((style & HORIZONTAL_ALIGN_BEGINNING) !is 0) horizontalAlignment = BEGINNING;
+ if ((style & HORIZONTAL_ALIGN_CENTER) !is 0) horizontalAlignment = CENTER;
+ if ((style & HORIZONTAL_ALIGN_FILL) !is 0) horizontalAlignment = FILL;
+ if ((style & HORIZONTAL_ALIGN_END) !is 0) horizontalAlignment = END;
+ grabExcessHorizontalSpace = (style & GRAB_HORIZONTAL) !is 0;
+ grabExcessVerticalSpace = (style & GRAB_VERTICAL) !is 0;
+}
+
+/**
+ * Constructs a new instance of GridData according to the parameters.
+ *
+ * @param horizontalAlignment how control will be positioned horizontally within a cell
+ * @param verticalAlignment how control will be positioned vertically within a cell
+ * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space
+ * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space
+ *
+ * @since 3.0
+ */
+public this (int horizontalAlignment, int verticalAlignment, bool grabExcessHorizontalSpace, bool grabExcessVerticalSpace) {
+ this (horizontalAlignment, verticalAlignment, grabExcessHorizontalSpace, grabExcessVerticalSpace, 1, 1);
+}
+
+/**
+ * Constructs a new instance of GridData according to the parameters.
+ *
+ * @param horizontalAlignment how control will be positioned horizontally within a cell
+ * @param verticalAlignment how control will be positioned vertically within a cell
+ * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space
+ * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space
+ * @param horizontalSpan the number of column cells that the control will take up
+ * @param verticalSpan the number of row cells that the control will take up
+ *
+ * @since 3.0
+ */
+public this (int horizontalAlignment, int verticalAlignment, bool grabExcessHorizontalSpace, bool grabExcessVerticalSpace, int horizontalSpan, int verticalSpan) {
+ this.horizontalAlignment = horizontalAlignment;
+ this.verticalAlignment = verticalAlignment;
+ this.grabExcessHorizontalSpace = grabExcessHorizontalSpace;
+ this.grabExcessVerticalSpace = grabExcessVerticalSpace;
+ this.horizontalSpan = horizontalSpan;
+ this.verticalSpan = verticalSpan;
+}
+
+/**
+ * Constructs a new instance of GridData according to the parameters.
+ * A value of SWT.DEFAULT indicates that no minimum width or
+ * no minimum height is specified.
+ *
+ * @param width a minimum width for the column
+ * @param height a minimum height for the row
+ *
+ * @since 3.0
+ */
+public this (int width, int height) {
+ this.widthHint = width;
+ this.heightHint = height;
+}
+
+void computeSize (Control control, int wHint, int hHint, bool flushCache) {
+ if (cacheWidth !is -1 && cacheHeight !is -1) return;
+ if (wHint is this.widthHint && hHint is this.heightHint) {
+ if (defaultWidth is -1 || defaultHeight is -1 || wHint !is defaultWhint || hHint !is defaultHhint) {
+ Point size = control.computeSize (wHint, hHint, flushCache);
+ defaultWhint = wHint;
+ defaultHhint = hHint;
+ defaultWidth = size.x;
+ defaultHeight = size.y;
+ }
+ cacheWidth = defaultWidth;
+ cacheHeight = defaultHeight;
+ return;
+ }
+ if (currentWidth is -1 || currentHeight is -1 || wHint !is currentWhint || hHint !is currentHhint) {
+ Point size = control.computeSize (wHint, hHint, flushCache);
+ currentWhint = wHint;
+ currentHhint = hHint;
+ currentWidth = size.x;
+ currentHeight = size.y;
+ }
+ cacheWidth = currentWidth;
+ cacheHeight = currentHeight;
+}
+
+void flushCache () {
+ cacheWidth = cacheHeight = -1;
+ defaultWidth = defaultHeight = -1;
+ currentWidth = currentHeight = -1;
+}
+
+char[] getName () {
+ char[] string = this.classinfo.name;
+ int index = locatePrior( string, '.');
+ if (index is string.length ) return string;
+ return string[ index + 1 .. string.length ];
+}
+
+/**
+ * Returns a string containing a concise, human-readable
+ * description of the receiver.
+ *
+ * @return a string representation of the GridData object
+ */
+public char[] toString () {
+ char[] hAlign = "";
+ switch (horizontalAlignment) {
+ case SWT.FILL: hAlign = "SWT.FILL"; break;
+ case SWT.BEGINNING: hAlign = "SWT.BEGINNING"; break;
+ case SWT.LEFT: hAlign = "SWT.LEFT"; break;
+ case SWT.END: hAlign = "SWT.END"; break;
+ case END: hAlign = "GridData.END"; break;
+ case SWT.RIGHT: hAlign = "SWT.RIGHT"; break;
+ case SWT.CENTER: hAlign = "SWT.CENTER"; break;
+ case CENTER: hAlign = "GridData.CENTER"; break;
+ default: hAlign = "Undefined "~to!(char[])(horizontalAlignment); break;
+ }
+ char[] vAlign = "";
+ switch (verticalAlignment) {
+ case SWT.FILL: vAlign = "SWT.FILL"; break;
+ case SWT.BEGINNING: vAlign = "SWT.BEGINNING"; break;
+ case SWT.TOP: vAlign = "SWT.TOP"; break;
+ case SWT.END: vAlign = "SWT.END"; break;
+ case END: vAlign = "GridData.END"; break;
+ case SWT.BOTTOM: vAlign = "SWT.BOTTOM"; break;
+ case SWT.CENTER: vAlign = "SWT.CENTER"; break;
+ case CENTER: vAlign = "GridData.CENTER"; break;
+ default: vAlign = "Undefined "~to!(char[])(verticalAlignment); break;
+ }
+ char[] string = getName()~" {";
+ string ~= "horizontalAlignment="~to!(char[])(hAlign)~" ";
+ if (horizontalIndent !is 0) string ~= "horizontalIndent="~to!(char[])(horizontalIndent)~" ";
+ if (horizontalSpan !is 1) string ~= "horizontalSpan="~to!(char[])(horizontalSpan)~" ";
+ if (grabExcessHorizontalSpace) string ~= "grabExcessHorizontalSpace="~to!(char[])(grabExcessHorizontalSpace)~" ";
+ if (widthHint !is SWT.DEFAULT) string ~= "widthHint="~to!(char[])(widthHint)~" ";
+ if (minimumWidth !is 0) string ~= "minimumWidth="~to!(char[])(minimumWidth)~" ";
+ string ~= "verticalAlignment="~vAlign~" ";
+ if (verticalIndent !is 0) string ~= "verticalIndent="~to!(char[])(verticalIndent)~" ";
+ if (verticalSpan !is 1) string ~= "verticalSpan="~to!(char[])(verticalSpan)~" ";
+ if (grabExcessVerticalSpace) string ~= "grabExcessVerticalSpace="~to!(char[])(grabExcessVerticalSpace)~" ";
+ if (heightHint !is SWT.DEFAULT) string ~= "heightHint="~to!(char[])(heightHint)~" ";
+ if (minimumHeight !is 0) string ~= "minimumHeight="~to!(char[])(minimumHeight)~" ";
+ if (exclude) string ~= "exclude="~to!(char[])(exclude)~" ";
+ string = string.trim();
+ string ~= "}";
+ return string;
+}
+}
diff -r e300eb95bec4 -r 47febc12f0a7 dwt/layout/GridLayout.d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/dwt/layout/GridLayout.d Fri Jan 11 11:14:25 2008 +0100
@@ -0,0 +1,755 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2007 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+module dwt.layout.GridLayout;
+
+import dwt.layout.GridData;
+import dwt.SWT;
+import dwt.graphics.Point;
+import dwt.graphics.Rectangle;
+import dwt.widgets.Control;
+import dwt.widgets.Composite;
+import dwt.widgets.Layout;
+import dwt.widgets.Scrollable;
+
+import dwt.dwthelper.System;
+import dwt.dwthelper.Integer;
+
+import tango.text.Util;
+import tango.util.Convert;
+import Math = tango.math.Math;
+
+
+/**
+ * Instances of this class lay out the control children of a
+ * Composite
in a grid.
+ *
+ * GridLayout
has a number of configuration fields, and the
+ * controls it lays out can have an associated layout data object, called
+ * GridData
. The power of GridLayout
lies in the
+ * ability to configure GridData
for each control in the layout.
+ *
+ * The following code creates a shell managed by a GridLayout
+ * with 3 columns:
+ *
+ * Display display = new Display(); + * Shell shell = new Shell(display); + * GridLayout gridLayout = new GridLayout(); + * gridLayout.numColumns = 3; + * shell.setLayout(gridLayout); + *+ * The
numColumns
field is the most important field in a
+ * GridLayout
. Widgets are laid out in columns from left
+ * to right, and a new row is created when numColumns
+ 1
+ * controls are added to the Composite.
+ *
+ *
+ * @see GridData
+ */
+public final class GridLayout : Layout {
+
+ /**
+ * numColumns specifies the number of cell columns in the layout.
+ * If numColumns has a value less than 1, the layout will not
+ * set the size and position of any controls.
+ *
+ * The default value is 1.
+ */
+ public int numColumns = 1;
+
+ /**
+ * makeColumnsEqualWidth specifies whether all columns in the layout
+ * will be forced to have the same width.
+ *
+ * The default value is false.
+ */
+ public bool makeColumnsEqualWidth = false;
+
+ /**
+ * marginWidth specifies the number of pixels of horizontal margin
+ * that will be placed along the left and right edges of the layout.
+ *
+ * The default value is 5.
+ */
+ public int marginWidth = 5;
+
+ /**
+ * marginHeight specifies the number of pixels of vertical margin
+ * that will be placed along the top and bottom edges of the layout.
+ *
+ * The default value is 5.
+ */
+ public int marginHeight = 5;
+
+ /**
+ * marginLeft specifies the number of pixels of horizontal margin
+ * that will be placed along the left edge of the layout.
+ *
+ * The default value is 0.
+ *
+ * @since 3.1
+ */
+ public int marginLeft = 0;
+
+ /**
+ * marginTop specifies the number of pixels of vertical margin
+ * that will be placed along the top edge of the layout.
+ *
+ * The default value is 0.
+ *
+ * @since 3.1
+ */
+ public int marginTop = 0;
+
+ /**
+ * marginRight specifies the number of pixels of horizontal margin
+ * that will be placed along the right edge of the layout.
+ *
+ * The default value is 0.
+ *
+ * @since 3.1
+ */
+ public int marginRight = 0;
+
+ /**
+ * marginBottom specifies the number of pixels of vertical margin
+ * that will be placed along the bottom edge of the layout.
+ *
+ * The default value is 0.
+ *
+ * @since 3.1
+ */
+ public int marginBottom = 0;
+
+ /**
+ * horizontalSpacing specifies the number of pixels between the right
+ * edge of one cell and the left edge of its neighbouring cell to
+ * the right.
+ *
+ * The default value is 5.
+ */
+ public int horizontalSpacing = 5;
+
+ /**
+ * verticalSpacing specifies the number of pixels between the bottom
+ * edge of one cell and the top edge of its neighbouring cell underneath.
+ *
+ * The default value is 5.
+ */
+ public int verticalSpacing = 5;
+
+/**
+ * Constructs a new instance of this class.
+ */
+public this () {}
+
+/**
+ * Constructs a new instance of this class given the
+ * number of columns, and whether or not the columns
+ * should be forced to have the same width.
+ * If numColumns has a value less than 1, the layout will not
+ * set the size and position of any controls.
+ *
+ * @param numColumns the number of columns in the grid
+ * @param makeColumnsEqualWidth whether or not the columns will have equal width
+ *
+ * @since 2.0
+ */
+public this (int numColumns, bool makeColumnsEqualWidth) {
+ this.numColumns = numColumns;
+ this.makeColumnsEqualWidth = makeColumnsEqualWidth;
+}
+
+protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache_) {
+ Point size = layout (composite, false, 0, 0, wHint, hHint, flushCache_);
+ if (wHint !is SWT.DEFAULT) size.x = wHint;
+ if (hHint !is SWT.DEFAULT) size.y = hHint;
+ return size;
+}
+
+protected bool flushCache (Control control) {
+ Object data = control.getLayoutData ();
+ if (data !is null) (cast(GridData) data).flushCache ();
+ return true;
+}
+
+GridData getData (Control [][] grid, int row, int column, int rowCount, int columnCount, bool first) {
+ Control control = grid [row] [column];
+ if (control !is null) {
+ GridData data = cast(GridData) control.getLayoutData ();
+ int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount));
+ int vSpan = Math.max (1, data.verticalSpan);
+ int i = first ? row + vSpan - 1 : row - vSpan + 1;
+ int j = first ? column + hSpan - 1 : column - hSpan + 1;
+ if (0 <= i && i < rowCount) {
+ if (0 <= j && j < columnCount) {
+ if (control is grid [i][j]) return data;
+ }
+ }
+ }
+ return null;
+}
+
+protected void layout (Composite composite, bool flushCache_) {
+ Rectangle rect = composite.getClientArea ();
+ layout (composite, true, rect.x, rect.y, rect.width, rect.height, flushCache_);
+}
+
+Point layout (Composite composite, bool move, int x, int y, int width, int height, bool flushCache_) {
+ if (numColumns < 1) {
+ return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
+ }
+ Control [] children = composite.getChildren ();
+ int count = 0;
+ for (int i=0; i 0) {
+ if (data.cacheWidth < data.minimumWidth) {
+ int trim = 0;
+ //TEMPORARY CODE
+ if ( auto sa = cast(Scrollable)child ) {
+ Rectangle rect = sa.computeTrim (0, 0, 0, 0);
+ trim = rect.width;
+ } else {
+ trim = child.getBorderWidth () * 2;
+ }
+ data.cacheWidth = data.cacheHeight = SWT.DEFAULT;
+ data.computeSize (child, Math.max (0, data.minimumWidth - trim), data.heightHint, false);
+ }
+ }
+ if (data.grabExcessVerticalSpace && data.minimumHeight > 0) {
+ data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight);
+ }
+ }
+
+ /* Build the grid */
+ int row = 0, column = 0, rowCount = 0, columnCount = numColumns;
+ Control [][] grid = new Control [][]( 4, columnCount );
+ for (int i=0; i= grid.length) {
+ Control [][] newGrid = new Control[][]( lastRow + 4, columnCount );
+ SimpleType!(Control[]).arraycopy (grid, 0, newGrid, 0, grid.length);
+ grid = newGrid;
+ }
+ if (grid [row] is null) {
+ grid [row] = new Control [columnCount];
+ }
+ while (column < columnCount && grid [row] [column] !is null) {
+ column++;
+ }
+ int endCount = column + hSpan;
+ if (endCount <= columnCount) {
+ int index = column;
+ while (index < endCount && grid [row] [index] is null) {
+ index++;
+ }
+ if (index is endCount) break;
+ column = index;
+ }
+ if (column + hSpan >= columnCount) {
+ column = 0;
+ row++;
+ }
+ }
+ for (int j=0; j 1) {
+ int spanWidth = 0, spanMinWidth = 0, spanExpandCount = 0;
+ for (int k=0; k 0) {
+ if (makeColumnsEqualWidth) {
+ int equalWidth = (w + spanWidth) / hSpan;
+ int remainder = (w + spanWidth) % hSpan, last = -1;
+ for (int k = 0; k < hSpan; k++) {
+ widths [last=j-k] = Math.max (equalWidth, widths [j-k]);
+ }
+ if (last > -1) widths [last] += remainder;
+ } else {
+ if (spanExpandCount is 0) {
+ widths [j] += w;
+ } else {
+ int delta = w / spanExpandCount;
+ int remainder = w % spanExpandCount, last = -1;
+ for (int k = 0; k < hSpan; k++) {
+ if (expandColumn [j-k]) {
+ widths [last=j-k] += delta;
+ }
+ }
+ if (last > -1) widths [last] += remainder;
+ }
+ }
+ }
+ if (!data.grabExcessHorizontalSpace || data.minimumWidth !is 0) {
+ w = !data.grabExcessHorizontalSpace || data.minimumWidth is SWT.DEFAULT ? data.cacheWidth : data.minimumWidth;
+ w += data.horizontalIndent - spanMinWidth - (hSpan - 1) * horizontalSpacing;
+ if (w > 0) {
+ if (spanExpandCount is 0) {
+ minWidths [j] += w;
+ } else {
+ int delta = w / spanExpandCount;
+ int remainder = w % spanExpandCount, last = -1;
+ for (int k = 0; k < hSpan; k++) {
+ if (expandColumn [j-k]) {
+ minWidths [last=j-k] += delta;
+ }
+ }
+ if (last > -1) minWidths [last] += remainder;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (makeColumnsEqualWidth) {
+ int minColumnWidth = 0;
+ int columnWidth = 0;
+ for (int i=0; i 0;
+ widths [i] = columnWidth;
+ }
+ } else {
+ if (width !is SWT.DEFAULT && expandCount > 0) {
+ int totalWidth = 0;
+ for (int i=0; i minWidths [j]) {
+ widths [last = j] = widths [j] + delta;
+ } else {
+ widths [j] = minWidths [j];
+ expandColumn [j] = false;
+ c--;
+ }
+ }
+ }
+ if (last > -1) widths [last] += remainder;
+
+ for (int j=0; j 1) {
+ if (!data.grabExcessHorizontalSpace || data.minimumWidth !is 0) {
+ int spanWidth = 0, spanExpandCount = 0;
+ for (int k=0; k 0) {
+ if (spanExpandCount is 0) {
+ widths [j] += w;
+ } else {
+ int delta2 = w / spanExpandCount;
+ int remainder2 = w % spanExpandCount, last2 = -1;
+ for (int k = 0; k < hSpan; k++) {
+ if (expandColumn [j-k]) {
+ widths [last2=j-k] += delta2;
+ }
+ }
+ if (last2 > -1) widths [last2] += remainder2;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (c is 0) break;
+ totalWidth = 0;
+ for (int i=0; i currentWidth)) {
+ int trim = 0;
+ if ( auto sa = cast(Scrollable)child ) {
+ Rectangle rect = sa.computeTrim (0, 0, 0, 0);
+ trim = rect.width;
+ } else {
+ trim = child.getBorderWidth () * 2;
+ }
+ data.cacheWidth = data.cacheHeight = SWT.DEFAULT;
+ data.computeSize (child, Math.max (0, currentWidth - trim), data.heightHint, false);
+ if (data.grabExcessVerticalSpace && data.minimumHeight > 0) {
+ data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight);
+ }
+ if (flush is null) flush = new GridData [count];
+ flush [flushLength++] = data;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* Row heights */
+ int availableHeight = height - verticalSpacing * (rowCount - 1) - (marginTop + marginHeight * 2 + marginBottom);
+ expandCount = 0;
+ int [] heights = new int [rowCount];
+ int [] minHeights = new int [rowCount];
+ bool [] expandRow = new bool [rowCount];
+ for (int i=0; i 1) {
+ int spanHeight = 0, spanMinHeight = 0, spanExpandCount = 0;
+ for (int k=0; k 0) {
+ if (spanExpandCount is 0) {
+ heights [i] += h;
+ } else {
+ int delta = h / spanExpandCount;
+ int remainder = h % spanExpandCount, last = -1;
+ for (int k = 0; k < vSpan; k++) {
+ if (expandRow [i-k]) {
+ heights [last=i-k] += delta;
+ }
+ }
+ if (last > -1) heights [last] += remainder;
+ }
+ }
+ if (!data.grabExcessVerticalSpace || data.minimumHeight !is 0) {
+ h = !data.grabExcessVerticalSpace || data.minimumHeight is SWT.DEFAULT ? data.cacheHeight : data.minimumHeight;
+ h += data.verticalIndent - spanMinHeight - (vSpan - 1) * verticalSpacing;
+ if (h > 0) {
+ if (spanExpandCount is 0) {
+ minHeights [i] += h;
+ } else {
+ int delta = h / spanExpandCount;
+ int remainder = h % spanExpandCount, last = -1;
+ for (int k = 0; k < vSpan; k++) {
+ if (expandRow [i-k]) {
+ minHeights [last=i-k] += delta;
+ }
+ }
+ if (last > -1) minHeights [last] += remainder;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (height !is SWT.DEFAULT && expandCount > 0) {
+ int totalHeight = 0;
+ for (int i=0; i minHeights [i]) {
+ heights [last = i] = heights [i] + delta;
+ } else {
+ heights [i] = minHeights [i];
+ expandRow [i] = false;
+ c--;
+ }
+ }
+ }
+ if (last > -1) heights [last] += remainder;
+
+ for (int i=0; i 1) {
+ if (!data.grabExcessVerticalSpace || data.minimumHeight !is 0) {
+ int spanHeight = 0, spanExpandCount = 0;
+ for (int k=0; k 0) {
+ if (spanExpandCount is 0) {
+ heights [i] += h;
+ } else {
+ int delta2 = h / spanExpandCount;
+ int remainder2 = h % spanExpandCount, last2 = -1;
+ for (int k = 0; k < vSpan; k++) {
+ if (expandRow [i-k]) {
+ heights [last2=i-k] += delta2;
+ }
+ }
+ if (last2 > -1) heights [last2] += remainder2;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ if (c is 0) break;
+ totalHeight = 0;
+ for (int i=0; i