]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/msgdlg.cpp
73548ad9f219a8478e3212e69e0017688b5f3d9b
[wxWidgets.git] / src / mac / classic / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "msgdlg.h"
14 #endif
15
16 #include "wx/app.h"
17 #include "wx/msgdlg.h"
18 #include "wx/intl.h"
19 #include "wx/mac/uma.h"
20
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
23 #endif
24
25 wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
26 long style, const wxPoint& pos)
27 {
28 m_caption = caption;
29 m_message = message;
30 m_dialogStyle = style;
31 m_parent = parent;
32 }
33
34 int wxMessageDialog::ShowModal()
35 {
36 int resultbutton = wxID_CANCEL ;
37
38 short result ;
39
40 wxASSERT_MSG( ( m_dialogStyle & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
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
52 #if TARGET_CARBON
53 if ( UMAGetSystemVersion() >= 0x1000 )
54 {
55 AlertStdCFStringAlertParamRec param ;
56 wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ;
57 wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ;
58
59 wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
60 wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());
61
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 }
88 // the msw implementation even shows an ok button if it is not specified, we'll do the same
89 else
90 {
91 if (m_dialogStyle & wxCANCEL)
92 {
93 // thats a cancel missing
94 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
95 param.cancelText = (CFStringRef) kAlertDefaultCancelText ;
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 }
111 /*
112 else
113 {
114 skipDialog = true ;
115 }
116 */
117
118 param.position = kWindowDefaultPosition;
119 if ( !skipDialog )
120 {
121 DialogRef alertRef ;
122 CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
123 RunStandardAlert( alertRef , NULL , &result ) ;
124 }
125 if ( skipDialog )
126 return wxID_CANCEL ;
127 }
128 else
129 #endif
130 {
131 AlertStdAlertParamRec param;
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 ) ;
141 wxMacStringToPascal( m_message , pascalText ) ;
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 {
170 param.defaultText = (StringPtr) kAlertDefaultOKText ;
171 param.cancelText = (StringPtr) kAlertDefaultCancelText ;
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, &param, &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 ;
261 }
262