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