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