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