View | Details | Raw Unified | Return to bug 170201 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/swt/snippets/Snippet253.java (+52 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2004 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
 *******************************************************************************/
11
package org.eclipse.swt.snippets;
12
13
/* 
14
 * example snippet: Hello World
15
 *
16
 * For a list of all SWT example snippets see
17
 * http://www.eclipse.org/swt/snippets/
18
 */
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.layout.FillLayout;
21
import org.eclipse.swt.layout.RowData;
22
import org.eclipse.swt.layout.RowLayout;
23
import org.eclipse.swt.widgets.*;
24
25
public class Snippet253 {
26
27
public static void main (String [] args) {
28
	Display display = new Display ();
29
	Shell shell = new Shell(display);
30
	shell.setLayout(new FillLayout());
31
	Group group = new Group(shell,SWT.NONE);
32
	group.setLayout(new RowLayout());
33
	
34
	Button b = new Button(group,SWT.PUSH);
35
	b.setText("50%-Fixed");
36
	b.setLayoutData(new RowData(SWT.DEFAULT,SWT.DEFAULT,1,0));
37
	
38
	b = new Button(group,SWT.PUSH);
39
	b.setText("Fixed");
40
	b.setLayoutData(new RowData(100,SWT.DEFAULT));
41
	
42
	b = new Button(group,SWT.PUSH);
43
	b.setText("50%-Fixed");
44
	b.setLayoutData(new RowData(SWT.DEFAULT,SWT.DEFAULT,1,0));
45
	
46
	shell.open ();
47
	while (!shell.isDisposed ()) {
48
		if (!display.readAndDispatch ()) display.sleep ();
49
	}
50
	display.dispose ();
51
}
52
}
(-)Eclipse SWT/common/org/eclipse/swt/layout/RowLayout.java (-9 / +59 lines)
Lines 196-207 Link Here
196
	return extent;
196
	return extent;
197
}
197
}
198
198
199
Point computeSize (Control control, boolean flushCache) {
199
Point computeSize (Control control, boolean flushCache, double totalWidthWeight, double totalHeightWeight, int containerWidth, int containerHeight) {
200
	int wHint = SWT.DEFAULT, hHint = SWT.DEFAULT;
200
	int wHint = SWT.DEFAULT, hHint = SWT.DEFAULT;
201
	RowData data = (RowData) control.getLayoutData ();
201
	RowData data = (RowData) control.getLayoutData ();
202
	if (data != null) {
202
	if (data != null) {
203
		wHint = data.width;
203
		wHint = Math.max(data.width, (data.widthWeight > 0)?(int)(data.widthWeight/totalWidthWeight*containerWidth):data.width );
204
		hHint = data.height;
204
		hHint = Math.max(data.height, (data.heightWeight > 0)?(int)(data.heightWeight/totalHeightWeight*containerHeight):data.height);
205
	}
205
	}
206
	return control.computeSize (wHint, hHint, flushCache);
206
	return control.computeSize (wHint, hHint, flushCache);
207
}
207
}
Lines 229-249 Link Here
229
Point layoutHorizontal (Composite composite, boolean move, boolean wrap, int width, boolean flushCache) {
229
Point layoutHorizontal (Composite composite, boolean move, boolean wrap, int width, boolean flushCache) {
230
	Control [] children = composite.getChildren ();
230
	Control [] children = composite.getChildren ();
231
	int count = 0;
231
	int count = 0;
232
	
233
	Rectangle rect = composite.getClientArea ();
234
	int totalWidthWeight = 0;
235
	int totalHeightWeight = 0;
236
	int heightToUse=rect.height - (marginTop + marginHeight * 2 + marginBottom);
237
	int widthToUse=rect.width - (marginLeft + marginWidth * 2 + marginRight);
238
	
232
	for (int i=0; i<children.length; i++) {
239
	for (int i=0; i<children.length; i++) {
233
		Control control = children [i];
240
		Control control = children [i];
234
		RowData data = (RowData) control.getLayoutData ();
241
		RowData data = (RowData) control.getLayoutData ();
235
		if (data == null || !data.exclude) {
242
		if (data == null || !data.exclude) {
236
			children [count++] = children [i];
243
			children [count++] = children [i];
244
			if( data != null ) {
245
				totalWidthWeight += data.widthWeight;
246
				totalHeightWeight += data.heightWeight;
247
				
248
				if( data.height != SWT.DEFAULT && data.heightWeight == 0 ) {
249
					heightToUse -= data.height;
250
				}
251
				
252
				if( data.width != SWT.DEFAULT && data.widthWeight == 0 ) {
253
					widthToUse -= data.width;
254
				}
255
			}
237
		} 
256
		} 
238
	}
257
	}
258
	
259
	heightToUse -= spacing * count;
260
	widthToUse -= spacing * count;
261
	
239
	if (count == 0) {
262
	if (count == 0) {
240
		return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
263
		return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
241
	}
264
	}
242
	int childWidth = 0, childHeight = 0, maxHeight = 0;
265
	int childWidth = 0, childHeight = 0, maxHeight = 0;
266
	
267
	
243
	if (!pack) {
268
	if (!pack) {
244
		for (int i=0; i<count; i++) {
269
		for (int i=0; i<count; i++) {
245
			Control child = children [i];
270
			Control child = children [i];
246
			Point size = computeSize (child, flushCache);
271
			Point size = computeSize (child, flushCache,totalWidthWeight,totalHeightWeight,widthToUse,heightToUse);
247
			childWidth = Math.max (childWidth, size.x);
272
			childWidth = Math.max (childWidth, size.x);
248
			childHeight = Math.max (childHeight, size.y);
273
			childHeight = Math.max (childHeight, size.y);
249
		}
274
		}
Lines 251-257 Link Here
251
	}
276
	}
252
	int clientX = 0, clientY = 0;
277
	int clientX = 0, clientY = 0;
253
	if (move) {
278
	if (move) {
254
		Rectangle rect = composite.getClientArea ();
279
		
255
		clientX = rect.x;
280
		clientX = rect.x;
256
		clientY = rect.y;
281
		clientY = rect.y;
257
	}
282
	}
Lines 266-272 Link Here
266
	for (int i=0; i<count; i++) {
291
	for (int i=0; i<count; i++) {
267
		Control child = children [i];
292
		Control child = children [i];
268
		if (pack) {
293
		if (pack) {
269
			Point size = computeSize (child, flushCache);
294
			Point size = computeSize (child, flushCache,totalWidthWeight,totalHeightWeight,widthToUse,heightToUse);
270
			childWidth = size.x;
295
			childWidth = size.x;
271
			childHeight = size.y;
296
			childHeight = size.y;
272
		}
297
		}
Lines 336-356 Link Here
336
Point layoutVertical (Composite composite, boolean move, boolean wrap, int height, boolean flushCache) {
361
Point layoutVertical (Composite composite, boolean move, boolean wrap, int height, boolean flushCache) {
337
	Control [] children = composite.getChildren ();
362
	Control [] children = composite.getChildren ();
338
	int count = 0;
363
	int count = 0;
364
	
365
	Rectangle rect = composite.getClientArea ();
366
	int totalWidthWeight = 0;
367
	int totalHeightWeight = 0;
368
	int heightToUse=rect.height - (marginTop + marginHeight * 2 + marginBottom);
369
	int widthToUse=rect.width - (marginLeft + marginWidth * 2 + marginRight);
370
	
339
	for (int i=0; i<children.length; i++) {
371
	for (int i=0; i<children.length; i++) {
340
		Control control = children [i];
372
		Control control = children [i];
341
		RowData data = (RowData) control.getLayoutData ();
373
		RowData data = (RowData) control.getLayoutData ();
342
		if (data == null || !data.exclude) {
374
		if (data == null || !data.exclude) {
343
			children [count++] = children [i];
375
			children [count++] = children [i];
376
			if( data != null ) {
377
				totalWidthWeight += data.widthWeight;
378
				totalHeightWeight += data.heightWeight;
379
				
380
				if( data.height != SWT.DEFAULT && data.heightWeight == 0 ) {
381
					heightToUse -= data.height;
382
				}
383
				
384
				if( data.width != SWT.DEFAULT && data.widthWeight == 0 ) {
385
					widthToUse -= data.width;
386
				}
387
			}
344
		} 
388
		} 
345
	}
389
	}
390
	
391
	heightToUse -= spacing * count;
392
	widthToUse -= spacing * count;
393
	
346
	if (count == 0) {
394
	if (count == 0) {
347
		return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
395
		return new Point (marginLeft + marginWidth * 2 + marginRight, marginTop + marginHeight * 2 + marginBottom);
348
	}
396
	}
349
	int childWidth = 0, childHeight = 0, maxWidth = 0;
397
	int childWidth = 0, childHeight = 0, maxWidth = 0;
398
	
399
	
350
	if (!pack) {
400
	if (!pack) {
351
		for (int i=0; i<count; i++) {
401
		for (int i=0; i<count; i++) {
352
			Control child = children [i];
402
			Control child = children [i];
353
			Point size = computeSize (child, flushCache);
403
			Point size = computeSize (child, flushCache,totalWidthWeight,totalHeightWeight,widthToUse,heightToUse);
354
			childWidth = Math.max (childWidth, size.x);
404
			childWidth = Math.max (childWidth, size.x);
355
			childHeight = Math.max (childHeight, size.y);
405
			childHeight = Math.max (childHeight, size.y);
356
		}
406
		}
Lines 358-364 Link Here
358
	}
408
	}
359
	int clientX = 0, clientY = 0;
409
	int clientX = 0, clientY = 0;
360
	if (move) {
410
	if (move) {
361
		Rectangle rect = composite.getClientArea ();
411
		
362
		clientX = rect.x;
412
		clientX = rect.x;
363
		clientY = rect.y;
413
		clientY = rect.y;
364
	}
414
	}
Lines 373-379 Link Here
373
	for (int i=0; i<count; i++) {
423
	for (int i=0; i<count; i++) {
374
		Control child = children [i];
424
		Control child = children [i];
375
		if (pack) {
425
		if (pack) {
376
			Point size = computeSize (child, flushCache);
426
			Point size = computeSize (child, flushCache,totalWidthWeight,totalHeightWeight,widthToUse,heightToUse);
377
			childWidth = size.x;
427
			childWidth = size.x;
378
			childHeight = size.y;
428
			childHeight = size.y;
379
		}
429
		}
(-)Eclipse SWT/common/org/eclipse/swt/layout/RowData.java (+33 lines)
Lines 67-72 Link Here
67
	 */
67
	 */
68
	public boolean exclude = false;
68
	public boolean exclude = false;
69
	
69
	
70
	/**
71
	 * widthWeight specifies the preferred width in comparison with the other 
72
	 * controls who are children of this container. In conjunction with this 
73
	 * value {@link #width} acts as the minimum value which and the maximum 
74
	 * is passed into Control.computeSize(int, int, boolean) 
75
	 */
76
	public int widthWeight = 0;
77
	
78
	/**
79
	 * heightWeight specifies the preferred height in comparison with the other 
80
	 * controls who are children of this container. In conjunction with this 
81
	 * value {@link #height} acts as the minimum value which and the maximum 
82
	 * is passed into Control.computeSize(int, int, boolean) 
83
	 */
84
	public int heightWeight = 0;
85
	
70
/**
86
/**
71
 * Constructs a new instance of RowData using
87
 * Constructs a new instance of RowData using
72
 * default values.
88
 * default values.
Lines 88-93 Link Here
88
}
104
}
89
105
90
/**
106
/**
107
 * Constructs a new instance of RowData according to the parameters.
108
 * A value of SWT.DEFAULT indicates that no minimum width or
109
 * no minimum height is specified.
110
 * 
111
 * @param width a minimum width for the control
112
 * @param height a minimum height for the control
113
 * @param widthWeight the width weight of the control in comparison with other controls
114
 * @param heightWeight the height weight of the control in comparison with other controls
115
 */
116
public RowData (int width, int height, int widthWeight, int heightWeight) {
117
	this.width = width;
118
	this.height = height;
119
	this.widthWeight = widthWeight;
120
	this.heightWeight = heightWeight;
121
}
122
123
/**
91
 * Constructs a new instance of RowData according to the parameter.
124
 * Constructs a new instance of RowData according to the parameter.
92
 * A value of SWT.DEFAULT indicates that no minimum width or
125
 * A value of SWT.DEFAULT indicates that no minimum width or
93
 * no minimum height is specified.
126
 * no minimum height is specified.

Return to bug 170201