]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/msgdlg.cpp
switch to pImpl pattern for mac printing
[wxWidgets.git] / src / mac / carbon / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-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 short language = 0 ;
26
27 void wxMacConvertNewlines( const char *source , char * destination ) ;
28 void wxMacConvertNewlines( const char *source , char * destination )
29 {
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 ;
53 }
54
55 wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
56 long style, const wxPoint& pos)
57 {
58 m_caption = caption;
59 m_message = message;
60 m_dialogStyle = style;
61 m_parent = parent;
62 }
63
64 int wxMessageDialog::ShowModal()
65 {
66 int resultbutton = wxID_CANCEL ;
67
68 short result ;
69
70 wxASSERT_MSG( ( m_dialogStyle & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
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
82 #if TARGET_CARBON
83 if ( UMAGetSystemVersion() >= 0x1000 )
84 {
85 AlertStdCFStringAlertParamRec param ;
86 wxMacCFStringHolder cfNoString(_("No")) ;
87 wxMacCFStringHolder cfYesString( _("Yes")) ;
88
89 wxMacCFStringHolder cfTitle(m_caption);
90 wxMacCFStringHolder cfText(m_message);
91
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 }
118 // the msw implementation even shows an ok button if it is not specified, we'll do the same
119 else
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 }
141 /*
142 else
143 {
144 skipDialog = true ;
145 }
146 */
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 }
155 if ( skipDialog )
156 return wxID_CANCEL ;
157 }
158 else
159 #endif
160 {
161 AlertStdAlertParamRec param;
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 ) ;
171 wxMacStringToPascal( m_message , pascalText ) ;
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 ;
292 }
293