]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/msgdlg.cpp
Exit on error was too strict.
[wxWidgets.git] / src / mac / classic / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/msgdlg.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/app.h"
20 #endif
21
22 #include "wx/mac/uma.h"
23
24 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
25
26 wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
27 long style, const wxPoint& pos)
28 {
29 m_caption = caption;
30 m_message = message;
31 m_parent = parent;
32 SetMessageDialogStyle(style);
33 }
34
35 int wxMessageDialog::ShowModal()
36 {
37 int resultbutton = wxID_CANCEL ;
38
39 short result ;
40
41 const long style = GetMessageDialogStyle();
42
43 wxASSERT_MSG( ( style & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
44
45 AlertType alertType = kAlertPlainAlert ;
46 if (style & wxICON_EXCLAMATION)
47 alertType = kAlertNoteAlert ;
48 else if (style & wxICON_HAND)
49 alertType = kAlertStopAlert ;
50 else if (style & wxICON_INFORMATION)
51 alertType = kAlertNoteAlert ;
52 else if (style & wxICON_QUESTION)
53 alertType = kAlertCautionAlert ;
54
55 #if TARGET_CARBON
56 if ( UMAGetSystemVersion() >= 0x1000 )
57 {
58 AlertStdCFStringAlertParamRec param ;
59 wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ;
60 wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ;
61
62 wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
63 wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());
64
65 param.movable = true;
66 param.flags = 0 ;
67
68 bool skipDialog = false ;
69
70 if (style & wxYES_NO)
71 {
72 if (style & wxCANCEL)
73 {
74 param.defaultText = cfYesString ;
75 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
76 param.otherText = cfNoString ;
77 param.helpButton = false ;
78 param.defaultButton = kAlertStdAlertOKButton;
79 param.cancelButton = kAlertStdAlertCancelButton;
80 }
81 else
82 {
83 param.defaultText = cfYesString ;
84 param.cancelText = NULL;
85 param.otherText = cfNoString ;
86 param.helpButton = false ;
87 param.defaultButton = kAlertStdAlertOKButton;
88 param.cancelButton = 0;
89 }
90 }
91 // the msw implementation even shows an ok button if it is not specified, we'll do the same
92 else
93 {
94 if (style & wxCANCEL)
95 {
96 // thats a cancel missing
97 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
98 param.cancelText = (CFStringRef) kAlertDefaultCancelText ;
99 param.otherText = NULL;
100 param.helpButton = false ;
101 param.defaultButton = kAlertStdAlertOKButton;
102 param.cancelButton = 0;
103 }
104 else
105 {
106 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
107 param.cancelText = NULL;
108 param.otherText = NULL;
109 param.helpButton = false ;
110 param.defaultButton = kAlertStdAlertOKButton;
111 param.cancelButton = 0;
112 }
113 }
114 /*
115 else
116 {
117 skipDialog = true ;
118 }
119 */
120
121 param.position = kWindowDefaultPosition;
122 if ( !skipDialog )
123 {
124 DialogRef alertRef ;
125 CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
126 RunStandardAlert( alertRef , NULL , &result ) ;
127 }
128 if ( skipDialog )
129 return wxID_CANCEL ;
130 }
131 else
132 #endif
133 {
134 AlertStdAlertParamRec param;
135
136 Str255 yesPString ;
137 Str255 noPString ;
138
139 Str255 pascalTitle ;
140 Str255 pascalText ;
141 wxMacStringToPascal( m_caption , pascalTitle ) ;
142 wxMacStringToPascal( _("Yes") , yesPString ) ;
143 wxMacStringToPascal( _("No") , noPString ) ;
144 wxMacStringToPascal( m_message , pascalText ) ;
145
146 param.movable = true;
147 param.filterProc = NULL ;
148 if (style & wxYES_NO)
149 {
150 if (style & wxCANCEL)
151 {
152 param.defaultText = yesPString ;
153 param.cancelText = (StringPtr) kAlertDefaultCancelText;
154 param.otherText = noPString ;
155 param.helpButton = false ;
156 param.defaultButton = kAlertStdAlertOKButton;
157 param.cancelButton = kAlertStdAlertCancelButton;
158 }
159 else
160 {
161 param.defaultText = yesPString ;
162 param.cancelText = NULL;
163 param.otherText = noPString ;
164 param.helpButton = false ;
165 param.defaultButton = kAlertStdAlertOKButton;
166 param.cancelButton = 0;
167 }
168 }
169 else if (style & wxOK)
170 {
171 if (style & wxCANCEL)
172 {
173 param.defaultText = (StringPtr) kAlertDefaultOKText ;
174 param.cancelText = (StringPtr) kAlertDefaultCancelText ;
175 param.otherText = NULL;
176 param.helpButton = false ;
177 param.defaultButton = kAlertStdAlertOKButton;
178 param.cancelButton = 0;
179 }
180 else
181 {
182 param.defaultText = (StringPtr) kAlertDefaultOKText ;
183 param.cancelText = NULL;
184 param.otherText = NULL;
185 param.helpButton = false ;
186 param.defaultButton = kAlertStdAlertOKButton;
187 param.cancelButton = 0;
188 }
189 }
190 else
191 {
192 return resultbutton ;
193 }
194
195 param.position = 0;
196
197 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
198 }
199
200 if (style & wxOK)
201 {
202 if (style & wxCANCEL)
203 {
204 //TODO add Cancelbutton
205 switch( result )
206 {
207 case 1 :
208 resultbutton = wxID_OK ;
209 break ;
210 case 2 :
211 break ;
212 case 3 :
213 break ;
214 }
215 }
216 else
217 {
218 switch( result )
219 {
220 case 1 :
221 resultbutton = wxID_OK ;
222 break ;
223 case 2 :
224 break ;
225 case 3 :
226 break ;
227 }
228 }
229 }
230 else if (style & wxYES_NO)
231 {
232 if (style & wxCANCEL)
233 {
234 switch( result )
235 {
236 case 1 :
237 resultbutton = wxID_YES ;
238 break ;
239 case 2 :
240 resultbutton = wxID_CANCEL ;
241 break ;
242 case 3 :
243 resultbutton = wxID_NO ;
244 break ;
245 }
246 }
247 else
248 {
249 switch( result )
250 {
251 case 1 :
252 resultbutton = wxID_YES ;
253 break ;
254 case 2 :
255 break ;
256 case 3 :
257 resultbutton = wxID_NO ;
258 break ;
259 }
260 }
261 }
262
263 return resultbutton ;
264 }