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