]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/msgdlg.cpp
popup activation scope and l&f
[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
204abcd4 21#include "wx/thread.h"
519cb848 22#include "wx/mac/uma.h"
e9576ca5 23
51c4d2a5 24
e9576ca5 25IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
e9576ca5 26
51c4d2a5 27
2afb9e16
VZ
28wxMessageDialog::wxMessageDialog(wxWindow *parent,
29 const wxString& message,
30 const wxString& caption,
31 long style,
89954433 32 const wxPoint& WXUNUSED(pos))
2afb9e16 33 : wxMessageDialogBase(parent, message, caption, style)
e9576ca5 34{
2afb9e16
VZ
35 m_yes = _("Yes");
36 m_no = _("No");
37 m_ok = _("OK");
38 m_cancel = _("Cancel");
39}
40
41bool wxMessageDialog::SetYesNoLabels(const wxString& yes,const wxString& no)
42{
43 m_yes = yes;
44 m_no = no;
45 return true;
46}
47
48bool wxMessageDialog::SetYesNoCancelLabels(const wxString& yes, const wxString& no, const wxString& cancel)
49{
50 m_yes = yes;
51 m_no = no;
52 m_cancel = cancel;
53 return true;
54}
55
56bool wxMessageDialog::SetOKLabel(const wxString& ok)
57{
58 m_ok = ok;
59 return true;
60}
61
62bool wxMessageDialog::SetOKCancelLabels(const wxString& ok, const wxString& cancel)
63{
64 m_ok = ok;
65 m_cancel = cancel;
66 return true;
e9576ca5
SC
67}
68
69int wxMessageDialog::ShowModal()
70{
51c4d2a5 71 int resultbutton = wxID_CANCEL;
e5b50758 72
e5b50758
WS
73 const long style = GetMessageDialogStyle();
74
51c4d2a5 75 wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
e5b50758 76
51c4d2a5 77 AlertType alertType = kAlertPlainAlert;
e5b50758 78 if (style & wxICON_EXCLAMATION)
6239ee05 79 alertType = kAlertCautionAlert;
e5b50758 80 else if (style & wxICON_HAND)
51c4d2a5 81 alertType = kAlertStopAlert;
e5b50758 82 else if (style & wxICON_INFORMATION)
51c4d2a5 83 alertType = kAlertNoteAlert;
e5b50758 84 else if (style & wxICON_QUESTION)
6239ee05 85 alertType = kAlertNoteAlert;
e5b50758 86
2afb9e16
VZ
87
88 // work out what to display
89 // if the extended text is empty then we use the caption as the title
90 // and the message as the text (for backwards compatibility)
91 // but if the extended message is not empty then we use the message as the title
92 // and the extended message as the text because that makes more sense
93
94 wxString msgtitle,msgtext;
95 if(m_extendedMessage.IsEmpty())
96 {
97 msgtitle = m_caption;
98 msgtext = m_message;
99 }
100 else
101 {
102 msgtitle = m_message;
103 msgtext = m_extendedMessage;
104 }
105
106
5a253c3f
SC
107 if ( !wxIsMainThread() )
108 {
109 CFStringRef defaultButtonTitle = NULL;
110 CFStringRef alternateButtonTitle = NULL;
111 CFStringRef otherButtonTitle = NULL;
51c4d2a5 112
34a3ed01
VS
113 wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
114 wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
51c4d2a5 115
34a3ed01
VS
116 wxCFStringRef cfNoString( m_no.c_str(), GetFont().GetEncoding() );
117 wxCFStringRef cfYesString( m_yes.c_str(), GetFont().GetEncoding() );
118 wxCFStringRef cfOKString( m_ok.c_str() , GetFont().GetEncoding()) ;
119 wxCFStringRef cfCancelString( m_cancel.c_str(), GetFont().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
166 {
5a253c3f 167 short result;
57a21e6c 168
51c4d2a5 169 AlertStdCFStringAlertParamRec param;
34a3ed01
VS
170 wxCFStringRef cfNoString( m_no.c_str(), GetFont().GetEncoding() );
171 wxCFStringRef cfYesString( m_yes.c_str(), GetFont().GetEncoding() );
172 wxCFStringRef cfOKString( m_ok.c_str(), GetFont().GetEncoding() );
173 wxCFStringRef cfCancelString( m_cancel.c_str(), GetFont().GetEncoding() );
e5b50758 174
34a3ed01
VS
175 wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
176 wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
e5b50758 177
e40298d5 178 param.movable = true;
51c4d2a5
DS
179 param.flags = 0;
180 param.version = kStdCFStringAlertVersionOne;
e5b50758 181
51c4d2a5 182 bool skipDialog = false;
e5b50758
WS
183
184 if (style & wxYES_NO)
e40298d5 185 {
e5b50758 186 if (style & wxCANCEL)
e40298d5 187 {
51c4d2a5 188 param.defaultText = cfYesString;
2afb9e16 189 param.cancelText = cfCancelString;
51c4d2a5
DS
190 param.otherText = cfNoString;
191 param.helpButton = false;
e5b50758 192 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
51c4d2a5 193 param.cancelButton = kAlertStdAlertCancelButton;
e40298d5
JS
194 }
195 else
196 {
51c4d2a5
DS
197 param.defaultText = cfYesString;
198 param.cancelText = NULL;
199 param.otherText = cfNoString;
200 param.helpButton = false;
e5b50758 201 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
51c4d2a5 202 param.cancelButton = 0;
e40298d5
JS
203 }
204 }
51c4d2a5 205 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
e5b50758 206 else
e40298d5 207 {
e5b50758 208 if (style & wxCANCEL)
e40298d5 209 {
51c4d2a5 210 // that's a cancel missing
2afb9e16
VZ
211 param.defaultText = cfOKString;
212 param.cancelText = cfCancelString;
51c4d2a5
DS
213 param.otherText = NULL;
214 param.helpButton = false;
e40298d5 215 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 216 param.cancelButton = 0;
e40298d5
JS
217 }
218 else
219 {
2afb9e16 220 param.defaultText = cfOKString;
51c4d2a5
DS
221 param.cancelText = NULL;
222 param.otherText = NULL;
223 param.helpButton = false;
e40298d5 224 param.defaultButton = kAlertStdAlertOKButton;
51c4d2a5 225 param.cancelButton = 0;
e40298d5
JS
226 }
227 }
e5b50758 228
e40298d5
JS
229 param.position = kWindowDefaultPosition;
230 if ( !skipDialog )
231 {
51c4d2a5
DS
232 DialogRef alertRef;
233 CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
234 RunStandardAlert( alertRef, NULL, &result );
235 }
236 else
237 {
238 return wxID_CANCEL;
e40298d5 239 }
e5b50758 240
5a253c3f 241 if (style & wxOK)
e40298d5 242 {
5a253c3f 243 switch ( result )
e40298d5 244 {
5a253c3f
SC
245 case 1:
246 resultbutton = wxID_OK;
247 break;
248
249 case 2:
250 // TODO: add Cancel button
251 // if (style & wxCANCEL)
252 // resultbutton = wxID_CANCEL;
253 break;
254
255 case 3:
256 default:
257 break;
e40298d5
JS
258 }
259 }
5a253c3f 260 else if (style & wxYES_NO)
e40298d5 261 {
5a253c3f 262 switch ( result )
e40298d5 263 {
5a253c3f
SC
264 case 1:
265 resultbutton = wxID_YES;
266 break;
51c4d2a5 267
5a253c3f
SC
268 case 2:
269 if (!(style & wxCANCEL))
270 resultbutton = wxID_CANCEL;
271 break;
51c4d2a5 272
5a253c3f
SC
273 case 3:
274 resultbutton = wxID_NO;
275 break;
51c4d2a5 276
5a253c3f
SC
277 default:
278 break;
279 }
e40298d5 280 }
e5b50758 281 }
51c4d2a5
DS
282
283 return resultbutton;
e9576ca5 284}