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
, wxT("this style is not supported on Mac") );
45 AlertType alertType
= kAlertPlainAlert
;
46 if (style
& wxICON_EXCLAMATION
)
47 alertType
= kAlertCautionAlert
;
48 else if (style
& wxICON_HAND
)
49 alertType
= kAlertStopAlert
;
50 else if (style
& wxICON_INFORMATION
)
51 alertType
= kAlertNoteAlert
;
52 else if (style
& wxICON_QUESTION
)
53 alertType
= kAlertNoteAlert
;
56 // work out what to display
57 // if the extended text is empty then we use the caption as the title
58 // and the message as the text (for backwards compatibility)
59 // but if the extended message is not empty then we use the message as the title
60 // and the extended message as the text because that makes more sense
62 wxString msgtitle
,msgtext
;
63 if(m_extendedMessage
.IsEmpty())
71 msgtext
= m_extendedMessage
;
75 if ( !wxIsMainThread() )
77 CFStringRef defaultButtonTitle
= NULL
;
78 CFStringRef alternateButtonTitle
= NULL
;
79 CFStringRef otherButtonTitle
= NULL
;
81 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
82 wxCFStringRef
cfText( msgtext
, GetFont().GetEncoding() );
84 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
85 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
86 wxCFStringRef
cfOKString( GetOKLabel().c_str() , GetFont().GetEncoding()) ;
87 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
89 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
93 if ( style
& wxNO_DEFAULT
)
95 defaultButtonTitle
= cfNoString
;
96 alternateButtonTitle
= cfYesString
;
97 buttonId
[0] = wxID_NO
;
98 buttonId
[1] = wxID_YES
;
102 defaultButtonTitle
= cfYesString
;
103 alternateButtonTitle
= cfNoString
;
104 buttonId
[0] = wxID_YES
;
105 buttonId
[1] = wxID_NO
;
107 if (style
& wxCANCEL
)
109 otherButtonTitle
= cfCancelString
;
110 buttonId
[2] = wxID_CANCEL
;
115 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
116 buttonId
[0] = wxID_OK
;
117 // using null as default title does not work on earlier systems
118 defaultButtonTitle
= cfOKString
;
119 if (style
& wxCANCEL
)
121 alternateButtonTitle
= cfCancelString
;
122 buttonId
[1] = wxID_CANCEL
;
126 CFOptionFlags exitButton
;
127 OSStatus err
= CFUserNotificationDisplayAlert(
128 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
129 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
131 resultbutton
= buttonId
[exitButton
];
137 AlertStdCFStringAlertParamRec param
;
138 wxCFStringRef
cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
139 wxCFStringRef
cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
140 wxCFStringRef
cfOKString( GetOKLabel().c_str(), GetFont().GetEncoding() );
141 wxCFStringRef
cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
143 wxCFStringRef
cfTitle( msgtitle
, GetFont().GetEncoding() );
144 wxCFStringRef
cfText( msgtext
, GetFont().GetEncoding() );
146 param
.movable
= true;
148 param
.version
= kStdCFStringAlertVersionOne
;
150 bool skipDialog
= false;
152 if (style
& wxYES_NO
)
154 if (style
& wxCANCEL
)
156 param
.defaultText
= cfYesString
;
157 param
.cancelText
= cfCancelString
;
158 param
.otherText
= cfNoString
;
159 param
.helpButton
= false;
160 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
161 param
.cancelButton
= kAlertStdAlertCancelButton
;
165 param
.defaultText
= cfYesString
;
166 param
.cancelText
= NULL
;
167 param
.otherText
= cfNoString
;
168 param
.helpButton
= false;
169 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
170 param
.cancelButton
= 0;
173 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
176 if (style
& wxCANCEL
)
178 // that's a cancel missing
179 param
.defaultText
= cfOKString
;
180 param
.cancelText
= cfCancelString
;
181 param
.otherText
= NULL
;
182 param
.helpButton
= false;
183 param
.defaultButton
= kAlertStdAlertOKButton
;
184 param
.cancelButton
= 0;
188 param
.defaultText
= cfOKString
;
189 param
.cancelText
= NULL
;
190 param
.otherText
= NULL
;
191 param
.helpButton
= false;
192 param
.defaultButton
= kAlertStdAlertOKButton
;
193 param
.cancelButton
= 0;
197 param
.position
= kWindowDefaultPosition
;
201 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
202 RunStandardAlert( alertRef
, NULL
, &result
);
214 resultbutton
= wxID_OK
;
218 // TODO: add Cancel button
219 // if (style & wxCANCEL)
220 // resultbutton = wxID_CANCEL;
228 else if (style
& wxYES_NO
)
233 resultbutton
= wxID_YES
;
237 if (!(style
& wxCANCEL
))
238 resultbutton
= wxID_CANCEL
;
242 resultbutton
= wxID_NO
;