]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/msgdlg.cpp
mingw32 compilation fixes
[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 #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 strcpy( (char*) pascalTitle , m_caption ) ;
76 c2pstr( (char*) pascalTitle ) ;
77 strcpy( (char*) pascalText , m_message ) ;
78 wxMacConvertNewlines( (char*)pascalText ,(char*) pascalText) ;
79 c2pstr( (char*) pascalText ) ;
80
81 if ( !UMAHasAppearance() )
82 {
83 int resourceID ;
84
85 if (m_dialogStyle & wxYES_NO)
86 {
87 if (m_dialogStyle & wxCANCEL)
88 resourceID = kMacYesNoCancelAlertResourceID;
89 else
90 resourceID = kMacYesNoAlertResourceID + language * 10 ;
91 }
92 else if (m_dialogStyle & wxOK)
93 {
94 if (m_dialogStyle & wxCANCEL)
95 resourceID = kMacOKAlertResourceID; // wrong
96 else
97 resourceID = kMacOKAlertResourceID;
98 }
99 else
100 {
101 return resultbutton ;
102 }
103 /*
104 if (hWnd)
105 msStyle |= MB_APPLMODAL;
106 else
107 msStyle |= MB_TASKMODAL;
108 */
109
110 ParamText( pascalTitle , pascalText , NULL , NULL ) ;
111
112 if (m_dialogStyle & wxICON_EXCLAMATION)
113 result = Alert( resourceID , NULL ) ;
114 else if (m_dialogStyle & wxICON_HAND)
115 result = StopAlert( resourceID , NULL ) ;
116 else if (m_dialogStyle & wxICON_INFORMATION)
117 result = NoteAlert( resourceID , NULL ) ;
118 else if (m_dialogStyle & wxICON_QUESTION)
119 result = CautionAlert( resourceID , NULL ) ;
120 else
121 result = Alert( resourceID , NULL ) ;
122
123 resultbutton = result ;
124
125 if (m_dialogStyle & wxYES_NO)
126 {
127 if (m_dialogStyle & wxCANCEL)
128 {
129 switch( result )
130 {
131 case 1 :
132 resultbutton = wxID_YES ;
133 break ;
134 case 2 :
135 resultbutton = wxID_NO ;
136 break ;
137 case 3 :
138 resultbutton = wxID_CANCEL ;
139 break ;
140 }
141 }
142 else
143 {
144 switch( result )
145 {
146 case 1 :
147 resultbutton = wxID_YES ;
148 break ;
149 case 2 :
150 resultbutton = wxID_NO ;
151 break ;
152 case 3 :
153 break ;
154 }
155 }
156 }
157 }
158 else
159 {
160 AlertStdAlertParamRec param;
161
162 param.movable = true;
163 param.filterProc = NULL ;
164
165 if (m_dialogStyle & wxYES_NO)
166 {
167 if (m_dialogStyle & wxCANCEL)
168 {
169 param.defaultText = "\pYes" ;
170 param.cancelText = (StringPtr) kAlertDefaultCancelText;
171 param.otherText = "\pNo";
172 param.helpButton = false ;
173 param.defaultButton = kAlertStdAlertOKButton;
174 param.cancelButton = kAlertStdAlertCancelButton;
175 }
176 else
177 {
178 param.defaultText = "\pYes" ;
179 param.cancelText = NULL;
180 param.otherText = "\pNo";
181 param.helpButton = false ;
182 param.defaultButton = kAlertStdAlertOKButton;
183 param.cancelButton = 0;
184 }
185 }
186 else if (m_dialogStyle & wxOK)
187 {
188 if (m_dialogStyle & wxCANCEL)
189 {
190 // thats a cancel missing
191 param.defaultText = (StringPtr) kAlertDefaultOKText ;
192 param.cancelText = NULL;
193 param.otherText = NULL;
194 param.helpButton = false ;
195 param.defaultButton = kAlertStdAlertOKButton;
196 param.cancelButton = 0;
197 }
198 else
199 {
200 param.defaultText = (StringPtr) kAlertDefaultOKText ;
201 param.cancelText = NULL;
202 param.otherText = NULL;
203 param.helpButton = false ;
204 param.defaultButton = kAlertStdAlertOKButton;
205 param.cancelButton = 0;
206 }
207 }
208 else
209 {
210 return resultbutton ;
211 }
212
213 param.position = 0;
214
215 if (m_dialogStyle & wxICON_EXCLAMATION)
216 StandardAlert( kAlertNoteAlert, pascalTitle, pascalText, &param, &result );
217 else if (m_dialogStyle & wxICON_HAND)
218 StandardAlert( kAlertStopAlert, pascalTitle, pascalText, &param, &result );
219 else if (m_dialogStyle & wxICON_INFORMATION)
220 StandardAlert( kAlertNoteAlert, pascalTitle, pascalText, &param, &result );
221 else if (m_dialogStyle & wxICON_QUESTION)
222 StandardAlert( kAlertCautionAlert, pascalTitle, pascalText, &param, &result );
223 else
224 StandardAlert( kAlertPlainAlert, pascalTitle, pascalText, &param, &result );
225
226 if (m_dialogStyle & wxOK)
227 {
228 if (m_dialogStyle & wxCANCEL)
229 {
230 //TODO add Cancelbutton
231 switch( result )
232 {
233 case 1 :
234 resultbutton = wxID_OK ;
235 break ;
236 case 2 :
237 break ;
238 case 3 :
239 break ;
240 }
241 }
242 else
243 {
244 switch( result )
245 {
246 case 1 :
247 resultbutton = wxID_OK ;
248 break ;
249 case 2 :
250 break ;
251 case 3 :
252 break ;
253 }
254 }
255 }
256 else if (m_dialogStyle & wxYES_NO)
257 {
258 if (m_dialogStyle & wxCANCEL)
259 {
260 switch( result )
261 {
262 case 1 :
263 resultbutton = wxID_YES ;
264 break ;
265 case 2 :
266 resultbutton = wxID_CANCEL ;
267 break ;
268 case 3 :
269 resultbutton = wxID_NO ;
270 break ;
271 }
272 }
273 else
274 {
275 switch( result )
276 {
277 case 1 :
278 resultbutton = wxID_YES ;
279 break ;
280 case 2 :
281 break ;
282 case 3 :
283 resultbutton = wxID_NO ;
284 break ;
285 }
286 }
287 }
288 }
289 return resultbutton ;
290 }
291