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