Mercurial > projects > dwt-mac
comparison dwt/widgets/MessageBox.d @ 128:07399639c0c8
Added DWT extension to dwt.widgets.MessageBox
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sat, 17 Jan 2009 16:26:49 +0100 |
parents | 62202ce0039f |
children | 1a0129cab08e |
comparison
equal
deleted
inserted
replaced
127:8086e7b181a3 | 128:07399639c0c8 |
---|---|
50 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a> | 50 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a> |
51 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | 51 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
52 */ | 52 */ |
53 public class MessageBox : Dialog { | 53 public class MessageBox : Dialog { |
54 String message = ""; | 54 String message = ""; |
55 private bool allowNullParent = false; | |
55 | 56 |
56 | 57 |
57 /** | 58 /** |
58 * Constructs a new instance of this class given only its parent. | 59 * Constructs a new instance of this class given only its parent. |
59 * | 60 * |
95 * </ul> | 96 * </ul> |
96 */ | 97 */ |
97 public this (Shell parent, int style) { | 98 public this (Shell parent, int style) { |
98 super (parent, super.checkStyle (parent, checkStyle (style))); | 99 super (parent, super.checkStyle (parent, checkStyle (style))); |
99 checkSubclass (); | 100 checkSubclass (); |
101 } | |
102 | |
103 /++ | |
104 + DWT extension, a MessageBox with no parent | |
105 +/ | |
106 public this (int style) { | |
107 allowNullParent = true; | |
108 super (parent, super.checkStyle (parent, checkStyle (style))); | |
109 checkSubclass (); | |
110 } | |
111 //PORT | |
112 //actually, the parent can be null | |
113 override void checkParent (Shell parent){ | |
114 if( !allowNullParent ){ | |
115 super.checkParent( parent ); | |
116 } | |
100 } | 117 } |
101 | 118 |
102 static int checkStyle (int style) { | 119 static int checkStyle (int style) { |
103 int mask = (DWT.YES | DWT.NO | DWT.OK | DWT.CANCEL | DWT.ABORT | DWT.RETRY | DWT.IGNORE); | 120 int mask = (DWT.YES | DWT.NO | DWT.OK | DWT.CANCEL | DWT.ABORT | DWT.RETRY | DWT.IGNORE); |
104 int bits = style & mask; | 121 int bits = style & mask; |
173 case DWT.ABORT | DWT.RETRY | DWT.IGNORE: | 190 case DWT.ABORT | DWT.RETRY | DWT.IGNORE: |
174 defaultButton = NSString.stringWith(DWT.getMessage("DWT_Abort")); | 191 defaultButton = NSString.stringWith(DWT.getMessage("DWT_Abort")); |
175 alternateButton = NSString.stringWith(DWT.getMessage("DWT_Retry")); | 192 alternateButton = NSString.stringWith(DWT.getMessage("DWT_Retry")); |
176 otherButton = NSString.stringWith(DWT.getMessage("DWT_Ignore")); | 193 otherButton = NSString.stringWith(DWT.getMessage("DWT_Ignore")); |
177 break; | 194 break; |
195 default: | |
178 } | 196 } |
179 NSString title = NSString.stringWith(this.title !is null ? this.title : ""); | 197 NSString title = NSString.stringWith(this.title !is null ? this.title : ""); |
180 NSString message = NSString.stringWith(this.message !is null ? this.message : ""); | 198 NSString message = NSString.stringWith(this.message !is null ? this.message : ""); |
181 NSAlert alert = NSAlert.alertWithMessageText(NSString.stringWith(""), defaultButton, alternateButton, otherButton, message); | 199 NSAlert alert = NSAlert.alertWithMessageText(NSString.stringWith(""), defaultButton, alternateButton, otherButton, message); |
182 (new NSWindow(alert.window().id)).setTitle(title); | 200 (new NSWindow(alert.window().id)).setTitle(title); |
185 switch (bits) { | 203 switch (bits) { |
186 case DWT.OK: | 204 case DWT.OK: |
187 switch (response) { | 205 switch (response) { |
188 case OS.NSAlertDefaultReturn: | 206 case OS.NSAlertDefaultReturn: |
189 return DWT.OK; | 207 return DWT.OK; |
208 default: | |
190 } | 209 } |
191 break; | 210 break; |
192 case DWT.CANCEL: | 211 case DWT.CANCEL: |
193 switch (response) { | 212 switch (response) { |
194 case OS.NSAlertDefaultReturn: | 213 case OS.NSAlertDefaultReturn: |
195 return DWT.CANCEL; | 214 return DWT.CANCEL; |
215 default: | |
196 } | 216 } |
197 break; | 217 break; |
198 case DWT.OK | DWT.CANCEL: | 218 case DWT.OK | DWT.CANCEL: |
199 switch (response) { | 219 switch (response) { |
200 case OS.NSAlertDefaultReturn: | 220 case OS.NSAlertDefaultReturn: |
201 return DWT.OK; | 221 return DWT.OK; |
202 case OS.NSAlertAlternateReturn: | 222 case OS.NSAlertAlternateReturn: |
203 return DWT.CANCEL; | 223 return DWT.CANCEL; |
224 default: | |
204 } | 225 } |
205 break; | 226 break; |
206 case DWT.YES: | 227 case DWT.YES: |
207 switch (response) { | 228 switch (response) { |
208 case OS.NSAlertDefaultReturn: | 229 case OS.NSAlertDefaultReturn: |
209 return DWT.YES; | 230 return DWT.YES; |
231 default: | |
210 } | 232 } |
211 break; | 233 break; |
212 case DWT.NO: | 234 case DWT.NO: |
213 switch (response) { | 235 switch (response) { |
214 case OS.NSAlertDefaultReturn: | 236 case OS.NSAlertDefaultReturn: |
215 return DWT.NO; | 237 return DWT.NO; |
238 default: | |
216 } | 239 } |
217 break; | 240 break; |
218 case DWT.YES | DWT.NO: | 241 case DWT.YES | DWT.NO: |
219 switch (response) { | 242 switch (response) { |
220 case OS.NSAlertDefaultReturn: | 243 case OS.NSAlertDefaultReturn: |
221 return DWT.YES; | 244 return DWT.YES; |
222 case OS.NSAlertAlternateReturn: | 245 case OS.NSAlertAlternateReturn: |
223 return DWT.NO; | 246 return DWT.NO; |
247 default: | |
224 } | 248 } |
225 break; | 249 break; |
226 case DWT.YES | DWT.NO | DWT.CANCEL: | 250 case DWT.YES | DWT.NO | DWT.CANCEL: |
227 switch (response) { | 251 switch (response) { |
228 case OS.NSAlertDefaultReturn: | 252 case OS.NSAlertDefaultReturn: |
229 return DWT.YES; | 253 return DWT.YES; |
230 case OS.NSAlertAlternateReturn: | 254 case OS.NSAlertAlternateReturn: |
231 return DWT.NO; | 255 return DWT.NO; |
232 case OS.NSAlertOtherReturn: | 256 case OS.NSAlertOtherReturn: |
233 return DWT.CANCEL; | 257 return DWT.CANCEL; |
258 default: | |
234 } | 259 } |
235 break; | 260 break; |
236 case DWT.RETRY | DWT.CANCEL: | 261 case DWT.RETRY | DWT.CANCEL: |
237 switch (response) { | 262 switch (response) { |
238 case OS.NSAlertDefaultReturn: | 263 case OS.NSAlertDefaultReturn: |
239 return DWT.RETRY; | 264 return DWT.RETRY; |
240 case OS.NSAlertAlternateReturn: | 265 case OS.NSAlertAlternateReturn: |
241 return DWT.CANCEL; | 266 return DWT.CANCEL; |
267 default: | |
242 } | 268 } |
243 break; | 269 break; |
244 case DWT.ABORT | DWT.RETRY | DWT.IGNORE: | 270 case DWT.ABORT | DWT.RETRY | DWT.IGNORE: |
245 switch (response) { | 271 switch (response) { |
246 case OS.NSAlertDefaultReturn: | 272 case OS.NSAlertDefaultReturn: |
247 return DWT.ABORT; | 273 return DWT.ABORT; |
248 case OS.NSAlertAlternateReturn: | 274 case OS.NSAlertAlternateReturn: |
249 return DWT.RETRY; | 275 return DWT.RETRY; |
250 case OS.NSAlertOtherReturn: | 276 case OS.NSAlertOtherReturn: |
251 return DWT.IGNORE; | 277 return DWT.IGNORE; |
252 } | 278 default: |
253 break; | 279 } |
280 break; | |
281 default: | |
254 } | 282 } |
255 return DWT.CANCEL; | 283 return DWT.CANCEL; |
256 } | 284 } |
257 | 285 |
258 /** | 286 /** |
269 public void setMessage (String string) { | 297 public void setMessage (String string) { |
270 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 298 //if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
271 message = string; | 299 message = string; |
272 } | 300 } |
273 | 301 |
274 } | 302 /++ |
303 + DWT extension | |
304 +/ | |
305 public static int showMessageBox(String str, String title, Shell shell, int style) { | |
306 MessageBox msgBox = (shell is null ) ? new MessageBox( style ) : new MessageBox(shell, style); | |
307 msgBox.setMessage(str); | |
308 if(title !is null){ | |
309 msgBox.setText(title); | |
310 } | |
311 return msgBox.open(); | |
312 } | |
313 | |
314 /// DWT extension | |
315 public static int showInfo(String str, String title = null, Shell shell = null) { | |
316 return showMessageBox( str, title, shell, DWT.OK | DWT.ICON_INFORMATION ); | |
317 } | |
318 | |
319 /// DWT extension | |
320 alias showInfo showInformation; | |
321 | |
322 /// DWT extension | |
323 public static int showWarning(String str, String title = null, Shell shell = null) { | |
324 return showMessageBox( str, title, shell, DWT.OK | DWT.ICON_WARNING ); | |
325 } | |
326 | |
327 /// DWT extension | |
328 public static int showError(String str, String title = null, Shell shell = null) { | |
329 return showMessageBox( str, title, shell, DWT.OK | DWT.ICON_ERROR ); | |
330 } | |
331 | |
332 } |