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/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 : wxMessageDialogWithCustomLabels(parent
, message
, caption
, style
)
37 int wxMessageDialog::ShowModal()
39 int resultbutton
= wxID_CANCEL
;
41 const long style
= GetMessageDialogStyle();
43 wxASSERT_MSG( (style
& 0x3F) != wxYES
,
44 "this style is not supported on Mac" );
46 AlertType alertType
= kAlertPlainAlert
;
48 switch ( GetEffectiveIcon() )
51 alertType
= kAlertStopAlert
;
55 alertType
= kAlertCautionAlert
;
59 case wxICON_INFORMATION
:
60 alertType
= kAlertNoteAlert
;
64 // (the standard alert has two slots [title, text]
65 // for the three wxStrings [caption, message, extended message])
67 // if the extended text is empty we use the caption and
68 // the message (for backwards compatibility)
70 // if the extended text is not empty we ignore the caption
71 // and use the message and the extended message
74 wxString msgtitle
,msgtext
;
75 if(m_extendedMessage
.IsEmpty())
77 if ( m_caption
.IsEmpty() )
88 msgtext
= m_extendedMessage
;
92 if ( !wxIsMainThread() )
94 CFStringRef defaultButtonTitle
= NULL
;
95 CFStringRef alternateButtonTitle
= NULL
;
96 CFStringRef otherButtonTitle
= NULL
;
98 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
99 wxCFStringRef
cfText( msgtext
, GetFont().GetEncoding() );
101 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
102 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
103 wxCFStringRef
cfOKString( GetOKLabel().c_str() , GetFont().GetEncoding()) ;
104 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
106 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
108 if (style
& wxYES_NO
)
110 if ( style
& wxNO_DEFAULT
)
112 defaultButtonTitle
= cfNoString
;
113 alternateButtonTitle
= cfYesString
;
114 buttonId
[0] = wxID_NO
;
115 buttonId
[1] = wxID_YES
;
119 defaultButtonTitle
= cfYesString
;
120 alternateButtonTitle
= cfNoString
;
121 buttonId
[0] = wxID_YES
;
122 buttonId
[1] = wxID_NO
;
124 if (style
& wxCANCEL
)
126 otherButtonTitle
= cfCancelString
;
127 buttonId
[2] = wxID_CANCEL
;
132 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
133 buttonId
[0] = wxID_OK
;
134 // using null as default title does not work on earlier systems
135 defaultButtonTitle
= cfOKString
;
136 if (style
& wxCANCEL
)
138 alternateButtonTitle
= cfCancelString
;
139 buttonId
[1] = wxID_CANCEL
;
143 CFOptionFlags exitButton
;
144 OSStatus err
= CFUserNotificationDisplayAlert(
145 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
146 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
148 resultbutton
= buttonId
[exitButton
];
154 AlertStdCFStringAlertParamRec param
;
155 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
156 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
157 wxCFStringRef
cfOKString( GetOKLabel().c_str(), GetFont().GetEncoding() );
158 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
160 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
161 wxCFStringRef cfText
= msgtext
.IsEmpty() ? NULL
: wxCFStringRef( msgtext
, GetFont().GetEncoding() );
163 param
.movable
= true;
165 param
.version
= kStdCFStringAlertVersionOne
;
167 bool skipDialog
= false;
169 if (style
& wxYES_NO
)
171 if (style
& wxCANCEL
)
173 param
.defaultText
= cfYesString
;
174 param
.cancelText
= cfCancelString
;
175 param
.otherText
= cfNoString
;
176 param
.helpButton
= false;
177 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
178 param
.cancelButton
= kAlertStdAlertCancelButton
;
182 param
.defaultText
= cfYesString
;
183 param
.cancelText
= NULL
;
184 param
.otherText
= cfNoString
;
185 param
.helpButton
= false;
186 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
187 param
.cancelButton
= 0;
190 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
193 if (style
& wxCANCEL
)
195 // that's a cancel missing
196 param
.defaultText
= cfOKString
;
197 param
.cancelText
= cfCancelString
;
198 param
.otherText
= NULL
;
199 param
.helpButton
= false;
200 param
.defaultButton
= kAlertStdAlertOKButton
;
201 param
.cancelButton
= 0;
205 param
.defaultText
= cfOKString
;
206 param
.cancelText
= NULL
;
207 param
.otherText
= NULL
;
208 param
.helpButton
= false;
209 param
.defaultButton
= kAlertStdAlertOKButton
;
210 param
.cancelButton
= 0;
214 param
.position
= kWindowDefaultPosition
;
218 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
219 wxDialog::OSXBeginModalDialog();
220 RunStandardAlert( alertRef
, NULL
, &result
);
221 wxDialog::OSXEndModalDialog();
233 resultbutton
= wxID_OK
;
237 // TODO: add Cancel button
238 // if (style & wxCANCEL)
239 // resultbutton = wxID_CANCEL;
247 else if (style
& wxYES_NO
)
252 resultbutton
= wxID_YES
;
256 if (!(style
& wxCANCEL
))
257 resultbutton
= wxID_CANCEL
;
261 resultbutton
= wxID_NO
;
270 SetReturnCode(resultbutton
);