]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/msgdlg.cpp
Explicitly forward non-command events along to the native control first.
[wxWidgets.git] / src / mac / carbon / msgdlg.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/mac/carbon/msgdlg.cpp
e9576ca5 3// Purpose: wxMessageDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
e5b50758 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e5b50758 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
e9576ca5 14#include "wx/msgdlg.h"
88a7a4e1
WS
15
16#ifndef WX_PRECOMP
17 #include "wx/intl.h"
670f9935 18 #include "wx/app.h"
88a7a4e1
WS
19#endif
20
519cb848 21#include "wx/mac/uma.h"
e9576ca5 22
51c4d2a5 23
e9576ca5 24IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
e9576ca5 25
51c4d2a5
DS
26
27wxMessageDialog::wxMessageDialog(
28 wxWindow *parent, const wxString& message, const wxString& caption,
29 long style, const wxPoint& pos )
e9576ca5
SC
30{
31 m_caption = caption;
32 m_message = message;
e9576ca5 33 m_parent = parent;
e5b50758 34 SetMessageDialogStyle(style);
e9576ca5
SC
35}
36
37int wxMessageDialog::ShowModal()
38{
51c4d2a5 39 int resultbutton = wxID_CANCEL;
e5b50758 40
e5b50758
WS
41 const long style = GetMessageDialogStyle();
42
51c4d2a5 43 wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
e5b50758 44
51c4d2a5 45 AlertType alertType = kAlertPlainAlert;
e5b50758 46 if (style & wxICON_EXCLAMATION)
51c4d2a5 47 alertType = kAlertNoteAlert;
e5b50758 48 else if (style & wxICON_HAND)
51c4d2a5 49 alertType = kAlertStopAlert;
e5b50758 50 else if (style & wxICON_INFORMATION)
51c4d2a5 51 alertType = kAlertNoteAlert;
e5b50758 52 else if (style & wxICON_QUESTION)
51c4d2a5 53 alertType = kAlertCautionAlert;
e5b50758 54
57a21e6c 55#if TARGET_API_MAC_OSX
51c4d2a5
DS
56 CFStringRef defaultButtonTitle = NULL;
57 CFStringRef alternateButtonTitle = NULL;
58 CFStringRef otherButtonTitle = NULL;
59
60 wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() );
61 wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() );
62
34cf96b2
SC
63 wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() );
64 wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() );
670f9935 65 wxMacCFStringHolder cfOKString( _("OK") , m_font.GetEncoding()) ;
34cf96b2 66 wxMacCFStringHolder cfCancelString( _("Cancel"), m_font.GetEncoding() );
51c4d2a5
DS
67
68 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
69
57a21e6c
SC
70 if (style & wxYES_NO)
71 {
72 if ( style & wxNO_DEFAULT )
73 {
51c4d2a5
DS
74 defaultButtonTitle = cfNoString;
75 alternateButtonTitle = cfYesString;
76 buttonId[0] = wxID_NO;
77 buttonId[1] = wxID_YES;
57a21e6c
SC
78 }
79 else
80 {
51c4d2a5
DS
81 defaultButtonTitle = cfYesString;
82 alternateButtonTitle = cfNoString;
83 buttonId[0] = wxID_YES;
84 buttonId[1] = wxID_NO;
57a21e6c
SC
85 }
86 if (style & wxCANCEL)
87 {
51c4d2a5
DS
88 otherButtonTitle = cfCancelString;
89 buttonId[2] = wxID_CANCEL;
57a21e6c
SC
90 }
91 }
92 else
93 {
51c4d2a5
DS
94 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
95 buttonId[0] = wxID_OK;
c8e597f8
SC
96 // using null as default title does not work on earlier systems
97 defaultButtonTitle = cfOKString;
57a21e6c
SC
98 if (style & wxCANCEL)
99 {
51c4d2a5
DS
100 alternateButtonTitle = cfCancelString;
101 buttonId[1] = wxID_CANCEL;
57a21e6c
SC
102 }
103 }
104
51c4d2a5
DS
105 CFOptionFlags exitButton;
106 OSStatus err = CFUserNotificationDisplayAlert(
107 0, alertType, NULL, NULL, NULL, cfTitle, cfText,
108 defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton );
109 if (err == noErr)
110 resultbutton = buttonId[exitButton];
57a21e6c
SC
111
112#else
51c4d2a5
DS
113 short result;
114
992c81e2 115#if TARGET_CARBON
e40298d5
JS
116 if ( UMAGetSystemVersion() >= 0x1000 )
117 {
51c4d2a5 118 AlertStdCFStringAlertParamRec param;
34cf96b2
SC
119 wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() );
120 wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() );
e5b50758 121
51c4d2a5
DS
122 wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() );
123 wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() );
e5b50758 124
e40298d5 125 param.movable = true;
51c4d2a5
DS
126 param.flags = 0;
127 param.version = kStdCFStringAlertVersionOne;
e5b50758 128
51c4d2a5 129 bool skipDialog = false;
e5b50758
WS
130
131 if (style & wxYES_NO)
e40298d5 132 {
e5b50758 133 if (style & wxCANCEL)
e40298d5 134 {
51c4d2a5
DS
135 param.defaultText = cfYesString;
136 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
137 param.otherText = cfNoString;
138 param.helpButton = false;
e5b50758 139 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
51c4d2a5 140 param.cancelButton = kAlertStdAlertCancelButton;
e40298d5
JS
141 }
142 else
143 {
51c4d2a5
DS
144 param.defaultText = cfYesString;
145 param.cancelText = NULL;
146 param.otherText = cfNoString;
147 param.helpButton = false;
e5b50758 148 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
51c4d2a5 149 param.cancelButton = 0;
e40298d5
JS
150 }
151 }
51c4d2a5 152 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
e5b50758 153 else
e40298d5 154 {
e5b50758 155 if (style & wxCANCEL)
e40298d5 156 {
51c4d2a5
DS
157 // that's a cancel missing
158 param.defaultText = (CFStringRef) kAlertDefaultOKText;
159 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
160 param.otherText = NULL;
161 param.helpButton = false;
e40298d5 162 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 163 param.cancelButton = 0;
e40298d5
JS
164 }
165 else
166 {
51c4d2a5
DS
167 param.defaultText = (CFStringRef) kAlertDefaultOKText;
168 param.cancelText = NULL;
169 param.otherText = NULL;
170 param.helpButton = false;
e40298d5 171 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 172 param.cancelButton = 0;
e40298d5
JS
173 }
174 }
51c4d2a5 175#if 0
e40298d5
JS
176 else
177 {
51c4d2a5 178 skipDialog = true;
e40298d5 179 }
51c4d2a5 180#endif
e5b50758 181
e40298d5
JS
182 param.position = kWindowDefaultPosition;
183 if ( !skipDialog )
184 {
51c4d2a5
DS
185 DialogRef alertRef;
186 CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
187 RunStandardAlert( alertRef, NULL, &result );
188 }
189 else
190 {
191 return wxID_CANCEL;
e40298d5 192 }
e40298d5
JS
193 }
194 else
992c81e2 195#endif
e40298d5 196 {
51c4d2a5
DS
197 AlertStdAlertParamRec param;
198 Str255 yesPString, noPString;
199 Str255 pascalTitle, pascalText;
e5b50758 200
51c4d2a5 201 wxMacStringToPascal( m_caption, pascalTitle );
34cf96b2
SC
202 wxMacStringToPascal( _("Yes"), yesPString );
203 wxMacStringToPascal( _("No"), noPString );
51c4d2a5 204 wxMacStringToPascal( m_message, pascalText );
e5b50758 205
51c4d2a5
DS
206 param.movable = true;
207 param.filterProc = NULL;
e5b50758 208
e5b50758 209 if (style & wxYES_NO)
e40298d5 210 {
e5b50758 211 if (style & wxCANCEL)
e40298d5 212 {
51c4d2a5
DS
213 param.defaultText = yesPString;
214 param.cancelText = (StringPtr) kAlertDefaultCancelText;
215 param.otherText = noPString;
216 param.helpButton = false;
e40298d5 217 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 218 param.cancelButton = kAlertStdAlertCancelButton;
e40298d5
JS
219 }
220 else
221 {
51c4d2a5
DS
222 param.defaultText = yesPString;
223 param.cancelText = NULL;
224 param.otherText = noPString;
225 param.helpButton = false;
e40298d5 226 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 227 param.cancelButton = 0;
e40298d5
JS
228 }
229 }
e5b50758 230 else if (style & wxOK)
e40298d5 231 {
e5b50758 232 if (style & wxCANCEL)
e40298d5 233 {
51c4d2a5
DS
234 param.defaultText = (StringPtr) kAlertDefaultOKText;
235 param.cancelText = (StringPtr) kAlertDefaultCancelText;
236 param.otherText = NULL;
237 param.helpButton = false;
e40298d5 238 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 239 param.cancelButton = 0;
e40298d5
JS
240 }
241 else
242 {
51c4d2a5
DS
243 param.defaultText = (StringPtr) kAlertDefaultOKText;
244 param.cancelText = NULL;
245 param.otherText = NULL;
246 param.helpButton = false;
e40298d5 247 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 248 param.cancelButton = 0;
e40298d5
JS
249 }
250 }
251 else
252 {
51c4d2a5 253 return resultbutton;
e40298d5 254 }
e5b50758 255
51c4d2a5 256 param.position = 0;
e40298d5
JS
257 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
258 }
e5b50758
WS
259
260 if (style & wxOK)
e40298d5 261 {
51c4d2a5 262 switch ( result )
e40298d5 263 {
51c4d2a5
DS
264 case 1:
265 resultbutton = wxID_OK;
266 break;
267
268 case 2:
269 // TODO: add Cancel button
270 // if (style & wxCANCEL)
271 // resultbutton = wxID_CANCEL;
272 break;
273
274 case 3:
275 default:
276 break;
e40298d5
JS
277 }
278 }
e5b50758 279 else if (style & wxYES_NO)
e40298d5 280 {
51c4d2a5 281 switch ( result )
e40298d5 282 {
51c4d2a5
DS
283 case 1:
284 resultbutton = wxID_YES;
285 break;
286
287 case 2:
288 if (!(style & wxCANCEL))
289 resultbutton = wxID_CANCEL;
290 break;
291
292 case 3:
293 resultbutton = wxID_NO;
294 break;
295
296 default:
297 break;
e40298d5 298 }
e5b50758 299 }
57a21e6c 300#endif
51c4d2a5
DS
301
302 return resultbutton;
e9576ca5 303}