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