annotate dwt/layout/FillLayout.d @ 212:ab60f3309436

reverted the char[] to String and use the an alias.
author Frank Benoit <benoit@tionex.de>
date Mon, 05 May 2008 00:12:38 +0200
parents d0bbd290530f
children fd9c62a2998e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
1 /*******************************************************************************
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
2 * Copyright (c) 2000, 2006 IBM Corporation and others.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
3 * All rights reserved. This program and the accompanying materials
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
4 * are made available under the terms of the Eclipse Public License v1.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
5 * which accompanies this distribution, and is available at
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
6 * http://www.eclipse.org/legal/epl-v10.html
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
7 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
8 * Contributors:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
9 * IBM Corporation - initial API and implementation
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
10 * Port to the D programming language:
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
11 * Frank Benoit <benoit@tionex.de>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
12 *******************************************************************************/
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
13 module dwt.layout.FillLayout;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
14
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
15 import dwt.DWT;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
16 import dwt.graphics.Point;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
17 import dwt.graphics.Rectangle;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
18 import dwt.widgets.Control;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
19 import dwt.widgets.Layout;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
20 import dwt.widgets.Composite;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
21 import dwt.widgets.Scrollable;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
22 import dwt.layout.FillData;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
23
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
24 import tango.util.Convert;
31
92c102dd64a3 Added all widgets modules as dummy. Most modules of accessible are equal to the linux version, except Accessible.
Frank Benoit <benoit@tionex.de>
parents: 0
diff changeset
25 import dwt.dwthelper.utils;
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
26
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
27 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
28 * <code>FillLayout</code> is the simplest layout class. It lays out
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
29 * controls in a single row or column, forcing them to be the same size.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
30 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
31 * Initially, the controls will all be as tall as the tallest control,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
32 * and as wide as the widest. <code>FillLayout</code> does not wrap,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
33 * but you can specify margins and spacing. You might use it to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
34 * lay out buttons in a task bar or tool bar, or to stack checkboxes
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
35 * in a <code>Group</code>. <code>FillLayout</code> can also be used
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
36 * when a <code>Composite</code> only has one child. For example,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
37 * if a <code>Shell</code> has a single <code>Group</code> child,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
38 * <code>FillLayout</code> will cause the <code>Group</code> to
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
39 * completely fill the <code>Shell</code> (if margins are 0).
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
40 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
41 * <p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
42 * Example code: first a <code>FillLayout</code> is created and
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
43 * its type field is set, and then the layout is set into the
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
44 * <code>Composite</code>. Note that in a <code>FillLayout</code>,
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
45 * children are always the same size, and they fill all available space.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
46 * <pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
47 * FillLayout fillLayout = new FillLayout();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
48 * fillLayout.type = DWT.VERTICAL;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
49 * shell.setLayout(fillLayout);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
50 * </pre>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
51 * </p>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
52 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
53 public final class FillLayout : Layout {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
54 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
55 * type specifies how controls will be positioned
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
56 * within the layout.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
57 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
58 * The default value is HORIZONTAL.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
59 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
60 * Possible values are: <ul>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
61 * <li>HORIZONTAL: Position the controls horizontally from left to right</li>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
62 * <li>VERTICAL: Position the controls vertically from top to bottom</li>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
63 * </ul>
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
64 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
65 public int type = DWT.HORIZONTAL;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
66
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
67 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
68 * marginWidth specifies the number of pixels of horizontal margin
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
69 * that will be placed along the left and right edges of the layout.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
70 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
71 * The default value is 0.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
72 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
73 * @since 3.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
74 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
75 public int marginWidth = 0;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
76
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
77 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
78 * marginHeight specifies the number of pixels of vertical margin
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
79 * that will be placed along the top and bottom edges of the layout.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
80 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
81 * The default value is 0.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
82 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
83 * @since 3.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
84 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
85 public int marginHeight = 0;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
86
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
87 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
88 * spacing specifies the number of pixels between the edge of one cell
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
89 * and the edge of its neighbouring cell.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
90 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
91 * The default value is 0.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
92 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
93 * @since 3.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
94 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
95 public int spacing = 0;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
96
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
97 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
98 * Constructs a new instance of this class.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
99 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
100 public this () {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
101 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
102
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
103 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
104 * Constructs a new instance of this class given the type.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
105 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
106 * @param type the type of fill layout
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
107 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
108 * @since 2.0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
109 */
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
110 public this (int type) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
111 this.type = type;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
112 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
113
48
9a64a7781bab Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents: 31
diff changeset
114 override protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache) {
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
115 Control [] children = composite.getChildren ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
116 int count = children.length;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
117 int maxWidth = 0, maxHeight = 0;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
118 for (int i=0; i<count; i++) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
119 Control child = children [i];
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
120 int w = wHint, h = hHint;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
121 if (count > 0) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
122 if (type is DWT.HORIZONTAL && wHint !is DWT.DEFAULT) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
123 w = Math.max (0, (wHint - (count - 1) * spacing) / count);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
124 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
125 if (type is DWT.VERTICAL && hHint !is DWT.DEFAULT) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
126 h = Math.max (0, (hHint - (count - 1) * spacing) / count);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
127 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
128 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
129 Point size = computeChildSize (child, w, h, flushCache);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
130 maxWidth = Math.max (maxWidth, size.x);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
131 maxHeight = Math.max (maxHeight, size.y);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
132 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
133 int width = 0, height = 0;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
134 if (type is DWT.HORIZONTAL) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
135 width = count * maxWidth;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
136 if (count !is 0) width += (count - 1) * spacing;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
137 height = maxHeight;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
138 } else {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
139 width = maxWidth;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
140 height = count * maxHeight;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
141 if (count !is 0) height += (count - 1) * spacing;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
142 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
143 width += marginWidth * 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
144 height += marginHeight * 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
145 if (wHint !is DWT.DEFAULT) width = wHint;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
146 if (hHint !is DWT.DEFAULT) height = hHint;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
147 return new Point (width, height);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
148 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
149
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
150 Point computeChildSize (Control control, int wHint, int hHint, bool flushCache) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
151 FillData data = cast(FillData)control.getLayoutData ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
152 if (data is null) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
153 data = new FillData ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
154 control.setLayoutData (data);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
155 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
156 Point size = null;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
157 if (wHint is DWT.DEFAULT && hHint is DWT.DEFAULT) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
158 size = data.computeSize (control, wHint, hHint, flushCache);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
159 } else {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
160 // TEMPORARY CODE
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
161 int trimX, trimY;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
162 if ( auto sa = cast(Scrollable)control ) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
163 Rectangle rect = sa.computeTrim (0, 0, 0, 0);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
164 trimX = rect.width;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
165 trimY = rect.height;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
166 } else {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
167 trimX = trimY = control.getBorderWidth () * 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
168 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
169 int w = wHint is DWT.DEFAULT ? wHint : Math.max (0, wHint - trimX);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
170 int h = hHint is DWT.DEFAULT ? hHint : Math.max (0, hHint - trimY);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
171 size = data.computeSize (control, w, h, flushCache);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
172 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
173 return size;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
174 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
175
48
9a64a7781bab Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents: 31
diff changeset
176 override protected bool flushCache (Control control) {
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
177 Object data = control.getLayoutData();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
178 if (data !is null) (cast(FillData)data).flushCache();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
179 return true;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
180 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
181
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 193
diff changeset
182 String getName () {
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 193
diff changeset
183 String string = this.classinfo.name;
193
d0bbd290530f Fix import conflict
Frank Benoit <benoit@tionex.de>
parents: 48
diff changeset
184 int index = string.lastIndexOf( '.');
d0bbd290530f Fix import conflict
Frank Benoit <benoit@tionex.de>
parents: 48
diff changeset
185 if (index is -1 ) return string;
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
186 return string[ index + 1 .. string.length ];
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
187 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
188
48
9a64a7781bab Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents: 31
diff changeset
189 override protected void layout (Composite composite, bool flushCache) {
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
190 Rectangle rect = composite.getClientArea ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
191 Control [] children = composite.getChildren ();
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
192 int count = children.length;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
193 if (count is 0) return;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
194 int width = rect.width - marginWidth * 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
195 int height = rect.height - marginHeight * 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
196 if (type is DWT.HORIZONTAL) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
197 width -= (count - 1) * spacing;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
198 int x = rect.x + marginWidth, extra = width % count;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
199 int y = rect.y + marginHeight, cellWidth = width / count;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
200 for (int i=0; i<count; i++) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
201 Control child = children [i];
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
202 int childWidth = cellWidth;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
203 if (i is 0) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
204 childWidth += extra / 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
205 } else {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
206 if (i is count - 1) childWidth += (extra + 1) / 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
207 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
208 child.setBounds (x, y, childWidth, height);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
209 x += childWidth + spacing;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
210 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
211 } else {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
212 height -= (count - 1) * spacing;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
213 int x = rect.x + marginWidth, cellHeight = height / count;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
214 int y = rect.y + marginHeight, extra = height % count;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
215 for (int i=0; i<count; i++) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
216 Control child = children [i];
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
217 int childHeight = cellHeight;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
218 if (i is 0) {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
219 childHeight += extra / 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
220 } else {
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
221 if (i is count - 1) childHeight += (extra + 1) / 2;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
222 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
223 child.setBounds (x, y, width, childHeight);
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
224 y += childHeight + spacing;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
225 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
226 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
227 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
228
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
229 /**
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
230 * Returns a string containing a concise, human-readable
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
231 * description of the receiver.
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
232 *
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
233 * @return a string representation of the layout
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
234 */
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 193
diff changeset
235 override public String toString () {
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 193
diff changeset
236 String string = getName () ~ " {";
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
237 string ~= "type="~((type is DWT.VERTICAL) ? "DWT.VERTICAL" : "DWT.HORIZONTAL")~" ";
212
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 193
diff changeset
238 if (marginWidth !is 0) string ~= "marginWidth="~to!(String)(marginWidth)~" ";
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 193
diff changeset
239 if (marginHeight !is 0) string ~= "marginHeight="~to!(String)(marginHeight)~" ";
ab60f3309436 reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents: 193
diff changeset
240 if (spacing !is 0) string ~= "spacing="~to!(String)(spacing)~" ";
193
d0bbd290530f Fix import conflict
Frank Benoit <benoit@tionex.de>
parents: 48
diff changeset
241 string = string.trim();
0
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
242 string ~= "}";
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
243 return string;
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
244 }
5406a8f6526d Add initial files
John Reimer <terminal.node@gmail.com
parents:
diff changeset
245 }