Mercurial > projects > dwt-linux
annotate dwt/widgets/Dialog.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | 380bad9f6852 |
children | 5a30aa9820f3 |
rev | line source |
---|---|
122
45921f44a4b2
Fix: stack access from listener in AddressBook example
Frank Benoit <benoit@tionex.de>
parents:
108
diff
changeset
|
1 /******************************************************************************* |
77 | 2 * Copyright (c) 2000, 2005 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 | |
108 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
77 | 12 *******************************************************************************/ |
13 module dwt.widgets.Dialog; | |
14 | |
238 | 15 import dwt.dwthelper.utils; |
16 | |
77 | 17 |
18 import dwt.DWT; | |
19 import dwt.DWTException; | |
20 import dwt.widgets.Shell; | |
21 import dwt.widgets.Display; | |
240 | 22 import dwt.widgets.Widget; |
77 | 23 |
24 /** | |
25 * This class is the abstract superclass of the classes | |
26 * that represent the built in platform dialogs. | |
27 * A <code>Dialog</code> typically contains other widgets | |
28 * that are not accessible. A <code>Dialog</code> is not | |
29 * a <code>Widget</code>. | |
30 * <p> | |
31 * This class can also be used as the abstract superclass | |
32 * for user-designed dialogs. Such dialogs usually consist | |
33 * of a Shell with child widgets. The basic template for a | |
34 * user-defined dialog typically looks something like this: | |
35 * <pre><code> | |
36 * public class MyDialog extends Dialog { | |
37 * Object result; | |
38 * | |
39 * public MyDialog (Shell parent, int style) { | |
40 * super (parent, style); | |
41 * } | |
42 * public MyDialog (Shell parent) { | |
43 * this (parent, 0); // your default style bits go here (not the Shell's style bits) | |
44 * } | |
45 * public Object open () { | |
46 * Shell parent = getParent(); | |
47 * Shell shell = new Shell(parent, DWT.DIALOG_TRIM | DWT.APPLICATION_MODAL); | |
48 * shell.setText(getText()); | |
49 * // Your code goes here (widget creation, set result, etc). | |
50 * shell.open(); | |
51 * Display display = parent.getDisplay(); | |
52 * while (!shell.isDisposed()) { | |
53 * if (!display.readAndDispatch()) display.sleep(); | |
54 * } | |
55 * return result; | |
56 * } | |
57 * } | |
58 * </pre></code> | |
59 * <p> | |
60 * Note: The <em>modality</em> styles supported by this class | |
61 * are treated as <em>HINT</em>s, because not all are supported | |
62 * by every subclass on every platform. If a modality style is | |
63 * not supported, it is "upgraded" to a more restrictive modality | |
64 * style that is supported. For example, if <code>PRIMARY_MODAL</code> | |
65 * is not supported by a particular dialog, it would be upgraded to | |
66 * <code>APPLICATION_MODAL</code>. In addition, as is the case | |
67 * for shells, the window manager for the desktop on which the | |
68 * instance is visible has ultimate control over the appearance | |
69 * and behavior of the instance, including its modality. | |
70 * <dl> | |
71 * <dt><b>Styles:</b></dt> | |
72 * <dd>APPLICATION_MODAL, PRIMARY_MODAL, SYSTEM_MODAL</dd> | |
73 * <dt><b>Events:</b></dt> | |
74 * <dd>(none)</dd> | |
75 * </dl> | |
76 * <p> | |
77 * Note: Only one of the styles APPLICATION_MODAL, PRIMARY_MODAL, | |
78 * and SYSTEM_MODAL may be specified. | |
79 * </p> | |
80 * | |
81 * @see Shell | |
82 */ | |
83 | |
84 public abstract class Dialog { | |
85 int style; | |
86 Shell parent; | |
238 | 87 String title; |
77 | 88 |
89 /** | |
90 * Constructs a new instance of this class given only its | |
91 * parent. | |
92 * | |
93 * @param parent a shell which will be the parent of the new instance | |
94 * | |
95 * @exception IllegalArgumentException <ul> | |
96 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
97 * </ul> | |
98 * @exception DWTException <ul> | |
99 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
100 * </ul> | |
101 */ | |
102 public this (Shell parent) { | |
103 this (parent, DWT.PRIMARY_MODAL); | |
104 } | |
105 | |
106 /** | |
107 * Constructs a new instance of this class given its parent | |
108 * and a style value describing its behavior and appearance. | |
109 * <p> | |
110 * The style value is either one of the style constants defined in | |
111 * class <code>DWT</code> which is applicable to instances of this | |
112 * class, or must be built by <em>bitwise OR</em>'ing together | |
113 * (that is, using the <code>int</code> "|" operator) two or more | |
114 * of those <code>DWT</code> style constants. The class description | |
115 * lists the style constants that are applicable to the class. | |
116 * Style bits are also inherited from superclasses. | |
117 * | |
118 * @param parent a shell which will be the parent of the new instance | |
119 * @param style the style of dialog to construct | |
120 * | |
121 * @exception IllegalArgumentException <ul> | |
122 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
123 * </ul> | |
124 * @exception DWTException <ul> | |
125 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
126 * </ul> | |
127 * | |
128 * @see DWT#PRIMARY_MODAL | |
129 * @see DWT#APPLICATION_MODAL | |
130 * @see DWT#SYSTEM_MODAL | |
131 */ | |
132 public this (Shell parent, int style) { | |
133 checkParent (parent); | |
134 this.parent = parent; | |
135 this.style = style; | |
136 title = ""; | |
137 } | |
138 | |
139 /** | |
140 * Checks that this class can be subclassed. | |
141 * <p> | |
142 * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>. | |
143 * </p> | |
144 * | |
145 * @exception DWTException <ul> | |
146 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> | |
147 * </ul> | |
148 * | |
149 * @see Widget#checkSubclass | |
150 */ | |
151 protected void checkSubclass () { | |
152 //PORTING_TODO: implement Display.isValidClass and Class? | |
153 /+if (!Display.isValidClass (getClass ())) { | |
154 error (DWT.ERROR_INVALID_SUBCLASS); | |
155 }+/ | |
156 } | |
157 | |
158 /** | |
159 * Throws an exception if the specified widget can not be | |
160 * used as a parent for the receiver. | |
161 * | |
162 * @exception IllegalArgumentException <ul> | |
163 * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> | |
164 * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> | |
165 * </ul> | |
166 * @exception DWTException <ul> | |
167 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> | |
168 * </ul> | |
169 */ | |
170 void checkParent (Shell parent) { | |
171 if (parent is null) error (DWT.ERROR_NULL_ARGUMENT); | |
172 parent.checkWidget (); | |
173 } | |
174 | |
240 | 175 static int checkStyle (Shell parent, int style) { |
176 if ((style & (DWT.PRIMARY_MODAL | DWT.APPLICATION_MODAL | DWT.SYSTEM_MODAL)) is 0) { | |
177 style |= DWT.APPLICATION_MODAL; | |
178 } | |
179 style &= ~DWT.MIRRORED; | |
180 if ((style & (DWT.LEFT_TO_RIGHT | DWT.RIGHT_TO_LEFT)) is 0) { | |
181 if (parent !is null) { | |
182 if ((parent.style & DWT.LEFT_TO_RIGHT) !is 0) style |= DWT.LEFT_TO_RIGHT; | |
183 if ((parent.style & DWT.RIGHT_TO_LEFT) !is 0) style |= DWT.RIGHT_TO_LEFT; | |
184 } | |
185 } | |
186 return Widget.checkBits (style, DWT.LEFT_TO_RIGHT, DWT.RIGHT_TO_LEFT, 0, 0, 0, 0); | |
187 } | |
188 | |
77 | 189 /** |
190 * Does whatever dialog specific cleanup is required, and then | |
191 * uses the code in <code>DWTError.error</code> to handle the error. | |
192 * | |
193 * @param code the descriptive error code | |
194 * | |
195 * @see DWT#error(int) | |
196 */ | |
197 void error (int code) { | |
198 DWT.error(code); | |
199 } | |
200 | |
201 /** | |
202 * Returns the receiver's parent, which must be a <code>Shell</code> | |
203 * or null. | |
204 * | |
205 * @return the receiver's parent | |
206 * | |
207 * @exception DWTException <ul> | |
208 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
209 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
210 * </ul> | |
211 */ | |
212 public Shell getParent () { | |
213 return parent; | |
214 } | |
215 | |
216 /** | |
217 * Returns the receiver's style information. | |
218 * <p> | |
219 * Note that, the value which is returned by this method <em>may | |
220 * not match</em> the value which was provided to the constructor | |
221 * when the receiver was created. | |
222 * </p> | |
223 * | |
224 * @return the style bits | |
225 * | |
226 * @exception DWTException <ul> | |
227 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
228 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
229 * </ul> | |
230 */ | |
231 public int getStyle () { | |
232 return style; | |
233 } | |
234 | |
235 /** | |
236 * Returns the receiver's text, which is the string that the | |
237 * window manager will typically display as the receiver's | |
238 * <em>title</em>. If the text has not previously been set, | |
239 * returns an empty string. | |
240 * | |
241 * @return the text | |
242 * | |
243 * @exception DWTException <ul> | |
244 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
245 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
246 * </ul> | |
247 */ | |
238 | 248 public String getText () { |
77 | 249 return title; |
250 } | |
251 | |
252 /** | |
253 * Sets the receiver's text, which is the string that the | |
254 * window manager will typically display as the receiver's | |
255 * <em>title</em>, to the argument, which must not be null. | |
256 * | |
257 * @param string the new text | |
258 * | |
259 * @exception IllegalArgumentException <ul> | |
260 * <li>ERROR_NULL_ARGUMENT - if the text is null</li> | |
261 * </ul> | |
262 * @exception DWTException <ul> | |
263 * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> | |
264 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> | |
265 * </ul> | |
266 */ | |
238 | 267 public void setText (String string) { |
77 | 268 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
269 title = string; | |
270 } | |
271 | |
272 } |