Mercurial > projects > dwt-win
annotate dwt/layout/GridLayout.d @ 197:184ab53b7785
Changes and fixes for jface
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 10 Apr 2008 11:19:49 +0200 |
parents | 9a64a7781bab |
children | ab60f3309436 |
rev | line source |
---|---|
0 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwt.layout.GridLayout; | |
14 | |
15 import dwt.layout.GridData; | |
16 import dwt.DWT; | |
17 import dwt.graphics.Point; | |
18 import dwt.graphics.Rectangle; | |
19 import dwt.widgets.Control; | |
20 import dwt.widgets.Composite; | |
21 import dwt.widgets.Layout; | |
22 import dwt.widgets.Scrollable; | |
23 | |
24 import dwt.dwthelper.System; | |
25 | |
26 import tango.text.Util; | |
27 import tango.util.Convert; | |
28 import Math = tango.math.Math; | |
29 | |
30 | |
31 /** | |
32 * Instances of this class lay out the control children of a | |
33 * <code>Composite</code> in a grid. | |
34 * <p> | |
35 * <code>GridLayout</code> has a number of configuration fields, and the | |
36 * controls it lays out can have an associated layout data object, called | |
37 * <code>GridData</code>. The power of <code>GridLayout</code> lies in the | |
38 * ability to configure <code>GridData</code> for each control in the layout. | |
39 * </p> | |
40 * <p> | |
41 * The following code creates a shell managed by a <code>GridLayout</code> | |
42 * with 3 columns: | |
43 * <pre> | |
44 * Display display = new Display(); | |
45 * Shell shell = new Shell(display); | |
46 * GridLayout gridLayout = new GridLayout(); | |
47 * gridLayout.numColumns = 3; | |
48 * shell.setLayout(gridLayout); | |
49 * </pre> | |
50 * The <code>numColumns</code> field is the most important field in a | |
51 * <code>GridLayout</code>. Widgets are laid out in columns from left | |
52 * to right, and a new row is created when <code>numColumns</code> + 1 | |
53 * controls are added to the <code>Composite<code>. | |
54 * </p> | |
55 * | |
56 * @see GridData | |
57 */ | |
58 public final class GridLayout : Layout { | |
59 | |
60 /** | |
61 * numColumns specifies the number of cell columns in the layout. | |
62 * If numColumns has a value less than 1, the layout will not | |
63 * set the size and position of any controls. | |
64 * | |
65 * The default value is 1. | |
66 */ | |
67 public int numColumns = 1; | |
68 | |
69 /** | |
70 * makeColumnsEqualWidth specifies whether all columns in the layout | |
71 * will be forced to have the same width. | |
72 * | |
73 * The default value is false. | |
74 */ | |
75 public bool makeColumnsEqualWidth = false; | |
76 | |
77 /** | |
78 * marginWidth specifies the number of pixels of horizontal margin | |
79 * that will be placed along the left and right edges of the layout. | |
80 * | |
81 * The default value is 5. | |
82 */ | |
83 public int marginWidth = 5; | |
84 | |
85 /** | |
86 * marginHeight specifies the number of pixels of vertical margin | |
87 * that will be placed along the top and bottom edges of the layout. | |
88 * | |
89 * The default value is 5. | |
90 */ | |
91 public int marginHeight = 5; | |
92 | |
93 /** | |
94 * marginLeft specifies the number of pixels of horizontal margin | |
95 * that will be placed along the left edge of the layout. | |
96 * | |
97 * The default value is 0. | |
98 * | |
99 * @since 3.1 | |
100 */ | |
101 public int marginLeft = 0; | |
102 | |
103 /** | |
104 * marginTop specifies the number of pixels of vertical margin | |
105 * that will be placed along the top edge of the layout. | |
106 * | |
107 * The default value is 0. | |
108 * | |
109 * @since 3.1 | |
110 */ | |
111 public int marginTop = 0; | |
112 | |
113 /** | |
114 * marginRight specifies the number of pixels of horizontal margin | |
115 * that will be placed along the right edge of the layout. | |
116 * | |
117 * The default value is 0. | |
118 * | |
119 * @since 3.1 | |
120 */ | |
121 public int marginRight = 0; | |
122 | |
123 /** | |
124 * marginBottom specifies the number of pixels of vertical margin | |
125 * that will be placed along the bottom edge of the layout. | |
126 * | |
127 * The default value is 0. | |
128 * | |
129 * @since 3.1 | |
130 */ | |
131 public int marginBottom = 0; | |
132 | |
133 /** | |
134 * horizontalSpacing specifies the number of pixels between the right | |
135 * edge of one cell and the left edge of its neighbouring cell to | |
136 * the right. | |
137 * | |
138 * The default value is 5. | |
139 */ | |
140 public int horizontalSpacing = 5; | |
141 | |
142 /** | |
143 * verticalSpacing specifies the number of pixels between the bottom | |
144 * edge of one cell and the top edge of its neighbouring cell underneath. | |
145 * | |
146 * The default value is 5. | |
147 */ | |
148 public int verticalSpacing = 5; | |
149 | |
150 /** | |
151 * Constructs a new instance of this class. | |
152 */ | |
153 public this () {} | |
154 | |
155 /** | |
156 * Constructs a new instance of this class given the | |
157 * number of columns, and whether or not the columns | |
158 * should be forced to have the same width. | |
159 * If numColumns has a value less than 1, the layout will not | |
160 * set the size and position of any controls. | |
161 * | |
162 * @param numColumns the number of columns in the grid | |
163 * @param makeColumnsEqualWidth whether or not the columns will have equal width | |
164 * | |
165 * @since 2.0 | |
166 */ | |
167 public this (int numColumns, bool makeColumnsEqualWidth) { | |
168 this.numColumns = numColumns; | |
169 this.makeColumnsEqualWidth = makeColumnsEqualWidth; | |
170 } | |
171 | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
172 override protected Point computeSize (Composite composite, int wHint, int hHint, bool flushCache_) { |
0 | 173 Point size = layout (composite, false, 0, 0, wHint, hHint, flushCache_); |
174 if (wHint !is DWT.DEFAULT) size.x = wHint; | |
175 if (hHint !is DWT.DEFAULT) size.y = hHint; | |
176 return size; | |
177 } | |
178 | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
179 override protected bool flushCache (Control control) { |
0 | 180 Object data = control.getLayoutData (); |
181 if (data !is null) (cast(GridData) data).flushCache (); | |
182 return true; | |
183 } | |
184 | |
185 GridData getData (Control [][] grid, int row, int column, int rowCount, int columnCount, bool first) { | |
186 Control control = grid [row] [column]; | |
187 if (control !is null) { | |
188 GridData data = cast(GridData) control.getLayoutData (); | |
189 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); | |
190 int vSpan = Math.max (1, data.verticalSpan); | |
191 int i = first ? row + vSpan - 1 : row - vSpan + 1; | |
192 int j = first ? column + hSpan - 1 : column - hSpan + 1; | |
193 if (0 <= i && i < rowCount) { | |
194 if (0 <= j && j < columnCount) { | |
195 if (control is grid [i][j]) return data; | |
196 } | |
197 } | |
198 } | |
199 return null; | |
200 } | |
201 | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
202 override protected void layout (Composite composite, bool flushCache_) { |
0 | 203 Rectangle rect = composite.getClientArea (); |
204 layout (composite, true, rect.x, rect.y, rect.width, rect.height, flushCache_); | |
205 } | |
206 | |
207 Point layout (Composite composite, bool move, int x, int y, int width, int height, bool flushCache_) { | |
208 if (numColumns < 1) { | |
209 return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); | |
210 } | |
211 Control [] children = composite.getChildren (); | |
212 int count = 0; | |
213 for (int i=0; i<children.length; i++) { | |
214 Control control = children [i]; | |
215 GridData data = cast(GridData) control.getLayoutData (); | |
216 if (data is null || !data.exclude) { | |
217 children [count++] = children [i]; | |
218 } | |
219 } | |
220 if (count is 0) { | |
221 return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom); | |
222 } | |
223 for (int i=0; i<count; i++) { | |
224 Control child = children [i]; | |
225 GridData data = cast(GridData) child.getLayoutData (); | |
226 if (data is null) child.setLayoutData (data = new GridData ()); | |
227 if (flushCache_) data.flushCache (); | |
228 data.computeSize (child, data.widthHint, data.heightHint, flushCache_); | |
229 if (data.grabExcessHorizontalSpace && data.minimumWidth > 0) { | |
230 if (data.cacheWidth < data.minimumWidth) { | |
231 int trim = 0; | |
232 //TEMPORARY CODE | |
233 if ( auto sa = cast(Scrollable)child ) { | |
234 Rectangle rect = sa.computeTrim (0, 0, 0, 0); | |
235 trim = rect.width; | |
236 } else { | |
237 trim = child.getBorderWidth () * 2; | |
238 } | |
239 data.cacheWidth = data.cacheHeight = DWT.DEFAULT; | |
240 data.computeSize (child, Math.max (0, data.minimumWidth - trim), data.heightHint, false); | |
241 } | |
242 } | |
243 if (data.grabExcessVerticalSpace && data.minimumHeight > 0) { | |
244 data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight); | |
245 } | |
246 } | |
247 | |
248 /* Build the grid */ | |
249 int row = 0, column = 0, rowCount = 0, columnCount = numColumns; | |
250 Control [][] grid = new Control [][]( 4, columnCount ); | |
251 for (int i=0; i<count; i++) { | |
252 Control child = children [i]; | |
253 GridData data = cast(GridData) child.getLayoutData (); | |
254 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); | |
255 int vSpan = Math.max (1, data.verticalSpan); | |
256 while (true) { | |
257 int lastRow = row + vSpan; | |
258 if (lastRow >= grid.length) { | |
259 Control [][] newGrid = new Control[][]( lastRow + 4, columnCount ); | |
260 SimpleType!(Control[]).arraycopy (grid, 0, newGrid, 0, grid.length); | |
261 grid = newGrid; | |
262 } | |
263 if (grid [row] is null) { | |
264 grid [row] = new Control [columnCount]; | |
265 } | |
266 while (column < columnCount && grid [row] [column] !is null) { | |
267 column++; | |
268 } | |
269 int endCount = column + hSpan; | |
270 if (endCount <= columnCount) { | |
271 int index = column; | |
272 while (index < endCount && grid [row] [index] is null) { | |
273 index++; | |
274 } | |
275 if (index is endCount) break; | |
276 column = index; | |
277 } | |
278 if (column + hSpan >= columnCount) { | |
279 column = 0; | |
280 row++; | |
281 } | |
282 } | |
283 for (int j=0; j<vSpan; j++) { | |
284 if (grid [row + j] is null) { | |
285 grid [row + j] = new Control [columnCount]; | |
286 } | |
287 for (int k=0; k<hSpan; k++) { | |
288 grid [row + j] [column + k] = child; | |
289 } | |
290 } | |
291 rowCount = Math.max (rowCount, row + vSpan); | |
292 column += hSpan; | |
293 } | |
294 | |
295 /* Column widths */ | |
296 int availableWidth = width - horizontalSpacing * (columnCount - 1) - (marginLeft + marginWidth * 2 + marginRight); | |
297 int expandCount = 0; | |
298 int [] widths = new int [columnCount]; | |
299 int [] minWidths = new int [columnCount]; | |
300 bool [] expandColumn = new bool [columnCount]; | |
301 for (int j=0; j<columnCount; j++) { | |
302 for (int i=0; i<rowCount; i++) { | |
303 GridData data = getData (grid, i, j, rowCount, columnCount, true); | |
304 if (data !is null) { | |
305 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); | |
306 if (hSpan is 1) { | |
307 int w = data.cacheWidth + data.horizontalIndent; | |
308 widths [j] = Math.max (widths [j], w); | |
309 if (data.grabExcessHorizontalSpace) { | |
310 if (!expandColumn [j]) expandCount++; | |
311 expandColumn [j] = true; | |
312 } | |
313 if (!data.grabExcessHorizontalSpace || data.minimumWidth !is 0) { | |
314 w = !data.grabExcessHorizontalSpace || data.minimumWidth is DWT.DEFAULT ? data.cacheWidth : data.minimumWidth; | |
315 w += data.horizontalIndent; | |
316 minWidths [j] = Math.max (minWidths [j], w); | |
317 } | |
318 } | |
319 } | |
320 } | |
321 for (int i=0; i<rowCount; i++) { | |
322 GridData data = getData (grid, i, j, rowCount, columnCount, false); | |
323 if (data !is null) { | |
324 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); | |
325 if (hSpan > 1) { | |
326 int spanWidth = 0, spanMinWidth = 0, spanExpandCount = 0; | |
327 for (int k=0; k<hSpan; k++) { | |
328 spanWidth += widths [j-k]; | |
329 spanMinWidth += minWidths [j-k]; | |
330 if (expandColumn [j-k]) spanExpandCount++; | |
331 } | |
332 if (data.grabExcessHorizontalSpace && spanExpandCount is 0) { | |
333 expandCount++; | |
334 expandColumn [j] = true; | |
335 } | |
336 int w = data.cacheWidth + data.horizontalIndent - spanWidth - (hSpan - 1) * horizontalSpacing; | |
337 if (w > 0) { | |
338 if (makeColumnsEqualWidth) { | |
339 int equalWidth = (w + spanWidth) / hSpan; | |
340 int remainder = (w + spanWidth) % hSpan, last = -1; | |
341 for (int k = 0; k < hSpan; k++) { | |
342 widths [last=j-k] = Math.max (equalWidth, widths [j-k]); | |
343 } | |
344 if (last > -1) widths [last] += remainder; | |
345 } else { | |
346 if (spanExpandCount is 0) { | |
347 widths [j] += w; | |
348 } else { | |
349 int delta = w / spanExpandCount; | |
350 int remainder = w % spanExpandCount, last = -1; | |
351 for (int k = 0; k < hSpan; k++) { | |
352 if (expandColumn [j-k]) { | |
353 widths [last=j-k] += delta; | |
354 } | |
355 } | |
356 if (last > -1) widths [last] += remainder; | |
357 } | |
358 } | |
359 } | |
360 if (!data.grabExcessHorizontalSpace || data.minimumWidth !is 0) { | |
361 w = !data.grabExcessHorizontalSpace || data.minimumWidth is DWT.DEFAULT ? data.cacheWidth : data.minimumWidth; | |
362 w += data.horizontalIndent - spanMinWidth - (hSpan - 1) * horizontalSpacing; | |
363 if (w > 0) { | |
364 if (spanExpandCount is 0) { | |
365 minWidths [j] += w; | |
366 } else { | |
367 int delta = w / spanExpandCount; | |
368 int remainder = w % spanExpandCount, last = -1; | |
369 for (int k = 0; k < hSpan; k++) { | |
370 if (expandColumn [j-k]) { | |
371 minWidths [last=j-k] += delta; | |
372 } | |
373 } | |
374 if (last > -1) minWidths [last] += remainder; | |
375 } | |
376 } | |
377 } | |
378 } | |
379 } | |
380 } | |
381 } | |
382 if (makeColumnsEqualWidth) { | |
383 int minColumnWidth = 0; | |
384 int columnWidth = 0; | |
385 for (int i=0; i<columnCount; i++) { | |
386 minColumnWidth = Math.max (minColumnWidth, minWidths [i]); | |
387 columnWidth = Math.max (columnWidth, widths [i]); | |
388 } | |
389 columnWidth = width is DWT.DEFAULT || expandCount is 0 ? columnWidth : Math.max (minColumnWidth, availableWidth / columnCount); | |
390 for (int i=0; i<columnCount; i++) { | |
391 expandColumn [i] = expandCount > 0; | |
392 widths [i] = columnWidth; | |
393 } | |
394 } else { | |
395 if (width !is DWT.DEFAULT && expandCount > 0) { | |
396 int totalWidth = 0; | |
397 for (int i=0; i<columnCount; i++) { | |
398 totalWidth += widths [i]; | |
399 } | |
400 int c = expandCount; | |
401 int delta = (availableWidth - totalWidth) / c; | |
402 int remainder = (availableWidth - totalWidth) % c; | |
403 int last = -1; | |
404 while (totalWidth !is availableWidth) { | |
405 for (int j=0; j<columnCount; j++) { | |
406 if (expandColumn [j]) { | |
407 if (widths [j] + delta > minWidths [j]) { | |
408 widths [last = j] = widths [j] + delta; | |
409 } else { | |
410 widths [j] = minWidths [j]; | |
411 expandColumn [j] = false; | |
412 c--; | |
413 } | |
414 } | |
415 } | |
416 if (last > -1) widths [last] += remainder; | |
417 | |
418 for (int j=0; j<columnCount; j++) { | |
419 for (int i=0; i<rowCount; i++) { | |
420 GridData data = getData (grid, i, j, rowCount, columnCount, false); | |
421 if (data !is null) { | |
422 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); | |
423 if (hSpan > 1) { | |
424 if (!data.grabExcessHorizontalSpace || data.minimumWidth !is 0) { | |
425 int spanWidth = 0, spanExpandCount = 0; | |
426 for (int k=0; k<hSpan; k++) { | |
427 spanWidth += widths [j-k]; | |
428 if (expandColumn [j-k]) spanExpandCount++; | |
429 } | |
430 int w = !data.grabExcessHorizontalSpace || data.minimumWidth is DWT.DEFAULT ? data.cacheWidth : data.minimumWidth; | |
431 w += data.horizontalIndent - spanWidth - (hSpan - 1) * horizontalSpacing; | |
432 if (w > 0) { | |
433 if (spanExpandCount is 0) { | |
434 widths [j] += w; | |
435 } else { | |
436 int delta2 = w / spanExpandCount; | |
437 int remainder2 = w % spanExpandCount, last2 = -1; | |
438 for (int k = 0; k < hSpan; k++) { | |
439 if (expandColumn [j-k]) { | |
440 widths [last2=j-k] += delta2; | |
441 } | |
442 } | |
443 if (last2 > -1) widths [last2] += remainder2; | |
444 } | |
445 } | |
446 } | |
447 } | |
448 } | |
449 } | |
450 } | |
451 if (c is 0) break; | |
452 totalWidth = 0; | |
453 for (int i=0; i<columnCount; i++) { | |
454 totalWidth += widths [i]; | |
455 } | |
456 delta = (availableWidth - totalWidth) / c; | |
457 remainder = (availableWidth - totalWidth) % c; | |
458 last = -1; | |
459 } | |
460 } | |
461 } | |
462 | |
463 /* Wrapping */ | |
464 GridData [] flush = null; | |
465 int flushLength = 0; | |
466 if (width !is DWT.DEFAULT) { | |
467 for (int j=0; j<columnCount; j++) { | |
468 for (int i=0; i<rowCount; i++) { | |
469 GridData data = getData (grid, i, j, rowCount, columnCount, false); | |
470 if (data !is null) { | |
471 if (data.heightHint is DWT.DEFAULT) { | |
472 Control child = grid [i][j]; | |
473 //TEMPORARY CODE | |
474 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); | |
475 int currentWidth = 0; | |
476 for (int k=0; k<hSpan; k++) { | |
477 currentWidth += widths [j-k]; | |
478 } | |
479 currentWidth += (hSpan - 1) * horizontalSpacing - data.horizontalIndent; | |
480 if ((currentWidth !is data.cacheWidth && data.horizontalAlignment is DWT.FILL) || (data.cacheWidth > currentWidth)) { | |
481 int trim = 0; | |
482 if ( auto sa = cast(Scrollable)child ) { | |
483 Rectangle rect = sa.computeTrim (0, 0, 0, 0); | |
484 trim = rect.width; | |
485 } else { | |
486 trim = child.getBorderWidth () * 2; | |
487 } | |
488 data.cacheWidth = data.cacheHeight = DWT.DEFAULT; | |
489 data.computeSize (child, Math.max (0, currentWidth - trim), data.heightHint, false); | |
490 if (data.grabExcessVerticalSpace && data.minimumHeight > 0) { | |
491 data.cacheHeight = Math.max (data.cacheHeight, data.minimumHeight); | |
492 } | |
493 if (flush is null) flush = new GridData [count]; | |
494 flush [flushLength++] = data; | |
495 } | |
496 } | |
497 } | |
498 } | |
499 } | |
500 } | |
501 | |
502 /* Row heights */ | |
503 int availableHeight = height - verticalSpacing * (rowCount - 1) - (marginTop + marginHeight * 2 + marginBottom); | |
504 expandCount = 0; | |
505 int [] heights = new int [rowCount]; | |
506 int [] minHeights = new int [rowCount]; | |
507 bool [] expandRow = new bool [rowCount]; | |
508 for (int i=0; i<rowCount; i++) { | |
509 for (int j=0; j<columnCount; j++) { | |
510 GridData data = getData (grid, i, j, rowCount, columnCount, true); | |
511 if (data !is null) { | |
512 int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount)); | |
513 if (vSpan is 1) { | |
514 int h = data.cacheHeight + data.verticalIndent; | |
515 heights [i] = Math.max (heights [i], h); | |
516 if (data.grabExcessVerticalSpace) { | |
517 if (!expandRow [i]) expandCount++; | |
518 expandRow [i] = true; | |
519 } | |
520 if (!data.grabExcessVerticalSpace || data.minimumHeight !is 0) { | |
521 h = !data.grabExcessVerticalSpace || data.minimumHeight is DWT.DEFAULT ? data.cacheHeight : data.minimumHeight; | |
522 h += data.verticalIndent; | |
523 minHeights [i] = Math.max (minHeights [i], h); | |
524 } | |
525 } | |
526 } | |
527 } | |
528 for (int j=0; j<columnCount; j++) { | |
529 GridData data = getData (grid, i, j, rowCount, columnCount, false); | |
530 if (data !is null) { | |
531 int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount)); | |
532 if (vSpan > 1) { | |
533 int spanHeight = 0, spanMinHeight = 0, spanExpandCount = 0; | |
534 for (int k=0; k<vSpan; k++) { | |
535 spanHeight += heights [i-k]; | |
536 spanMinHeight += minHeights [i-k]; | |
537 if (expandRow [i-k]) spanExpandCount++; | |
538 } | |
539 if (data.grabExcessVerticalSpace && spanExpandCount is 0) { | |
540 expandCount++; | |
541 expandRow [i] = true; | |
542 } | |
543 int h = data.cacheHeight + data.verticalIndent - spanHeight - (vSpan - 1) * verticalSpacing; | |
544 if (h > 0) { | |
545 if (spanExpandCount is 0) { | |
546 heights [i] += h; | |
547 } else { | |
548 int delta = h / spanExpandCount; | |
549 int remainder = h % spanExpandCount, last = -1; | |
550 for (int k = 0; k < vSpan; k++) { | |
551 if (expandRow [i-k]) { | |
552 heights [last=i-k] += delta; | |
553 } | |
554 } | |
555 if (last > -1) heights [last] += remainder; | |
556 } | |
557 } | |
558 if (!data.grabExcessVerticalSpace || data.minimumHeight !is 0) { | |
559 h = !data.grabExcessVerticalSpace || data.minimumHeight is DWT.DEFAULT ? data.cacheHeight : data.minimumHeight; | |
560 h += data.verticalIndent - spanMinHeight - (vSpan - 1) * verticalSpacing; | |
561 if (h > 0) { | |
562 if (spanExpandCount is 0) { | |
563 minHeights [i] += h; | |
564 } else { | |
565 int delta = h / spanExpandCount; | |
566 int remainder = h % spanExpandCount, last = -1; | |
567 for (int k = 0; k < vSpan; k++) { | |
568 if (expandRow [i-k]) { | |
569 minHeights [last=i-k] += delta; | |
570 } | |
571 } | |
572 if (last > -1) minHeights [last] += remainder; | |
573 } | |
574 } | |
575 } | |
576 } | |
577 } | |
578 } | |
579 } | |
580 if (height !is DWT.DEFAULT && expandCount > 0) { | |
581 int totalHeight = 0; | |
582 for (int i=0; i<rowCount; i++) { | |
583 totalHeight += heights [i]; | |
584 } | |
585 int c = expandCount; | |
586 int delta = (availableHeight - totalHeight) / c; | |
587 int remainder = (availableHeight - totalHeight) % c; | |
588 int last = -1; | |
589 while (totalHeight !is availableHeight) { | |
590 for (int i=0; i<rowCount; i++) { | |
591 if (expandRow [i]) { | |
592 if (heights [i] + delta > minHeights [i]) { | |
593 heights [last = i] = heights [i] + delta; | |
594 } else { | |
595 heights [i] = minHeights [i]; | |
596 expandRow [i] = false; | |
597 c--; | |
598 } | |
599 } | |
600 } | |
601 if (last > -1) heights [last] += remainder; | |
602 | |
603 for (int i=0; i<rowCount; i++) { | |
604 for (int j=0; j<columnCount; j++) { | |
605 GridData data = getData (grid, i, j, rowCount, columnCount, false); | |
606 if (data !is null) { | |
607 int vSpan = Math.max (1, Math.min (data.verticalSpan, rowCount)); | |
608 if (vSpan > 1) { | |
609 if (!data.grabExcessVerticalSpace || data.minimumHeight !is 0) { | |
610 int spanHeight = 0, spanExpandCount = 0; | |
611 for (int k=0; k<vSpan; k++) { | |
612 spanHeight += heights [i-k]; | |
613 if (expandRow [i-k]) spanExpandCount++; | |
614 } | |
615 int h = !data.grabExcessVerticalSpace || data.minimumHeight is DWT.DEFAULT ? data.cacheHeight : data.minimumHeight; | |
616 h += data.verticalIndent - spanHeight - (vSpan - 1) * verticalSpacing; | |
617 if (h > 0) { | |
618 if (spanExpandCount is 0) { | |
619 heights [i] += h; | |
620 } else { | |
621 int delta2 = h / spanExpandCount; | |
622 int remainder2 = h % spanExpandCount, last2 = -1; | |
623 for (int k = 0; k < vSpan; k++) { | |
624 if (expandRow [i-k]) { | |
625 heights [last2=i-k] += delta2; | |
626 } | |
627 } | |
628 if (last2 > -1) heights [last2] += remainder2; | |
629 } | |
630 } | |
631 } | |
632 } | |
633 } | |
634 } | |
635 } | |
636 if (c is 0) break; | |
637 totalHeight = 0; | |
638 for (int i=0; i<rowCount; i++) { | |
639 totalHeight += heights [i]; | |
640 } | |
641 delta = (availableHeight - totalHeight) / c; | |
642 remainder = (availableHeight - totalHeight) % c; | |
643 last = -1; | |
644 } | |
645 } | |
646 | |
647 /* Position the controls */ | |
648 if (move) { | |
649 int gridY = y + marginTop + marginHeight; | |
650 for (int i=0; i<rowCount; i++) { | |
651 int gridX = x + marginLeft + marginWidth; | |
652 for (int j=0; j<columnCount; j++) { | |
653 GridData data = getData (grid, i, j, rowCount, columnCount, true); | |
654 if (data !is null) { | |
655 int hSpan = Math.max (1, Math.min (data.horizontalSpan, columnCount)); | |
656 int vSpan = Math.max (1, data.verticalSpan); | |
657 int cellWidth = 0, cellHeight = 0; | |
658 for (int k=0; k<hSpan; k++) { | |
659 cellWidth += widths [j+k]; | |
660 } | |
661 for (int k=0; k<vSpan; k++) { | |
662 cellHeight += heights [i+k]; | |
663 } | |
664 cellWidth += horizontalSpacing * (hSpan - 1); | |
665 int childX = gridX + data.horizontalIndent; | |
666 int childWidth = Math.min (data.cacheWidth, cellWidth); | |
667 switch (data.horizontalAlignment) { | |
668 case DWT.CENTER: | |
669 case GridData.CENTER: | |
670 childX += Math.max (0, (cellWidth - data.horizontalIndent - childWidth) / 2); | |
671 break; | |
672 case DWT.RIGHT: | |
673 case DWT.END: | |
674 case GridData.END: | |
675 childX += Math.max (0, cellWidth - data.horizontalIndent - childWidth); | |
676 break; | |
677 case DWT.FILL: | |
678 childWidth = cellWidth - data.horizontalIndent; | |
679 break; | |
680 default: | |
681 } | |
682 cellHeight += verticalSpacing * (vSpan - 1); | |
683 int childY = gridY + data.verticalIndent; | |
684 int childHeight = Math.min (data.cacheHeight, cellHeight); | |
685 switch (data.verticalAlignment) { | |
686 case DWT.CENTER: | |
687 case GridData.CENTER: | |
688 childY += Math.max (0, (cellHeight - data.verticalIndent - childHeight) / 2); | |
689 break; | |
690 case DWT.BOTTOM: | |
691 case DWT.END: | |
692 case GridData.END: | |
693 childY += Math.max (0, cellHeight - data.verticalIndent - childHeight); | |
694 break; | |
695 case DWT.FILL: | |
696 childHeight = cellHeight - data.verticalIndent; | |
697 break; | |
698 default: | |
699 } | |
700 Control child = grid [i][j]; | |
701 if (child !is null) { | |
702 child.setBounds (childX, childY, childWidth, childHeight); | |
703 } | |
704 } | |
705 gridX += widths [j] + horizontalSpacing; | |
706 } | |
707 gridY += heights [i] + verticalSpacing; | |
708 } | |
709 } | |
710 | |
711 // clean up cache | |
712 for (int i = 0; i < flushLength; i++) { | |
713 flush [i].cacheWidth = flush [i].cacheHeight = -1; | |
714 } | |
715 | |
716 int totalDefaultWidth = 0; | |
717 int totalDefaultHeight = 0; | |
718 for (int i=0; i<columnCount; i++) { | |
719 totalDefaultWidth += widths [i]; | |
720 } | |
721 for (int i=0; i<rowCount; i++) { | |
722 totalDefaultHeight += heights [i]; | |
723 } | |
724 totalDefaultWidth += horizontalSpacing * (columnCount - 1) + marginLeft + marginWidth * 2 + marginRight; | |
725 totalDefaultHeight += verticalSpacing * (rowCount - 1) + marginTop + marginHeight * 2 + marginBottom; | |
726 return new Point (totalDefaultWidth, totalDefaultHeight); | |
727 } | |
728 | |
729 char[] getName () { | |
730 char[] string = this.classinfo.name; | |
731 int index = locatePrior( string, '.'); | |
732 if (index is string.length ) return string; | |
733 return string[ index + 1 .. string.length ]; | |
734 } | |
735 | |
736 /** | |
737 * Returns a string containing a concise, human-readable | |
738 * description of the receiver. | |
739 * | |
740 * @return a string representation of the layout | |
741 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
0
diff
changeset
|
742 override public char[] toString () { |
0 | 743 char[] string = getName ()~" {"; |
744 if (numColumns !is 1) string ~= "numColumns="~to!(char[])(numColumns)~" "; | |
745 if (makeColumnsEqualWidth) string ~= "makeColumnsEqualWidth="~to!(char[])(makeColumnsEqualWidth)~" "; | |
746 if (marginWidth !is 0) string ~= "marginWidth="~to!(char[])(marginWidth)~" "; | |
747 if (marginHeight !is 0) string ~= "marginHeight="~to!(char[])(marginHeight)~" "; | |
748 if (marginLeft !is 0) string ~= "marginLeft="~to!(char[])(marginLeft)~" "; | |
749 if (marginRight !is 0) string ~= "marginRight="~to!(char[])(marginRight)~" "; | |
750 if (marginTop !is 0) string ~= "marginTop="~to!(char[])(marginTop)~" "; | |
751 if (marginBottom !is 0) string ~= "marginBottom="~to!(char[])(marginBottom)~" "; | |
752 if (horizontalSpacing !is 0) string ~= "horizontalSpacing="~to!(char[])(horizontalSpacing)~" "; | |
753 if (verticalSpacing !is 0) string ~= "verticalSpacing="~to!(char[])(verticalSpacing)~" "; | |
754 string = string.trim(); | |
755 string ~= "}"; | |
756 return string; | |
757 } | |
758 } |