]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
e5b50758 | 2 | // Name: src/mac/carbon/msgdlg.cpp |
e9576ca5 | 3 | // Purpose: wxMessageDialog |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
e5b50758 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
e5b50758 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 | 14 | #include "wx/msgdlg.h" |
88a7a4e1 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/intl.h" | |
670f9935 | 18 | #include "wx/app.h" |
88a7a4e1 WS |
19 | #endif |
20 | ||
519cb848 | 21 | #include "wx/mac/uma.h" |
e9576ca5 | 22 | |
51c4d2a5 | 23 | |
e9576ca5 | 24 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
e9576ca5 | 25 | |
51c4d2a5 DS |
26 | |
27 | wxMessageDialog::wxMessageDialog( | |
28 | wxWindow *parent, const wxString& message, const wxString& caption, | |
29 | long style, const wxPoint& pos ) | |
e9576ca5 SC |
30 | { |
31 | m_caption = caption; | |
32 | m_message = message; | |
e9576ca5 | 33 | m_parent = parent; |
e5b50758 | 34 | SetMessageDialogStyle(style); |
e9576ca5 SC |
35 | } |
36 | ||
37 | int wxMessageDialog::ShowModal() | |
38 | { | |
51c4d2a5 | 39 | int resultbutton = wxID_CANCEL; |
e5b50758 | 40 | |
e5b50758 WS |
41 | const long style = GetMessageDialogStyle(); |
42 | ||
51c4d2a5 | 43 | wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") ); |
e5b50758 | 44 | |
51c4d2a5 | 45 | AlertType alertType = kAlertPlainAlert; |
e5b50758 | 46 | if (style & wxICON_EXCLAMATION) |
51c4d2a5 | 47 | alertType = kAlertNoteAlert; |
e5b50758 | 48 | else if (style & wxICON_HAND) |
51c4d2a5 | 49 | alertType = kAlertStopAlert; |
e5b50758 | 50 | else if (style & wxICON_INFORMATION) |
51c4d2a5 | 51 | alertType = kAlertNoteAlert; |
e5b50758 | 52 | else if (style & wxICON_QUESTION) |
51c4d2a5 | 53 | alertType = kAlertCautionAlert; |
e5b50758 | 54 | |
57a21e6c | 55 | #if TARGET_API_MAC_OSX |
5a253c3f SC |
56 | if ( !wxIsMainThread() ) |
57 | { | |
58 | CFStringRef defaultButtonTitle = NULL; | |
59 | CFStringRef alternateButtonTitle = NULL; | |
60 | CFStringRef otherButtonTitle = NULL; | |
51c4d2a5 | 61 | |
5a253c3f SC |
62 | wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); |
63 | wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); | |
51c4d2a5 | 64 | |
5a253c3f SC |
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() ); | |
51c4d2a5 | 69 | |
5a253c3f | 70 | int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; |
51c4d2a5 | 71 | |
5a253c3f | 72 | if (style & wxYES_NO) |
57a21e6c | 73 | { |
5a253c3f SC |
74 | if ( style & wxNO_DEFAULT ) |
75 | { | |
76 | defaultButtonTitle = cfNoString; | |
77 | alternateButtonTitle = cfYesString; | |
78 | buttonId[0] = wxID_NO; | |
79 | buttonId[1] = wxID_YES; | |
80 | } | |
81 | else | |
82 | { | |
83 | defaultButtonTitle = cfYesString; | |
84 | alternateButtonTitle = cfNoString; | |
85 | buttonId[0] = wxID_YES; | |
86 | buttonId[1] = wxID_NO; | |
87 | } | |
88 | if (style & wxCANCEL) | |
89 | { | |
90 | otherButtonTitle = cfCancelString; | |
91 | buttonId[2] = wxID_CANCEL; | |
92 | } | |
57a21e6c SC |
93 | } |
94 | else | |
95 | { | |
5a253c3f SC |
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) | |
101 | { | |
102 | alternateButtonTitle = cfCancelString; | |
103 | buttonId[1] = wxID_CANCEL; | |
104 | } | |
57a21e6c | 105 | } |
5a253c3f SC |
106 | |
107 | CFOptionFlags exitButton; | |
108 | OSStatus err = CFUserNotificationDisplayAlert( | |
109 | 0, alertType, NULL, NULL, NULL, cfTitle, cfText, | |
110 | defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton ); | |
111 | if (err == noErr) | |
112 | resultbutton = buttonId[exitButton]; | |
57a21e6c SC |
113 | } |
114 | else | |
5a253c3f | 115 | #endif |
57a21e6c | 116 | { |
5a253c3f | 117 | short result; |
57a21e6c | 118 | |
51c4d2a5 | 119 | AlertStdCFStringAlertParamRec param; |
34cf96b2 SC |
120 | wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() ); |
121 | wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() ); | |
e5b50758 | 122 | |
51c4d2a5 DS |
123 | wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); |
124 | wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); | |
e5b50758 | 125 | |
e40298d5 | 126 | param.movable = true; |
51c4d2a5 DS |
127 | param.flags = 0; |
128 | param.version = kStdCFStringAlertVersionOne; | |
e5b50758 | 129 | |
51c4d2a5 | 130 | bool skipDialog = false; |
e5b50758 WS |
131 | |
132 | if (style & wxYES_NO) | |
e40298d5 | 133 | { |
e5b50758 | 134 | if (style & wxCANCEL) |
e40298d5 | 135 | { |
51c4d2a5 DS |
136 | param.defaultText = cfYesString; |
137 | param.cancelText = (CFStringRef) kAlertDefaultCancelText; | |
138 | param.otherText = cfNoString; | |
139 | param.helpButton = false; | |
e5b50758 | 140 | param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; |
51c4d2a5 | 141 | param.cancelButton = kAlertStdAlertCancelButton; |
e40298d5 JS |
142 | } |
143 | else | |
144 | { | |
51c4d2a5 DS |
145 | param.defaultText = cfYesString; |
146 | param.cancelText = NULL; | |
147 | param.otherText = cfNoString; | |
148 | param.helpButton = false; | |
e5b50758 | 149 | param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; |
51c4d2a5 | 150 | param.cancelButton = 0; |
e40298d5 JS |
151 | } |
152 | } | |
51c4d2a5 | 153 | // the MSW implementation even shows an OK button if it is not specified, we'll do the same |
e5b50758 | 154 | else |
e40298d5 | 155 | { |
e5b50758 | 156 | if (style & wxCANCEL) |
e40298d5 | 157 | { |
51c4d2a5 DS |
158 | // that's a cancel missing |
159 | param.defaultText = (CFStringRef) kAlertDefaultOKText; | |
160 | param.cancelText = (CFStringRef) kAlertDefaultCancelText; | |
161 | param.otherText = NULL; | |
162 | param.helpButton = false; | |
e40298d5 | 163 | param.defaultButton = kAlertStdAlertOKButton; |
51c4d2a5 | 164 | param.cancelButton = 0; |
e40298d5 JS |
165 | } |
166 | else | |
167 | { | |
51c4d2a5 DS |
168 | param.defaultText = (CFStringRef) kAlertDefaultOKText; |
169 | param.cancelText = NULL; | |
170 | param.otherText = NULL; | |
171 | param.helpButton = false; | |
e40298d5 | 172 | param.defaultButton = kAlertStdAlertOKButton; |
51c4d2a5 | 173 | param.cancelButton = 0; |
e40298d5 JS |
174 | } |
175 | } | |
e5b50758 | 176 | |
e40298d5 JS |
177 | param.position = kWindowDefaultPosition; |
178 | if ( !skipDialog ) | |
179 | { | |
51c4d2a5 DS |
180 | DialogRef alertRef; |
181 | CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); | |
182 | RunStandardAlert( alertRef, NULL, &result ); | |
183 | } | |
184 | else | |
185 | { | |
186 | return wxID_CANCEL; | |
e40298d5 | 187 | } |
e5b50758 | 188 | |
5a253c3f | 189 | if (style & wxOK) |
e40298d5 | 190 | { |
5a253c3f | 191 | switch ( result ) |
e40298d5 | 192 | { |
5a253c3f SC |
193 | case 1: |
194 | resultbutton = wxID_OK; | |
195 | break; | |
196 | ||
197 | case 2: | |
198 | // TODO: add Cancel button | |
199 | // if (style & wxCANCEL) | |
200 | // resultbutton = wxID_CANCEL; | |
201 | break; | |
202 | ||
203 | case 3: | |
204 | default: | |
205 | break; | |
e40298d5 JS |
206 | } |
207 | } | |
5a253c3f | 208 | else if (style & wxYES_NO) |
e40298d5 | 209 | { |
5a253c3f | 210 | switch ( result ) |
e40298d5 | 211 | { |
5a253c3f SC |
212 | case 1: |
213 | resultbutton = wxID_YES; | |
214 | break; | |
51c4d2a5 | 215 | |
5a253c3f SC |
216 | case 2: |
217 | if (!(style & wxCANCEL)) | |
218 | resultbutton = wxID_CANCEL; | |
219 | break; | |
51c4d2a5 | 220 | |
5a253c3f SC |
221 | case 3: |
222 | resultbutton = wxID_NO; | |
223 | break; | |
51c4d2a5 | 224 | |
5a253c3f SC |
225 | default: |
226 | break; | |
227 | } | |
e40298d5 | 228 | } |
e5b50758 | 229 | } |
51c4d2a5 DS |
230 | |
231 | return resultbutton; | |
e9576ca5 | 232 | } |