comparison dwt/layout/RowData.d @ 40:fbe68c33eeee

Sync layout with dwt-linux
author Frank Benoit <benoit@tionex.de>
date Tue, 07 Oct 2008 14:41:31 +0200
parents 1a8b3cb347e0
children d8635bb48c7c
comparison
equal deleted inserted replaced
39:43be986a1372 40:fbe68c33eeee
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2006 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
8 * Contributors: 8 * Contributors:
9 * IBM Corporation - initial API and implementation 9 * IBM Corporation - initial API and implementation
10 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
10 *******************************************************************************/ 12 *******************************************************************************/
11 module dwt.layout.RowData; 13 module dwt.layout.RowData;
12 14
15 import dwt.DWT;
16 import dwt.graphics.Point;
17 import dwt.widgets.Control;
18
19 import tango.util.Convert;
13 import dwt.dwthelper.utils; 20 import dwt.dwthelper.utils;
14 21
15 import dwt.DWT;
16 import dwt.graphics.Point;
17
18 /** 22 /**
19 * Each control controlled by a <code>RowLayout</code> can have its initial 23 * Each control controlled by a <code>RowLayout</code> can have its initial
20 * width and height specified by setting a <code>RowData</code> object 24 * width and height specified by setting a <code>RowData</code> object
21 * into the control. 25 * into the control.
22 * <p> 26 * <p>
23 * The following code uses a <code>RowData</code> object to change the initial 27 * The following code uses a <code>RowData</code> object to change the initial
24 * size of a <code>Button</code> in a <code>Shell</code>: 28 * size of a <code>Button</code> in a <code>Shell</code>:
25 * <pre> 29 * <pre>
29 * Button button1 = new Button(shell, DWT.PUSH); 33 * Button button1 = new Button(shell, DWT.PUSH);
30 * button1.setText("Button 1"); 34 * button1.setText("Button 1");
31 * button1.setLayoutData(new RowData(50, 40)); 35 * button1.setLayoutData(new RowData(50, 40));
32 * </pre> 36 * </pre>
33 * </p> 37 * </p>
34 * 38 *
35 * @see RowLayout 39 * @see RowLayout
40 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
36 */ 41 */
37 public final class RowData { 42 public final class RowData {
38 /** 43 /**
39 * width specifies the desired width in pixels. This value 44 * width specifies the desired width in pixels. This value
40 * is the wHint passed into Control.computeSize(int, int, bool) 45 * is the wHint passed into Control.computeSize(int, int, bool)
41 * to determine the preferred size of the control. 46 * to determine the preferred size of the control.
42 * 47 *
43 * The default value is DWT.DEFAULT. 48 * The default value is DWT.DEFAULT.
44 * 49 *
45 * @see dwt.widgets.Control#computeSize(int, int, bool) 50 * @see dwt.widgets.Control#computeSize(int, int, bool)
46 */ 51 */
47 public int width = DWT.DEFAULT; 52 public int width = DWT.DEFAULT;
48 /** 53 /**
49 * height specifies the preferred height in pixels. This value 54 * height specifies the preferred height in pixels. This value
50 * is the hHint passed into Control.computeSize(int, int, bool) 55 * is the hHint passed into Control.computeSize(int, int, bool)
51 * to determine the preferred size of the control. 56 * to determine the preferred size of the control.
52 * 57 *
53 * The default value is DWT.DEFAULT. 58 * The default value is DWT.DEFAULT.
54 * 59 *
55 * @see dwt.widgets.Control#computeSize(int, int, bool) 60 * @see dwt.widgets.Control#computeSize(int, int, bool)
56 */ 61 */
57 public int height = DWT.DEFAULT; 62 public int height = DWT.DEFAULT;
58 63
59 /** 64 /**
60 * exclude informs the layout to ignore this control when sizing 65 * exclude informs the layout to ignore this control when sizing
61 * and positioning controls. If this value is <code>true</code>, 66 * and positioning controls. If this value is <code>true</code>,
62 * the size and position of the control will not be managed by the 67 * the size and position of the control will not be managed by the
63 * layout. If this value is <code>false</code>, the size and 68 * layout. If this value is <code>false</code>, the size and
64 * position of the control will be computed and assigned. 69 * position of the control will be computed and assigned.
65 * 70 *
66 * The default value is <code>false</code>. 71 * The default value is <code>false</code>.
67 * 72 *
68 * @since 3.1 73 * @since 3.1
69 */ 74 */
70 public bool exclude = false; 75 public bool exclude = false;
71 76
72 /** 77 /**
73 * Constructs a new instance of RowData using 78 * Constructs a new instance of RowData using
74 * default values. 79 * default values.
75 */ 80 */
76 public this () { 81 public this () {
78 83
79 /** 84 /**
80 * Constructs a new instance of RowData according to the parameters. 85 * Constructs a new instance of RowData according to the parameters.
81 * A value of DWT.DEFAULT indicates that no minimum width or 86 * A value of DWT.DEFAULT indicates that no minimum width or
82 * no minimum height is specified. 87 * no minimum height is specified.
83 * 88 *
84 * @param width a minimum width for the control 89 * @param width a minimum width for the control
85 * @param height a minimum height for the control 90 * @param height a minimum height for the control
86 */ 91 */
87 public this (int width, int height) { 92 public this (int width, int height) {
88 this.width = width; 93 this.width = width;
91 96
92 /** 97 /**
93 * Constructs a new instance of RowData according to the parameter. 98 * Constructs a new instance of RowData according to the parameter.
94 * A value of DWT.DEFAULT indicates that no minimum width or 99 * A value of DWT.DEFAULT indicates that no minimum width or
95 * no minimum height is specified. 100 * no minimum height is specified.
96 * 101 *
97 * @param point a point whose x coordinate specifies a minimum width for the control 102 * @param point a point whose x coordinate specifies a minimum width for the control
98 * and y coordinate specifies a minimum height for the control 103 * and y coordinate specifies a minimum height for the control
99 */ 104 */
100 public this (Point point) { 105 public this (Point point) {
101 this (point.x, point.y); 106 this (point.x, point.y);
102 } 107 }
103 108
104 String getName () { 109 String getName () {
105 String string = getClass ().getName (); 110 String string = this.classinfo.name;
106 int index = string.lastIndexOf ('.'); 111 int index = string.lastIndexOf('.');
107 if (index is -1) return string; 112 if (index is -1 ) return string;
108 return string.substring (index + 1, string.length ()); 113 return string[ index + 1 .. string.length ];
109 } 114 }
110 115
111 /** 116 /**
112 * Returns a string containing a concise, human-readable 117 * Returns a string containing a concise, human-readable
113 * description of the receiver. 118 * description of the receiver.
114 * 119 *
115 * @return a string representation of the RowData object 120 * @return a string representation of the RowData object
116 */ 121 */
117 public String toString () { 122 override public String toString () {
118 String string = getName ()+" {"; 123 String string = getName ()~" {";
119 if (width !is DWT.DEFAULT) string += "width="+width+" "; 124 if (width !is DWT.DEFAULT) string ~= "width="~to!(String)(width)~" ";
120 if (height !is DWT.DEFAULT) string += "height="+height+" "; 125 if (height !is DWT.DEFAULT) string ~= "height="~to!(String)(height)~" ";
121 if (exclude) string += "exclude="+exclude+" "; 126 if (exclude) string ~= "exclude="~to!(String)(exclude)~" ";
122 string = string.trim(); 127 string = string.trim();
123 string += "}"; 128 string ~= "}";
124 return string; 129 return string;
125 } 130 }
126 } 131 }