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