]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/msgdlg.cpp
about menu item changes : can appear anywhere in a menu, separator lines above or...
[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 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "msgdlg.h"
14#endif
15
3d1a4878
SC
16#include "wx/wxprec.h"
17
03e11df5 18#include "wx/app.h"
e9576ca5 19#include "wx/msgdlg.h"
49e95e1d 20#include "wx/intl.h"
519cb848 21#include "wx/mac/uma.h"
e9576ca5 22
2f1ae414 23#if !USE_SHARED_LIBRARY
e9576ca5 24IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
2f1ae414 25#endif
e9576ca5
SC
26
27wxMessageDialog::wxMessageDialog(wxWindow *parent, const wxString& message, const wxString& caption,
e40298d5 28 long style, const wxPoint& pos)
e9576ca5
SC
29{
30 m_caption = caption;
31 m_message = message;
e9576ca5 32 m_parent = parent;
e5b50758 33 SetMessageDialogStyle(style);
e9576ca5
SC
34}
35
36int wxMessageDialog::ShowModal()
37{
e40298d5 38 int resultbutton = wxID_CANCEL ;
e5b50758 39
e40298d5 40 short result ;
e5b50758
WS
41
42 const long style = GetMessageDialogStyle();
43
44 wxASSERT_MSG( ( style & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ;
45
e40298d5 46 AlertType alertType = kAlertPlainAlert ;
e5b50758 47 if (style & wxICON_EXCLAMATION)
e40298d5 48 alertType = kAlertNoteAlert ;
e5b50758 49 else if (style & wxICON_HAND)
e40298d5 50 alertType = kAlertStopAlert ;
e5b50758 51 else if (style & wxICON_INFORMATION)
e40298d5 52 alertType = kAlertNoteAlert ;
e5b50758 53 else if (style & wxICON_QUESTION)
e40298d5 54 alertType = kAlertCautionAlert ;
e5b50758 55
992c81e2 56#if TARGET_CARBON
e40298d5
JS
57 if ( UMAGetSystemVersion() >= 0x1000 )
58 {
59 AlertStdCFStringAlertParamRec param ;
a9412f8f
SC
60 wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ;
61 wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ;
e5b50758 62
a9412f8f
SC
63 wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding());
64 wxMacCFStringHolder cfText(m_message , m_font.GetEncoding());
e5b50758 65
e40298d5
JS
66 param.movable = true;
67 param.flags = 0 ;
939a2e80 68 param.version = kStdCFStringAlertVersionOne ;
e5b50758 69
e40298d5 70 bool skipDialog = false ;
e5b50758
WS
71
72 if (style & wxYES_NO)
e40298d5 73 {
e5b50758 74 if (style & wxCANCEL)
e40298d5
JS
75 {
76 param.defaultText = cfYesString ;
77 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
78 param.otherText = cfNoString ;
79 param.helpButton = false ;
e5b50758 80 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
e40298d5
JS
81 param.cancelButton = kAlertStdAlertCancelButton;
82 }
83 else
84 {
85 param.defaultText = cfYesString ;
86 param.cancelText = NULL;
87 param.otherText = cfNoString ;
88 param.helpButton = false ;
e5b50758 89 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
e40298d5
JS
90 param.cancelButton = 0;
91 }
92 }
c4a49e11 93 // the msw implementation even shows an ok button if it is not specified, we'll do the same
e5b50758 94 else
e40298d5 95 {
e5b50758 96 if (style & wxCANCEL)
e40298d5
JS
97 {
98 // thats a cancel missing
99 param.defaultText = (CFStringRef) kAlertDefaultOKText ;
b7aec135 100 param.cancelText = (CFStringRef) kAlertDefaultCancelText ;
e40298d5
JS
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 }
c4a49e11 116 /*
e40298d5
JS
117 else
118 {
119 skipDialog = true ;
120 }
c4a49e11 121 */
e5b50758 122
e40298d5
JS
123 param.position = kWindowDefaultPosition;
124 if ( !skipDialog )
125 {
126 DialogRef alertRef ;
127 CreateStandardAlert( alertType , cfTitle , cfText , &param , &alertRef ) ;
128 RunStandardAlert( alertRef , NULL , &result ) ;
129 }
e5b50758 130 if ( skipDialog )
e40298d5
JS
131 return wxID_CANCEL ;
132 }
133 else
992c81e2 134#endif
e40298d5
JS
135 {
136 AlertStdAlertParamRec param;
e5b50758 137
e40298d5
JS
138 Str255 yesPString ;
139 Str255 noPString ;
e5b50758 140
e40298d5
JS
141 Str255 pascalTitle ;
142 Str255 pascalText ;
143 wxMacStringToPascal( m_caption , pascalTitle ) ;
144 wxMacStringToPascal( _("Yes") , yesPString ) ;
145 wxMacStringToPascal( _("No") , noPString ) ;
427ff662 146 wxMacStringToPascal( m_message , pascalText ) ;
e5b50758 147
e40298d5
JS
148 param.movable = true;
149 param.filterProc = NULL ;
e5b50758 150 if (style & wxYES_NO)
e40298d5 151 {
e5b50758 152 if (style & wxCANCEL)
e40298d5
JS
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 }
e5b50758 171 else if (style & wxOK)
e40298d5 172 {
e5b50758 173 if (style & wxCANCEL)
e40298d5 174 {
e40298d5 175 param.defaultText = (StringPtr) kAlertDefaultOKText ;
b7aec135 176 param.cancelText = (StringPtr) kAlertDefaultCancelText ;
e40298d5
JS
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 }
e5b50758 196
e40298d5 197 param.position = 0;
e5b50758 198
e40298d5
JS
199 StandardAlert( alertType, pascalTitle, pascalText, &param, &result );
200 }
e5b50758
WS
201
202 if (style & wxOK)
e40298d5 203 {
e5b50758 204 if (style & wxCANCEL)
e40298d5
JS
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 }
e5b50758 232 else if (style & wxYES_NO)
e40298d5 233 {
e5b50758 234 if (style & wxCANCEL)
e40298d5
JS
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 }
e5b50758
WS
263 }
264
e40298d5 265 return resultbutton ;
e9576ca5
SC
266}
267