Mercurial > projects > dwt-mac
comparison dwt/widgets/Group.d @ 45:d8635bb48c7c
Merge with SWT 3.5
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Mon, 01 Dec 2008 17:07:00 +0100 |
parents | e831403a80a9 |
children | cfa563df4fdd |
comparison
equal
deleted
inserted
replaced
44:ca5e494f2bbf | 45:d8635bb48c7c |
---|---|
1 /******************************************************************************* | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2007 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 * |
15 | 15 |
16 import dwt.DWT; | 16 import dwt.DWT; |
17 import dwt.DWTException; | 17 import dwt.DWTException; |
18 import dwt.graphics.Rectangle; | 18 import dwt.graphics.Rectangle; |
19 import dwt.internal.cocoa.NSBox; | 19 import dwt.internal.cocoa.NSBox; |
20 import dwt.internal.cocoa.NSFont; | |
20 import dwt.internal.cocoa.NSRect; | 21 import dwt.internal.cocoa.NSRect; |
21 import dwt.internal.cocoa.NSSize; | 22 import dwt.internal.cocoa.NSSize; |
22 import dwt.internal.cocoa.NSString; | 23 import dwt.internal.cocoa.NSString; |
23 import dwt.internal.cocoa.NSView; | 24 import dwt.internal.cocoa.NSView; |
25 import dwt.internal.cocoa.OS; | |
24 import dwt.internal.cocoa.SWTBox; | 26 import dwt.internal.cocoa.SWTBox; |
25 import dwt.internal.cocoa.SWTView; | 27 import dwt.internal.cocoa.SWTView; |
26 | 28 |
27 /** | 29 /** |
28 * Instances of this class provide an etched border | 30 * Instances of this class provide an etched border |
41 * <p> | 43 * <p> |
42 * Note: Only one of the above styles may be specified. | 44 * Note: Only one of the above styles may be specified. |
43 * </p><p> | 45 * </p><p> |
44 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | 46 * IMPORTANT: This class is <em>not</em> intended to be subclassed. |
45 * </p> | 47 * </p> |
48 * | |
49 * @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> | |
46 */ | 51 */ |
47 public class Group : Composite { | 52 public class Group : Composite { |
48 SWTView contentView; | 53 NSView contentView; |
49 String text = ""; | 54 String text = ""; |
50 | 55 |
51 /** | 56 /** |
52 * Constructs a new instance of this class given its parent | 57 * Constructs a new instance of this class given its parent |
53 * and a style value describing its behavior and appearance. | 58 * and a style value describing its behavior and appearance. |
101 } | 106 } |
102 | 107 |
103 public Rectangle computeTrim (int x, int y, int width, int height) { | 108 public Rectangle computeTrim (int x, int y, int width, int height) { |
104 checkWidget (); | 109 checkWidget (); |
105 NSBox widget = cast(NSBox)view; | 110 NSBox widget = cast(NSBox)view; |
111 int border = (int)Math.ceil (widget.borderWidth ()); | |
106 NSSize margins = widget.contentViewMargins(); | 112 NSSize margins = widget.contentViewMargins(); |
107 NSRect frame = contentView.frame(); | 113 NSRect frame = contentView.frame(); |
108 width += margins.width * 2; | 114 width += (margins.width + border) * 2; |
109 height += margins.height * 2 + frame.y; | 115 height += (margins.height + border) * 2 + frame.y; |
110 return super.computeTrim(x, y, width, height); | 116 return super.computeTrim(x, y, width, height); |
111 } | 117 } |
112 | 118 |
113 NSView contentView () { | 119 NSView contentView () { |
114 return contentView; | 120 return contentView; |
115 } | 121 } |
116 | 122 |
123 void deregister () { | |
124 super.deregister (); | |
125 display.removeWidget (contentView); | |
126 SWTBox box = (SWTBox)view; | |
127 display.removeWidget (box.titleCell()); | |
128 } | |
129 | |
117 void createHandle () { | 130 void createHandle () { |
118 SWTBox widget = cast(SWTBox)new SWTBox().alloc(); | 131 NSBox widget = cast(NSBox)(new SWTBox()).alloc(); |
119 widget.initWithFrame(new NSRect()); | 132 widget.initWithFrame(new NSRect()); |
120 widget.setTitle(NSString.stringWith("")); | 133 widget.setTitlePosition(OS.NSNoTitle); |
121 widget.setTag(jniRef); | 134 NSView contentWidget = (NSView)new SWTView().alloc(); |
122 SWTView contentWidget = cast(SWTView)new SWTView().alloc(); | |
123 contentWidget.initWithFrame(new NSRect()); | 135 contentWidget.initWithFrame(new NSRect()); |
124 contentWidget.setTag(jniRef); | |
125 // contentWidget.setDrawsBackground(false); | 136 // contentWidget.setDrawsBackground(false); |
126 widget.setContentView(contentWidget); | 137 widget.setContentView(contentWidget); |
127 contentView = contentWidget; | 138 contentView = contentWidget; |
128 view = widget; | 139 view = widget; |
129 parent.contentView().addSubview_(widget); | |
130 } | 140 } |
131 | 141 |
132 public Rectangle getClientArea () { | 142 public Rectangle getClientArea () { |
133 checkWidget(); | 143 checkWidget(); |
134 NSRect rect = contentView.bounds(); | 144 NSRect rect = contentView.bounds(); |
154 public String getText () { | 164 public String getText () { |
155 checkWidget (); | 165 checkWidget (); |
156 return text; | 166 return text; |
157 } | 167 } |
158 | 168 |
169 float getThemeAlpha () { | |
170 return 0.25f * parent.getThemeAlpha (); | |
171 } | |
172 | |
173 void register () { | |
174 super.register (); | |
175 display.addWidget (contentView, this); | |
176 SWTBox box = (SWTBox)view; | |
177 display.addWidget (box.titleCell(), this); | |
178 } | |
179 | |
159 void releaseHandle () { | 180 void releaseHandle () { |
160 super.releaseHandle (); | 181 super.releaseHandle (); |
161 if (contentView !is null) { | 182 if (contentView !is null) contentView.release(); |
162 contentView.setTag(-1); | |
163 contentView.release(); | |
164 } | |
165 contentView = null; | 183 contentView = null; |
184 } | |
185 | |
186 void setFont(NSFont font) { | |
187 ((NSBox) view).setTitleFont(font); | |
166 } | 188 } |
167 | 189 |
168 /** | 190 /** |
169 * Sets the receiver's text, which is the string that will | 191 * Sets the receiver's text, which is the string that will |
170 * be displayed as the receiver's <em>title</em>, to the argument, | 192 * be displayed as the receiver's <em>title</em>, to the argument, |
194 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 216 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
195 text = string; | 217 text = string; |
196 char [] buffer = new char [text.length ()]; | 218 char [] buffer = new char [text.length ()]; |
197 text.getChars (0, buffer.length, buffer, 0); | 219 text.getChars (0, buffer.length, buffer, 0); |
198 int length = fixMnemonic (buffer); | 220 int length = fixMnemonic (buffer); |
199 (cast(NSBox)view).setTitle(NSString.stringWithCharacters(buffer, length)); | 221 NSBox box = cast(NSBox)view; |
200 } | 222 box.setTitlePosition(length is 0 ? OS.NSNoTitle : OS.NSAtTop); |
201 | 223 box.setTitle(NSString.stringWithCharacters(buffer, length)); |
202 } | 224 } |
225 | |
226 } |