1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/msgdlg.h"
21 #include "wx/mac/uma.h"
24 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
27 wxMessageDialog::wxMessageDialog(
28 wxWindow
*parent
, const wxString
& message
, const wxString
& caption
,
29 long style
, const wxPoint
& pos
)
34 SetMessageDialogStyle(style
);
37 int wxMessageDialog::ShowModal()
39 int resultbutton
= wxID_CANCEL
;
41 const long style
= GetMessageDialogStyle();
43 wxASSERT_MSG( (style
& 0x3F) != wxYES
, wxT("this style is not supported on Mac") );
45 AlertType alertType
= kAlertPlainAlert
;
46 if (style
& wxICON_EXCLAMATION
)
47 alertType
= kAlertNoteAlert
;
48 else if (style
& wxICON_HAND
)
49 alertType
= kAlertStopAlert
;
50 else if (style
& wxICON_INFORMATION
)
51 alertType
= kAlertNoteAlert
;
52 else if (style
& wxICON_QUESTION
)
53 alertType
= kAlertCautionAlert
;
55 #if TARGET_API_MAC_OSX
56 CFStringRef defaultButtonTitle
= NULL
;
57 CFStringRef alternateButtonTitle
= NULL
;
58 CFStringRef otherButtonTitle
= NULL
;
60 wxMacCFStringHolder
cfTitle( m_caption
, m_font
.GetEncoding() );
61 wxMacCFStringHolder
cfText( m_message
, m_font
.GetEncoding() );
63 wxMacCFStringHolder
cfNoString( _("No"), m_font
.GetEncoding() );
64 wxMacCFStringHolder
cfYesString( _("Yes"), m_font
.GetEncoding() );
65 wxMacCFStringHolder
cfOKString( _("OK") , m_font
.GetEncoding()) ;
66 wxMacCFStringHolder
cfCancelString( _("Cancel"), m_font
.GetEncoding() );
68 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
72 if ( style
& wxNO_DEFAULT
)
74 defaultButtonTitle
= cfNoString
;
75 alternateButtonTitle
= cfYesString
;
76 buttonId
[0] = wxID_NO
;
77 buttonId
[1] = wxID_YES
;
81 defaultButtonTitle
= cfYesString
;
82 alternateButtonTitle
= cfNoString
;
83 buttonId
[0] = wxID_YES
;
84 buttonId
[1] = wxID_NO
;
88 otherButtonTitle
= cfCancelString
;
89 buttonId
[2] = wxID_CANCEL
;
94 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
95 buttonId
[0] = wxID_OK
;
96 // using null as default title does not work on earlier systems
97 defaultButtonTitle
= cfOKString
;
100 alternateButtonTitle
= cfCancelString
;
101 buttonId
[1] = wxID_CANCEL
;
105 CFOptionFlags exitButton
;
106 OSStatus err
= CFUserNotificationDisplayAlert(
107 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
108 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
110 resultbutton
= buttonId
[exitButton
];
116 if ( UMAGetSystemVersion() >= 0x1000 )
118 AlertStdCFStringAlertParamRec param
;
119 wxMacCFStringHolder
cfNoString( _("No"), m_font
.GetEncoding() );
120 wxMacCFStringHolder
cfYesString( _("Yes"), m_font
.GetEncoding() );
122 wxMacCFStringHolder
cfTitle( m_caption
, m_font
.GetEncoding() );
123 wxMacCFStringHolder
cfText( m_message
, m_font
.GetEncoding() );
125 param
.movable
= true;
127 param
.version
= kStdCFStringAlertVersionOne
;
129 bool skipDialog
= false;
131 if (style
& wxYES_NO
)
133 if (style
& wxCANCEL
)
135 param
.defaultText
= cfYesString
;
136 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
137 param
.otherText
= cfNoString
;
138 param
.helpButton
= false;
139 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
140 param
.cancelButton
= kAlertStdAlertCancelButton
;
144 param
.defaultText
= cfYesString
;
145 param
.cancelText
= NULL
;
146 param
.otherText
= cfNoString
;
147 param
.helpButton
= false;
148 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
149 param
.cancelButton
= 0;
152 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
155 if (style
& wxCANCEL
)
157 // that's a cancel missing
158 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
159 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
160 param
.otherText
= NULL
;
161 param
.helpButton
= false;
162 param
.defaultButton
= kAlertStdAlertOKButton
;
163 param
.cancelButton
= 0;
167 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
168 param
.cancelText
= NULL
;
169 param
.otherText
= NULL
;
170 param
.helpButton
= false;
171 param
.defaultButton
= kAlertStdAlertOKButton
;
172 param
.cancelButton
= 0;
182 param
.position
= kWindowDefaultPosition
;
186 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
187 RunStandardAlert( alertRef
, NULL
, &result
);
197 AlertStdAlertParamRec param
;
198 Str255 yesPString
, noPString
;
199 Str255 pascalTitle
, pascalText
;
201 wxMacStringToPascal( m_caption
, pascalTitle
);
202 wxMacStringToPascal( _("Yes"), yesPString
);
203 wxMacStringToPascal( _("No"), noPString
);
204 wxMacStringToPascal( m_message
, pascalText
);
206 param
.movable
= true;
207 param
.filterProc
= NULL
;
209 if (style
& wxYES_NO
)
211 if (style
& wxCANCEL
)
213 param
.defaultText
= yesPString
;
214 param
.cancelText
= (StringPtr
) kAlertDefaultCancelText
;
215 param
.otherText
= noPString
;
216 param
.helpButton
= false;
217 param
.defaultButton
= kAlertStdAlertOKButton
;
218 param
.cancelButton
= kAlertStdAlertCancelButton
;
222 param
.defaultText
= yesPString
;
223 param
.cancelText
= NULL
;
224 param
.otherText
= noPString
;
225 param
.helpButton
= false;
226 param
.defaultButton
= kAlertStdAlertOKButton
;
227 param
.cancelButton
= 0;
230 else if (style
& wxOK
)
232 if (style
& wxCANCEL
)
234 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
235 param
.cancelText
= (StringPtr
) kAlertDefaultCancelText
;
236 param
.otherText
= NULL
;
237 param
.helpButton
= false;
238 param
.defaultButton
= kAlertStdAlertOKButton
;
239 param
.cancelButton
= 0;
243 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
244 param
.cancelText
= NULL
;
245 param
.otherText
= NULL
;
246 param
.helpButton
= false;
247 param
.defaultButton
= kAlertStdAlertOKButton
;
248 param
.cancelButton
= 0;
257 StandardAlert( alertType
, pascalTitle
, pascalText
, ¶m
, &result
);
265 resultbutton
= wxID_OK
;
269 // TODO: add Cancel button
270 // if (style & wxCANCEL)
271 // resultbutton = wxID_CANCEL;
279 else if (style
& wxYES_NO
)
284 resultbutton
= wxID_YES
;
288 if (!(style
& wxCANCEL
))
289 resultbutton
= wxID_CANCEL
;
293 resultbutton
= wxID_NO
;