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