]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/msgdlg.cpp
another new version of wxStringTokenizer (with tests and docs)
[wxWidgets.git] / src / mac / carbon / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: AUTHOR
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "msgdlg.h"
14 #endif
15
16 #include "wx/msgdlg.h"
17 #include "wx/mac/uma.h"
18
19 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
20
21 #define kMacOKAlertResourceID 128
22 #define kMacYesNoAlertResourceID 129
23 #define kMacYesNoCancelAlertResourceID 130
24 #define kMacNoYesAlertResourceID 131
25 #define kMacNoYesCancelAlertResourceID 132
26
27 short language = 0 ;
28
29 void wxMacConvertNewlines( const char *source , char * destination )
30 {
31 const char *s = source ;
32 char *d = destination ;
33
34 while( *s )
35 {
36 switch( *s )
37 {
38 case 0x0a :
39 *d++ = 0x0d ;
40 ++s ;
41 break ;
42 case 0x0d :
43 *d++ = 0x0d ;
44 ++s ;
45 if ( *s == 0x0a )
46 ++s ;
47 break ;
48 default :
49 *d++ = *s++ ;
50 break ;
51 }
52 }
53 *d = 0 ;
54 }
55
56 wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
57 long style, const wxPoint& pos)
58 {
59 m_caption = caption;
60 m_message = message;
61 m_dialogStyle = style;
62 m_parent = parent;
63 }
64
65 int wxMessageDialog::ShowModal()
66 {
67 int resultbutton = wxID_CANCEL ;
68
69 short result ;
70 Str255 pascalTitle ;
71 Str255 pascalText ;
72
73
74 if (wxApp::s_macDefaultEncodingIsPC)
75 {
76 strcpy( (char*) pascalTitle , wxMacMakeMacStringFromPC( m_caption ) ) ;
77 strcpy( (char*) pascalText , wxMacMakeMacStringFromPC( m_message) ) ;
78 }
79 else
80 {
81 strcpy( (char*) pascalTitle , m_caption ) ;
82 strcpy( (char*) pascalText , m_message ) ;
83 }
84
85 c2pstr( (char*) pascalTitle ) ;
86 wxMacConvertNewlines( (char*)pascalText ,(char*) pascalText) ;
87 c2pstr( (char*) pascalText ) ;
88
89 wxASSERT_MSG( ( m_dialogStyle & 0x3F ) != wxYES , "this style is not supported on mac" ) ;
90
91 if ( !UMAHasAppearance() )
92 {
93 int resourceID ;
94
95 if (m_dialogStyle & wxYES_NO)
96 {
97 if (m_dialogStyle & wxCANCEL)
98 resourceID = kMacYesNoCancelAlertResourceID;
99 else
100 resourceID = kMacYesNoAlertResourceID + language * 10 ;
101 }
102 else if (m_dialogStyle & wxOK)
103 {
104 if (m_dialogStyle & wxCANCEL)
105 resourceID = kMacOKAlertResourceID; // wrong
106 else
107 resourceID = kMacOKAlertResourceID;
108 }
109 else
110 {
111 return resultbutton ;
112 }
113 /*
114 if (hWnd)
115 msStyle |= MB_APPLMODAL;
116 else
117 msStyle |= MB_TASKMODAL;
118 */
119
120 ParamText( pascalTitle , pascalText , NULL , NULL ) ;
121
122 if (m_dialogStyle & wxICON_EXCLAMATION)
123 result = Alert( resourceID , NULL ) ;
124 else if (m_dialogStyle & wxICON_HAND)
125 result = StopAlert( resourceID , NULL ) ;
126 else if (m_dialogStyle & wxICON_INFORMATION)
127 result = NoteAlert( resourceID , NULL ) ;
128 else if (m_dialogStyle & wxICON_QUESTION)
129 result = CautionAlert( resourceID , NULL ) ;
130 else
131 result = Alert( resourceID , NULL ) ;
132
133 resultbutton = result ;
134
135 if (m_dialogStyle & wxYES_NO)
136 {
137 if (m_dialogStyle & wxCANCEL)
138 {
139 switch( result )
140 {
141 case 1 :
142 resultbutton = wxID_YES ;
143 break ;
144 case 2 :
145 resultbutton = wxID_NO ;
146 break ;
147 case 3 :
148 resultbutton = wxID_CANCEL ;
149 break ;
150 }
151 }
152 else
153 {
154 switch( result )
155 {
156 case 1 :
157 resultbutton = wxID_YES ;
158 break ;
159 case 2 :
160 resultbutton = wxID_NO ;
161 break ;
162 case 3 :
163 break ;
164 }
165 }
166 }
167 }
168 else
169 {
170 AlertStdAlertParamRec param;
171
172 param.movable = true;
173 param.filterProc = NULL ;
174
175 if (m_dialogStyle & wxYES_NO)
176 {
177 if (m_dialogStyle & wxCANCEL)
178 {
179 param.defaultText = "\pYes" ;
180 param.cancelText = (StringPtr) kAlertDefaultCancelText;
181 param.otherText = "\pNo";
182 param.helpButton = false ;
183 param.defaultButton = kAlertStdAlertOKButton;
184 param.cancelButton = kAlertStdAlertCancelButton;
185 }
186 else
187 {
188 param.defaultText = "\pYes" ;
189 param.cancelText = NULL;
190 param.otherText = "\pNo";
191 param.helpButton = false ;
192 param.defaultButton = kAlertStdAlertOKButton;
193 param.cancelButton = 0;
194 }
195 }
196 else if (m_dialogStyle & wxOK)
197 {
198 if (m_dialogStyle & wxCANCEL)
199 {
200 // thats a cancel missing
201 param.defaultText = (StringPtr) kAlertDefaultOKText ;
202 param.cancelText = NULL;
203 param.otherText = NULL;
204 param.helpButton = false ;
205 param.defaultButton = kAlertStdAlertOKButton;
206 param.cancelButton = 0;
207 }
208 else
209 {
210 param.defaultText = (StringPtr) kAlertDefaultOKText ;
211 param.cancelText = NULL;
212 param.otherText = NULL;
213 param.helpButton = false ;
214 param.defaultButton = kAlertStdAlertOKButton;
215 param.cancelButton = 0;
216 }
217 }
218 else
219 {
220 return resultbutton ;
221 }
222
223 param.position = 0;
224
225 if (m_dialogStyle & wxICON_EXCLAMATION)
226 StandardAlert( kAlertNoteAlert, pascalTitle, pascalText, &param, &result );
227 else if (m_dialogStyle & wxICON_HAND)
228 StandardAlert( kAlertStopAlert, pascalTitle, pascalText, &param, &result );
229 else if (m_dialogStyle & wxICON_INFORMATION)
230 StandardAlert( kAlertNoteAlert, pascalTitle, pascalText, &param, &result );
231 else if (m_dialogStyle & wxICON_QUESTION)
232 StandardAlert( kAlertCautionAlert, pascalTitle, pascalText, &param, &result );
233 else
234 StandardAlert( kAlertPlainAlert, pascalTitle, pascalText, &param, &result );
235
236 if (m_dialogStyle & wxOK)
237 {
238 if (m_dialogStyle & wxCANCEL)
239 {
240 //TODO add Cancelbutton
241 switch( result )
242 {
243 case 1 :
244 resultbutton = wxID_OK ;
245 break ;
246 case 2 :
247 break ;
248 case 3 :
249 break ;
250 }
251 }
252 else
253 {
254 switch( result )
255 {
256 case 1 :
257 resultbutton = wxID_OK ;
258 break ;
259 case 2 :
260 break ;
261 case 3 :
262 break ;
263 }
264 }
265 }
266 else if (m_dialogStyle & wxYES_NO)
267 {
268 if (m_dialogStyle & wxCANCEL)
269 {
270 switch( result )
271 {
272 case 1 :
273 resultbutton = wxID_YES ;
274 break ;
275 case 2 :
276 resultbutton = wxID_CANCEL ;
277 break ;
278 case 3 :
279 resultbutton = wxID_NO ;
280 break ;
281 }
282 }
283 else
284 {
285 switch( result )
286 {
287 case 1 :
288 resultbutton = wxID_YES ;
289 break ;
290 case 2 :
291 break ;
292 case 3 :
293 resultbutton = wxID_NO ;
294 break ;
295 }
296 }
297 }
298 }
299 return resultbutton ;
300 }
301