]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/msgdlg.cpp
Accidently checked for invalid image index rather than using the mask.
[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 #include "wx/app.h"
19 #endif
20
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( _("No"), m_font.GetEncoding() );
64 wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() );
65 wxMacCFStringHolder cfOKString( _("OK") , m_font.GetEncoding()) ;
66 wxMacCFStringHolder cfCancelString( _("Cancel"), m_font.GetEncoding() );
67
68 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
69
70 if (style & wxYES_NO)
71 {
72 if ( style & wxNO_DEFAULT )
73 {
74 defaultButtonTitle = cfNoString;
75 alternateButtonTitle = cfYesString;
76 buttonId[0] = wxID_NO;
77 buttonId[1] = wxID_YES;
78 }
79 else
80 {
81 defaultButtonTitle = cfYesString;
82 alternateButtonTitle = cfNoString;
83 buttonId[0] = wxID_YES;
84 buttonId[1] = wxID_NO;
85 }
86 if (style & wxCANCEL)
87 {
88 otherButtonTitle = cfCancelString;
89 buttonId[2] = wxID_CANCEL;
90 }
91 }
92 else
93 {
94 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
95 buttonId[0] = wxID_OK;
96 // using null as default title does not work on earlier systems
97 defaultButtonTitle = cfOKString;
98 if (style & wxCANCEL)
99 {
100 alternateButtonTitle = cfCancelString;
101 buttonId[1] = wxID_CANCEL;
102 }
103 }
104
105 CFOptionFlags exitButton;
106 OSStatus err = CFUserNotificationDisplayAlert(
107 0, alertType, NULL, NULL, NULL, cfTitle, cfText,
108 defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton );
109 if (err == noErr)
110 resultbutton = buttonId[exitButton];
111
112 #else
113 short result;
114
115 #if TARGET_CARBON
116 if ( UMAGetSystemVersion() >= 0x1000 )
117 {
118 AlertStdCFStringAlertParamRec param;
119 wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() );
120 wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() );
121
122 wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() );
123 wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() );
124
125 param.movable = true;
126 param.flags = 0;
127 param.version = kStdCFStringAlertVersionOne;
128
129 bool skipDialog = false;
130
131 if (style & wxYES_NO)
132 {
133 if (style & wxCANCEL)
134 {
135 param.defaultText = cfYesString;
136 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
137 param.otherText = cfNoString;
138 param.helpButton = false;
139 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
140 param.cancelButton = kAlertStdAlertCancelButton;
141 }
142 else
143 {
144 param.defaultText = cfYesString;
145 param.cancelText = NULL;
146 param.otherText = cfNoString;
147 param.helpButton = false;
148 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
149 param.cancelButton = 0;
150 }
151 }
152 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
153 else
154 {
155 if (style & wxCANCEL)
156 {
157 // that's a cancel missing
158 param.defaultText = (CFStringRef) kAlertDefaultOKText;
159 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
160 param.otherText = NULL;
161 param.helpButton = false;
162 param.defaultButton = kAlertStdAlertOKButton;
163 param.cancelButton = 0;
164 }
165 else
166 {
167 param.defaultText = (CFStringRef) kAlertDefaultOKText;
168 param.cancelText = NULL;
169 param.otherText = NULL;
170 param.helpButton = false;
171 param.defaultButton = kAlertStdAlertOKButton;
172 param.cancelButton = 0;
173 }
174 }
175 #if 0
176 else
177 {
178 skipDialog = true;
179 }
180 #endif
181
182 param.position = kWindowDefaultPosition;
183 if ( !skipDialog )
184 {
185 DialogRef alertRef;
186 CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
187 RunStandardAlert( alertRef, NULL, &result );
188 }
189 else
190 {
191 return wxID_CANCEL;
192 }
193 }
194 else
195 #endif
196 {
197 AlertStdAlertParamRec param;
198 Str255 yesPString, noPString;
199 Str255 pascalTitle, pascalText;
200
201 wxMacStringToPascal( m_caption, pascalTitle );
202 wxMacStringToPascal( _("Yes"), yesPString );
203 wxMacStringToPascal( _("No"), noPString );
204 wxMacStringToPascal( m_message, pascalText );
205
206 param.movable = true;
207 param.filterProc = NULL;
208
209 if (style & wxYES_NO)
210 {
211 if (style & wxCANCEL)
212 {
213 param.defaultText = yesPString;
214 param.cancelText = (StringPtr) kAlertDefaultCancelText;
215 param.otherText = noPString;
216 param.helpButton = false;
217 param.defaultButton = kAlertStdAlertOKButton;
218 param.cancelButton = kAlertStdAlertCancelButton;
219 }
220 else
221 {
222 param.defaultText = yesPString;
223 param.cancelText = NULL;
224 param.otherText = noPString;
225 param.helpButton = false;
226 param.defaultButton = kAlertStdAlertOKButton;
227 param.cancelButton = 0;
228 }
229 }
230 else if (style & wxOK)
231 {
232 if (style & wxCANCEL)
233 {
234 param.defaultText = (StringPtr) kAlertDefaultOKText;
235 param.cancelText = (StringPtr) kAlertDefaultCancelText;
236 param.otherText = NULL;
237 param.helpButton = false;
238 param.defaultButton = kAlertStdAlertOKButton;
239 param.cancelButton = 0;
240 }
241 else
242 {
243 param.defaultText = (StringPtr) kAlertDefaultOKText;
244 param.cancelText = NULL;
245 param.otherText = NULL;
246 param.helpButton = false;
247 param.defaultButton = kAlertStdAlertOKButton;
248 param.cancelButton = 0;
249 }
250 }
251 else
252 {
253 return resultbutton;
254 }
255
256 param.position = 0;
257 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
258 }
259
260 if (style & wxOK)
261 {
262 switch ( result )
263 {
264 case 1:
265 resultbutton = wxID_OK;
266 break;
267
268 case 2:
269 // TODO: add Cancel button
270 // if (style & wxCANCEL)
271 // resultbutton = wxID_CANCEL;
272 break;
273
274 case 3:
275 default:
276 break;
277 }
278 }
279 else if (style & wxYES_NO)
280 {
281 switch ( result )
282 {
283 case 1:
284 resultbutton = wxID_YES;
285 break;
286
287 case 2:
288 if (!(style & wxCANCEL))
289 resultbutton = wxID_CANCEL;
290 break;
291
292 case 3:
293 resultbutton = wxID_NO;
294 break;
295
296 default:
297 break;
298 }
299 }
300 #endif
301
302 return resultbutton;
303 }