1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
13 #include "wx/msgdlg.h"
20 #include "wx/thread.h"
21 #include "wx/modalhook.h"
22 #include "wx/osx/uma.h"
25 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
28 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
29 const wxString
& message
,
30 const wxString
& caption
,
32 const wxPoint
& WXUNUSED(pos
))
33 : wxMessageDialogBase(parent
, message
, caption
, style
)
37 int wxMessageDialog::ShowModal()
39 WX_HOOK_MODAL_DIALOG();
41 int resultbutton
= wxID_CANCEL
;
43 const long style
= GetMessageDialogStyle();
45 wxASSERT_MSG( (style
& 0x3F) != wxYES
,
46 "this style is not supported on Mac" );
48 AlertType alertType
= kAlertPlainAlert
;
50 switch ( GetEffectiveIcon() )
53 alertType
= kAlertStopAlert
;
57 alertType
= kAlertCautionAlert
;
61 case wxICON_INFORMATION
:
62 alertType
= kAlertNoteAlert
;
66 // (the standard alert has two slots [title, text]
67 // for the three wxStrings [caption, message, extended message])
69 // if the extended text is empty we use the caption and
70 // the message (for backwards compatibility)
72 // if the extended text is not empty we ignore the caption
73 // and use the message and the extended message
76 wxString msgtitle
,msgtext
;
77 if(m_extendedMessage
.IsEmpty())
79 if ( m_caption
.IsEmpty() )
90 msgtext
= m_extendedMessage
;
94 if ( !wxIsMainThread() )
96 CFStringRef defaultButtonTitle
= NULL
;
97 CFStringRef alternateButtonTitle
= NULL
;
98 CFStringRef otherButtonTitle
= NULL
;
100 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
101 wxCFStringRef
cfText( msgtext
, GetFont().GetEncoding() );
103 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
104 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
105 wxCFStringRef
cfOKString( GetOKLabel().c_str() , GetFont().GetEncoding()) ;
106 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
108 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
110 if (style
& wxYES_NO
)
112 if ( style
& wxNO_DEFAULT
)
114 defaultButtonTitle
= cfNoString
;
115 alternateButtonTitle
= cfYesString
;
116 buttonId
[0] = wxID_NO
;
117 buttonId
[1] = wxID_YES
;
121 defaultButtonTitle
= cfYesString
;
122 alternateButtonTitle
= cfNoString
;
123 buttonId
[0] = wxID_YES
;
124 buttonId
[1] = wxID_NO
;
126 if (style
& wxCANCEL
)
128 otherButtonTitle
= cfCancelString
;
129 buttonId
[2] = wxID_CANCEL
;
134 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
135 buttonId
[0] = wxID_OK
;
136 // using null as default title does not work on earlier systems
137 defaultButtonTitle
= cfOKString
;
138 if (style
& wxCANCEL
)
140 alternateButtonTitle
= cfCancelString
;
141 buttonId
[1] = wxID_CANCEL
;
145 CFOptionFlags exitButton
;
146 OSStatus err
= CFUserNotificationDisplayAlert(
147 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
148 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
150 resultbutton
= buttonId
[exitButton
];
156 AlertStdCFStringAlertParamRec param
;
157 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
158 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
159 wxCFStringRef
cfOKString( GetOKLabel().c_str(), GetFont().GetEncoding() );
160 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
162 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
163 wxCFStringRef cfText
= msgtext
.IsEmpty() ? NULL
: wxCFStringRef( msgtext
, GetFont().GetEncoding() );
165 param
.movable
= true;
167 param
.version
= kStdCFStringAlertVersionOne
;
169 bool skipDialog
= false;
171 if (style
& wxYES_NO
)
173 if (style
& wxCANCEL
)
175 param
.defaultText
= cfYesString
;
176 param
.cancelText
= cfCancelString
;
177 param
.otherText
= cfNoString
;
178 param
.helpButton
= false;
179 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
180 param
.cancelButton
= kAlertStdAlertCancelButton
;
184 param
.defaultText
= cfYesString
;
185 param
.cancelText
= NULL
;
186 param
.otherText
= cfNoString
;
187 param
.helpButton
= false;
188 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
189 param
.cancelButton
= 0;
192 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
195 if (style
& wxCANCEL
)
197 // that's a cancel missing
198 param
.defaultText
= cfOKString
;
199 param
.cancelText
= cfCancelString
;
200 param
.otherText
= NULL
;
201 param
.helpButton
= false;
202 param
.defaultButton
= kAlertStdAlertOKButton
;
203 param
.cancelButton
= 0;
207 param
.defaultText
= cfOKString
;
208 param
.cancelText
= NULL
;
209 param
.otherText
= NULL
;
210 param
.helpButton
= false;
211 param
.defaultButton
= kAlertStdAlertOKButton
;
212 param
.cancelButton
= 0;
216 param
.position
= kWindowDefaultPosition
;
220 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
221 wxDialog::OSXBeginModalDialog();
222 RunStandardAlert( alertRef
, NULL
, &result
);
223 wxDialog::OSXEndModalDialog();
235 resultbutton
= wxID_OK
;
239 // TODO: add Cancel button
240 // if (style & wxCANCEL)
241 // resultbutton = wxID_CANCEL;
249 else if (style
& wxYES_NO
)
254 resultbutton
= wxID_YES
;
258 if (!(style
& wxCANCEL
))
259 resultbutton
= wxID_CANCEL
;
263 resultbutton
= wxID_NO
;
272 SetReturnCode(resultbutton
);