]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msgdlg.cpp | |
3 | // Purpose: wxMessageDialog | |
4 | // Author: AUTHOR | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $$ | |
8 | // Copyright: (c) AUTHOR | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "msgdlg.h" | |
14 | #endif | |
15 | ||
16 | #include "wx/msgdlg.h" | |
519cb848 | 17 | #include "wx/mac/uma.h" |
e9576ca5 | 18 | |
e9576ca5 | 19 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
e9576ca5 | 20 | |
519cb848 SC |
21 | #define kMacOKAlertResourceID 128 |
22 | #define kMacYesNoAlertResourceID 129 | |
23 | #define kMacYesNoCancelAlertResourceID 130 | |
24 | #define kMacNoYesAlertResourceID 131 | |
25 | #define kMacNoYesCancelAlertResourceID 132 | |
26 | ||
27 | short language = 0 ; | |
28 | ||
29 | void wxMacConvertNewlines( const char *source , char * destination ) | |
30 | { | |
31 | const char *s = source ; | |
32 | char *d = destination ; | |
33 | ||
34 | while( *s ) | |
35 | { | |
36 | switch( *s ) | |
37 | { | |
38 | case 0x0a : | |
39 | *d++ = 0x0d ; | |
40 | ++s ; | |
41 | break ; | |
42 | case 0x0d : | |
43 | *d++ = 0x0d ; | |
44 | ++s ; | |
45 | if ( *s == 0x0a ) | |
46 | ++s ; | |
47 | break ; | |
48 | default : | |
49 | *d++ = *s++ ; | |
50 | break ; | |
51 | } | |
52 | } | |
53 | *d = 0 ; | |
54 | } | |
55 | ||
e9576ca5 SC |
56 | wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption, |
57 | long style, const wxPoint& pos) | |
58 | { | |
59 | m_caption = caption; | |
60 | m_message = message; | |
61 | m_dialogStyle = style; | |
62 | m_parent = parent; | |
63 | } | |
64 | ||
65 | int wxMessageDialog::ShowModal() | |
66 | { | |
519cb848 SC |
67 | int resultbutton = wxID_CANCEL ; |
68 | ||
69 | short result ; | |
70 | Str255 pascalTitle ; | |
71 | Str255 pascalText ; | |
72 | ||
73 | strcpy( (char*) pascalTitle , m_caption ) ; | |
74 | c2pstr( (char*) pascalTitle ) ; | |
75 | strcpy( (char*) pascalText , m_message ) ; | |
76 | wxMacConvertNewlines( (char*)pascalText ,(char*) pascalText) ; | |
77 | c2pstr( (char*) pascalText ) ; | |
78 | ||
79 | if ( !UMAHasAppearance() ) | |
80 | { | |
81 | int resourceID ; | |
82 | ||
83 | if (m_dialogStyle & wxYES_NO) | |
84 | { | |
85 | if (m_dialogStyle & wxCANCEL) | |
86 | resourceID = kMacYesNoCancelAlertResourceID; | |
87 | else | |
88 | resourceID = kMacYesNoAlertResourceID + language * 10 ; | |
89 | } | |
90 | else if (m_dialogStyle & wxOK) | |
91 | { | |
92 | if (m_dialogStyle & wxCANCEL) | |
93 | resourceID = kMacOKAlertResourceID; // wrong | |
94 | else | |
95 | resourceID = kMacOKAlertResourceID; | |
96 | } | |
97 | else | |
98 | { | |
99 | return resultbutton ; | |
100 | } | |
101 | /* | |
102 | if (hWnd) | |
103 | msStyle |= MB_APPLMODAL; | |
104 | else | |
105 | msStyle |= MB_TASKMODAL; | |
106 | */ | |
107 | ||
108 | ParamText( pascalTitle , pascalText , NULL , NULL ) ; | |
109 | ||
110 | if (m_dialogStyle & wxICON_EXCLAMATION) | |
111 | result = Alert( resourceID , NULL ) ; | |
112 | else if (m_dialogStyle & wxICON_HAND) | |
113 | result = StopAlert( resourceID , NULL ) ; | |
114 | else if (m_dialogStyle & wxICON_INFORMATION) | |
115 | result = NoteAlert( resourceID , NULL ) ; | |
116 | else if (m_dialogStyle & wxICON_QUESTION) | |
117 | result = CautionAlert( resourceID , NULL ) ; | |
118 | else | |
119 | result = Alert( resourceID , NULL ) ; | |
120 | ||
121 | resultbutton = result ; | |
122 | ||
123 | if (m_dialogStyle & wxYES_NO) | |
124 | { | |
125 | if (m_dialogStyle & wxCANCEL) | |
126 | { | |
127 | switch( result ) | |
128 | { | |
129 | case 1 : | |
130 | resultbutton = wxID_YES ; | |
131 | break ; | |
132 | case 2 : | |
133 | resultbutton = wxID_NO ; | |
134 | break ; | |
135 | case 3 : | |
136 | resultbutton = wxID_CANCEL ; | |
137 | break ; | |
138 | } | |
139 | } | |
140 | else | |
141 | { | |
142 | switch( result ) | |
143 | { | |
144 | case 1 : | |
145 | resultbutton = wxID_YES ; | |
146 | break ; | |
147 | case 2 : | |
148 | resultbutton = wxID_NO ; | |
149 | break ; | |
150 | case 3 : | |
151 | break ; | |
152 | } | |
153 | } | |
154 | } | |
155 | } | |
156 | else | |
157 | { | |
158 | AlertStdAlertParamRec param; | |
159 | ||
160 | param.movable = true; | |
161 | param.filterProc = NULL ; | |
162 | ||
163 | if (m_dialogStyle & wxYES_NO) | |
164 | { | |
165 | if (m_dialogStyle & wxCANCEL) | |
166 | { | |
167 | param.defaultText = "\pYes" ; | |
168 | param.cancelText = (StringPtr) kAlertDefaultCancelText; | |
169 | param.otherText = "\pNo"; | |
170 | param.helpButton = false ; | |
171 | param.defaultButton = kAlertStdAlertOKButton; | |
172 | param.cancelButton = kAlertStdAlertCancelButton; | |
173 | } | |
174 | else | |
175 | { | |
176 | param.defaultText = "\pYes" ; | |
177 | param.cancelText = NULL; | |
178 | param.otherText = "\pNo"; | |
179 | param.helpButton = false ; | |
180 | param.defaultButton = kAlertStdAlertOKButton; | |
181 | param.cancelButton = 0; | |
182 | } | |
183 | } | |
184 | else if (m_dialogStyle & wxOK) | |
185 | { | |
186 | if (m_dialogStyle & wxCANCEL) | |
187 | { | |
188 | // thats a cancel missing | |
189 | param.defaultText = (StringPtr) kAlertDefaultOKText ; | |
190 | param.cancelText = NULL; | |
191 | param.otherText = NULL; | |
192 | param.helpButton = false ; | |
193 | param.defaultButton = kAlertStdAlertOKButton; | |
194 | param.cancelButton = 0; | |
195 | } | |
196 | else | |
197 | { | |
198 | param.defaultText = (StringPtr) kAlertDefaultOKText ; | |
199 | param.cancelText = NULL; | |
200 | param.otherText = NULL; | |
201 | param.helpButton = false ; | |
202 | param.defaultButton = kAlertStdAlertOKButton; | |
203 | param.cancelButton = 0; | |
204 | } | |
205 | } | |
206 | else | |
207 | { | |
208 | return resultbutton ; | |
209 | } | |
210 | ||
211 | param.position = 0; | |
212 | ||
213 | if (m_dialogStyle & wxICON_EXCLAMATION) | |
214 | StandardAlert( kAlertNoteAlert, pascalTitle, pascalText, ¶m, &result ); | |
215 | else if (m_dialogStyle & wxICON_HAND) | |
216 | StandardAlert( kAlertStopAlert, pascalTitle, pascalText, ¶m, &result ); | |
217 | else if (m_dialogStyle & wxICON_INFORMATION) | |
218 | StandardAlert( kAlertNoteAlert, pascalTitle, pascalText, ¶m, &result ); | |
219 | else if (m_dialogStyle & wxICON_QUESTION) | |
220 | StandardAlert( kAlertCautionAlert, pascalTitle, pascalText, ¶m, &result ); | |
221 | else | |
222 | StandardAlert( kAlertPlainAlert, pascalTitle, pascalText, ¶m, &result ); | |
223 | ||
224 | if (m_dialogStyle & wxOK) | |
225 | { | |
226 | if (m_dialogStyle & wxCANCEL) | |
227 | { | |
228 | //TODO add Cancelbutton | |
229 | switch( result ) | |
230 | { | |
231 | case 1 : | |
232 | resultbutton = wxID_OK ; | |
233 | break ; | |
234 | case 2 : | |
235 | break ; | |
236 | case 3 : | |
237 | break ; | |
238 | } | |
239 | } | |
240 | else | |
241 | { | |
242 | switch( result ) | |
243 | { | |
244 | case 1 : | |
245 | resultbutton = wxID_OK ; | |
246 | break ; | |
247 | case 2 : | |
248 | break ; | |
249 | case 3 : | |
250 | break ; | |
251 | } | |
252 | } | |
253 | } | |
254 | else if (m_dialogStyle & wxYES_NO) | |
255 | { | |
256 | if (m_dialogStyle & wxCANCEL) | |
257 | { | |
258 | switch( result ) | |
259 | { | |
260 | case 1 : | |
261 | resultbutton = wxID_YES ; | |
262 | break ; | |
263 | case 2 : | |
264 | resultbutton = wxID_CANCEL ; | |
265 | break ; | |
266 | case 3 : | |
267 | resultbutton = wxID_NO ; | |
268 | break ; | |
269 | } | |
270 | } | |
271 | else | |
272 | { | |
273 | switch( result ) | |
274 | { | |
275 | case 1 : | |
276 | resultbutton = wxID_YES ; | |
277 | break ; | |
278 | case 2 : | |
279 | break ; | |
280 | case 3 : | |
281 | resultbutton = wxID_NO ; | |
282 | break ; | |
283 | } | |
284 | } | |
285 | } | |
286 | } | |
287 | return resultbutton ; | |
e9576ca5 SC |
288 | } |
289 |