Mercurial > projects > dwt-mac
comparison dwt/widgets/Group.d @ 69:39340f7612f8
Ported dwt.widgets.Group
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Tue, 23 Dec 2008 23:21:45 +0100 |
parents | cfa563df4fdd |
children | 63a09873578e |
comparison
equal
deleted
inserted
replaced
68:cce7edf30dae | 69:39340f7612f8 |
---|---|
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 * | |
11 * Port to the D programming language: | |
12 * Jacob Carlborg <doob@me.com> | |
10 *******************************************************************************/ | 13 *******************************************************************************/ |
11 module dwt.widgets.Group; | 14 module dwt.widgets.Group; |
12 | 15 |
13 import dwt.dwthelper.utils; | 16 import dwt.dwthelper.utils; |
14 | 17 |
23 import dwt.internal.cocoa.NSString; | 26 import dwt.internal.cocoa.NSString; |
24 import dwt.internal.cocoa.NSView; | 27 import dwt.internal.cocoa.NSView; |
25 import dwt.internal.cocoa.OS; | 28 import dwt.internal.cocoa.OS; |
26 import dwt.internal.cocoa.SWTBox; | 29 import dwt.internal.cocoa.SWTBox; |
27 import dwt.internal.cocoa.SWTView; | 30 import dwt.internal.cocoa.SWTView; |
31 | |
32 import dwt.widgets.Composite; | |
28 | 33 |
29 /** | 34 /** |
30 * Instances of this class provide an etched border | 35 * Instances of this class provide an etched border |
31 * with an optional title. | 36 * with an optional title. |
32 * <p> | 37 * <p> |
48 * | 53 * |
49 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> | 54 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a> |
50 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | 55 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
51 */ | 56 */ |
52 public class Group : Composite { | 57 public class Group : Composite { |
53 NSView contentView; | 58 NSView contentView_; |
54 String text = ""; | 59 String text = ""; |
55 | 60 |
56 /** | 61 /** |
57 * Constructs a new instance of this class given its parent | 62 * Constructs a new instance of this class given its parent |
58 * and a style value describing its behavior and appearance. | 63 * and a style value describing its behavior and appearance. |
106 } | 111 } |
107 | 112 |
108 public Rectangle computeTrim (int x, int y, int width, int height) { | 113 public Rectangle computeTrim (int x, int y, int width, int height) { |
109 checkWidget (); | 114 checkWidget (); |
110 NSBox widget = cast(NSBox)view; | 115 NSBox widget = cast(NSBox)view; |
111 int border = (int)Math.ceil (widget.borderWidth ()); | 116 int border = cast(int)Math.ceil (widget.borderWidth ()); |
112 NSSize margins = widget.contentViewMargins(); | 117 NSSize margins = widget.contentViewMargins(); |
113 NSRect frame = contentView.frame(); | 118 NSRect frame = contentView.frame(); |
114 width += (margins.width + border) * 2; | 119 width += (margins.width + border) * 2; |
115 height += (margins.height + border) * 2 + frame.y; | 120 height += (margins.height + border) * 2 + frame.y; |
116 return super.computeTrim(x, y, width, height); | 121 return super.computeTrim(x, y, width, height); |
121 } | 126 } |
122 | 127 |
123 void deregister () { | 128 void deregister () { |
124 super.deregister (); | 129 super.deregister (); |
125 display.removeWidget (contentView); | 130 display.removeWidget (contentView); |
126 SWTBox box = (SWTBox)view; | 131 SWTBox box = cast(SWTBox)view; |
127 display.removeWidget (box.titleCell()); | 132 display.removeWidget (box.titleCell()); |
128 } | 133 } |
129 | 134 |
130 void createHandle () { | 135 void createHandle () { |
131 NSBox widget = cast(NSBox)(new SWTBox()).alloc(); | 136 NSBox widget = cast(NSBox)(new SWTBox()).alloc(); |
132 widget.initWithFrame(NSRect()); | 137 widget.initWithFrame(NSRect()); |
133 widget.setTitlePosition(OS.NSNoTitle); | 138 widget.setTitlePosition(OS.NSNoTitle); |
134 NSView contentWidget = (NSView)new SWTView().alloc(); | 139 NSView contentWidget = cast(NSView)(new SWTView()).alloc(); |
135 contentWidget.initWithFrame(NSRect()); | 140 contentWidget.initWithFrame(NSRect()); |
136 // contentWidget.setDrawsBackground(false); | 141 // contentWidget.setDrawsBackground(false); |
137 widget.setContentView(contentWidget); | 142 widget.setContentView(contentWidget); |
138 contentView = contentWidget; | 143 contentView_ = contentWidget; |
139 view = widget; | 144 view = widget; |
140 } | 145 } |
141 | 146 |
142 public Rectangle getClientArea () { | 147 public Rectangle getClientArea () { |
143 checkWidget(); | 148 checkWidget(); |
171 } | 176 } |
172 | 177 |
173 void register () { | 178 void register () { |
174 super.register (); | 179 super.register (); |
175 display.addWidget (contentView, this); | 180 display.addWidget (contentView, this); |
176 SWTBox box = (SWTBox)view; | 181 SWTBox box = cast(SWTBox)view; |
177 display.addWidget (box.titleCell(), this); | 182 display.addWidget (box.titleCell(), this); |
178 } | 183 } |
179 | 184 |
180 void releaseHandle () { | 185 void releaseHandle () { |
181 super.releaseHandle (); | 186 super.releaseHandle (); |
182 if (contentView !is null) contentView.release(); | 187 if (contentView !is null) contentView.release(); |
183 contentView = null; | 188 contentView_ = null; |
184 } | 189 } |
185 | 190 |
186 void setFont(NSFont font) { | 191 void setFont(NSFont font) { |
187 ((NSBox) view).setTitleFont(font); | 192 (cast(NSBox) view).setTitleFont(font); |
188 } | 193 } |
189 | 194 |
190 /** | 195 /** |
191 * Sets the receiver's text, which is the string that will | 196 * Sets the receiver's text, which is the string that will |
192 * be displayed as the receiver's <em>title</em>, to the argument, | 197 * be displayed as the receiver's <em>title</em>, to the argument, |
218 char [] buffer = new char [text.length ()]; | 223 char [] buffer = new char [text.length ()]; |
219 text.getChars (0, buffer.length, buffer, 0); | 224 text.getChars (0, buffer.length, buffer, 0); |
220 int length = fixMnemonic (buffer); | 225 int length = fixMnemonic (buffer); |
221 NSBox box = cast(NSBox)view; | 226 NSBox box = cast(NSBox)view; |
222 box.setTitlePosition(length is 0 ? OS.NSNoTitle : OS.NSAtTop); | 227 box.setTitlePosition(length is 0 ? OS.NSNoTitle : OS.NSAtTop); |
223 box.setTitle(NSString.stringWithCharacters(buffer, length)); | 228 box.setTitle(NSString.stringWithCharacters(buffer.toString16().ptr, length)); |
224 } | 229 } |
225 | 230 |
226 } | 231 } |