comparison dwt/widgets/MessageBox.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents 1a8b3cb347e0
children 62202ce0039f
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.internal.cocoa.NSAlert; 18 import dwt.internal.cocoa.NSAlert;
19 import dwt.internal.cocoa.NSString; 19 import dwt.internal.cocoa.NSString;
20 import dwt.internal.cocoa.NSWindow;
20 import dwt.internal.cocoa.OS; 21 import dwt.internal.cocoa.OS;
21 22
22 /** 23 /**
23 * Instances of this class are used to inform or warn the user. 24 * Instances of this class are used to inform or warn the user.
24 * <dl> 25 * <dl>
36 * ICON_WARNING and ICON_WORKING may be specified. 37 * ICON_WARNING and ICON_WORKING may be specified.
37 * </p><p> 38 * </p><p>
38 * IMPORTANT: This class is intended to be subclassed <em>only</em> 39 * IMPORTANT: This class is intended to be subclassed <em>only</em>
39 * within the DWT implementation. 40 * within the DWT implementation.
40 * </p> 41 * </p>
42 *
43 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample, Dialog tab</a>
44 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
41 */ 45 */
42 public class MessageBox : Dialog { 46 public class MessageBox : Dialog {
43 String message = ""; 47 String message = "";
44 48
45 49
82 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> 86 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
83 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> 87 * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
84 * </ul> 88 * </ul>
85 */ 89 */
86 public this (Shell parent, int style) { 90 public this (Shell parent, int style) {
87 super (parent, checkStyle (style)); 91 super (parent, checkStyle (parent, checkStyle (style)));
88 checkSubclass (); 92 checkSubclass ();
89 } 93 }
90 94
91 static int checkStyle (int style) { 95 static int checkStyle (int style) {
92 if ((style & (DWT.PRIMARY_MODAL | DWT.APPLICATION_MODAL | DWT.SYSTEM_MODAL)) is 0) style |= DWT.APPLICATION_MODAL;
93 int mask = (DWT.YES | DWT.NO | DWT.OK | DWT.CANCEL | DWT.ABORT | DWT.RETRY | DWT.IGNORE); 96 int mask = (DWT.YES | DWT.NO | DWT.OK | DWT.CANCEL | DWT.ABORT | DWT.RETRY | DWT.IGNORE);
94 int bits = style & mask; 97 int bits = style & mask;
95 if (bits is DWT.OK || bits is DWT.CANCEL || bits is (DWT.OK | DWT.CANCEL)) return style; 98 if (bits is DWT.OK || bits is DWT.CANCEL || bits is (DWT.OK | DWT.CANCEL)) return style;
96 if (bits is DWT.YES || bits is DWT.NO || bits is (DWT.YES | DWT.NO) || bits is (DWT.YES | DWT.NO | DWT.CANCEL)) return style; 99 if (bits is DWT.YES || bits is DWT.NO || bits is (DWT.YES | DWT.NO) || bits is (DWT.YES | DWT.NO | DWT.CANCEL)) return style;
97 if (bits is (DWT.RETRY | DWT.CANCEL) || bits is (DWT.ABORT | DWT.RETRY | DWT.IGNORE)) return style; 100 if (bits is (DWT.RETRY | DWT.CANCEL) || bits is (DWT.ABORT | DWT.RETRY | DWT.IGNORE)) return style;
134 int bits = style & mask; 137 int bits = style & mask;
135 switch (bits) { 138 switch (bits) {
136 case DWT.OK: 139 case DWT.OK:
137 break; 140 break;
138 case DWT.CANCEL: 141 case DWT.CANCEL:
139 defaultButton = NSString.stringWith(DWT.getMessage("SWT_Cancel")); 142 defaultButton = NSString.stringWith(DWT.getMessage("DWT_Cancel"));
140 break; 143 break;
141 case DWT.OK | DWT.CANCEL: 144 case DWT.OK | DWT.CANCEL:
142 alternateButton = NSString.stringWith(DWT.getMessage("SWT_Cancel")); 145 alternateButton = NSString.stringWith(DWT.getMessage("DWT_Cancel"));
143 break; 146 break;
144 case DWT.YES: 147 case DWT.YES:
145 defaultButton = NSString.stringWith(DWT.getMessage("SWT_Yes")); 148 defaultButton = NSString.stringWith(DWT.getMessage("DWT_Yes"));
146 break; 149 break;
147 case DWT.NO: 150 case DWT.NO:
148 defaultButton = NSString.stringWith(DWT.getMessage("SWT_No")); 151 defaultButton = NSString.stringWith(DWT.getMessage("DWT_No"));
149 break; 152 break;
150 case DWT.YES | DWT.NO: 153 case DWT.YES | DWT.NO:
151 defaultButton = NSString.stringWith(DWT.getMessage("SWT_Yes")); 154 defaultButton = NSString.stringWith(DWT.getMessage("DWT_Yes"));
152 alternateButton = NSString.stringWith(DWT.getMessage("SWT_No")); 155 alternateButton = NSString.stringWith(DWT.getMessage("DWT_No"));
153 break; 156 break;
154 case DWT.YES | DWT.NO | DWT.CANCEL: 157 case DWT.YES | DWT.NO | DWT.CANCEL:
155 defaultButton = NSString.stringWith(DWT.getMessage("SWT_Yes")); 158 defaultButton = NSString.stringWith(DWT.getMessage("DWT_Yes"));
156 alternateButton = NSString.stringWith(DWT.getMessage("SWT_No")); 159 alternateButton = NSString.stringWith(DWT.getMessage("DWT_No"));
157 otherButton = NSString.stringWith(DWT.getMessage("SWT_Cancel")); 160 otherButton = NSString.stringWith(DWT.getMessage("DWT_Cancel"));
158 break; 161 break;
159 case DWT.RETRY | DWT.CANCEL: 162 case DWT.RETRY | DWT.CANCEL:
160 defaultButton = NSString.stringWith(DWT.getMessage("SWT_Retry")); 163 defaultButton = NSString.stringWith(DWT.getMessage("DWT_Retry"));
161 alternateButton = NSString.stringWith(DWT.getMessage("SWT_Cancel")); 164 alternateButton = NSString.stringWith(DWT.getMessage("DWT_Cancel"));
162 break; 165 break;
163 case DWT.ABORT | DWT.RETRY | DWT.IGNORE: 166 case DWT.ABORT | DWT.RETRY | DWT.IGNORE:
164 defaultButton = NSString.stringWith(DWT.getMessage("SWT_Abort")); 167 defaultButton = NSString.stringWith(DWT.getMessage("DWT_Abort"));
165 alternateButton = NSString.stringWith(DWT.getMessage("SWT_Retry")); 168 alternateButton = NSString.stringWith(DWT.getMessage("DWT_Retry"));
166 otherButton = NSString.stringWith(DWT.getMessage("SWT_Ignore")); 169 otherButton = NSString.stringWith(DWT.getMessage("DWT_Ignore"));
167 break; 170 break;
168 } 171 }
169 NSString title = NSString.stringWith(this.title !is null ? this.title : ""); 172 NSString title = NSString.stringWith(this.title !is null ? this.title : "");
170 NSString message = NSString.stringWith(this.message !is null ? this.message : ""); 173 NSString message = NSString.stringWith(this.message !is null ? this.message : "");
171 NSAlert alert = NSAlert.alertWithMessageText(title, defaultButton, alternateButton, otherButton, message); 174 NSAlert alert = NSAlert.alertWithMessageText(NSString.stringWith(""), defaultButton, alternateButton, otherButton, message);
175 new NSWindow(alert.window().id).setTitle(title);
172 alert.setAlertStyle(alertType); 176 alert.setAlertStyle(alertType);
173 int response = alert.runModal(); 177 int response = (int)/*64*/alert.runModal();
174 switch (bits) { 178 switch (bits) {
175 case DWT.OK: 179 case DWT.OK:
176 switch (response) { 180 switch (response) {
177 case OS.NSAlertDefaultReturn: 181 case OS.NSAlertDefaultReturn:
178 return DWT.OK; 182 return DWT.OK;