]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/msgdlg.cpp
guard code for mac / quickdraw
[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 26
2afb9e16
VZ
27wxMessageDialog::wxMessageDialog(wxWindow *parent,
28 const wxString& message,
29 const wxString& caption,
30 long style,
89954433 31 const wxPoint& WXUNUSED(pos))
2afb9e16 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
40bool wxMessageDialog::SetYesNoLabels(const wxString& yes,const wxString& no)
41{
42 m_yes = yes;
43 m_no = no;
44 return true;
45}
46
47bool 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
55bool wxMessageDialog::SetOKLabel(const wxString& ok)
56{
57 m_ok = ok;
58 return true;
59}
60
61bool wxMessageDialog::SetOKCancelLabels(const wxString& ok, const wxString& cancel)
62{
63 m_ok = ok;
64 m_cancel = cancel;
65 return true;
e9576ca5
SC
66}
67
68int 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)
6239ee05 78 alertType = kAlertCautionAlert;
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)
6239ee05 84 alertType = kAlertNoteAlert;
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
5a253c3f
SC
106 if ( !wxIsMainThread() )
107 {
108 CFStringRef defaultButtonTitle = NULL;
109 CFStringRef alternateButtonTitle = NULL;
110 CFStringRef otherButtonTitle = NULL;
51c4d2a5 111
2afb9e16
VZ
112 wxMacCFStringHolder cfTitle( msgtitle, m_font.GetEncoding() );
113 wxMacCFStringHolder cfText( msgtext, m_font.GetEncoding() );
51c4d2a5 114
2afb9e16
VZ
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() );
51c4d2a5 119
5a253c3f 120 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
51c4d2a5 121
5a253c3f 122 if (style & wxYES_NO)
57a21e6c 123 {
5a253c3f
SC
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 }
57a21e6c
SC
143 }
144 else
145 {
5a253c3f
SC
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 }
57a21e6c 155 }
5a253c3f
SC
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];
57a21e6c
SC
163 }
164 else
165 {
5a253c3f 166 short result;
57a21e6c 167
51c4d2a5 168 AlertStdCFStringAlertParamRec param;
2afb9e16
VZ
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() );
e5b50758 173
2afb9e16
VZ
174 wxMacCFStringHolder cfTitle( msgtitle, m_font.GetEncoding() );
175 wxMacCFStringHolder cfText( msgtext, m_font.GetEncoding() );
e5b50758 176
e40298d5 177 param.movable = true;
51c4d2a5
DS
178 param.flags = 0;
179 param.version = kStdCFStringAlertVersionOne;
e5b50758 180
51c4d2a5 181 bool skipDialog = false;
e5b50758
WS
182
183 if (style & wxYES_NO)
e40298d5 184 {
e5b50758 185 if (style & wxCANCEL)
e40298d5 186 {
51c4d2a5 187 param.defaultText = cfYesString;
2afb9e16 188 param.cancelText = cfCancelString;
51c4d2a5
DS
189 param.otherText = cfNoString;
190 param.helpButton = false;
e5b50758 191 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
51c4d2a5 192 param.cancelButton = kAlertStdAlertCancelButton;
e40298d5
JS
193 }
194 else
195 {
51c4d2a5
DS
196 param.defaultText = cfYesString;
197 param.cancelText = NULL;
198 param.otherText = cfNoString;
199 param.helpButton = false;
e5b50758 200 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
51c4d2a5 201 param.cancelButton = 0;
e40298d5
JS
202 }
203 }
51c4d2a5 204 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
e5b50758 205 else
e40298d5 206 {
e5b50758 207 if (style & wxCANCEL)
e40298d5 208 {
51c4d2a5 209 // that's a cancel missing
2afb9e16
VZ
210 param.defaultText = cfOKString;
211 param.cancelText = cfCancelString;
51c4d2a5
DS
212 param.otherText = NULL;
213 param.helpButton = false;
e40298d5 214 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 215 param.cancelButton = 0;
e40298d5
JS
216 }
217 else
218 {
2afb9e16 219 param.defaultText = cfOKString;
51c4d2a5
DS
220 param.cancelText = NULL;
221 param.otherText = NULL;
222 param.helpButton = false;
e40298d5 223 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 224 param.cancelButton = 0;
e40298d5
JS
225 }
226 }
e5b50758 227
e40298d5
JS
228 param.position = kWindowDefaultPosition;
229 if ( !skipDialog )
230 {
51c4d2a5
DS
231 DialogRef alertRef;
232 CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
233 RunStandardAlert( alertRef, NULL, &result );
234 }
235 else
236 {
237 return wxID_CANCEL;
e40298d5 238 }
e5b50758 239
5a253c3f 240 if (style & wxOK)
e40298d5 241 {
5a253c3f 242 switch ( result )
e40298d5 243 {
5a253c3f
SC
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;
e40298d5
JS
257 }
258 }
5a253c3f 259 else if (style & wxYES_NO)
e40298d5 260 {
5a253c3f 261 switch ( result )
e40298d5 262 {
5a253c3f
SC
263 case 1:
264 resultbutton = wxID_YES;
265 break;
51c4d2a5 266
5a253c3f
SC
267 case 2:
268 if (!(style & wxCANCEL))
269 resultbutton = wxID_CANCEL;
270 break;
51c4d2a5 271
5a253c3f
SC
272 case 3:
273 resultbutton = wxID_NO;
274 break;
51c4d2a5 275
5a253c3f
SC
276 default:
277 break;
278 }
e40298d5 279 }
e5b50758 280 }
51c4d2a5
DS
281
282 return resultbutton;
e9576ca5 283}