]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/msgdlg.cpp
focus setting must be possible even when not shown yet
[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 = (CFStringRef) kAlertDefaultCancelText ;
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 param.defaultText = (StringPtr) kAlertDefaultOKText ;
201 param.cancelText = (StringPtr) kAlertDefaultCancelText ;
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 ;
291 }
292