]> git.saurik.com Git - wxWidgets.git/blame - src/mac/msgdlg.cpp
Use a delegate instead of manually adding notifications. Not only is this
[wxWidgets.git] / src / mac / 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 ;
b7aec135 125 param.cancelText = (CFStringRef) kAlertDefaultCancelText ;
e40298d5
JS
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 {
e40298d5 200 param.defaultText = (StringPtr) kAlertDefaultOKText ;
b7aec135 201 param.cancelText = (StringPtr) kAlertDefaultCancelText ;
e40298d5
JS
202 param.otherText = NULL;
203 param.helpButton = false ;
204 param.defaultButton = kAlertStdAlertOKButton;
205 param.cancelButton = 0;
206 }
207 else
208 {
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 }
217 else
218 {
219 return resultbutton ;
220 }
221
222 param.position = 0;
223
224 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
225 }
226
227 if (m_dialogStyle & wxOK)
228 {
229 if (m_dialogStyle & wxCANCEL)
230 {
231 //TODO add Cancelbutton
232 switch( result )
233 {
234 case 1 :
235 resultbutton = wxID_OK ;
236 break ;
237 case 2 :
238 break ;
239 case 3 :
240 break ;
241 }
242 }
243 else
244 {
245 switch( result )
246 {
247 case 1 :
248 resultbutton = wxID_OK ;
249 break ;
250 case 2 :
251 break ;
252 case 3 :
253 break ;
254 }
255 }
256 }
257 else if (m_dialogStyle & wxYES_NO)
258 {
259 if (m_dialogStyle & wxCANCEL)
260 {
261 switch( result )
262 {
263 case 1 :
264 resultbutton = wxID_YES ;
265 break ;
266 case 2 :
267 resultbutton = wxID_CANCEL ;
268 break ;
269 case 3 :
270 resultbutton = wxID_NO ;
271 break ;
272 }
273 }
274 else
275 {
276 switch( result )
277 {
278 case 1 :
279 resultbutton = wxID_YES ;
280 break ;
281 case 2 :
282 break ;
283 case 3 :
284 resultbutton = wxID_NO ;
285 break ;
286 }
287 }
288 }
289
290 return resultbutton ;
e9576ca5
SC
291}
292