]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/mac/carbon/msgdlg.cpp | |
3 | // Purpose: wxMessageDialog | |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/wxprec.h" | |
13 | ||
14 | #include "wx/app.h" | |
15 | #include "wx/msgdlg.h" | |
16 | #include "wx/intl.h" | |
17 | #include "wx/mac/uma.h" | |
18 | ||
19 | ||
20 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) | |
21 | ||
22 | ||
23 | wxMessageDialog::wxMessageDialog( | |
24 | wxWindow *parent, const wxString& message, const wxString& caption, | |
25 | long style, const wxPoint& pos ) | |
26 | { | |
27 | m_caption = caption; | |
28 | m_message = message; | |
29 | m_parent = parent; | |
30 | SetMessageDialogStyle(style); | |
31 | } | |
32 | ||
33 | int wxMessageDialog::ShowModal() | |
34 | { | |
35 | int resultbutton = wxID_CANCEL; | |
36 | ||
37 | const long style = GetMessageDialogStyle(); | |
38 | ||
39 | wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") ); | |
40 | ||
41 | AlertType alertType = kAlertPlainAlert; | |
42 | if (style & wxICON_EXCLAMATION) | |
43 | alertType = kAlertNoteAlert; | |
44 | else if (style & wxICON_HAND) | |
45 | alertType = kAlertStopAlert; | |
46 | else if (style & wxICON_INFORMATION) | |
47 | alertType = kAlertNoteAlert; | |
48 | else if (style & wxICON_QUESTION) | |
49 | alertType = kAlertCautionAlert; | |
50 | ||
51 | #if TARGET_API_MAC_OSX | |
52 | CFStringRef defaultButtonTitle = NULL; | |
53 | CFStringRef alternateButtonTitle = NULL; | |
54 | CFStringRef otherButtonTitle = NULL; | |
55 | ||
56 | wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); | |
57 | wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); | |
58 | ||
59 | wxMacCFStringHolder cfNoString( wxT("No"), m_font.GetEncoding() ); | |
60 | wxMacCFStringHolder cfYesString( wxT("Yes"), m_font.GetEncoding() ); | |
61 | wxMacCFStringHolder cfCancelString( wxT("Cancel"), m_font.GetEncoding() ); | |
62 | ||
63 | int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; | |
64 | ||
65 | if (style & wxYES_NO) | |
66 | { | |
67 | if ( style & wxNO_DEFAULT ) | |
68 | { | |
69 | defaultButtonTitle = cfNoString; | |
70 | alternateButtonTitle = cfYesString; | |
71 | buttonId[0] = wxID_NO; | |
72 | buttonId[1] = wxID_YES; | |
73 | } | |
74 | else | |
75 | { | |
76 | defaultButtonTitle = cfYesString; | |
77 | alternateButtonTitle = cfNoString; | |
78 | buttonId[0] = wxID_YES; | |
79 | buttonId[1] = wxID_NO; | |
80 | } | |
81 | if (style & wxCANCEL) | |
82 | { | |
83 | otherButtonTitle = cfCancelString; | |
84 | buttonId[2] = wxID_CANCEL; | |
85 | } | |
86 | } | |
87 | else | |
88 | { | |
89 | // the MSW implementation even shows an OK button if it is not specified, we'll do the same | |
90 | buttonId[0] = wxID_OK; | |
91 | if (style & wxCANCEL) | |
92 | { | |
93 | alternateButtonTitle = cfCancelString; | |
94 | buttonId[1] = wxID_CANCEL; | |
95 | } | |
96 | } | |
97 | ||
98 | CFOptionFlags exitButton; | |
99 | OSStatus err = CFUserNotificationDisplayAlert( | |
100 | 0, alertType, NULL, NULL, NULL, cfTitle, cfText, | |
101 | defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton ); | |
102 | if (err == noErr) | |
103 | resultbutton = buttonId[exitButton]; | |
104 | ||
105 | #else | |
106 | short result; | |
107 | ||
108 | #if TARGET_CARBON | |
109 | if ( UMAGetSystemVersion() >= 0x1000 ) | |
110 | { | |
111 | AlertStdCFStringAlertParamRec param; | |
112 | wxMacCFStringHolder cfNoString( wxT("No"), m_font.GetEncoding() ); | |
113 | wxMacCFStringHolder cfYesString( wxT("Yes"), m_font.GetEncoding() ); | |
114 | ||
115 | wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); | |
116 | wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); | |
117 | ||
118 | param.movable = true; | |
119 | param.flags = 0; | |
120 | param.version = kStdCFStringAlertVersionOne; | |
121 | ||
122 | bool skipDialog = false; | |
123 | ||
124 | if (style & wxYES_NO) | |
125 | { | |
126 | if (style & wxCANCEL) | |
127 | { | |
128 | param.defaultText = cfYesString; | |
129 | param.cancelText = (CFStringRef) kAlertDefaultCancelText; | |
130 | param.otherText = cfNoString; | |
131 | param.helpButton = false; | |
132 | param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; | |
133 | param.cancelButton = kAlertStdAlertCancelButton; | |
134 | } | |
135 | else | |
136 | { | |
137 | param.defaultText = cfYesString; | |
138 | param.cancelText = NULL; | |
139 | param.otherText = cfNoString; | |
140 | param.helpButton = false; | |
141 | param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; | |
142 | param.cancelButton = 0; | |
143 | } | |
144 | } | |
145 | // the MSW implementation even shows an OK button if it is not specified, we'll do the same | |
146 | else | |
147 | { | |
148 | if (style & wxCANCEL) | |
149 | { | |
150 | // that's a cancel missing | |
151 | param.defaultText = (CFStringRef) kAlertDefaultOKText; | |
152 | param.cancelText = (CFStringRef) kAlertDefaultCancelText; | |
153 | param.otherText = NULL; | |
154 | param.helpButton = false; | |
155 | param.defaultButton = kAlertStdAlertOKButton; | |
156 | param.cancelButton = 0; | |
157 | } | |
158 | else | |
159 | { | |
160 | param.defaultText = (CFStringRef) kAlertDefaultOKText; | |
161 | param.cancelText = NULL; | |
162 | param.otherText = NULL; | |
163 | param.helpButton = false; | |
164 | param.defaultButton = kAlertStdAlertOKButton; | |
165 | param.cancelButton = 0; | |
166 | } | |
167 | } | |
168 | #if 0 | |
169 | else | |
170 | { | |
171 | skipDialog = true; | |
172 | } | |
173 | #endif | |
174 | ||
175 | param.position = kWindowDefaultPosition; | |
176 | if ( !skipDialog ) | |
177 | { | |
178 | DialogRef alertRef; | |
179 | CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); | |
180 | RunStandardAlert( alertRef, NULL, &result ); | |
181 | } | |
182 | else | |
183 | { | |
184 | return wxID_CANCEL; | |
185 | } | |
186 | } | |
187 | else | |
188 | #endif | |
189 | { | |
190 | AlertStdAlertParamRec param; | |
191 | Str255 yesPString, noPString; | |
192 | Str255 pascalTitle, pascalText; | |
193 | ||
194 | wxMacStringToPascal( m_caption, pascalTitle ); | |
195 | wxMacStringToPascal( wxT("Yes"), yesPString ); | |
196 | wxMacStringToPascal( wxT("No"), noPString ); | |
197 | wxMacStringToPascal( m_message, pascalText ); | |
198 | ||
199 | param.movable = true; | |
200 | param.filterProc = NULL; | |
201 | ||
202 | if (style & wxYES_NO) | |
203 | { | |
204 | if (style & wxCANCEL) | |
205 | { | |
206 | param.defaultText = yesPString; | |
207 | param.cancelText = (StringPtr) kAlertDefaultCancelText; | |
208 | param.otherText = noPString; | |
209 | param.helpButton = false; | |
210 | param.defaultButton = kAlertStdAlertOKButton; | |
211 | param.cancelButton = kAlertStdAlertCancelButton; | |
212 | } | |
213 | else | |
214 | { | |
215 | param.defaultText = yesPString; | |
216 | param.cancelText = NULL; | |
217 | param.otherText = noPString; | |
218 | param.helpButton = false; | |
219 | param.defaultButton = kAlertStdAlertOKButton; | |
220 | param.cancelButton = 0; | |
221 | } | |
222 | } | |
223 | else if (style & wxOK) | |
224 | { | |
225 | if (style & wxCANCEL) | |
226 | { | |
227 | param.defaultText = (StringPtr) kAlertDefaultOKText; | |
228 | param.cancelText = (StringPtr) kAlertDefaultCancelText; | |
229 | param.otherText = NULL; | |
230 | param.helpButton = false; | |
231 | param.defaultButton = kAlertStdAlertOKButton; | |
232 | param.cancelButton = 0; | |
233 | } | |
234 | else | |
235 | { | |
236 | param.defaultText = (StringPtr) kAlertDefaultOKText; | |
237 | param.cancelText = NULL; | |
238 | param.otherText = NULL; | |
239 | param.helpButton = false; | |
240 | param.defaultButton = kAlertStdAlertOKButton; | |
241 | param.cancelButton = 0; | |
242 | } | |
243 | } | |
244 | else | |
245 | { | |
246 | return resultbutton; | |
247 | } | |
248 | ||
249 | param.position = 0; | |
250 | StandardAlert( alertType, pascalTitle, pascalText, ¶m, &result ); | |
251 | } | |
252 | ||
253 | if (style & wxOK) | |
254 | { | |
255 | switch ( result ) | |
256 | { | |
257 | case 1: | |
258 | resultbutton = wxID_OK; | |
259 | break; | |
260 | ||
261 | case 2: | |
262 | // TODO: add Cancel button | |
263 | // if (style & wxCANCEL) | |
264 | // resultbutton = wxID_CANCEL; | |
265 | break; | |
266 | ||
267 | case 3: | |
268 | default: | |
269 | break; | |
270 | } | |
271 | } | |
272 | else if (style & wxYES_NO) | |
273 | { | |
274 | switch ( result ) | |
275 | { | |
276 | case 1: | |
277 | resultbutton = wxID_YES; | |
278 | break; | |
279 | ||
280 | case 2: | |
281 | if (!(style & wxCANCEL)) | |
282 | resultbutton = wxID_CANCEL; | |
283 | break; | |
284 | ||
285 | case 3: | |
286 | resultbutton = wxID_NO; | |
287 | break; | |
288 | ||
289 | default: | |
290 | break; | |
291 | } | |
292 | } | |
293 | #endif | |
294 | ||
295 | return resultbutton; | |
296 | } | |
297 |