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