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(wxWindow
*parent
,
28 const wxString
& message
,
29 const wxString
& caption
,
31 const wxPoint
& WXUNUSED(pos
))
32 : wxMessageDialogBase(parent
, message
, caption
, style
)
37 m_cancel
= _("Cancel");
40 bool wxMessageDialog::SetYesNoLabels(const wxString
& yes
,const wxString
& no
)
47 bool wxMessageDialog::SetYesNoCancelLabels(const wxString
& yes
, const wxString
& no
, const wxString
& cancel
)
55 bool wxMessageDialog::SetOKLabel(const wxString
& ok
)
61 bool wxMessageDialog::SetOKCancelLabels(const wxString
& ok
, const wxString
& cancel
)
68 int wxMessageDialog::ShowModal()
70 int resultbutton
= wxID_CANCEL
;
72 const long style
= GetMessageDialogStyle();
74 wxASSERT_MSG( (style
& 0x3F) != wxYES
, wxT("this style is not supported on Mac") );
76 AlertType alertType
= kAlertPlainAlert
;
77 if (style
& wxICON_EXCLAMATION
)
78 alertType
= kAlertCautionAlert
;
79 else if (style
& wxICON_HAND
)
80 alertType
= kAlertStopAlert
;
81 else if (style
& wxICON_INFORMATION
)
82 alertType
= kAlertNoteAlert
;
83 else if (style
& wxICON_QUESTION
)
84 alertType
= kAlertNoteAlert
;
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
93 wxString msgtitle
,msgtext
;
94 if(m_extendedMessage
.IsEmpty())
101 msgtitle
= m_message
;
102 msgtext
= m_extendedMessage
;
106 if ( !wxIsMainThread() )
108 CFStringRef defaultButtonTitle
= NULL
;
109 CFStringRef alternateButtonTitle
= NULL
;
110 CFStringRef otherButtonTitle
= NULL
;
112 wxMacCFStringHolder
cfTitle( msgtitle
, m_font
.GetEncoding() );
113 wxMacCFStringHolder
cfText( msgtext
, m_font
.GetEncoding() );
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() );
120 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
122 if (style
& wxYES_NO
)
124 if ( style
& wxNO_DEFAULT
)
126 defaultButtonTitle
= cfNoString
;
127 alternateButtonTitle
= cfYesString
;
128 buttonId
[0] = wxID_NO
;
129 buttonId
[1] = wxID_YES
;
133 defaultButtonTitle
= cfYesString
;
134 alternateButtonTitle
= cfNoString
;
135 buttonId
[0] = wxID_YES
;
136 buttonId
[1] = wxID_NO
;
138 if (style
& wxCANCEL
)
140 otherButtonTitle
= cfCancelString
;
141 buttonId
[2] = wxID_CANCEL
;
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
)
152 alternateButtonTitle
= cfCancelString
;
153 buttonId
[1] = wxID_CANCEL
;
157 CFOptionFlags exitButton
;
158 OSStatus err
= CFUserNotificationDisplayAlert(
159 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
160 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
162 resultbutton
= buttonId
[exitButton
];
168 AlertStdCFStringAlertParamRec param
;
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() );
174 wxMacCFStringHolder
cfTitle( msgtitle
, m_font
.GetEncoding() );
175 wxMacCFStringHolder
cfText( msgtext
, m_font
.GetEncoding() );
177 param
.movable
= true;
179 param
.version
= kStdCFStringAlertVersionOne
;
181 bool skipDialog
= false;
183 if (style
& wxYES_NO
)
185 if (style
& wxCANCEL
)
187 param
.defaultText
= cfYesString
;
188 param
.cancelText
= cfCancelString
;
189 param
.otherText
= cfNoString
;
190 param
.helpButton
= false;
191 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
192 param
.cancelButton
= kAlertStdAlertCancelButton
;
196 param
.defaultText
= cfYesString
;
197 param
.cancelText
= NULL
;
198 param
.otherText
= cfNoString
;
199 param
.helpButton
= false;
200 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
201 param
.cancelButton
= 0;
204 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
207 if (style
& wxCANCEL
)
209 // that's a cancel missing
210 param
.defaultText
= cfOKString
;
211 param
.cancelText
= cfCancelString
;
212 param
.otherText
= NULL
;
213 param
.helpButton
= false;
214 param
.defaultButton
= kAlertStdAlertOKButton
;
215 param
.cancelButton
= 0;
219 param
.defaultText
= cfOKString
;
220 param
.cancelText
= NULL
;
221 param
.otherText
= NULL
;
222 param
.helpButton
= false;
223 param
.defaultButton
= kAlertStdAlertOKButton
;
224 param
.cancelButton
= 0;
228 param
.position
= kWindowDefaultPosition
;
232 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
233 RunStandardAlert( alertRef
, NULL
, &result
);
245 resultbutton
= wxID_OK
;
249 // TODO: add Cancel button
250 // if (style & wxCANCEL)
251 // resultbutton = wxID_CANCEL;
259 else if (style
& wxYES_NO
)
264 resultbutton
= wxID_YES
;
268 if (!(style
& wxCANCEL
))
269 resultbutton
= wxID_CANCEL
;
273 resultbutton
= wxID_NO
;