]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msgdlg.cpp | |
3 | // Purpose: wxMessageDialog | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $$ | |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "msgdlg.h" | |
14 | #endif | |
15 | ||
03e11df5 | 16 | #include "wx/app.h" |
e9576ca5 | 17 | #include "wx/msgdlg.h" |
49e95e1d | 18 | #include "wx/intl.h" |
519cb848 | 19 | #include "wx/mac/uma.h" |
e9576ca5 | 20 | |
2f1ae414 | 21 | #if !USE_SHARED_LIBRARY |
e9576ca5 | 22 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
2f1ae414 | 23 | #endif |
e9576ca5 SC |
24 | |
25 | wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption, | |
e40298d5 | 26 | long style, const wxPoint& pos) |
e9576ca5 SC |
27 | { |
28 | m_caption = caption; | |
29 | m_message = message; | |
30 | m_dialogStyle = style; | |
31 | m_parent = parent; | |
32 | } | |
33 | ||
34 | int wxMessageDialog::ShowModal() | |
35 | { | |
e40298d5 JS |
36 | int resultbutton = wxID_CANCEL ; |
37 | ||
38 | short result ; | |
39 | ||
427ff662 | 40 | wxASSERT_MSG( ( m_dialogStyle & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ; |
e40298d5 JS |
41 | |
42 | AlertType alertType = kAlertPlainAlert ; | |
43 | if (m_dialogStyle & wxICON_EXCLAMATION) | |
44 | alertType = kAlertNoteAlert ; | |
45 | else if (m_dialogStyle & wxICON_HAND) | |
46 | alertType = kAlertStopAlert ; | |
47 | else if (m_dialogStyle & wxICON_INFORMATION) | |
48 | alertType = kAlertNoteAlert ; | |
49 | else if (m_dialogStyle & wxICON_QUESTION) | |
50 | alertType = kAlertCautionAlert ; | |
51 | ||
992c81e2 | 52 | #if TARGET_CARBON |
e40298d5 JS |
53 | if ( UMAGetSystemVersion() >= 0x1000 ) |
54 | { | |
55 | AlertStdCFStringAlertParamRec param ; | |
a9412f8f SC |
56 | wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ; |
57 | wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ; | |
e40298d5 | 58 | |
a9412f8f SC |
59 | wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding()); |
60 | wxMacCFStringHolder cfText(m_message , m_font.GetEncoding()); | |
427ff662 | 61 | |
e40298d5 JS |
62 | param.movable = true; |
63 | param.flags = 0 ; | |
939a2e80 | 64 | param.version = kStdCFStringAlertVersionOne ; |
e40298d5 JS |
65 | |
66 | bool skipDialog = false ; | |
67 | ||
68 | if (m_dialogStyle & wxYES_NO) | |
69 | { | |
70 | if (m_dialogStyle & wxCANCEL) | |
71 | { | |
72 | param.defaultText = cfYesString ; | |
73 | param.cancelText = (CFStringRef) kAlertDefaultCancelText; | |
74 | param.otherText = cfNoString ; | |
75 | param.helpButton = false ; | |
939a2e80 | 76 | param.defaultButton = m_dialogStyle & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; |
e40298d5 JS |
77 | param.cancelButton = kAlertStdAlertCancelButton; |
78 | } | |
79 | else | |
80 | { | |
81 | param.defaultText = cfYesString ; | |
82 | param.cancelText = NULL; | |
83 | param.otherText = cfNoString ; | |
84 | param.helpButton = false ; | |
939a2e80 | 85 | param.defaultButton = m_dialogStyle & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; |
e40298d5 JS |
86 | param.cancelButton = 0; |
87 | } | |
88 | } | |
c4a49e11 SC |
89 | // the msw implementation even shows an ok button if it is not specified, we'll do the same |
90 | else | |
e40298d5 JS |
91 | { |
92 | if (m_dialogStyle & wxCANCEL) | |
93 | { | |
94 | // thats a cancel missing | |
95 | param.defaultText = (CFStringRef) kAlertDefaultOKText ; | |
b7aec135 | 96 | param.cancelText = (CFStringRef) kAlertDefaultCancelText ; |
e40298d5 JS |
97 | param.otherText = NULL; |
98 | param.helpButton = false ; | |
99 | param.defaultButton = kAlertStdAlertOKButton; | |
100 | param.cancelButton = 0; | |
101 | } | |
102 | else | |
103 | { | |
104 | param.defaultText = (CFStringRef) kAlertDefaultOKText ; | |
105 | param.cancelText = NULL; | |
106 | param.otherText = NULL; | |
107 | param.helpButton = false ; | |
108 | param.defaultButton = kAlertStdAlertOKButton; | |
109 | param.cancelButton = 0; | |
110 | } | |
111 | } | |
c4a49e11 | 112 | /* |
e40298d5 JS |
113 | else |
114 | { | |
115 | skipDialog = true ; | |
116 | } | |
c4a49e11 | 117 | */ |
e40298d5 JS |
118 | |
119 | param.position = kWindowDefaultPosition; | |
120 | if ( !skipDialog ) | |
121 | { | |
122 | DialogRef alertRef ; | |
123 | CreateStandardAlert( alertType , cfTitle , cfText , ¶m , &alertRef ) ; | |
124 | RunStandardAlert( alertRef , NULL , &result ) ; | |
125 | } | |
427ff662 | 126 | if ( skipDialog ) |
e40298d5 JS |
127 | return wxID_CANCEL ; |
128 | } | |
129 | else | |
992c81e2 | 130 | #endif |
e40298d5 JS |
131 | { |
132 | AlertStdAlertParamRec param; | |
e40298d5 JS |
133 | |
134 | Str255 yesPString ; | |
135 | Str255 noPString ; | |
136 | ||
137 | Str255 pascalTitle ; | |
138 | Str255 pascalText ; | |
139 | wxMacStringToPascal( m_caption , pascalTitle ) ; | |
140 | wxMacStringToPascal( _("Yes") , yesPString ) ; | |
141 | wxMacStringToPascal( _("No") , noPString ) ; | |
427ff662 | 142 | wxMacStringToPascal( m_message , pascalText ) ; |
e40298d5 JS |
143 | |
144 | param.movable = true; | |
145 | param.filterProc = NULL ; | |
146 | if (m_dialogStyle & wxYES_NO) | |
147 | { | |
148 | if (m_dialogStyle & wxCANCEL) | |
149 | { | |
150 | param.defaultText = yesPString ; | |
151 | param.cancelText = (StringPtr) kAlertDefaultCancelText; | |
152 | param.otherText = noPString ; | |
153 | param.helpButton = false ; | |
154 | param.defaultButton = kAlertStdAlertOKButton; | |
155 | param.cancelButton = kAlertStdAlertCancelButton; | |
156 | } | |
157 | else | |
158 | { | |
159 | param.defaultText = yesPString ; | |
160 | param.cancelText = NULL; | |
161 | param.otherText = noPString ; | |
162 | param.helpButton = false ; | |
163 | param.defaultButton = kAlertStdAlertOKButton; | |
164 | param.cancelButton = 0; | |
165 | } | |
166 | } | |
167 | else if (m_dialogStyle & wxOK) | |
168 | { | |
169 | if (m_dialogStyle & wxCANCEL) | |
170 | { | |
e40298d5 | 171 | param.defaultText = (StringPtr) kAlertDefaultOKText ; |
b7aec135 | 172 | param.cancelText = (StringPtr) kAlertDefaultCancelText ; |
e40298d5 JS |
173 | param.otherText = NULL; |
174 | param.helpButton = false ; | |
175 | param.defaultButton = kAlertStdAlertOKButton; | |
176 | param.cancelButton = 0; | |
177 | } | |
178 | else | |
179 | { | |
180 | param.defaultText = (StringPtr) kAlertDefaultOKText ; | |
181 | param.cancelText = NULL; | |
182 | param.otherText = NULL; | |
183 | param.helpButton = false ; | |
184 | param.defaultButton = kAlertStdAlertOKButton; | |
185 | param.cancelButton = 0; | |
186 | } | |
187 | } | |
188 | else | |
189 | { | |
190 | return resultbutton ; | |
191 | } | |
192 | ||
193 | param.position = 0; | |
194 | ||
195 | StandardAlert( alertType, pascalTitle, pascalText, ¶m, &result ); | |
196 | } | |
197 | ||
198 | if (m_dialogStyle & wxOK) | |
199 | { | |
200 | if (m_dialogStyle & wxCANCEL) | |
201 | { | |
202 | //TODO add Cancelbutton | |
203 | switch( result ) | |
204 | { | |
205 | case 1 : | |
206 | resultbutton = wxID_OK ; | |
207 | break ; | |
208 | case 2 : | |
209 | break ; | |
210 | case 3 : | |
211 | break ; | |
212 | } | |
213 | } | |
214 | else | |
215 | { | |
216 | switch( result ) | |
217 | { | |
218 | case 1 : | |
219 | resultbutton = wxID_OK ; | |
220 | break ; | |
221 | case 2 : | |
222 | break ; | |
223 | case 3 : | |
224 | break ; | |
225 | } | |
226 | } | |
227 | } | |
228 | else if (m_dialogStyle & wxYES_NO) | |
229 | { | |
230 | if (m_dialogStyle & wxCANCEL) | |
231 | { | |
232 | switch( result ) | |
233 | { | |
234 | case 1 : | |
235 | resultbutton = wxID_YES ; | |
236 | break ; | |
237 | case 2 : | |
238 | resultbutton = wxID_CANCEL ; | |
239 | break ; | |
240 | case 3 : | |
241 | resultbutton = wxID_NO ; | |
242 | break ; | |
243 | } | |
244 | } | |
245 | else | |
246 | { | |
247 | switch( result ) | |
248 | { | |
249 | case 1 : | |
250 | resultbutton = wxID_YES ; | |
251 | break ; | |
252 | case 2 : | |
253 | break ; | |
254 | case 3 : | |
255 | resultbutton = wxID_NO ; | |
256 | break ; | |
257 | } | |
258 | } | |
259 | } | |
260 | ||
261 | return resultbutton ; | |
e9576ca5 SC |
262 | } |
263 |