1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/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/thread.h"
22 #include "wx/modalhook.h"
23 #include "wx/osx/uma.h"
26 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
29 wxMessageDialog::wxMessageDialog(wxWindow
*parent
,
30 const wxString
& message
,
31 const wxString
& caption
,
33 const wxPoint
& WXUNUSED(pos
))
34 : wxMessageDialogBase(parent
, message
, caption
, style
)
38 int wxMessageDialog::ShowModal()
40 WX_HOOK_MODAL_DIALOG();
42 int resultbutton
= wxID_CANCEL
;
44 const long style
= GetMessageDialogStyle();
46 wxASSERT_MSG( (style
& 0x3F) != wxYES
,
47 "this style is not supported on Mac" );
49 AlertType alertType
= kAlertPlainAlert
;
51 switch ( GetEffectiveIcon() )
54 alertType
= kAlertStopAlert
;
58 alertType
= kAlertCautionAlert
;
62 case wxICON_INFORMATION
:
63 alertType
= kAlertNoteAlert
;
67 // (the standard alert has two slots [title, text]
68 // for the three wxStrings [caption, message, extended message])
70 // if the extended text is empty we use the caption and
71 // the message (for backwards compatibility)
73 // if the extended text is not empty we ignore the caption
74 // and use the message and the extended message
77 wxString msgtitle
,msgtext
;
78 if(m_extendedMessage
.IsEmpty())
80 if ( m_caption
.IsEmpty() )
91 msgtext
= m_extendedMessage
;
95 if ( !wxIsMainThread() )
97 CFStringRef defaultButtonTitle
= NULL
;
98 CFStringRef alternateButtonTitle
= NULL
;
99 CFStringRef otherButtonTitle
= NULL
;
101 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
102 wxCFStringRef
cfText( msgtext
, GetFont().GetEncoding() );
104 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
105 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
106 wxCFStringRef
cfOKString( GetOKLabel().c_str() , GetFont().GetEncoding()) ;
107 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
109 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
111 if (style
& wxYES_NO
)
113 if ( style
& wxNO_DEFAULT
)
115 defaultButtonTitle
= cfNoString
;
116 alternateButtonTitle
= cfYesString
;
117 buttonId
[0] = wxID_NO
;
118 buttonId
[1] = wxID_YES
;
122 defaultButtonTitle
= cfYesString
;
123 alternateButtonTitle
= cfNoString
;
124 buttonId
[0] = wxID_YES
;
125 buttonId
[1] = wxID_NO
;
127 if (style
& wxCANCEL
)
129 otherButtonTitle
= cfCancelString
;
130 buttonId
[2] = wxID_CANCEL
;
135 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
136 buttonId
[0] = wxID_OK
;
137 // using null as default title does not work on earlier systems
138 defaultButtonTitle
= cfOKString
;
139 if (style
& wxCANCEL
)
141 alternateButtonTitle
= cfCancelString
;
142 buttonId
[1] = wxID_CANCEL
;
146 CFOptionFlags exitButton
;
147 OSStatus err
= CFUserNotificationDisplayAlert(
148 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
149 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
151 resultbutton
= buttonId
[exitButton
];
157 AlertStdCFStringAlertParamRec param
;
158 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
159 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
160 wxCFStringRef
cfOKString( GetOKLabel().c_str(), GetFont().GetEncoding() );
161 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
163 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
164 wxCFStringRef cfText
= msgtext
.IsEmpty() ? NULL
: wxCFStringRef( msgtext
, GetFont().GetEncoding() );
166 param
.movable
= true;
168 param
.version
= kStdCFStringAlertVersionOne
;
170 bool skipDialog
= false;
172 if (style
& wxYES_NO
)
174 if (style
& wxCANCEL
)
176 param
.defaultText
= cfYesString
;
177 param
.cancelText
= cfCancelString
;
178 param
.otherText
= cfNoString
;
179 param
.helpButton
= false;
180 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
181 param
.cancelButton
= kAlertStdAlertCancelButton
;
185 param
.defaultText
= cfYesString
;
186 param
.cancelText
= NULL
;
187 param
.otherText
= cfNoString
;
188 param
.helpButton
= false;
189 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
190 param
.cancelButton
= 0;
193 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
196 if (style
& wxCANCEL
)
198 // that's a cancel missing
199 param
.defaultText
= cfOKString
;
200 param
.cancelText
= cfCancelString
;
201 param
.otherText
= NULL
;
202 param
.helpButton
= false;
203 param
.defaultButton
= kAlertStdAlertOKButton
;
204 param
.cancelButton
= 0;
208 param
.defaultText
= cfOKString
;
209 param
.cancelText
= NULL
;
210 param
.otherText
= NULL
;
211 param
.helpButton
= false;
212 param
.defaultButton
= kAlertStdAlertOKButton
;
213 param
.cancelButton
= 0;
217 param
.position
= kWindowDefaultPosition
;
221 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
222 wxDialog::OSXBeginModalDialog();
223 RunStandardAlert( alertRef
, NULL
, &result
);
224 wxDialog::OSXEndModalDialog();
236 resultbutton
= wxID_OK
;
240 // TODO: add Cancel button
241 // if (style & wxCANCEL)
242 // resultbutton = wxID_CANCEL;
250 else if (style
& wxYES_NO
)
255 resultbutton
= wxID_YES
;
259 if (!(style
& wxCANCEL
))
260 resultbutton
= wxID_CANCEL
;
264 resultbutton
= wxID_NO
;
273 SetReturnCode(resultbutton
);