25
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2008 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 org.eclipse.swt.layout.GridData;
|
|
14
|
|
15 import org.eclipse.swt.SWT;
|
|
16 import org.eclipse.swt.graphics.Point;
|
|
17 import org.eclipse.swt.widgets.Control;
|
|
18
|
48
|
19 import java.lang.all;
|
|
20 version(Tango){
|
51
|
21 import tango.util.Convert;
|
48
|
22 } else { // Phobos
|
51
|
23 import std.conv;
|
48
|
24 }
|
25
|
25
|
|
26 /**
|
|
27 * <code>GridData</code> is the layout data object associated with
|
|
28 * <code>GridLayout</code>. To set a <code>GridData</code> object into a
|
|
29 * control, you use the <code>Control.setLayoutData(Object)</code> method.
|
|
30 * <p>
|
|
31 * There are two ways to create a <code>GridData</code> object with certain
|
|
32 * fields set. The first is to set the fields directly, like this:
|
|
33 * <pre>
|
|
34 * GridData gridData = new GridData();
|
|
35 * gridData.horizontalAlignment = GridData.FILL;
|
|
36 * gridData.grabExcessHorizontalSpace = true;
|
|
37 * button1.setLayoutData(gridData);
|
|
38 * </pre>
|
|
39 * The second is to take advantage of convenience style bits defined
|
|
40 * by <code>GridData</code>:
|
|
41 * <pre>
|
|
42 * button1.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL));
|
|
43 * </pre>
|
|
44 * </p>
|
|
45 * <p>
|
|
46 * NOTE: Do not reuse <code>GridData</code> objects. Every control in a
|
|
47 * <code>Composite</code> that is managed by a <code>GridLayout</code>
|
|
48 * must have a unique <code>GridData</code> object. If the layout data
|
|
49 * for a control in a <code>GridLayout</code> is null at layout time,
|
|
50 * a unique <code>GridData</code> object is created for it.
|
|
51 * </p>
|
|
52 *
|
|
53 * @see GridLayout
|
|
54 * @see Control#setLayoutData
|
|
55 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
|
|
56 */
|
|
57 public final class GridData {
|
|
58 /**
|
|
59 * verticalAlignment specifies how controls will be positioned
|
|
60 * vertically within a cell.
|
|
61 *
|
|
62 * The default value is CENTER.
|
|
63 *
|
|
64 * Possible values are: <ul>
|
|
65 * <li>SWT.BEGINNING (or SWT.TOP): Position the control at the top of the cell</li>
|
|
66 * <li>SWT.CENTER: Position the control in the vertical center of the cell</li>
|
|
67 * <li>SWT.END (or SWT.BOTTOM): Position the control at the bottom of the cell</li>
|
|
68 * <li>SWT.FILL: Resize the control to fill the cell vertically</li>
|
|
69 * </ul>
|
|
70 */
|
|
71 public int verticalAlignment = CENTER;
|
|
72
|
|
73 /**
|
|
74 * horizontalAlignment specifies how controls will be positioned
|
|
75 * horizontally within a cell.
|
|
76 *
|
|
77 * The default value is BEGINNING.
|
|
78 *
|
|
79 * Possible values are: <ul>
|
|
80 * <li>SWT.BEGINNING (or SWT.LEFT): Position the control at the left of the cell</li>
|
|
81 * <li>SWT.CENTER: Position the control in the horizontal center of the cell</li>
|
|
82 * <li>SWT.END (or SWT.RIGHT): Position the control at the right of the cell</li>
|
|
83 * <li>SWT.FILL: Resize the control to fill the cell horizontally</li>
|
|
84 * </ul>
|
|
85 */
|
|
86 public int horizontalAlignment = BEGINNING;
|
|
87
|
|
88 /**
|
|
89 * widthHint specifies the preferred width in pixels. This value
|
|
90 * is the wHint passed into Control.computeSize(int, int, bool)
|
|
91 * to determine the preferred size of the control.
|
|
92 *
|
|
93 * The default value is SWT.DEFAULT.
|
|
94 *
|
|
95 * @see Control#computeSize(int, int, bool)
|
|
96 */
|
|
97 public int widthHint = SWT.DEFAULT;
|
|
98
|
|
99 /**
|
|
100 * heightHint specifies the preferred height in pixels. This value
|
|
101 * is the hHint passed into Control.computeSize(int, int, bool)
|
|
102 * to determine the preferred size of the control.
|
|
103 *
|
|
104 * The default value is SWT.DEFAULT.
|
|
105 *
|
|
106 * @see Control#computeSize(int, int, bool)
|
|
107 */
|
|
108 public int heightHint = SWT.DEFAULT;
|
|
109
|
|
110 /**
|
|
111 * horizontalIndent specifies the number of pixels of indentation
|
|
112 * that will be placed along the left side of the cell.
|
|
113 *
|
|
114 * The default value is 0.
|
|
115 */
|
|
116 public int horizontalIndent = 0;
|
|
117
|
|
118 /**
|
|
119 * verticalIndent specifies the number of pixels of indentation
|
|
120 * that will be placed along the top side of the cell.
|
|
121 *
|
|
122 * The default value is 0.
|
|
123 *
|
|
124 * @since 3.1
|
|
125 */
|
|
126 public int verticalIndent = 0;
|
|
127
|
|
128 /**
|
|
129 * horizontalSpan specifies the number of column cells that the control
|
|
130 * will take up.
|
|
131 *
|
|
132 * The default value is 1.
|
|
133 */
|
|
134 public int horizontalSpan = 1;
|
|
135
|
|
136 /**
|
|
137 * verticalSpan specifies the number of row cells that the control
|
|
138 * will take up.
|
|
139 *
|
|
140 * The default value is 1.
|
|
141 */
|
|
142 public int verticalSpan = 1;
|
|
143
|
|
144 /**
|
|
145 * <p>grabExcessHorizontalSpace specifies whether the width of the cell
|
|
146 * changes depending on the size of the parent Composite. If
|
|
147 * grabExcessHorizontalSpace is <code>true</code>, the following rules
|
|
148 * apply to the width of the cell:</p>
|
|
149 * <ul>
|
|
150 * <li>If extra horizontal space is available in the parent, the cell will
|
|
151 * grow to be wider than its preferred width. The new width
|
|
152 * will be "preferred width + delta" where delta is the extra
|
|
153 * horizontal space divided by the number of grabbing columns.</li>
|
|
154 * <li>If there is not enough horizontal space available in the parent, the
|
|
155 * cell will shrink until it reaches its minimum width as specified by
|
|
156 * GridData.minimumWidth. The new width will be the maximum of
|
|
157 * "minimumWidth" and "preferred width - delta", where delta is
|
|
158 * the amount of space missing divided by the number of grabbing columns.</li>
|
|
159 * <li>If the parent is packed, the cell will be its preferred width
|
|
160 * as specified by GridData.widthHint.</li>
|
|
161 * <li>If the control spans multiple columns and there are no other grabbing
|
|
162 * controls in any of the spanned columns, the last column in the span will
|
|
163 * grab the extra space. If there is at least one other grabbing control
|
|
164 * in the span, the grabbing will be spread over the columns already
|
|
165 * marked as grabExcessHorizontalSpace.</li>
|
|
166 * </ul>
|
|
167 *
|
|
168 * <p>The default value is false.</p>
|
|
169 *
|
|
170 * @see GridData#minimumWidth
|
|
171 * @see GridData#widthHint
|
|
172 */
|
|
173 public bool grabExcessHorizontalSpace = false;
|
|
174
|
|
175 /**
|
|
176 * <p>grabExcessVerticalSpace specifies whether the height of the cell
|
|
177 * changes depending on the size of the parent Composite. If
|
|
178 * grabExcessVerticalSpace is <code>true</code>, the following rules
|
|
179 * apply to the height of the cell:</p>
|
|
180 * <ul>
|
|
181 * <li>If extra vertical space is available in the parent, the cell will
|
|
182 * grow to be taller than its preferred height. The new height
|
|
183 * will be "preferred height + delta" where delta is the extra
|
|
184 * vertical space divided by the number of grabbing rows.</li>
|
|
185 * <li>If there is not enough vertical space available in the parent, the
|
|
186 * cell will shrink until it reaches its minimum height as specified by
|
|
187 * GridData.minimumHeight. The new height will be the maximum of
|
|
188 * "minimumHeight" and "preferred height - delta", where delta is
|
|
189 * the amount of space missing divided by the number of grabbing rows.</li>
|
|
190 * <li>If the parent is packed, the cell will be its preferred height
|
|
191 * as specified by GridData.heightHint.</li>
|
|
192 * <li>If the control spans multiple rows and there are no other grabbing
|
|
193 * controls in any of the spanned rows, the last row in the span will
|
|
194 * grab the extra space. If there is at least one other grabbing control
|
|
195 * in the span, the grabbing will be spread over the rows already
|
|
196 * marked as grabExcessVerticalSpace.</li>
|
|
197 * </ul>
|
|
198 *
|
|
199 * <p>The default value is false.</p>
|
|
200 *
|
|
201 * @see GridData#minimumHeight
|
|
202 * @see GridData#heightHint
|
|
203 */
|
|
204 public bool grabExcessVerticalSpace = false;
|
|
205
|
|
206 /**
|
|
207 * minimumWidth specifies the minimum width in pixels. This value
|
|
208 * applies only if grabExcessHorizontalSpace is true. A value of
|
|
209 * SWT.DEFAULT means that the minimum width will be the result
|
|
210 * of Control.computeSize(int, int, bool) where wHint is
|
|
211 * determined by GridData.widthHint.
|
|
212 *
|
|
213 * The default value is 0.
|
|
214 *
|
|
215 * @since 3.1
|
|
216 * @see Control#computeSize(int, int, bool)
|
|
217 * @see GridData#widthHint
|
|
218 */
|
|
219 public int minimumWidth = 0;
|
|
220
|
|
221 /**
|
|
222 * minimumHeight specifies the minimum height in pixels. This value
|
|
223 * applies only if grabExcessVerticalSpace is true. A value of
|
|
224 * SWT.DEFAULT means that the minimum height will be the result
|
|
225 * of Control.computeSize(int, int, bool) where hHint is
|
|
226 * determined by GridData.heightHint.
|
|
227 *
|
|
228 * The default value is 0.
|
|
229 *
|
|
230 * @since 3.1
|
|
231 * @see Control#computeSize(int, int, bool)
|
|
232 * @see GridData#heightHint
|
|
233 */
|
|
234 public int minimumHeight = 0;
|
|
235
|
|
236 /**
|
|
237 * exclude informs the layout to ignore this control when sizing
|
|
238 * and positioning controls. If this value is <code>true</code>,
|
|
239 * the size and position of the control will not be managed by the
|
|
240 * layout. If this value is <code>false</code>, the size and
|
|
241 * position of the control will be computed and assigned.
|
|
242 *
|
|
243 * The default value is <code>false</code>.
|
|
244 *
|
|
245 * @since 3.1
|
|
246 */
|
|
247 public bool exclude = false;
|
|
248
|
|
249 /**
|
|
250 * Value for horizontalAlignment or verticalAlignment.
|
|
251 * Position the control at the top or left of the cell.
|
|
252 * Not recommended. Use SWT.BEGINNING, SWT.TOP or SWT.LEFT instead.
|
|
253 */
|
|
254 public static const int BEGINNING = SWT.BEGINNING;
|
|
255
|
|
256 /**
|
|
257 * Value for horizontalAlignment or verticalAlignment.
|
|
258 * Position the control in the vertical or horizontal center of the cell
|
|
259 * Not recommended. Use SWT.CENTER instead.
|
|
260 */
|
|
261 public static const int CENTER = 2;
|
|
262
|
|
263 /**
|
|
264 * Value for horizontalAlignment or verticalAlignment.
|
|
265 * Position the control at the bottom or right of the cell
|
|
266 * Not recommended. Use SWT.END, SWT.BOTTOM or SWT.RIGHT instead.
|
|
267 */
|
|
268 public static const int END = 3;
|
|
269
|
|
270 /**
|
|
271 * Value for horizontalAlignment or verticalAlignment.
|
|
272 * Resize the control to fill the cell horizontally or vertically.
|
|
273 * Not recommended. Use SWT.FILL instead.
|
|
274 */
|
|
275 public static const int FILL = SWT.FILL;
|
|
276
|
|
277 /**
|
|
278 * Style bit for <code>new GridData(int)</code>.
|
|
279 * Position the control at the top of the cell.
|
|
280 * Not recommended. Use
|
|
281 * <code>new GridData(int, SWT.BEGINNING, bool, bool)</code>
|
|
282 * instead.
|
|
283 */
|
|
284 public static const int VERTICAL_ALIGN_BEGINNING = 1 << 1;
|
|
285
|
|
286 /**
|
|
287 * Style bit for <code>new GridData(int)</code> to position the
|
|
288 * control in the vertical center of the cell.
|
|
289 * Not recommended. Use
|
|
290 * <code>new GridData(int, SWT.CENTER, bool, bool)</code>
|
|
291 * instead.
|
|
292 */
|
|
293 public static const int VERTICAL_ALIGN_CENTER = 1 << 2;
|
|
294
|
|
295 /**
|
|
296 * Style bit for <code>new GridData(int)</code> to position the
|
|
297 * control at the bottom of the cell.
|
|
298 * Not recommended. Use
|
|
299 * <code>new GridData(int, SWT.END, bool, bool)</code>
|
|
300 * instead.
|
|
301 */
|
|
302 public static const int VERTICAL_ALIGN_END = 1 << 3;
|
|
303
|
|
304 /**
|
|
305 * Style bit for <code>new GridData(int)</code> to resize the
|
|
306 * control to fill the cell vertically.
|
|
307 * Not recommended. Use
|
|
308 * <code>new GridData(int, SWT.FILL, bool, bool)</code>
|
|
309 * instead
|
|
310 */
|
|
311 public static const int VERTICAL_ALIGN_FILL = 1 << 4;
|
|
312
|
|
313 /**
|
|
314 * Style bit for <code>new GridData(int)</code> to position the
|
|
315 * control at the left of the cell.
|
|
316 * Not recommended. Use
|
|
317 * <code>new GridData(SWT.BEGINNING, int, bool, bool)</code>
|
|
318 * instead.
|
|
319 */
|
|
320 public static const int HORIZONTAL_ALIGN_BEGINNING = 1 << 5;
|
|
321
|
|
322 /**
|
|
323 * Style bit for <code>new GridData(int)</code> to position the
|
|
324 * control in the horizontal center of the cell.
|
|
325 * Not recommended. Use
|
|
326 * <code>new GridData(SWT.CENTER, int, bool, bool)</code>
|
|
327 * instead.
|
|
328 */
|
|
329 public static const int HORIZONTAL_ALIGN_CENTER = 1 << 6;
|
|
330
|
|
331 /**
|
|
332 * Style bit for <code>new GridData(int)</code> to position the
|
|
333 * control at the right of the cell.
|
|
334 * Not recommended. Use
|
|
335 * <code>new GridData(SWT.END, int, bool, bool)</code>
|
|
336 * instead.
|
|
337 */
|
|
338 public static const int HORIZONTAL_ALIGN_END = 1 << 7;
|
|
339
|
|
340 /**
|
|
341 * Style bit for <code>new GridData(int)</code> to resize the
|
|
342 * control to fill the cell horizontally.
|
|
343 * Not recommended. Use
|
|
344 * <code>new GridData(SWT.FILL, int, bool, bool)</code>
|
|
345 * instead.
|
|
346 */
|
|
347 public static const int HORIZONTAL_ALIGN_FILL = 1 << 8;
|
|
348
|
|
349 /**
|
|
350 * Style bit for <code>new GridData(int)</code> to resize the
|
|
351 * control to fit the remaining horizontal space.
|
|
352 * Not recommended. Use
|
|
353 * <code>new GridData(int, int, true, bool)</code>
|
|
354 * instead.
|
|
355 */
|
|
356 public static const int GRAB_HORIZONTAL = 1 << 9;
|
|
357
|
|
358 /**
|
|
359 * Style bit for <code>new GridData(int)</code> to resize the
|
|
360 * control to fit the remaining vertical space.
|
|
361 * Not recommended. Use
|
|
362 * <code>new GridData(int, int, bool, true)</code>
|
|
363 * instead.
|
|
364 */
|
|
365 public static const int GRAB_VERTICAL = 1 << 10;
|
|
366
|
|
367 /**
|
|
368 * Style bit for <code>new GridData(int)</code> to resize the
|
|
369 * control to fill the cell vertically and to fit the remaining
|
|
370 * vertical space.
|
|
371 * FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL
|
|
372 * Not recommended. Use
|
|
373 * <code>new GridData(int, SWT.FILL, bool, true)</code>
|
|
374 * instead.
|
|
375 */
|
|
376 public static const int FILL_VERTICAL = VERTICAL_ALIGN_FILL | GRAB_VERTICAL;
|
|
377
|
|
378 /**
|
|
379 * Style bit for <code>new GridData(int)</code> to resize the
|
|
380 * control to fill the cell horizontally and to fit the remaining
|
|
381 * horizontal space.
|
|
382 * FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL
|
|
383 * Not recommended. Use
|
|
384 * <code>new GridData(SWT.FILL, int, true, bool)</code>
|
|
385 * instead.
|
|
386 */
|
|
387 public static const int FILL_HORIZONTAL = HORIZONTAL_ALIGN_FILL | GRAB_HORIZONTAL;
|
|
388
|
|
389 /**
|
|
390 * Style bit for <code>new GridData(int)</code> to resize the
|
|
391 * control to fill the cell horizontally and vertically and
|
|
392 * to fit the remaining horizontal and vertical space.
|
|
393 * FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL
|
|
394 * Not recommended. Use
|
|
395 * <code>new GridData(SWT.FILL, SWT.FILL, true, true)</code>
|
|
396 * instead.
|
|
397 */
|
|
398 public static const int FILL_BOTH = FILL_VERTICAL | FILL_HORIZONTAL;
|
|
399
|
|
400 int cacheWidth = -1, cacheHeight = -1;
|
|
401 int defaultWhint, defaultHhint, defaultWidth = -1, defaultHeight = -1;
|
|
402 int currentWhint, currentHhint, currentWidth = -1, currentHeight = -1;
|
|
403
|
|
404 /**
|
|
405 * Constructs a new instance of GridData using
|
|
406 * default values.
|
|
407 */
|
|
408 public this () {
|
|
409 }
|
|
410
|
|
411 /**
|
|
412 * Constructs a new instance based on the GridData style.
|
|
413 * This constructor is not recommended.
|
|
414 *
|
|
415 * @param style the GridData style
|
|
416 */
|
|
417 public this (int style) {
|
|
418 if ((style & VERTICAL_ALIGN_BEGINNING) !is 0) verticalAlignment = BEGINNING;
|
|
419 if ((style & VERTICAL_ALIGN_CENTER) !is 0) verticalAlignment = CENTER;
|
|
420 if ((style & VERTICAL_ALIGN_FILL) !is 0) verticalAlignment = FILL;
|
|
421 if ((style & VERTICAL_ALIGN_END) !is 0) verticalAlignment = END;
|
|
422 if ((style & HORIZONTAL_ALIGN_BEGINNING) !is 0) horizontalAlignment = BEGINNING;
|
|
423 if ((style & HORIZONTAL_ALIGN_CENTER) !is 0) horizontalAlignment = CENTER;
|
|
424 if ((style & HORIZONTAL_ALIGN_FILL) !is 0) horizontalAlignment = FILL;
|
|
425 if ((style & HORIZONTAL_ALIGN_END) !is 0) horizontalAlignment = END;
|
|
426 grabExcessHorizontalSpace = (style & GRAB_HORIZONTAL) !is 0;
|
|
427 grabExcessVerticalSpace = (style & GRAB_VERTICAL) !is 0;
|
|
428 }
|
|
429
|
|
430 /**
|
|
431 * Constructs a new instance of GridData according to the parameters.
|
|
432 *
|
|
433 * @param horizontalAlignment how control will be positioned horizontally within a cell,
|
|
434 * one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL
|
|
435 * @param verticalAlignment how control will be positioned vertically within a cell,
|
|
436 * one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL
|
|
437 * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space
|
|
438 * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space
|
|
439 *
|
|
440 * @since 3.0
|
|
441 */
|
|
442 public this (int horizontalAlignment, int verticalAlignment, bool grabExcessHorizontalSpace, bool grabExcessVerticalSpace) {
|
|
443 this (horizontalAlignment, verticalAlignment, grabExcessHorizontalSpace, grabExcessVerticalSpace, 1, 1);
|
|
444 }
|
|
445
|
|
446 /**
|
|
447 * Constructs a new instance of GridData according to the parameters.
|
|
448 *
|
|
449 * @param horizontalAlignment how control will be positioned horizontally within a cell,
|
|
450 * one of: SWT.BEGINNING (or SWT.LEFT), SWT.CENTER, SWT.END (or SWT.RIGHT), or SWT.FILL
|
|
451 * @param verticalAlignment how control will be positioned vertically within a cell,
|
|
452 * one of: SWT.BEGINNING (or SWT.TOP), SWT.CENTER, SWT.END (or SWT.BOTTOM), or SWT.FILL
|
|
453 * @param grabExcessHorizontalSpace whether cell will be made wide enough to fit the remaining horizontal space
|
|
454 * @param grabExcessVerticalSpace whether cell will be made high enough to fit the remaining vertical space
|
|
455 * @param horizontalSpan the number of column cells that the control will take up
|
|
456 * @param verticalSpan the number of row cells that the control will take up
|
|
457 *
|
|
458 * @since 3.0
|
|
459 */
|
|
460 public this (int horizontalAlignment, int verticalAlignment, bool grabExcessHorizontalSpace, bool grabExcessVerticalSpace, int horizontalSpan, int verticalSpan) {
|
|
461 this.horizontalAlignment = horizontalAlignment;
|
|
462 this.verticalAlignment = verticalAlignment;
|
|
463 this.grabExcessHorizontalSpace = grabExcessHorizontalSpace;
|
|
464 this.grabExcessVerticalSpace = grabExcessVerticalSpace;
|
|
465 this.horizontalSpan = horizontalSpan;
|
|
466 this.verticalSpan = verticalSpan;
|
|
467 }
|
|
468
|
|
469 /**
|
|
470 * Constructs a new instance of GridData according to the parameters.
|
|
471 * A value of SWT.DEFAULT indicates that no minimum width or
|
|
472 * no minimum height is specified.
|
|
473 *
|
|
474 * @param width a minimum width for the column
|
|
475 * @param height a minimum height for the row
|
|
476 *
|
|
477 * @since 3.0
|
|
478 */
|
|
479 public this (int width, int height) {
|
|
480 this.widthHint = width;
|
|
481 this.heightHint = height;
|
|
482 }
|
|
483
|
|
484 void computeSize (Control control, int wHint, int hHint, bool flushCache) {
|
|
485 if (cacheWidth !is -1 && cacheHeight !is -1) return;
|
|
486 if (wHint is this.widthHint && hHint is this.heightHint) {
|
|
487 if (defaultWidth is -1 || defaultHeight is -1 || wHint !is defaultWhint || hHint !is defaultHhint) {
|
|
488 Point size = control.computeSize (wHint, hHint, flushCache);
|
|
489 defaultWhint = wHint;
|
|
490 defaultHhint = hHint;
|
|
491 defaultWidth = size.x;
|
|
492 defaultHeight = size.y;
|
|
493 }
|
|
494 cacheWidth = defaultWidth;
|
|
495 cacheHeight = defaultHeight;
|
|
496 return;
|
|
497 }
|
|
498 if (currentWidth is -1 || currentHeight is -1 || wHint !is currentWhint || hHint !is currentHhint) {
|
|
499 Point size = control.computeSize (wHint, hHint, flushCache);
|
|
500 currentWhint = wHint;
|
|
501 currentHhint = hHint;
|
|
502 currentWidth = size.x;
|
|
503 currentHeight = size.y;
|
|
504 }
|
|
505 cacheWidth = currentWidth;
|
|
506 cacheHeight = currentHeight;
|
|
507 }
|
|
508
|
|
509 void flushCache () {
|
|
510 cacheWidth = cacheHeight = -1;
|
|
511 defaultWidth = defaultHeight = -1;
|
|
512 currentWidth = currentHeight = -1;
|
|
513 }
|
|
514
|
|
515 String getName () {
|
|
516 String string = this.classinfo.name;
|
|
517 int index = string.lastIndexOf('.');
|
|
518 if (index is -1 ) return string;
|
|
519 return string[ index + 1 .. string.length ];
|
|
520 }
|
|
521
|
|
522 /**
|
|
523 * Returns a string containing a concise, human-readable
|
|
524 * description of the receiver.
|
|
525 *
|
|
526 * @return a string representation of the GridData object
|
|
527 */
|
|
528 override public String toString () {
|
|
529 String hAlign = "";
|
|
530 switch (horizontalAlignment) {
|
|
531 case SWT.FILL: hAlign = "SWT.FILL"; break;
|
|
532 case SWT.BEGINNING: hAlign = "SWT.BEGINNING"; break;
|
|
533 case SWT.LEFT: hAlign = "SWT.LEFT"; break;
|
|
534 case SWT.END: hAlign = "SWT.END"; break;
|
|
535 case END: hAlign = "GridData.END"; break;
|
|
536 case SWT.RIGHT: hAlign = "SWT.RIGHT"; break;
|
|
537 case SWT.CENTER: hAlign = "SWT.CENTER"; break;
|
|
538 case CENTER: hAlign = "GridData.CENTER"; break;
|
|
539 default: hAlign = "Undefined "~to!(String)(horizontalAlignment); break;
|
|
540 }
|
|
541 String vAlign = "";
|
|
542 switch (verticalAlignment) {
|
|
543 case SWT.FILL: vAlign = "SWT.FILL"; break;
|
|
544 case SWT.BEGINNING: vAlign = "SWT.BEGINNING"; break;
|
|
545 case SWT.TOP: vAlign = "SWT.TOP"; break;
|
|
546 case SWT.END: vAlign = "SWT.END"; break;
|
|
547 case END: vAlign = "GridData.END"; break;
|
|
548 case SWT.BOTTOM: vAlign = "SWT.BOTTOM"; break;
|
|
549 case SWT.CENTER: vAlign = "SWT.CENTER"; break;
|
|
550 case CENTER: vAlign = "GridData.CENTER"; break;
|
|
551 default: vAlign = "Undefined "~to!(String)(verticalAlignment); break;
|
|
552 }
|
|
553 String string = getName()~" {";
|
|
554 string ~= "horizontalAlignment="~to!(String)(hAlign)~" ";
|
|
555 if (horizontalIndent !is 0) string ~= "horizontalIndent="~to!(String)(horizontalIndent)~" ";
|
|
556 if (horizontalSpan !is 1) string ~= "horizontalSpan="~to!(String)(horizontalSpan)~" ";
|
|
557 if (grabExcessHorizontalSpace) string ~= "grabExcessHorizontalSpace="~to!(String)(grabExcessHorizontalSpace)~" ";
|
|
558 if (widthHint !is SWT.DEFAULT) string ~= "widthHint="~to!(String)(widthHint)~" ";
|
|
559 if (minimumWidth !is 0) string ~= "minimumWidth="~to!(String)(minimumWidth)~" ";
|
|
560 string ~= "verticalAlignment="~vAlign~" ";
|
|
561 if (verticalIndent !is 0) string ~= "verticalIndent="~to!(String)(verticalIndent)~" ";
|
|
562 if (verticalSpan !is 1) string ~= "verticalSpan="~to!(String)(verticalSpan)~" ";
|
|
563 if (grabExcessVerticalSpace) string ~= "grabExcessVerticalSpace="~to!(String)(grabExcessVerticalSpace)~" ";
|
|
564 if (heightHint !is SWT.DEFAULT) string ~= "heightHint="~to!(String)(heightHint)~" ";
|
|
565 if (minimumHeight !is 0) string ~= "minimumHeight="~to!(String)(minimumHeight)~" ";
|
|
566 if (exclude) string ~= "exclude="~to!(String)(exclude)~" ";
|
|
567 string = string.trim();
|
|
568 string ~= "}";
|
|
569 return string;
|
|
570 }
|
|
571 }
|