]>
Commit | Line | Data |
---|---|---|
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 | 24 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
e9576ca5 | 25 | |
51c4d2a5 | 26 | |
2afb9e16 VZ |
27 | wxMessageDialog::wxMessageDialog(wxWindow *parent, |
28 | const wxString& message, | |
29 | const wxString& caption, | |
30 | long style, | |
31 | const wxPoint& pos) | |
32 | : wxMessageDialogBase(parent, message, caption, style) | |
e9576ca5 | 33 | { |
2afb9e16 VZ |
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; | |
e9576ca5 SC |
66 | } |
67 | ||
68 | int wxMessageDialog::ShowModal() | |
69 | { | |
51c4d2a5 | 70 | int resultbutton = wxID_CANCEL; |
e5b50758 | 71 | |
e5b50758 WS |
72 | const long style = GetMessageDialogStyle(); |
73 | ||
51c4d2a5 | 74 | wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") ); |
e5b50758 | 75 | |
51c4d2a5 | 76 | AlertType alertType = kAlertPlainAlert; |
e5b50758 | 77 | if (style & wxICON_EXCLAMATION) |
51c4d2a5 | 78 | alertType = kAlertNoteAlert; |
e5b50758 | 79 | else if (style & wxICON_HAND) |
51c4d2a5 | 80 | alertType = kAlertStopAlert; |
e5b50758 | 81 | else if (style & wxICON_INFORMATION) |
51c4d2a5 | 82 | alertType = kAlertNoteAlert; |
e5b50758 | 83 | else if (style & wxICON_QUESTION) |
51c4d2a5 | 84 | alertType = kAlertCautionAlert; |
e5b50758 | 85 | |
2afb9e16 VZ |
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 | ||
57a21e6c | 106 | #if TARGET_API_MAC_OSX |
5a253c3f SC |
107 | if ( !wxIsMainThread() ) |
108 | { | |
109 | CFStringRef defaultButtonTitle = NULL; | |
110 | CFStringRef alternateButtonTitle = NULL; | |
111 | CFStringRef otherButtonTitle = NULL; | |
51c4d2a5 | 112 | |
2afb9e16 VZ |
113 | wxMacCFStringHolder cfTitle( msgtitle, m_font.GetEncoding() ); |
114 | wxMacCFStringHolder cfText( msgtext, m_font.GetEncoding() ); | |
51c4d2a5 | 115 | |
2afb9e16 VZ |
116 | wxMacCFStringHolder cfNoString( m_no.c_str(), m_font.GetEncoding() ); |
117 | wxMacCFStringHolder cfYesString( m_yes.c_str(), m_font.GetEncoding() ); | |
118 | wxMacCFStringHolder cfOKString( m_ok.c_str() , m_font.GetEncoding()) ; | |
119 | wxMacCFStringHolder cfCancelString( m_cancel.c_str(), m_font.GetEncoding() ); | |
51c4d2a5 | 120 | |
5a253c3f | 121 | int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; |
51c4d2a5 | 122 | |
5a253c3f | 123 | if (style & wxYES_NO) |
57a21e6c | 124 | { |
5a253c3f SC |
125 | if ( style & wxNO_DEFAULT ) |
126 | { | |
127 | defaultButtonTitle = cfNoString; | |
128 | alternateButtonTitle = cfYesString; | |
129 | buttonId[0] = wxID_NO; | |
130 | buttonId[1] = wxID_YES; | |
131 | } | |
132 | else | |
133 | { | |
134 | defaultButtonTitle = cfYesString; | |
135 | alternateButtonTitle = cfNoString; | |
136 | buttonId[0] = wxID_YES; | |
137 | buttonId[1] = wxID_NO; | |
138 | } | |
139 | if (style & wxCANCEL) | |
140 | { | |
141 | otherButtonTitle = cfCancelString; | |
142 | buttonId[2] = wxID_CANCEL; | |
143 | } | |
57a21e6c SC |
144 | } |
145 | else | |
146 | { | |
5a253c3f SC |
147 | // the MSW implementation even shows an OK button if it is not specified, we'll do the same |
148 | buttonId[0] = wxID_OK; | |
149 | // using null as default title does not work on earlier systems | |
150 | defaultButtonTitle = cfOKString; | |
151 | if (style & wxCANCEL) | |
152 | { | |
153 | alternateButtonTitle = cfCancelString; | |
154 | buttonId[1] = wxID_CANCEL; | |
155 | } | |
57a21e6c | 156 | } |
5a253c3f SC |
157 | |
158 | CFOptionFlags exitButton; | |
159 | OSStatus err = CFUserNotificationDisplayAlert( | |
160 | 0, alertType, NULL, NULL, NULL, cfTitle, cfText, | |
161 | defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton ); | |
162 | if (err == noErr) | |
163 | resultbutton = buttonId[exitButton]; | |
57a21e6c SC |
164 | } |
165 | else | |
5a253c3f | 166 | #endif |
57a21e6c | 167 | { |
5a253c3f | 168 | short result; |
57a21e6c | 169 | |
51c4d2a5 | 170 | AlertStdCFStringAlertParamRec param; |
2afb9e16 VZ |
171 | wxMacCFStringHolder cfNoString( m_no.c_str(), m_font.GetEncoding() ); |
172 | wxMacCFStringHolder cfYesString( m_yes.c_str(), m_font.GetEncoding() ); | |
173 | wxMacCFStringHolder cfOKString( m_ok.c_str(), m_font.GetEncoding() ); | |
174 | wxMacCFStringHolder cfCancelString( m_cancel.c_str(), m_font.GetEncoding() ); | |
e5b50758 | 175 | |
2afb9e16 VZ |
176 | wxMacCFStringHolder cfTitle( msgtitle, m_font.GetEncoding() ); |
177 | wxMacCFStringHolder cfText( msgtext, m_font.GetEncoding() ); | |
e5b50758 | 178 | |
e40298d5 | 179 | param.movable = true; |
51c4d2a5 DS |
180 | param.flags = 0; |
181 | param.version = kStdCFStringAlertVersionOne; | |
e5b50758 | 182 | |
51c4d2a5 | 183 | bool skipDialog = false; |
e5b50758 WS |
184 | |
185 | if (style & wxYES_NO) | |
e40298d5 | 186 | { |
e5b50758 | 187 | if (style & wxCANCEL) |
e40298d5 | 188 | { |
51c4d2a5 | 189 | param.defaultText = cfYesString; |
2afb9e16 | 190 | param.cancelText = cfCancelString; |
51c4d2a5 DS |
191 | param.otherText = cfNoString; |
192 | param.helpButton = false; | |
e5b50758 | 193 | param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; |
51c4d2a5 | 194 | param.cancelButton = kAlertStdAlertCancelButton; |
e40298d5 JS |
195 | } |
196 | else | |
197 | { | |
51c4d2a5 DS |
198 | param.defaultText = cfYesString; |
199 | param.cancelText = NULL; | |
200 | param.otherText = cfNoString; | |
201 | param.helpButton = false; | |
e5b50758 | 202 | param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; |
51c4d2a5 | 203 | param.cancelButton = 0; |
e40298d5 JS |
204 | } |
205 | } | |
51c4d2a5 | 206 | // the MSW implementation even shows an OK button if it is not specified, we'll do the same |
e5b50758 | 207 | else |
e40298d5 | 208 | { |
e5b50758 | 209 | if (style & wxCANCEL) |
e40298d5 | 210 | { |
51c4d2a5 | 211 | // that's a cancel missing |
2afb9e16 VZ |
212 | param.defaultText = cfOKString; |
213 | param.cancelText = cfCancelString; | |
51c4d2a5 DS |
214 | param.otherText = NULL; |
215 | param.helpButton = false; | |
e40298d5 | 216 | param.defaultButton = kAlertStdAlertOKButton; |
51c4d2a5 | 217 | param.cancelButton = 0; |
e40298d5 JS |
218 | } |
219 | else | |
220 | { | |
2afb9e16 | 221 | param.defaultText = cfOKString; |
51c4d2a5 DS |
222 | param.cancelText = NULL; |
223 | param.otherText = NULL; | |
224 | param.helpButton = false; | |
e40298d5 | 225 | param.defaultButton = kAlertStdAlertOKButton; |
51c4d2a5 | 226 | param.cancelButton = 0; |
e40298d5 JS |
227 | } |
228 | } | |
e5b50758 | 229 | |
e40298d5 JS |
230 | param.position = kWindowDefaultPosition; |
231 | if ( !skipDialog ) | |
232 | { | |
51c4d2a5 DS |
233 | DialogRef alertRef; |
234 | CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); | |
235 | RunStandardAlert( alertRef, NULL, &result ); | |
236 | } | |
237 | else | |
238 | { | |
239 | return wxID_CANCEL; | |
e40298d5 | 240 | } |
e5b50758 | 241 | |
5a253c3f | 242 | if (style & wxOK) |
e40298d5 | 243 | { |
5a253c3f | 244 | switch ( result ) |
e40298d5 | 245 | { |
5a253c3f SC |
246 | case 1: |
247 | resultbutton = wxID_OK; | |
248 | break; | |
249 | ||
250 | case 2: | |
251 | // TODO: add Cancel button | |
252 | // if (style & wxCANCEL) | |
253 | // resultbutton = wxID_CANCEL; | |
254 | break; | |
255 | ||
256 | case 3: | |
257 | default: | |
258 | break; | |
e40298d5 JS |
259 | } |
260 | } | |
5a253c3f | 261 | else if (style & wxYES_NO) |
e40298d5 | 262 | { |
5a253c3f | 263 | switch ( result ) |
e40298d5 | 264 | { |
5a253c3f SC |
265 | case 1: |
266 | resultbutton = wxID_YES; | |
267 | break; | |
51c4d2a5 | 268 | |
5a253c3f SC |
269 | case 2: |
270 | if (!(style & wxCANCEL)) | |
271 | resultbutton = wxID_CANCEL; | |
272 | break; | |
51c4d2a5 | 273 | |
5a253c3f SC |
274 | case 3: |
275 | resultbutton = wxID_NO; | |
276 | break; | |
51c4d2a5 | 277 | |
5a253c3f SC |
278 | default: |
279 | break; | |
280 | } | |
e40298d5 | 281 | } |
e5b50758 | 282 | } |
51c4d2a5 DS |
283 | |
284 | return resultbutton; | |
e9576ca5 | 285 | } |