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