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