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"
14 #include "wx/msgdlg.h"
21 #include "wx/mac/uma.h"
24 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
27 wxMessageDialog::wxMessageDialog(
28 wxWindow
*parent
, const wxString
& message
, const wxString
& caption
,
29 long style
, const wxPoint
& pos
)
34 SetMessageDialogStyle(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
= kAlertNoteAlert
;
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
= kAlertCautionAlert
;
55 #if TARGET_API_MAC_OSX
56 if ( !wxIsMainThread() )
58 CFStringRef defaultButtonTitle
= NULL
;
59 CFStringRef alternateButtonTitle
= NULL
;
60 CFStringRef otherButtonTitle
= NULL
;
62 wxMacCFStringHolder
cfTitle( m_caption
, m_font
.GetEncoding() );
63 wxMacCFStringHolder
cfText( m_message
, m_font
.GetEncoding() );
65 wxMacCFStringHolder
cfNoString( _("No"), m_font
.GetEncoding() );
66 wxMacCFStringHolder
cfYesString( _("Yes"), m_font
.GetEncoding() );
67 wxMacCFStringHolder
cfOKString( _("OK") , m_font
.GetEncoding()) ;
68 wxMacCFStringHolder
cfCancelString( _("Cancel"), m_font
.GetEncoding() );
70 int buttonId
[4] = { 0, 0, 0, wxID_CANCEL
/* time-out */ };
74 if ( style
& wxNO_DEFAULT
)
76 defaultButtonTitle
= cfNoString
;
77 alternateButtonTitle
= cfYesString
;
78 buttonId
[0] = wxID_NO
;
79 buttonId
[1] = wxID_YES
;
83 defaultButtonTitle
= cfYesString
;
84 alternateButtonTitle
= cfNoString
;
85 buttonId
[0] = wxID_YES
;
86 buttonId
[1] = wxID_NO
;
90 otherButtonTitle
= cfCancelString
;
91 buttonId
[2] = wxID_CANCEL
;
96 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
97 buttonId
[0] = wxID_OK
;
98 // using null as default title does not work on earlier systems
99 defaultButtonTitle
= cfOKString
;
100 if (style
& wxCANCEL
)
102 alternateButtonTitle
= cfCancelString
;
103 buttonId
[1] = wxID_CANCEL
;
107 CFOptionFlags exitButton
;
108 OSStatus err
= CFUserNotificationDisplayAlert(
109 0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
,
110 defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton
);
112 resultbutton
= buttonId
[exitButton
];
119 AlertStdCFStringAlertParamRec param
;
120 wxMacCFStringHolder
cfNoString( _("No"), m_font
.GetEncoding() );
121 wxMacCFStringHolder
cfYesString( _("Yes"), m_font
.GetEncoding() );
123 wxMacCFStringHolder
cfTitle( m_caption
, m_font
.GetEncoding() );
124 wxMacCFStringHolder
cfText( m_message
, m_font
.GetEncoding() );
126 param
.movable
= true;
128 param
.version
= kStdCFStringAlertVersionOne
;
130 bool skipDialog
= false;
132 if (style
& wxYES_NO
)
134 if (style
& wxCANCEL
)
136 param
.defaultText
= cfYesString
;
137 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
138 param
.otherText
= cfNoString
;
139 param
.helpButton
= false;
140 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
141 param
.cancelButton
= kAlertStdAlertCancelButton
;
145 param
.defaultText
= cfYesString
;
146 param
.cancelText
= NULL
;
147 param
.otherText
= cfNoString
;
148 param
.helpButton
= false;
149 param
.defaultButton
= style
& wxNO_DEFAULT
? kAlertStdAlertOtherButton
: kAlertStdAlertOKButton
;
150 param
.cancelButton
= 0;
153 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
156 if (style
& wxCANCEL
)
158 // that's a cancel missing
159 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
160 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
161 param
.otherText
= NULL
;
162 param
.helpButton
= false;
163 param
.defaultButton
= kAlertStdAlertOKButton
;
164 param
.cancelButton
= 0;
168 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
169 param
.cancelText
= NULL
;
170 param
.otherText
= NULL
;
171 param
.helpButton
= false;
172 param
.defaultButton
= kAlertStdAlertOKButton
;
173 param
.cancelButton
= 0;
177 param
.position
= kWindowDefaultPosition
;
181 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
);
182 RunStandardAlert( alertRef
, NULL
, &result
);
194 resultbutton
= wxID_OK
;
198 // TODO: add Cancel button
199 // if (style & wxCANCEL)
200 // resultbutton = wxID_CANCEL;
208 else if (style
& wxYES_NO
)
213 resultbutton
= wxID_YES
;
217 if (!(style
& wxCANCEL
))
218 resultbutton
= wxID_CANCEL
;
222 resultbutton
= wxID_NO
;