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"
15 #include "wx/msgdlg.h"
17 #include "wx/mac/uma.h"
20 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
23 wxMessageDialog::wxMessageDialog(
24 wxWindow
*parent
, const wxString
& message
, const wxString
& caption
,
25 long style
, const wxPoint
& pos
)
30 SetMessageDialogStyle(style
);
33 int wxMessageDialog::ShowModal()
35 int resultbutton
= wxID_CANCEL
;
37 const long style
= GetMessageDialogStyle();
39 wxASSERT_MSG( (style
& 0x3F) != wxYES
, wxT("this style is not supported on Mac") );
41 AlertType alertType
= kAlertPlainAlert
;
42 if (style
& wxICON_EXCLAMATION
)
43 alertType
= kAlertNoteAlert
;
44 else if (style
& wxICON_HAND
)
45 alertType
= kAlertStopAlert
;
46 else if (style
& wxICON_INFORMATION
)
47 alertType
= kAlertNoteAlert
;
48 else if (style
& wxICON_QUESTION
)
49 alertType
= kAlertCautionAlert
;
51 #if TARGET_API_MAC_OSX
52 CFStringRef defaultButtonTitle
= NULL
;
53 CFStringRef alternateButtonTitle
= NULL
;
54 CFStringRef otherButtonTitle
= NULL
;
56 wxMacCFStringHolder
cfTitle( m_caption
, m_font
.GetEncoding() );
57 wxMacCFStringHolder
cfText( m_message
, m_font
.GetEncoding() );
59 wxMacCFStringHolder
cfNoString( wxT("No"), m_font
.GetEncoding() );
60 wxMacCFStringHolder
cfYesString( wxT("Yes"), m_font
.GetEncoding() );
61 wxMacCFStringHolder
cfCancelString( wxT("Cancel"), m_font
.GetEncoding() );
63 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
67 if ( style
& wxNO_DEFAULT
)
69 defaultButtonTitle
= cfNoString
;
70 alternateButtonTitle
= cfYesString
;
71 buttonId
[0] = wxID_NO
;
72 buttonId
[1] = wxID_YES
;
76 defaultButtonTitle
= cfYesString
;
77 alternateButtonTitle
= cfNoString
;
78 buttonId
[0] = wxID_YES
;
79 buttonId
[1] = wxID_NO
;
83 otherButtonTitle
= cfCancelString
;
84 buttonId
[2] = wxID_CANCEL
;
89 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
90 buttonId
[0] = wxID_OK
;
93 alternateButtonTitle
= cfCancelString
;
94 buttonId
[1] = wxID_CANCEL
;
98 CFOptionFlags exitButton
;
99 OSStatus err
= CFUserNotificationDisplayAlert(
100 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
101 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
103 resultbutton
= buttonId
[exitButton
];
109 if ( UMAGetSystemVersion() >= 0x1000 )
111 AlertStdCFStringAlertParamRec param
;
112 wxMacCFStringHolder
cfNoString( wxT("No"), m_font
.GetEncoding() );
113 wxMacCFStringHolder
cfYesString( wxT("Yes"), m_font
.GetEncoding() );
115 wxMacCFStringHolder
cfTitle( m_caption
, m_font
.GetEncoding() );
116 wxMacCFStringHolder
cfText( m_message
, m_font
.GetEncoding() );
118 param
.movable
= true;
120 param
.version
= kStdCFStringAlertVersionOne
;
122 bool skipDialog
= false;
124 if (style
& wxYES_NO
)
126 if (style
& wxCANCEL
)
128 param
.defaultText
= cfYesString
;
129 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
130 param
.otherText
= cfNoString
;
131 param
.helpButton
= false;
132 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
133 param
.cancelButton
= kAlertStdAlertCancelButton
;
137 param
.defaultText
= cfYesString
;
138 param
.cancelText
= NULL
;
139 param
.otherText
= cfNoString
;
140 param
.helpButton
= false;
141 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
142 param
.cancelButton
= 0;
145 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
148 if (style
& wxCANCEL
)
150 // that's a cancel missing
151 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
152 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
153 param
.otherText
= NULL
;
154 param
.helpButton
= false;
155 param
.defaultButton
= kAlertStdAlertOKButton
;
156 param
.cancelButton
= 0;
160 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
161 param
.cancelText
= NULL
;
162 param
.otherText
= NULL
;
163 param
.helpButton
= false;
164 param
.defaultButton
= kAlertStdAlertOKButton
;
165 param
.cancelButton
= 0;
175 param
.position
= kWindowDefaultPosition
;
179 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
180 RunStandardAlert( alertRef
, NULL
, &result
);
190 AlertStdAlertParamRec param
;
191 Str255 yesPString
, noPString
;
192 Str255 pascalTitle
, pascalText
;
194 wxMacStringToPascal( m_caption
, pascalTitle
);
195 wxMacStringToPascal( wxT("Yes"), yesPString
);
196 wxMacStringToPascal( wxT("No"), noPString
);
197 wxMacStringToPascal( m_message
, pascalText
);
199 param
.movable
= true;
200 param
.filterProc
= NULL
;
202 if (style
& wxYES_NO
)
204 if (style
& wxCANCEL
)
206 param
.defaultText
= yesPString
;
207 param
.cancelText
= (StringPtr
) kAlertDefaultCancelText
;
208 param
.otherText
= noPString
;
209 param
.helpButton
= false;
210 param
.defaultButton
= kAlertStdAlertOKButton
;
211 param
.cancelButton
= kAlertStdAlertCancelButton
;
215 param
.defaultText
= yesPString
;
216 param
.cancelText
= NULL
;
217 param
.otherText
= noPString
;
218 param
.helpButton
= false;
219 param
.defaultButton
= kAlertStdAlertOKButton
;
220 param
.cancelButton
= 0;
223 else if (style
& wxOK
)
225 if (style
& wxCANCEL
)
227 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
228 param
.cancelText
= (StringPtr
) kAlertDefaultCancelText
;
229 param
.otherText
= NULL
;
230 param
.helpButton
= false;
231 param
.defaultButton
= kAlertStdAlertOKButton
;
232 param
.cancelButton
= 0;
236 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
237 param
.cancelText
= NULL
;
238 param
.otherText
= NULL
;
239 param
.helpButton
= false;
240 param
.defaultButton
= kAlertStdAlertOKButton
;
241 param
.cancelButton
= 0;
250 StandardAlert( alertType
, pascalTitle
, pascalText
, ¶m
, &result
);
258 resultbutton
= wxID_OK
;
262 // TODO: add Cancel button
263 // if (style & wxCANCEL)
264 // resultbutton = wxID_CANCEL;
272 else if (style
& wxYES_NO
)
277 resultbutton
= wxID_YES
;
281 if (!(style
& wxCANCEL
))
282 resultbutton
= wxID_CANCEL
;
286 resultbutton
= wxID_NO
;