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