]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/msgdlg.cpp
Added dash support
[wxWidgets.git] / src / mac / carbon / msgdlg.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: msgdlg.cpp
3// Purpose: wxMessageDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $$
a31a5f85 8// Copyright: (c) Stefan Csomor
e40298d5 9// Licence: wxWindows licence
e9576ca5
SC
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
25short language = 0 ;
26
3d2791f1 27void wxMacConvertNewlines( const char *source , char * destination ) ;
519cb848
SC
28void wxMacConvertNewlines( const char *source , char * destination )
29{
e40298d5
JS
30 const char *s = source ;
31 char *d = destination ;
32
33 while( *s )
34 {
35 switch( *s )
36 {
37 case 0x0a :
38 *d++ = 0x0d ;
39 ++s ;
40 break ;
41 case 0x0d :
42 *d++ = 0x0d ;
43 ++s ;
44 if ( *s == 0x0a )
45 ++s ;
46 break ;
47 default :
48 *d++ = *s++ ;
49 break ;
50 }
51 }
52 *d = 0 ;
519cb848
SC
53}
54
e9576ca5 55wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
e40298d5 56 long style, const wxPoint& pos)
e9576ca5
SC
57{
58 m_caption = caption;
59 m_message = message;
60 m_dialogStyle = style;
61 m_parent = parent;
62}
63
64int wxMessageDialog::ShowModal()
65{
e40298d5
JS
66 int resultbutton = wxID_CANCEL ;
67
68 short result ;
69
427ff662 70 wxASSERT_MSG( ( m_dialogStyle & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
e40298d5
JS
71
72 AlertType alertType = kAlertPlainAlert ;
73 if (m_dialogStyle & wxICON_EXCLAMATION)
74 alertType = kAlertNoteAlert ;
75 else if (m_dialogStyle & wxICON_HAND)
76 alertType = kAlertStopAlert ;
77 else if (m_dialogStyle & wxICON_INFORMATION)
78 alertType = kAlertNoteAlert ;
79 else if (m_dialogStyle & wxICON_QUESTION)
80 alertType = kAlertCautionAlert ;
81
992c81e2 82#if TARGET_CARBON
e40298d5
JS
83 if ( UMAGetSystemVersion() >= 0x1000 )
84 {
85 AlertStdCFStringAlertParamRec param ;
427ff662
SC
86 wxMacCFStringHolder cfNoString(_("No")) ;
87 wxMacCFStringHolder cfYesString( _("Yes")) ;
e40298d5 88
427ff662
SC
89 wxMacCFStringHolder cfTitle(m_caption);
90 wxMacCFStringHolder cfText(m_message);
91
e40298d5
JS
92 param.movable = true;
93 param.flags = 0 ;
94
95 bool skipDialog = false ;
96
97 if (m_dialogStyle & wxYES_NO)
98 {
99 if (m_dialogStyle & wxCANCEL)
100 {
101 param.defaultText = cfYesString ;
102 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
103 param.otherText = cfNoString ;
104 param.helpButton = false ;
105 param.defaultButton = kAlertStdAlertOKButton;
106 param.cancelButton = kAlertStdAlertCancelButton;
107 }
108 else
109 {
110 param.defaultText = cfYesString ;
111 param.cancelText = NULL;
112 param.otherText = cfNoString ;
113 param.helpButton = false ;
114 param.defaultButton = kAlertStdAlertOKButton;
115 param.cancelButton = 0;
116 }
117 }
c4a49e11
SC
118 // the msw implementation even shows an ok button if it is not specified, we'll do the same
119 else
e40298d5
JS
120 {
121 if (m_dialogStyle & wxCANCEL)
122 {
123 // thats a cancel missing
124 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
125 param.cancelText = NULL;
126 param.otherText = NULL;
127 param.helpButton = false ;
128 param.defaultButton = kAlertStdAlertOKButton;
129 param.cancelButton = 0;
130 }
131 else
132 {
133 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
134 param.cancelText = NULL;
135 param.otherText = NULL;
136 param.helpButton = false ;
137 param.defaultButton = kAlertStdAlertOKButton;
138 param.cancelButton = 0;
139 }
140 }
c4a49e11 141 /*
e40298d5
JS
142 else
143 {
144 skipDialog = true ;
145 }
c4a49e11 146 */
e40298d5
JS
147
148 param.position = kWindowDefaultPosition;
149 if ( !skipDialog )
150 {
151 DialogRef alertRef ;
152 CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
153 RunStandardAlert( alertRef , NULL , &result ) ;
154 }
427ff662 155 if ( skipDialog )
e40298d5
JS
156 return wxID_CANCEL ;
157 }
158 else
992c81e2 159#endif
e40298d5
JS
160 {
161 AlertStdAlertParamRec param;
e40298d5
JS
162
163 Str255 yesPString ;
164 Str255 noPString ;
165
166 Str255 pascalTitle ;
167 Str255 pascalText ;
168 wxMacStringToPascal( m_caption , pascalTitle ) ;
169 wxMacStringToPascal( _("Yes") , yesPString ) ;
170 wxMacStringToPascal( _("No") , noPString ) ;
427ff662 171 wxMacStringToPascal( m_message , pascalText ) ;
e40298d5
JS
172
173 param.movable = true;
174 param.filterProc = NULL ;
175 if (m_dialogStyle & wxYES_NO)
176 {
177 if (m_dialogStyle & wxCANCEL)
178 {
179 param.defaultText = yesPString ;
180 param.cancelText = (StringPtr) kAlertDefaultCancelText;
181 param.otherText = noPString ;
182 param.helpButton = false ;
183 param.defaultButton = kAlertStdAlertOKButton;
184 param.cancelButton = kAlertStdAlertCancelButton;
185 }
186 else
187 {
188 param.defaultText = yesPString ;
189 param.cancelText = NULL;
190 param.otherText = noPString ;
191 param.helpButton = false ;
192 param.defaultButton = kAlertStdAlertOKButton;
193 param.cancelButton = 0;
194 }
195 }
196 else if (m_dialogStyle & wxOK)
197 {
198 if (m_dialogStyle & wxCANCEL)
199 {
200 // thats a cancel missing
201 param.defaultText = (StringPtr) kAlertDefaultOKText ;
202 param.cancelText = NULL;
203 param.otherText = NULL;
204 param.helpButton = false ;
205 param.defaultButton = kAlertStdAlertOKButton;
206 param.cancelButton = 0;
207 }
208 else
209 {
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 }
218 else
219 {
220 return resultbutton ;
221 }
222
223 param.position = 0;
224
225 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
226 }
227
228 if (m_dialogStyle & wxOK)
229 {
230 if (m_dialogStyle & wxCANCEL)
231 {
232 //TODO add Cancelbutton
233 switch( result )
234 {
235 case 1 :
236 resultbutton = wxID_OK ;
237 break ;
238 case 2 :
239 break ;
240 case 3 :
241 break ;
242 }
243 }
244 else
245 {
246 switch( result )
247 {
248 case 1 :
249 resultbutton = wxID_OK ;
250 break ;
251 case 2 :
252 break ;
253 case 3 :
254 break ;
255 }
256 }
257 }
258 else if (m_dialogStyle & wxYES_NO)
259 {
260 if (m_dialogStyle & wxCANCEL)
261 {
262 switch( result )
263 {
264 case 1 :
265 resultbutton = wxID_YES ;
266 break ;
267 case 2 :
268 resultbutton = wxID_CANCEL ;
269 break ;
270 case 3 :
271 resultbutton = wxID_NO ;
272 break ;
273 }
274 }
275 else
276 {
277 switch( result )
278 {
279 case 1 :
280 resultbutton = wxID_YES ;
281 break ;
282 case 2 :
283 break ;
284 case 3 :
285 resultbutton = wxID_NO ;
286 break ;
287 }
288 }
289 }
290
291 return resultbutton ;
e9576ca5
SC
292}
293