Mercurial > projects > dwt-mac
comparison dwt/widgets/Group.d @ 0:380af2bdd8e5
Upload of whole dwt tree
author | Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com> |
---|---|
date | Sat, 09 Aug 2008 17:00:02 +0200 |
parents | |
children | 649b8e223d5a |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:380af2bdd8e5 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2007 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 module dwt.widgets.Group; | |
12 | |
13 import dwt.dwthelper.utils; | |
14 | |
15 | |
16 import dwt.DWT; | |
17 import dwt.DWTException; | |
18 import dwt.graphics.Rectangle; | |
19 import dwt.internal.cocoa.NSBox; | |
20 import dwt.internal.cocoa.NSRect; | |
21 import dwt.internal.cocoa.NSSize; | |
22 import dwt.internal.cocoa.NSString; | |
23 import dwt.internal.cocoa.NSView; | |
24 import dwt.internal.cocoa.SWTBox; | |
25 import dwt.internal.cocoa.SWTView; | |
26 | |
27 /** | |
28 * Instances of this class provide an etched border | |
29 * with an optional title. | |
30 * <p> | |
31 * Shadow styles are hints and may not be honoured | |
32 * by the platform. To create a group with the | |
33 * default shadow style for the platform, do not | |
34 * specify a shadow style. | |
35 * <dl> | |
36 * <dt><b>Styles:</b></dt> | |
37 * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> | |
38 * <dt><b>Events:</b></dt> | |
39 * <dd>(none)</dd> | |
40 * </dl> | |
41 * <p> | |
42 * Note: Only one of the above styles may be specified. | |
43 * </p><p> | |
44 * IMPORTANT: This class is <em>not</em> intended to be subclassed. | |
45 * </p> | |
46 */ | |
47 public class Group extends Composite { | |
48 SWTView contentView; | |
49 String text = ""; | |
50 | |
51 /** | |
52 * Constructs a new instance of this class given its parent | |
53 * and a style value describing its behavior and appearance. | |
54 * <p> | |
55 * The style value is either one of the style constants defined in | |
56 * class <code>DWT</code> which is applicable to instances of this | |
57 * class, or must be built by <em>bitwise OR</em>'ing together | |
58 * (that is, using the <code>int</code> "|" operator) two or more | |
59 * of those <code>DWT</code> style constants. The class description | |
60 * lists the style constants that are applicable to the class. | |
61 * Style bits are also inherited from superclasses. | |
62 * </p> | |
63 * | |
64 * @param parent a composite control which will be the parent of the new instance (cannot be null) | |
65 * @param style the style of control to construct | |
66 * | |
67 * @exception IllegalArgumentException <ul> | |
68 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
69 * </ul> | |
70 * @exception DWTException <ul> | |
71 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
72 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
73 * </ul> | |
74 * | |
75 * @see DWT#SHADOW_ETCHED_IN | |
76 * @see DWT#SHADOW_ETCHED_OUT | |
77 * @see DWT#SHADOW_IN | |
78 * @see DWT#SHADOW_OUT | |
79 * @see DWT#SHADOW_NONE | |
80 * @see Widget#checkSubclass | |
81 * @see Widget#getStyle | |
82 */ | |
83 public Group (Composite parent, int style) { | |
84 super (parent, checkStyle (style)); | |
85 } | |
86 | |
87 static int checkStyle (int style) { | |
88 style |= DWT.NO_FOCUS; | |
89 /* | |
90 * Even though it is legal to create this widget | |
91 * with scroll bars, they serve no useful purpose | |
92 * because they do not automatically scroll the | |
93 * widget's client area. The fix is to clear | |
94 * the DWT style. | |
95 */ | |
96 return style & ~(DWT.H_SCROLL | DWT.V_SCROLL); | |
97 } | |
98 | |
99 protected void checkSubclass () { | |
100 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); | |
101 } | |
102 | |
103 public Rectangle computeTrim (int x, int y, int width, int height) { | |
104 checkWidget (); | |
105 NSBox widget = (NSBox)view; | |
106 NSSize margins = widget.contentViewMargins(); | |
107 NSRect frame = contentView.frame(); | |
108 width += margins.width * 2; | |
109 height += margins.height * 2 + frame.y; | |
110 return super.computeTrim(x, y, width, height); | |
111 } | |
112 | |
113 NSView contentView () { | |
114 return contentView; | |
115 } | |
116 | |
117 void createHandle () { | |
118 SWTBox widget = (SWTBox)new SWTBox().alloc(); | |
119 widget.initWithFrame(new NSRect()); | |
120 widget.setTitle(NSString.stringWith("")); | |
121 widget.setTag(jniRef); | |
122 SWTView contentWidget = (SWTView)new SWTView().alloc(); | |
123 contentWidget.initWithFrame(new NSRect()); | |
124 contentWidget.setTag(jniRef); | |
125 // contentWidget.setDrawsBackground(false); | |
126 widget.setContentView(contentWidget); | |
127 contentView = contentWidget; | |
128 view = widget; | |
129 parent.contentView().addSubview_(widget); | |
130 } | |
131 | |
132 public Rectangle getClientArea () { | |
133 checkWidget(); | |
134 NSRect rect = contentView.bounds(); | |
135 return new Rectangle((int)rect.x, (int)rect.y, (int)rect.width, (int)rect.height); | |
136 } | |
137 | |
138 String getNameText () { | |
139 return getText (); | |
140 } | |
141 | |
142 /** | |
143 * Returns the receiver's text, which is the string that the | |
144 * is used as the <em>title</em>. If the text has not previously | |
145 * been set, returns an empty string. | |
146 * | |
147 * @return the text | |
148 * | |
149 * @exception DWTException <ul> | |
150 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
151 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
152 * </ul> | |
153 */ | |
154 public String getText () { | |
155 checkWidget (); | |
156 return text; | |
157 } | |
158 | |
159 void releaseHandle () { | |
160 super.releaseHandle (); | |
161 if (contentView !is null) { | |
162 contentView.setTag(-1); | |
163 contentView.release(); | |
164 } | |
165 contentView = null; | |
166 } | |
167 | |
168 /** | |
169 * Sets the receiver's text, which is the string that will | |
170 * be displayed as the receiver's <em>title</em>, to the argument, | |
171 * which may not be null. The string may include the mnemonic character. | |
172 * </p> | |
173 * Mnemonics are indicated by an '&' that causes the next | |
174 * character to be the mnemonic. When the user presses a | |
175 * key sequence that matches the mnemonic, focus is assigned | |
176 * to the first child of the group. On most platforms, the | |
177 * mnemonic appears underlined but may be emphasised in a | |
178 * platform specific manner. The mnemonic indicator character | |
179 * '&' can be escaped by doubling it in the string, causing | |
180 * a single '&' to be displayed. | |
181 * </p> | |
182 * @param string the new text | |
183 * | |
184 * @exception IllegalArgumentException <ul> | |
185 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
186 * </ul> | |
187 * @exception DWTException <ul> | |
188 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
189 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
190 * </ul> | |
191 */ | |
192 public void setText (String string) { | |
193 checkWidget(); | |
194 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | |
195 text = string; | |
196 char [] buffer = new char [text.length ()]; | |
197 text.getChars (0, buffer.length, buffer, 0); | |
198 int length = fixMnemonic (buffer); | |
199 ((NSBox)view).setTitle(NSString.stringWithCharacters(buffer, length)); | |
200 } | |
201 | |
202 } |