]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/msgdlg.cpp
Fix for mistake with const for non pointer/reference with corrections in documentation.
[wxWidgets.git] / src / mac / carbon / msgdlg.cpp
CommitLineData
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/mac/carbon/msgdlg.cpp
e9576ca5 3// Purpose: wxMessageDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5
SC
5// Modified by:
6// Created: 04/01/98
e5b50758 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
e5b50758 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878
SC
12#include "wx/wxprec.h"
13
03e11df5 14#include "wx/app.h"
e9576ca5 15#include "wx/msgdlg.h"
49e95e1d 16#include "wx/intl.h"
519cb848 17#include "wx/mac/uma.h"
e9576ca5 18
e9576ca5 19IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
e9576ca5
SC
20
21wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
e40298d5 22 long style, const wxPoint& pos)
e9576ca5
SC
23{
24 m_caption = caption;
25 m_message = message;
e9576ca5 26 m_parent = parent;
e5b50758 27 SetMessageDialogStyle(style);
e9576ca5
SC
28}
29
30int wxMessageDialog::ShowModal()
31{
e40298d5 32 int resultbutton = wxID_CANCEL ;
e5b50758 33
e40298d5 34 short result ;
e5b50758
WS
35
36 const long style = GetMessageDialogStyle();
37
38 wxASSERT_MSG( ( style & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
39
e40298d5 40 AlertType alertType = kAlertPlainAlert ;
e5b50758 41 if (style & wxICON_EXCLAMATION)
e40298d5 42 alertType = kAlertNoteAlert ;
e5b50758 43 else if (style & wxICON_HAND)
e40298d5 44 alertType = kAlertStopAlert ;
e5b50758 45 else if (style & wxICON_INFORMATION)
e40298d5 46 alertType = kAlertNoteAlert ;
e5b50758 47 else if (style & wxICON_QUESTION)
e40298d5 48 alertType = kAlertCautionAlert ;
e5b50758 49
992c81e2 50#if TARGET_CARBON
e40298d5
JS
51 if ( UMAGetSystemVersion() >= 0x1000 )
52 {
53 AlertStdCFStringAlertParamRec param ;
a9412f8f
SC
54 wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ;
55 wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ;
e5b50758 56
a9412f8f
SC
57 wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
58 wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());
e5b50758 59
e40298d5
JS
60 param.movable = true;
61 param.flags = 0 ;
939a2e80 62 param.version = kStdCFStringAlertVersionOne ;
e5b50758 63
e40298d5 64 bool skipDialog = false ;
e5b50758
WS
65
66 if (style & wxYES_NO)
e40298d5 67 {
e5b50758 68 if (style & wxCANCEL)
e40298d5
JS
69 {
70 param.defaultText = cfYesString ;
71 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
72 param.otherText = cfNoString ;
73 param.helpButton = false ;
e5b50758 74 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
e40298d5
JS
75 param.cancelButton = kAlertStdAlertCancelButton;
76 }
77 else
78 {
79 param.defaultText = cfYesString ;
80 param.cancelText = NULL;
81 param.otherText = cfNoString ;
82 param.helpButton = false ;
e5b50758 83 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
e40298d5
JS
84 param.cancelButton = 0;
85 }
86 }
c4a49e11 87 // the msw implementation even shows an ok button if it is not specified, we'll do the same
e5b50758 88 else
e40298d5 89 {
e5b50758 90 if (style & wxCANCEL)
e40298d5
JS
91 {
92 // thats a cancel missing
93 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
b7aec135 94 param.cancelText = (CFStringRef) kAlertDefaultCancelText ;
e40298d5
JS
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 }
c4a49e11 110 /*
e40298d5
JS
111 else
112 {
113 skipDialog = true ;
114 }
c4a49e11 115 */
e5b50758 116
e40298d5
JS
117 param.position = kWindowDefaultPosition;
118 if ( !skipDialog )
119 {
120 DialogRef alertRef ;
121 CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
122 RunStandardAlert( alertRef , NULL , &result ) ;
123 }
e5b50758 124 if ( skipDialog )
e40298d5
JS
125 return wxID_CANCEL ;
126 }
127 else
992c81e2 128#endif
e40298d5
JS
129 {
130 AlertStdAlertParamRec param;
e5b50758 131
e40298d5
JS
132 Str255 yesPString ;
133 Str255 noPString ;
e5b50758 134
e40298d5
JS
135 Str255 pascalTitle ;
136 Str255 pascalText ;
137 wxMacStringToPascal( m_caption , pascalTitle ) ;
138 wxMacStringToPascal( _("Yes") , yesPString ) ;
139 wxMacStringToPascal( _("No") , noPString ) ;
427ff662 140 wxMacStringToPascal( m_message , pascalText ) ;
e5b50758 141
e40298d5
JS
142 param.movable = true;
143 param.filterProc = NULL ;
e5b50758 144 if (style & wxYES_NO)
e40298d5 145 {
e5b50758 146 if (style & wxCANCEL)
e40298d5
JS
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 }
e5b50758 165 else if (style & wxOK)
e40298d5 166 {
e5b50758 167 if (style & wxCANCEL)
e40298d5 168 {
e40298d5 169 param.defaultText = (StringPtr) kAlertDefaultOKText ;
b7aec135 170 param.cancelText = (StringPtr) kAlertDefaultCancelText ;
e40298d5
JS
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 }
e5b50758 190
e40298d5 191 param.position = 0;
e5b50758 192
e40298d5
JS
193 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
194 }
e5b50758
WS
195
196 if (style & wxOK)
e40298d5 197 {
e5b50758 198 if (style & wxCANCEL)
e40298d5
JS
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 }
e5b50758 226 else if (style & wxYES_NO)
e40298d5 227 {
e5b50758 228 if (style & wxCANCEL)
e40298d5
JS
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 }
e5b50758
WS
257 }
258
e40298d5 259 return resultbutton ;
e9576ca5
SC
260}
261