]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/msgdlg.cpp
removed code refreshing toolbar on every MDI child move -- no idea why was it there...
[wxWidgets.git] / src / mac / carbon / msgdlg.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/mac/carbon/msgdlg.cpp
e9576ca5 3// Purpose: wxMessageDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
e5b50758 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e5b50758 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
03e11df5 14#include "wx/app.h"
e9576ca5 15#include "wx/msgdlg.h"
49e95e1d 16#include "wx/intl.h"
519cb848 17#include "wx/mac/uma.h"
e9576ca5 18
e9576ca5 19IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
e9576ca5
SC
20
21wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
e40298d5 22 long style, const wxPoint& pos)
e9576ca5
SC
23{
24 m_caption = caption;
25 m_message = message;
e9576ca5 26 m_parent = parent;
e5b50758 27 SetMessageDialogStyle(style);
e9576ca5
SC
28}
29
30int wxMessageDialog::ShowModal()
31{
e40298d5 32 int resultbutton = wxID_CANCEL ;
e5b50758 33
e5b50758
WS
34 const long style = GetMessageDialogStyle();
35
36 wxASSERT_MSG( ( style & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
37
e40298d5 38 AlertType alertType = kAlertPlainAlert ;
e5b50758 39 if (style & wxICON_EXCLAMATION)
e40298d5 40 alertType = kAlertNoteAlert ;
e5b50758 41 else if (style & wxICON_HAND)
e40298d5 42 alertType = kAlertStopAlert ;
e5b50758 43 else if (style & wxICON_INFORMATION)
e40298d5 44 alertType = kAlertNoteAlert ;
e5b50758 45 else if (style & wxICON_QUESTION)
e40298d5 46 alertType = kAlertCautionAlert ;
e5b50758 47
57a21e6c
SC
48#if TARGET_API_MAC_OSX
49 CFStringRef defaultButtonTitle = NULL ;
50 CFStringRef alternateButtonTitle = NULL ;
51 CFStringRef otherButtonTitle = NULL ;
52
53 wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
54 wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());
55
56 wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ;
57 wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ;
58 wxMacCFStringHolder cfCancelString( _("Cancel") , m_font.GetEncoding()) ;
59
60 int buttonId[4] = { 0 , 0 , 0 , wxID_CANCEL /* time-out */ } ;
61
62 if (style & wxYES_NO)
63 {
64 if ( style & wxNO_DEFAULT )
65 {
66 defaultButtonTitle = cfNoString ;
67 alternateButtonTitle = cfYesString ;
68 buttonId[0] = wxID_NO ;
69 buttonId[1] = wxID_YES ;
70 }
71 else
72 {
73 defaultButtonTitle = cfYesString ;
74 alternateButtonTitle = cfNoString ;
75 buttonId[0] = wxID_YES ;
76 buttonId[1] = wxID_NO ;
77 }
78 if (style & wxCANCEL)
79 {
80 otherButtonTitle = cfCancelString ;
81 buttonId[2] = wxID_CANCEL ;
82 }
83 }
84 else
85 {
86 // the msw implementation even shows an ok button if it is not specified, we'll do the same
87 buttonId[0] = wxID_OK ;
88 if (style & wxCANCEL)
89 {
90 alternateButtonTitle = cfCancelString ;
91 buttonId[1] = wxID_CANCEL ;
92 }
93 }
94
95 CFOptionFlags exitButton ;
96 OSStatus err = CFUserNotificationDisplayAlert ( 0 , alertType , NULL , NULL , NULL , cfTitle , cfText ,
97 defaultButtonTitle , alternateButtonTitle , otherButtonTitle , &exitButton );
98 if ( err == noErr )
99 resultbutton = buttonId[exitButton] ;
100
101#else
102 short result ;
103
992c81e2 104#if TARGET_CARBON
e40298d5
JS
105 if ( UMAGetSystemVersion() >= 0x1000 )
106 {
107 AlertStdCFStringAlertParamRec param ;
a9412f8f
SC
108 wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ;
109 wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ;
e5b50758 110
a9412f8f
SC
111 wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
112 wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());
e5b50758 113
e40298d5
JS
114 param.movable = true;
115 param.flags = 0 ;
939a2e80 116 param.version = kStdCFStringAlertVersionOne ;
e5b50758 117
e40298d5 118 bool skipDialog = false ;
e5b50758
WS
119
120 if (style & wxYES_NO)
e40298d5 121 {
e5b50758 122 if (style & wxCANCEL)
e40298d5
JS
123 {
124 param.defaultText = cfYesString ;
125 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
126 param.otherText = cfNoString ;
127 param.helpButton = false ;
e5b50758 128 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
e40298d5
JS
129 param.cancelButton = kAlertStdAlertCancelButton;
130 }
131 else
132 {
133 param.defaultText = cfYesString ;
134 param.cancelText = NULL;
135 param.otherText = cfNoString ;
136 param.helpButton = false ;
e5b50758 137 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
e40298d5
JS
138 param.cancelButton = 0;
139 }
140 }
c4a49e11 141 // the msw implementation even shows an ok button if it is not specified, we'll do the same
e5b50758 142 else
e40298d5 143 {
e5b50758 144 if (style & wxCANCEL)
e40298d5
JS
145 {
146 // thats a cancel missing
147 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
b7aec135 148 param.cancelText = (CFStringRef) kAlertDefaultCancelText ;
e40298d5
JS
149 param.otherText = NULL;
150 param.helpButton = false ;
151 param.defaultButton = kAlertStdAlertOKButton;
152 param.cancelButton = 0;
153 }
154 else
155 {
156 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
157 param.cancelText = NULL;
158 param.otherText = NULL;
159 param.helpButton = false ;
160 param.defaultButton = kAlertStdAlertOKButton;
161 param.cancelButton = 0;
162 }
163 }
c4a49e11 164 /*
e40298d5
JS
165 else
166 {
167 skipDialog = true ;
168 }
c4a49e11 169 */
e5b50758 170
e40298d5
JS
171 param.position = kWindowDefaultPosition;
172 if ( !skipDialog )
173 {
174 DialogRef alertRef ;
175 CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
176 RunStandardAlert( alertRef , NULL , &result ) ;
177 }
e5b50758 178 if ( skipDialog )
e40298d5
JS
179 return wxID_CANCEL ;
180 }
181 else
992c81e2 182#endif
e40298d5
JS
183 {
184 AlertStdAlertParamRec param;
e5b50758 185
e40298d5
JS
186 Str255 yesPString ;
187 Str255 noPString ;
e5b50758 188
e40298d5
JS
189 Str255 pascalTitle ;
190 Str255 pascalText ;
191 wxMacStringToPascal( m_caption , pascalTitle ) ;
192 wxMacStringToPascal( _("Yes") , yesPString ) ;
193 wxMacStringToPascal( _("No") , noPString ) ;
427ff662 194 wxMacStringToPascal( m_message , pascalText ) ;
e5b50758 195
e40298d5
JS
196 param.movable = true;
197 param.filterProc = NULL ;
e5b50758 198 if (style & wxYES_NO)
e40298d5 199 {
e5b50758 200 if (style & wxCANCEL)
e40298d5
JS
201 {
202 param.defaultText = yesPString ;
203 param.cancelText = (StringPtr) kAlertDefaultCancelText;
204 param.otherText = noPString ;
205 param.helpButton = false ;
206 param.defaultButton = kAlertStdAlertOKButton;
207 param.cancelButton = kAlertStdAlertCancelButton;
208 }
209 else
210 {
211 param.defaultText = yesPString ;
212 param.cancelText = NULL;
213 param.otherText = noPString ;
214 param.helpButton = false ;
215 param.defaultButton = kAlertStdAlertOKButton;
216 param.cancelButton = 0;
217 }
218 }
e5b50758 219 else if (style & wxOK)
e40298d5 220 {
e5b50758 221 if (style & wxCANCEL)
e40298d5 222 {
e40298d5 223 param.defaultText = (StringPtr) kAlertDefaultOKText ;
b7aec135 224 param.cancelText = (StringPtr) kAlertDefaultCancelText ;
e40298d5
JS
225 param.otherText = NULL;
226 param.helpButton = false ;
227 param.defaultButton = kAlertStdAlertOKButton;
228 param.cancelButton = 0;
229 }
230 else
231 {
232 param.defaultText = (StringPtr) kAlertDefaultOKText ;
233 param.cancelText = NULL;
234 param.otherText = NULL;
235 param.helpButton = false ;
236 param.defaultButton = kAlertStdAlertOKButton;
237 param.cancelButton = 0;
238 }
239 }
240 else
241 {
242 return resultbutton ;
243 }
e5b50758 244
e40298d5 245 param.position = 0;
e5b50758 246
e40298d5
JS
247 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
248 }
e5b50758
WS
249
250 if (style & wxOK)
e40298d5 251 {
e5b50758 252 if (style & wxCANCEL)
e40298d5
JS
253 {
254 //TODO add Cancelbutton
255 switch( result )
256 {
257 case 1 :
258 resultbutton = wxID_OK ;
259 break ;
260 case 2 :
261 break ;
262 case 3 :
263 break ;
264 }
265 }
266 else
267 {
268 switch( result )
269 {
270 case 1 :
271 resultbutton = wxID_OK ;
272 break ;
273 case 2 :
274 break ;
275 case 3 :
276 break ;
277 }
278 }
279 }
e5b50758 280 else if (style & wxYES_NO)
e40298d5 281 {
e5b50758 282 if (style & wxCANCEL)
e40298d5
JS
283 {
284 switch( result )
285 {
286 case 1 :
287 resultbutton = wxID_YES ;
288 break ;
289 case 2 :
290 resultbutton = wxID_CANCEL ;
291 break ;
292 case 3 :
293 resultbutton = wxID_NO ;
294 break ;
295 }
296 }
297 else
298 {
299 switch( result )
300 {
301 case 1 :
302 resultbutton = wxID_YES ;
303 break ;
304 case 2 :
305 break ;
306 case 3 :
307 resultbutton = wxID_NO ;
308 break ;
309 }
310 }
e5b50758 311 }
57a21e6c
SC
312#endif
313
e40298d5 314 return resultbutton ;
e9576ca5
SC
315}
316