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