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