]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/msgdlg.cpp
Fixed GetIcon to keep up with return type change on all other platforms.
[wxWidgets.git] / src / mac / classic / msgdlg.cpp
CommitLineData
2646f485 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/mac/classic/msgdlg.cpp
2646f485
SC
3// Purpose: wxMessageDialog
4// Author: Stefan Csomor
5// Modified by:
6// Created: 04/01/98
e5b50758 7// RCS-ID: $Id$
2646f485 8// Copyright: (c) Stefan Csomor
e5b50758 9// Licence: wxWindows licence
2646f485
SC
10/////////////////////////////////////////////////////////////////////////////
11
2646f485
SC
12#include "wx/app.h"
13#include "wx/msgdlg.h"
14#include "wx/intl.h"
15#include "wx/mac/uma.h"
16
2646f485 17IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
2646f485
SC
18
19wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
20 long style, const wxPoint& pos)
21{
22 m_caption = caption;
23 m_message = message;
2646f485 24 m_parent = parent;
e5b50758 25 SetMessageDialogStyle(style);
2646f485
SC
26}
27
28int wxMessageDialog::ShowModal()
29{
30 int resultbutton = wxID_CANCEL ;
e5b50758 31
2646f485 32 short result ;
e5b50758
WS
33
34 const long style = GetMessageDialogStyle();
35
36 wxASSERT_MSG( ( style & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
37
2646f485 38 AlertType alertType = kAlertPlainAlert ;
e5b50758 39 if (style & wxICON_EXCLAMATION)
2646f485 40 alertType = kAlertNoteAlert ;
e5b50758 41 else if (style & wxICON_HAND)
2646f485 42 alertType = kAlertStopAlert ;
e5b50758 43 else if (style & wxICON_INFORMATION)
2646f485 44 alertType = kAlertNoteAlert ;
e5b50758 45 else if (style & wxICON_QUESTION)
2646f485 46 alertType = kAlertCautionAlert ;
e5b50758 47
2646f485
SC
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()) ;
e5b50758 54
2646f485
SC
55 wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
56 wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());
e5b50758 57
2646f485
SC
58 param.movable = true;
59 param.flags = 0 ;
e5b50758 60
2646f485 61 bool skipDialog = false ;
e5b50758
WS
62
63 if (style & wxYES_NO)
2646f485 64 {
e5b50758 65 if (style & wxCANCEL)
2646f485
SC
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
e5b50758 85 else
2646f485 86 {
e5b50758 87 if (style & wxCANCEL)
2646f485
SC
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 */
e5b50758 113
2646f485
SC
114 param.position = kWindowDefaultPosition;
115 if ( !skipDialog )
116 {
117 DialogRef alertRef ;
118 CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
119 RunStandardAlert( alertRef , NULL , &result ) ;
120 }
e5b50758 121 if ( skipDialog )
2646f485
SC
122 return wxID_CANCEL ;
123 }
124 else
125#endif
126 {
127 AlertStdAlertParamRec param;
e5b50758 128
2646f485
SC
129 Str255 yesPString ;
130 Str255 noPString ;
e5b50758 131
2646f485
SC
132 Str255 pascalTitle ;
133 Str255 pascalText ;
134 wxMacStringToPascal( m_caption , pascalTitle ) ;
135 wxMacStringToPascal( _("Yes") , yesPString ) ;
136 wxMacStringToPascal( _("No") , noPString ) ;
137 wxMacStringToPascal( m_message , pascalText ) ;
e5b50758 138
2646f485
SC
139 param.movable = true;
140 param.filterProc = NULL ;
e5b50758 141 if (style & wxYES_NO)
2646f485 142 {
e5b50758 143 if (style & wxCANCEL)
2646f485
SC
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 }
e5b50758 162 else if (style & wxOK)
2646f485 163 {
e5b50758 164 if (style & wxCANCEL)
2646f485
SC
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 }
e5b50758 187
2646f485 188 param.position = 0;
e5b50758 189
2646f485
SC
190 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
191 }
e5b50758
WS
192
193 if (style & wxOK)
2646f485 194 {
e5b50758 195 if (style & wxCANCEL)
2646f485
SC
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 }
e5b50758 223 else if (style & wxYES_NO)
2646f485 224 {
e5b50758 225 if (style & wxCANCEL)
2646f485
SC
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 }
e5b50758
WS
254 }
255
2646f485
SC
256 return resultbutton ;
257}
258