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