]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/msgdlg.cpp
don't assert in SetSelection(wxNOT_FOUND), just clear text zone contents (patch 1707475)
[wxWidgets.git] / src / mac / carbon / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/msgdlg.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/app.h"
19 #endif
20
21 #include "wx/mac/uma.h"
22
23
24 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
25
26
27 wxMessageDialog::wxMessageDialog(
28 wxWindow *parent, const wxString& message, const wxString& caption,
29 long style, const wxPoint& pos )
30 {
31 m_caption = caption;
32 m_message = message;
33 m_parent = parent;
34 SetMessageDialogStyle(style);
35 }
36
37 int wxMessageDialog::ShowModal()
38 {
39 int resultbutton = wxID_CANCEL;
40
41 const long style = GetMessageDialogStyle();
42
43 wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
44
45 AlertType alertType = kAlertPlainAlert;
46 if (style & wxICON_EXCLAMATION)
47 alertType = kAlertNoteAlert;
48 else if (style & wxICON_HAND)
49 alertType = kAlertStopAlert;
50 else if (style & wxICON_INFORMATION)
51 alertType = kAlertNoteAlert;
52 else if (style & wxICON_QUESTION)
53 alertType = kAlertCautionAlert;
54
55 #if TARGET_API_MAC_OSX
56 if ( !wxIsMainThread() )
57 {
58 CFStringRef defaultButtonTitle = NULL;
59 CFStringRef alternateButtonTitle = NULL;
60 CFStringRef otherButtonTitle = NULL;
61
62 wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() );
63 wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() );
64
65 wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() );
66 wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() );
67 wxMacCFStringHolder cfOKString( _("OK") , m_font.GetEncoding()) ;
68 wxMacCFStringHolder cfCancelString( _("Cancel"), m_font.GetEncoding() );
69
70 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
71
72 if (style & wxYES_NO)
73 {
74 if ( style & wxNO_DEFAULT )
75 {
76 defaultButtonTitle = cfNoString;
77 alternateButtonTitle = cfYesString;
78 buttonId[0] = wxID_NO;
79 buttonId[1] = wxID_YES;
80 }
81 else
82 {
83 defaultButtonTitle = cfYesString;
84 alternateButtonTitle = cfNoString;
85 buttonId[0] = wxID_YES;
86 buttonId[1] = wxID_NO;
87 }
88 if (style & wxCANCEL)
89 {
90 otherButtonTitle = cfCancelString;
91 buttonId[2] = wxID_CANCEL;
92 }
93 }
94 else
95 {
96 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
97 buttonId[0] = wxID_OK;
98 // using null as default title does not work on earlier systems
99 defaultButtonTitle = cfOKString;
100 if (style & wxCANCEL)
101 {
102 alternateButtonTitle = cfCancelString;
103 buttonId[1] = wxID_CANCEL;
104 }
105 }
106
107 CFOptionFlags exitButton;
108 OSStatus err = CFUserNotificationDisplayAlert(
109 0, alertType, NULL, NULL, NULL, cfTitle, cfText,
110 defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton );
111 if (err == noErr)
112 resultbutton = buttonId[exitButton];
113 }
114 else
115 #endif
116 {
117 short result;
118
119 AlertStdCFStringAlertParamRec param;
120 wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() );
121 wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() );
122
123 wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() );
124 wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() );
125
126 param.movable = true;
127 param.flags = 0;
128 param.version = kStdCFStringAlertVersionOne;
129
130 bool skipDialog = false;
131
132 if (style & wxYES_NO)
133 {
134 if (style & wxCANCEL)
135 {
136 param.defaultText = cfYesString;
137 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
138 param.otherText = cfNoString;
139 param.helpButton = false;
140 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
141 param.cancelButton = kAlertStdAlertCancelButton;
142 }
143 else
144 {
145 param.defaultText = cfYesString;
146 param.cancelText = NULL;
147 param.otherText = cfNoString;
148 param.helpButton = false;
149 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
150 param.cancelButton = 0;
151 }
152 }
153 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
154 else
155 {
156 if (style & wxCANCEL)
157 {
158 // that's a cancel missing
159 param.defaultText = (CFStringRef) kAlertDefaultOKText;
160 param.cancelText = (CFStringRef) kAlertDefaultCancelText;
161 param.otherText = NULL;
162 param.helpButton = false;
163 param.defaultButton = kAlertStdAlertOKButton;
164 param.cancelButton = 0;
165 }
166 else
167 {
168 param.defaultText = (CFStringRef) kAlertDefaultOKText;
169 param.cancelText = NULL;
170 param.otherText = NULL;
171 param.helpButton = false;
172 param.defaultButton = kAlertStdAlertOKButton;
173 param.cancelButton = 0;
174 }
175 }
176
177 param.position = kWindowDefaultPosition;
178 if ( !skipDialog )
179 {
180 DialogRef alertRef;
181 CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
182 RunStandardAlert( alertRef, NULL, &result );
183 }
184 else
185 {
186 return wxID_CANCEL;
187 }
188
189 if (style & wxOK)
190 {
191 switch ( result )
192 {
193 case 1:
194 resultbutton = wxID_OK;
195 break;
196
197 case 2:
198 // TODO: add Cancel button
199 // if (style & wxCANCEL)
200 // resultbutton = wxID_CANCEL;
201 break;
202
203 case 3:
204 default:
205 break;
206 }
207 }
208 else if (style & wxYES_NO)
209 {
210 switch ( result )
211 {
212 case 1:
213 resultbutton = wxID_YES;
214 break;
215
216 case 2:
217 if (!(style & wxCANCEL))
218 resultbutton = wxID_CANCEL;
219 break;
220
221 case 3:
222 resultbutton = wxID_NO;
223 break;
224
225 default:
226 break;
227 }
228 }
229 }
230
231 return resultbutton;
232 }