]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/msgdlg.cpp
added OnMouse which will trigger context menu events, added better DoMenuPopup implem...
[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 , "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 CFStringRef cfNoString = NULL ;
87 CFStringRef cfYesString = NULL ;
88
89 CFStringRef cfTitle = NULL;
90 CFStringRef cfText = NULL;
91
92 cfTitle = wxMacCreateCFString( m_caption ) ;
93 cfText = wxMacCreateCFString( m_message ) ;
94 cfNoString = wxMacCreateCFString( _("No") ) ;
95 cfYesString = wxMacCreateCFString( _("Yes") ) ;
96
97 param.movable = true;
98 param.flags = 0 ;
99
100 bool skipDialog = false ;
101
102 if (m_dialogStyle & wxYES_NO)
103 {
104 if (m_dialogStyle & wxCANCEL)
105 {
106 param.defaultText = cfYesString ;
107 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
108 param.otherText = cfNoString ;
109 param.helpButton = false ;
110 param.defaultButton = kAlertStdAlertOKButton;
111 param.cancelButton = kAlertStdAlertCancelButton;
112 }
113 else
114 {
115 param.defaultText = cfYesString ;
116 param.cancelText = NULL;
117 param.otherText = cfNoString ;
118 param.helpButton = false ;
119 param.defaultButton = kAlertStdAlertOKButton;
120 param.cancelButton = 0;
121 }
122 }
123 else if (m_dialogStyle & wxOK)
124 {
125 if (m_dialogStyle & wxCANCEL)
126 {
127 // thats a cancel missing
128 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
129 param.cancelText = NULL;
130 param.otherText = NULL;
131 param.helpButton = false ;
132 param.defaultButton = kAlertStdAlertOKButton;
133 param.cancelButton = 0;
134 }
135 else
136 {
137 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
138 param.cancelText = NULL;
139 param.otherText = NULL;
140 param.helpButton = false ;
141 param.defaultButton = kAlertStdAlertOKButton;
142 param.cancelButton = 0;
143 }
144 }
145 else
146 {
147 skipDialog = true ;
148 }
149
150 param.position = kWindowDefaultPosition;
151 if ( !skipDialog )
152 {
153 DialogRef alertRef ;
154 CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
155 RunStandardAlert( alertRef , NULL , &result ) ;
156 }
157 if(cfTitle != NULL)
158 CFRelease(cfTitle);
159 if(cfText != NULL)
160 CFRelease(cfText);
161 if(cfNoString != NULL)
162 CFRelease(cfNoString);
163 if(cfYesString != NULL)
164 CFRelease(cfYesString);
165 if ( skipDialog )
166 return wxID_CANCEL ;
167 }
168 else
169 #endif
170 {
171 AlertStdAlertParamRec param;
172 char cText[2048] ;
173
174 if (wxApp::s_macDefaultEncodingIsPC)
175 {
176 strcpy(cText , wxMacMakeMacStringFromPC( m_message) ) ;
177 }
178 else
179 {
180 strcpy( cText , m_message ) ;
181 }
182 wxMacConvertNewlines( cText , cText ) ;
183
184 Str255 yesPString ;
185 Str255 noPString ;
186
187 Str255 pascalTitle ;
188 Str255 pascalText ;
189 wxMacStringToPascal( m_caption , pascalTitle ) ;
190 wxMacStringToPascal( _("Yes") , yesPString ) ;
191 wxMacStringToPascal( _("No") , noPString ) ;
192 CopyCStringToPascal( cText , pascalText ) ;
193
194 param.movable = true;
195 param.filterProc = NULL ;
196 if (m_dialogStyle & wxYES_NO)
197 {
198 if (m_dialogStyle & wxCANCEL)
199 {
200 param.defaultText = yesPString ;
201 param.cancelText = (StringPtr) kAlertDefaultCancelText;
202 param.otherText = noPString ;
203 param.helpButton = false ;
204 param.defaultButton = kAlertStdAlertOKButton;
205 param.cancelButton = kAlertStdAlertCancelButton;
206 }
207 else
208 {
209 param.defaultText = yesPString ;
210 param.cancelText = NULL;
211 param.otherText = noPString ;
212 param.helpButton = false ;
213 param.defaultButton = kAlertStdAlertOKButton;
214 param.cancelButton = 0;
215 }
216 }
217 else if (m_dialogStyle & wxOK)
218 {
219 if (m_dialogStyle & wxCANCEL)
220 {
221 // thats a cancel missing
222 param.defaultText = (StringPtr) kAlertDefaultOKText ;
223 param.cancelText = NULL;
224 param.otherText = NULL;
225 param.helpButton = false ;
226 param.defaultButton = kAlertStdAlertOKButton;
227 param.cancelButton = 0;
228 }
229 else
230 {
231 param.defaultText = (StringPtr) kAlertDefaultOKText ;
232 param.cancelText = NULL;
233 param.otherText = NULL;
234 param.helpButton = false ;
235 param.defaultButton = kAlertStdAlertOKButton;
236 param.cancelButton = 0;
237 }
238 }
239 else
240 {
241 return resultbutton ;
242 }
243
244 param.position = 0;
245
246 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
247 }
248
249 if (m_dialogStyle & wxOK)
250 {
251 if (m_dialogStyle & wxCANCEL)
252 {
253 //TODO add Cancelbutton
254 switch( result )
255 {
256 case 1 :
257 resultbutton = wxID_OK ;
258 break ;
259 case 2 :
260 break ;
261 case 3 :
262 break ;
263 }
264 }
265 else
266 {
267 switch( result )
268 {
269 case 1 :
270 resultbutton = wxID_OK ;
271 break ;
272 case 2 :
273 break ;
274 case 3 :
275 break ;
276 }
277 }
278 }
279 else if (m_dialogStyle & wxYES_NO)
280 {
281 if (m_dialogStyle & wxCANCEL)
282 {
283 switch( result )
284 {
285 case 1 :
286 resultbutton = wxID_YES ;
287 break ;
288 case 2 :
289 resultbutton = wxID_CANCEL ;
290 break ;
291 case 3 :
292 resultbutton = wxID_NO ;
293 break ;
294 }
295 }
296 else
297 {
298 switch( result )
299 {
300 case 1 :
301 resultbutton = wxID_YES ;
302 break ;
303 case 2 :
304 break ;
305 case 3 :
306 resultbutton = wxID_NO ;
307 break ;
308 }
309 }
310 }
311
312 return resultbutton ;
313 }
314