]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/msgdlg.cpp
64 bit fixes
[wxWidgets.git] / src / mac / carbon / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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 #include "wx/wxprec.h"
13
14 #include "wx/msgdlg.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/app.h"
19 #endif
20
21 #include "wx/mac/uma.h"
22
23
24 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
25
26
27 wxMessageDialog::wxMessageDialog(wxWindow *parent,
28 const wxString& message,
29 const wxString& caption,
30 long style,
31 const wxPoint& WXUNUSED(pos))
32 : wxMessageDialogBase(parent, message, caption, style)
33 {
34 m_yes = _("Yes");
35 m_no = _("No");
36 m_ok = _("OK");
37 m_cancel = _("Cancel");
38 }
39
40 bool wxMessageDialog::SetYesNoLabels(const wxString& yes,const wxString& no)
41 {
42 m_yes = yes;
43 m_no = no;
44 return true;
45 }
46
47 bool wxMessageDialog::SetYesNoCancelLabels(const wxString& yes, const wxString& no, const wxString& cancel)
48 {
49 m_yes = yes;
50 m_no = no;
51 m_cancel = cancel;
52 return true;
53 }
54
55 bool wxMessageDialog::SetOKLabel(const wxString& ok)
56 {
57 m_ok = ok;
58 return true;
59 }
60
61 bool wxMessageDialog::SetOKCancelLabels(const wxString& ok, const wxString& cancel)
62 {
63 m_ok = ok;
64 m_cancel = cancel;
65 return true;
66 }
67
68 int wxMessageDialog::ShowModal()
69 {
70 int resultbutton = wxID_CANCEL;
71
72 const long style = GetMessageDialogStyle();
73
74 wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
75
76 AlertType alertType = kAlertPlainAlert;
77 if (style & wxICON_EXCLAMATION)
78 alertType = kAlertCautionAlert;
79 else if (style & wxICON_HAND)
80 alertType = kAlertStopAlert;
81 else if (style & wxICON_INFORMATION)
82 alertType = kAlertNoteAlert;
83 else if (style & wxICON_QUESTION)
84 alertType = kAlertNoteAlert;
85
86
87 // work out what to display
88 // if the extended text is empty then we use the caption as the title
89 // and the message as the text (for backwards compatibility)
90 // but if the extended message is not empty then we use the message as the title
91 // and the extended message as the text because that makes more sense
92
93 wxString msgtitle,msgtext;
94 if(m_extendedMessage.IsEmpty())
95 {
96 msgtitle = m_caption;
97 msgtext = m_message;
98 }
99 else
100 {
101 msgtitle = m_message;
102 msgtext = m_extendedMessage;
103 }
104
105
106 if ( !wxIsMainThread() )
107 {
108 CFStringRef defaultButtonTitle = NULL;
109 CFStringRef alternateButtonTitle = NULL;
110 CFStringRef otherButtonTitle = NULL;
111
112 wxMacCFStringHolder cfTitle( msgtitle, m_font.GetEncoding() );
113 wxMacCFStringHolder cfText( msgtext, m_font.GetEncoding() );
114
115 wxMacCFStringHolder cfNoString( m_no.c_str(), m_font.GetEncoding() );
116 wxMacCFStringHolder cfYesString( m_yes.c_str(), m_font.GetEncoding() );
117 wxMacCFStringHolder cfOKString( m_ok.c_str() , m_font.GetEncoding()) ;
118 wxMacCFStringHolder cfCancelString( m_cancel.c_str(), m_font.GetEncoding() );
119
120 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
121
122 if (style & wxYES_NO)
123 {
124 if ( style & wxNO_DEFAULT )
125 {
126 defaultButtonTitle = cfNoString;
127 alternateButtonTitle = cfYesString;
128 buttonId[0] = wxID_NO;
129 buttonId[1] = wxID_YES;
130 }
131 else
132 {
133 defaultButtonTitle = cfYesString;
134 alternateButtonTitle = cfNoString;
135 buttonId[0] = wxID_YES;
136 buttonId[1] = wxID_NO;
137 }
138 if (style & wxCANCEL)
139 {
140 otherButtonTitle = cfCancelString;
141 buttonId[2] = wxID_CANCEL;
142 }
143 }
144 else
145 {
146 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
147 buttonId[0] = wxID_OK;
148 // using null as default title does not work on earlier systems
149 defaultButtonTitle = cfOKString;
150 if (style & wxCANCEL)
151 {
152 alternateButtonTitle = cfCancelString;
153 buttonId[1] = wxID_CANCEL;
154 }
155 }
156
157 CFOptionFlags exitButton;
158 OSStatus err = CFUserNotificationDisplayAlert(
159 0, alertType, NULL, NULL, NULL, cfTitle, cfText,
160 defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton );
161 if (err == noErr)
162 resultbutton = buttonId[exitButton];
163 }
164 else
165 {
166 short result;
167
168 AlertStdCFStringAlertParamRec param;
169 wxMacCFStringHolder cfNoString( m_no.c_str(), m_font.GetEncoding() );
170 wxMacCFStringHolder cfYesString( m_yes.c_str(), m_font.GetEncoding() );
171 wxMacCFStringHolder cfOKString( m_ok.c_str(), m_font.GetEncoding() );
172 wxMacCFStringHolder cfCancelString( m_cancel.c_str(), m_font.GetEncoding() );
173
174 wxMacCFStringHolder cfTitle( msgtitle, m_font.GetEncoding() );
175 wxMacCFStringHolder cfText( msgtext, m_font.GetEncoding() );
176
177 param.movable = true;
178 param.flags = 0;
179 param.version = kStdCFStringAlertVersionOne;
180
181 bool skipDialog = false;
182
183 if (style & wxYES_NO)
184 {
185 if (style & wxCANCEL)
186 {
187 param.defaultText = cfYesString;
188 param.cancelText = cfCancelString;
189 param.otherText = cfNoString;
190 param.helpButton = false;
191 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
192 param.cancelButton = kAlertStdAlertCancelButton;
193 }
194 else
195 {
196 param.defaultText = cfYesString;
197 param.cancelText = NULL;
198 param.otherText = cfNoString;
199 param.helpButton = false;
200 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
201 param.cancelButton = 0;
202 }
203 }
204 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
205 else
206 {
207 if (style & wxCANCEL)
208 {
209 // that's a cancel missing
210 param.defaultText = cfOKString;
211 param.cancelText = cfCancelString;
212 param.otherText = NULL;
213 param.helpButton = false;
214 param.defaultButton = kAlertStdAlertOKButton;
215 param.cancelButton = 0;
216 }
217 else
218 {
219 param.defaultText = cfOKString;
220 param.cancelText = NULL;
221 param.otherText = NULL;
222 param.helpButton = false;
223 param.defaultButton = kAlertStdAlertOKButton;
224 param.cancelButton = 0;
225 }
226 }
227
228 param.position = kWindowDefaultPosition;
229 if ( !skipDialog )
230 {
231 DialogRef alertRef;
232 CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
233 RunStandardAlert( alertRef, NULL, &result );
234 }
235 else
236 {
237 return wxID_CANCEL;
238 }
239
240 if (style & wxOK)
241 {
242 switch ( result )
243 {
244 case 1:
245 resultbutton = wxID_OK;
246 break;
247
248 case 2:
249 // TODO: add Cancel button
250 // if (style & wxCANCEL)
251 // resultbutton = wxID_CANCEL;
252 break;
253
254 case 3:
255 default:
256 break;
257 }
258 }
259 else if (style & wxYES_NO)
260 {
261 switch ( result )
262 {
263 case 1:
264 resultbutton = wxID_YES;
265 break;
266
267 case 2:
268 if (!(style & wxCANCEL))
269 resultbutton = wxID_CANCEL;
270 break;
271
272 case 3:
273 resultbutton = wxID_NO;
274 break;
275
276 default:
277 break;
278 }
279 }
280 }
281
282 return resultbutton;
283 }