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