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
;
65 // work out what to display
66 // if the extended text is empty then we use the caption as the title
67 // and the message as the text (for backwards compatibility)
68 // but if the extended message is not empty then we use the message as the title
69 // and the extended message as the text because that makes more sense
71 wxString msgtitle
,msgtext
;
72 if(m_extendedMessage
.IsEmpty())
80 msgtext
= m_extendedMessage
;
84 if ( !wxIsMainThread() )
86 CFStringRef defaultButtonTitle
= NULL
;
87 CFStringRef alternateButtonTitle
= NULL
;
88 CFStringRef otherButtonTitle
= NULL
;
90 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
91 wxCFStringRef
cfText( msgtext
, GetFont().GetEncoding() );
93 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
94 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
95 wxCFStringRef
cfOKString( GetOKLabel().c_str() , GetFont().GetEncoding()) ;
96 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
98 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
100 if (style
& wxYES_NO
)
102 if ( style
& wxNO_DEFAULT
)
104 defaultButtonTitle
= cfNoString
;
105 alternateButtonTitle
= cfYesString
;
106 buttonId
[0] = wxID_NO
;
107 buttonId
[1] = wxID_YES
;
111 defaultButtonTitle
= cfYesString
;
112 alternateButtonTitle
= cfNoString
;
113 buttonId
[0] = wxID_YES
;
114 buttonId
[1] = wxID_NO
;
116 if (style
& wxCANCEL
)
118 otherButtonTitle
= cfCancelString
;
119 buttonId
[2] = wxID_CANCEL
;
124 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
125 buttonId
[0] = wxID_OK
;
126 // using null as default title does not work on earlier systems
127 defaultButtonTitle
= cfOKString
;
128 if (style
& wxCANCEL
)
130 alternateButtonTitle
= cfCancelString
;
131 buttonId
[1] = wxID_CANCEL
;
135 CFOptionFlags exitButton
;
136 OSStatus err
= CFUserNotificationDisplayAlert(
137 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
138 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
140 resultbutton
= buttonId
[exitButton
];
146 AlertStdCFStringAlertParamRec param
;
147 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
148 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
149 wxCFStringRef
cfOKString( GetOKLabel().c_str(), GetFont().GetEncoding() );
150 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
152 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
153 wxCFStringRef
cfText( msgtext
, GetFont().GetEncoding() );
155 param
.movable
= true;
157 param
.version
= kStdCFStringAlertVersionOne
;
159 bool skipDialog
= false;
161 if (style
& wxYES_NO
)
163 if (style
& wxCANCEL
)
165 param
.defaultText
= cfYesString
;
166 param
.cancelText
= cfCancelString
;
167 param
.otherText
= cfNoString
;
168 param
.helpButton
= false;
169 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
170 param
.cancelButton
= kAlertStdAlertCancelButton
;
174 param
.defaultText
= cfYesString
;
175 param
.cancelText
= NULL
;
176 param
.otherText
= cfNoString
;
177 param
.helpButton
= false;
178 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
179 param
.cancelButton
= 0;
182 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
185 if (style
& wxCANCEL
)
187 // that's a cancel missing
188 param
.defaultText
= cfOKString
;
189 param
.cancelText
= cfCancelString
;
190 param
.otherText
= NULL
;
191 param
.helpButton
= false;
192 param
.defaultButton
= kAlertStdAlertOKButton
;
193 param
.cancelButton
= 0;
197 param
.defaultText
= cfOKString
;
198 param
.cancelText
= NULL
;
199 param
.otherText
= NULL
;
200 param
.helpButton
= false;
201 param
.defaultButton
= kAlertStdAlertOKButton
;
202 param
.cancelButton
= 0;
206 param
.position
= kWindowDefaultPosition
;
210 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
211 RunStandardAlert( alertRef
, NULL
, &result
);
223 resultbutton
= wxID_OK
;
227 // TODO: add Cancel button
228 // if (style & wxCANCEL)
229 // resultbutton = wxID_CANCEL;
237 else if (style
& wxYES_NO
)
242 resultbutton
= wxID_YES
;
246 if (!(style
& wxCANCEL
))
247 resultbutton
= wxID_CANCEL
;
251 resultbutton
= wxID_NO
;
260 SetReturnCode(resultbutton
);