1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/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"
15 #include "wx/msgdlg.h"
17 #include "wx/mac/uma.h"
19 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
21 wxMessageDialog::wxMessageDialog(wxWindow
*parent
, const wxString
& message
, const wxString
& caption
,
22 long style
, const wxPoint
& pos
)
27 SetMessageDialogStyle(style
);
30 int wxMessageDialog::ShowModal()
32 int resultbutton
= wxID_CANCEL
;
34 const long style
= GetMessageDialogStyle();
36 wxASSERT_MSG( ( style
& 0x3F ) != wxYES
, wxT("this style is not supported on mac") ) ;
38 AlertType alertType
= kAlertPlainAlert
;
39 if (style
& wxICON_EXCLAMATION
)
40 alertType
= kAlertNoteAlert
;
41 else if (style
& wxICON_HAND
)
42 alertType
= kAlertStopAlert
;
43 else if (style
& wxICON_INFORMATION
)
44 alertType
= kAlertNoteAlert
;
45 else if (style
& wxICON_QUESTION
)
46 alertType
= kAlertCautionAlert
;
48 #if TARGET_API_MAC_OSX
49 CFStringRef defaultButtonTitle
= NULL
;
50 CFStringRef alternateButtonTitle
= NULL
;
51 CFStringRef otherButtonTitle
= NULL
;
53 wxMacCFStringHolder
cfTitle(m_caption
, m_font
.GetEncoding());
54 wxMacCFStringHolder
cfText(m_message
, m_font
.GetEncoding());
56 wxMacCFStringHolder
cfNoString(_("No") , m_font
.GetEncoding()) ;
57 wxMacCFStringHolder
cfYesString( _("Yes") , m_font
.GetEncoding()) ;
58 wxMacCFStringHolder
cfCancelString( _("Cancel") , m_font
.GetEncoding()) ;
60 int buttonId
[4] = { 0 , 0 , 0 , wxID_CANCEL
/* time-out */ } ;
64 if ( style
& wxNO_DEFAULT
)
66 defaultButtonTitle
= cfNoString
;
67 alternateButtonTitle
= cfYesString
;
68 buttonId
[0] = wxID_NO
;
69 buttonId
[1] = wxID_YES
;
73 defaultButtonTitle
= cfYesString
;
74 alternateButtonTitle
= cfNoString
;
75 buttonId
[0] = wxID_YES
;
76 buttonId
[1] = wxID_NO
;
80 otherButtonTitle
= cfCancelString
;
81 buttonId
[2] = wxID_CANCEL
;
86 // the msw implementation even shows an ok button if it is not specified, we'll do the same
87 buttonId
[0] = wxID_OK
;
90 alternateButtonTitle
= cfCancelString
;
91 buttonId
[1] = wxID_CANCEL
;
95 CFOptionFlags exitButton
;
96 OSStatus err
= CFUserNotificationDisplayAlert ( 0 , alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
97 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
99 resultbutton
= buttonId
[exitButton
] ;
105 if ( UMAGetSystemVersion() >= 0x1000 )
107 AlertStdCFStringAlertParamRec param
;
108 wxMacCFStringHolder
cfNoString(_("No") , m_font
.GetEncoding()) ;
109 wxMacCFStringHolder
cfYesString( _("Yes") , m_font
.GetEncoding()) ;
111 wxMacCFStringHolder
cfTitle(m_caption
, m_font
.GetEncoding());
112 wxMacCFStringHolder
cfText(m_message
, m_font
.GetEncoding());
114 param
.movable
= true;
116 param
.version
= kStdCFStringAlertVersionOne
;
118 bool skipDialog
= false ;
120 if (style
& wxYES_NO
)
122 if (style
& wxCANCEL
)
124 param
.defaultText
= cfYesString
;
125 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
126 param
.otherText
= cfNoString
;
127 param
.helpButton
= false ;
128 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
129 param
.cancelButton
= kAlertStdAlertCancelButton
;
133 param
.defaultText
= cfYesString
;
134 param
.cancelText
= NULL
;
135 param
.otherText
= cfNoString
;
136 param
.helpButton
= false ;
137 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
138 param
.cancelButton
= 0;
141 // the msw implementation even shows an ok button if it is not specified, we'll do the same
144 if (style
& wxCANCEL
)
146 // thats a cancel missing
147 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
148 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
149 param
.otherText
= NULL
;
150 param
.helpButton
= false ;
151 param
.defaultButton
= kAlertStdAlertOKButton
;
152 param
.cancelButton
= 0;
156 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
157 param
.cancelText
= NULL
;
158 param
.otherText
= NULL
;
159 param
.helpButton
= false ;
160 param
.defaultButton
= kAlertStdAlertOKButton
;
161 param
.cancelButton
= 0;
171 param
.position
= kWindowDefaultPosition
;
175 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
) ;
176 RunStandardAlert( alertRef
, NULL
, &result
) ;
184 AlertStdAlertParamRec param
;
191 wxMacStringToPascal( m_caption
, pascalTitle
) ;
192 wxMacStringToPascal( _("Yes") , yesPString
) ;
193 wxMacStringToPascal( _("No") , noPString
) ;
194 wxMacStringToPascal( m_message
, pascalText
) ;
196 param
.movable
= true;
197 param
.filterProc
= NULL
;
198 if (style
& wxYES_NO
)
200 if (style
& wxCANCEL
)
202 param
.defaultText
= yesPString
;
203 param
.cancelText
= (StringPtr
) kAlertDefaultCancelText
;
204 param
.otherText
= noPString
;
205 param
.helpButton
= false ;
206 param
.defaultButton
= kAlertStdAlertOKButton
;
207 param
.cancelButton
= kAlertStdAlertCancelButton
;
211 param
.defaultText
= yesPString
;
212 param
.cancelText
= NULL
;
213 param
.otherText
= noPString
;
214 param
.helpButton
= false ;
215 param
.defaultButton
= kAlertStdAlertOKButton
;
216 param
.cancelButton
= 0;
219 else if (style
& wxOK
)
221 if (style
& wxCANCEL
)
223 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
224 param
.cancelText
= (StringPtr
) kAlertDefaultCancelText
;
225 param
.otherText
= NULL
;
226 param
.helpButton
= false ;
227 param
.defaultButton
= kAlertStdAlertOKButton
;
228 param
.cancelButton
= 0;
232 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
233 param
.cancelText
= NULL
;
234 param
.otherText
= NULL
;
235 param
.helpButton
= false ;
236 param
.defaultButton
= kAlertStdAlertOKButton
;
237 param
.cancelButton
= 0;
242 return resultbutton
;
247 StandardAlert( alertType
, pascalTitle
, pascalText
, ¶m
, &result
);
252 if (style
& wxCANCEL
)
254 //TODO add Cancelbutton
258 resultbutton
= wxID_OK
;
271 resultbutton
= wxID_OK
;
280 else if (style
& wxYES_NO
)
282 if (style
& wxCANCEL
)
287 resultbutton
= wxID_YES
;
290 resultbutton
= wxID_CANCEL
;
293 resultbutton
= wxID_NO
;
302 resultbutton
= wxID_YES
;
307 resultbutton
= wxID_NO
;
314 return resultbutton
;