]>
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 ; | |
64 | ||
65 | bool skipDialog = false ; | |
66 | ||
67 | if (m_dialogStyle & wxYES_NO) | |
68 | { | |
69 | if (m_dialogStyle & wxCANCEL) | |
70 | { | |
71 | param.defaultText = cfYesString ; | |
72 | param.cancelText = (CFStringRef) kAlertDefaultCancelText; | |
73 | param.otherText = cfNoString ; | |
74 | param.helpButton = false ; | |
75 | param.defaultButton = kAlertStdAlertOKButton; | |
76 | param.cancelButton = kAlertStdAlertCancelButton; | |
77 | } | |
78 | else | |
79 | { | |
80 | param.defaultText = cfYesString ; | |
81 | param.cancelText = NULL; | |
82 | param.otherText = cfNoString ; | |
83 | param.helpButton = false ; | |
84 | param.defaultButton = kAlertStdAlertOKButton; | |
85 | param.cancelButton = 0; | |
86 | } | |
87 | } | |
c4a49e11 SC |
88 | // the msw implementation even shows an ok button if it is not specified, we'll do the same |
89 | else | |
e40298d5 JS |
90 | { |
91 | if (m_dialogStyle & wxCANCEL) | |
92 | { | |
93 | // thats a cancel missing | |
94 | param.defaultText = (CFStringRef) kAlertDefaultOKText ; | |
b7aec135 | 95 | param.cancelText = (CFStringRef) kAlertDefaultCancelText ; |
e40298d5 JS |
96 | param.otherText = NULL; |
97 | param.helpButton = false ; | |
98 | param.defaultButton = kAlertStdAlertOKButton; | |
99 | param.cancelButton = 0; | |
100 | } | |
101 | else | |
102 | { | |
103 | param.defaultText = (CFStringRef) kAlertDefaultOKText ; | |
104 | param.cancelText = NULL; | |
105 | param.otherText = NULL; | |
106 | param.helpButton = false ; | |
107 | param.defaultButton = kAlertStdAlertOKButton; | |
108 | param.cancelButton = 0; | |
109 | } | |
110 | } | |
c4a49e11 | 111 | /* |
e40298d5 JS |
112 | else |
113 | { | |
114 | skipDialog = true ; | |
115 | } | |
c4a49e11 | 116 | */ |
e40298d5 JS |
117 | |
118 | param.position = kWindowDefaultPosition; | |
119 | if ( !skipDialog ) | |
120 | { | |
121 | DialogRef alertRef ; | |
122 | CreateStandardAlert( alertType , cfTitle , cfText , ¶m , &alertRef ) ; | |
123 | RunStandardAlert( alertRef , NULL , &result ) ; | |
124 | } | |
427ff662 | 125 | if ( skipDialog ) |
e40298d5 JS |
126 | return wxID_CANCEL ; |
127 | } | |
128 | else | |
992c81e2 | 129 | #endif |
e40298d5 JS |
130 | { |
131 | AlertStdAlertParamRec param; | |
e40298d5 JS |
132 | |
133 | Str255 yesPString ; | |
134 | Str255 noPString ; | |
135 | ||
136 | Str255 pascalTitle ; | |
137 | Str255 pascalText ; | |
138 | wxMacStringToPascal( m_caption , pascalTitle ) ; | |
139 | wxMacStringToPascal( _("Yes") , yesPString ) ; | |
140 | wxMacStringToPascal( _("No") , noPString ) ; | |
427ff662 | 141 | wxMacStringToPascal( m_message , pascalText ) ; |
e40298d5 JS |
142 | |
143 | param.movable = true; | |
144 | param.filterProc = NULL ; | |
145 | if (m_dialogStyle & wxYES_NO) | |
146 | { | |
147 | if (m_dialogStyle & wxCANCEL) | |
148 | { | |
149 | param.defaultText = yesPString ; | |
150 | param.cancelText = (StringPtr) kAlertDefaultCancelText; | |
151 | param.otherText = noPString ; | |
152 | param.helpButton = false ; | |
153 | param.defaultButton = kAlertStdAlertOKButton; | |
154 | param.cancelButton = kAlertStdAlertCancelButton; | |
155 | } | |
156 | else | |
157 | { | |
158 | param.defaultText = yesPString ; | |
159 | param.cancelText = NULL; | |
160 | param.otherText = noPString ; | |
161 | param.helpButton = false ; | |
162 | param.defaultButton = kAlertStdAlertOKButton; | |
163 | param.cancelButton = 0; | |
164 | } | |
165 | } | |
166 | else if (m_dialogStyle & wxOK) | |
167 | { | |
168 | if (m_dialogStyle & wxCANCEL) | |
169 | { | |
e40298d5 | 170 | param.defaultText = (StringPtr) kAlertDefaultOKText ; |
b7aec135 | 171 | param.cancelText = (StringPtr) kAlertDefaultCancelText ; |
e40298d5 JS |
172 | param.otherText = NULL; |
173 | param.helpButton = false ; | |
174 | param.defaultButton = kAlertStdAlertOKButton; | |
175 | param.cancelButton = 0; | |
176 | } | |
177 | else | |
178 | { | |
179 | param.defaultText = (StringPtr) kAlertDefaultOKText ; | |
180 | param.cancelText = NULL; | |
181 | param.otherText = NULL; | |
182 | param.helpButton = false ; | |
183 | param.defaultButton = kAlertStdAlertOKButton; | |
184 | param.cancelButton = 0; | |
185 | } | |
186 | } | |
187 | else | |
188 | { | |
189 | return resultbutton ; | |
190 | } | |
191 | ||
192 | param.position = 0; | |
193 | ||
194 | StandardAlert( alertType, pascalTitle, pascalText, ¶m, &result ); | |
195 | } | |
196 | ||
197 | if (m_dialogStyle & wxOK) | |
198 | { | |
199 | if (m_dialogStyle & wxCANCEL) | |
200 | { | |
201 | //TODO add Cancelbutton | |
202 | switch( result ) | |
203 | { | |
204 | case 1 : | |
205 | resultbutton = wxID_OK ; | |
206 | break ; | |
207 | case 2 : | |
208 | break ; | |
209 | case 3 : | |
210 | break ; | |
211 | } | |
212 | } | |
213 | else | |
214 | { | |
215 | switch( result ) | |
216 | { | |
217 | case 1 : | |
218 | resultbutton = wxID_OK ; | |
219 | break ; | |
220 | case 2 : | |
221 | break ; | |
222 | case 3 : | |
223 | break ; | |
224 | } | |
225 | } | |
226 | } | |
227 | else if (m_dialogStyle & wxYES_NO) | |
228 | { | |
229 | if (m_dialogStyle & wxCANCEL) | |
230 | { | |
231 | switch( result ) | |
232 | { | |
233 | case 1 : | |
234 | resultbutton = wxID_YES ; | |
235 | break ; | |
236 | case 2 : | |
237 | resultbutton = wxID_CANCEL ; | |
238 | break ; | |
239 | case 3 : | |
240 | resultbutton = wxID_NO ; | |
241 | break ; | |
242 | } | |
243 | } | |
244 | else | |
245 | { | |
246 | switch( result ) | |
247 | { | |
248 | case 1 : | |
249 | resultbutton = wxID_YES ; | |
250 | break ; | |
251 | case 2 : | |
252 | break ; | |
253 | case 3 : | |
254 | resultbutton = wxID_NO ; | |
255 | break ; | |
256 | } | |
257 | } | |
258 | } | |
259 | ||
260 | return resultbutton ; | |
e9576ca5 SC |
261 | } |
262 |