]> git.saurik.com Git - wxWidgets.git/blame - src/osx/carbon/msgdlg.cpp
making gradients working again
[wxWidgets.git] / src / osx / carbon / msgdlg.cpp
CommitLineData
489468fe 1/////////////////////////////////////////////////////////////////////////////
524c47aa 2// Name: src/osx/carbon/msgdlg.cpp
489468fe
SC
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/thread.h"
1f0c8f31 22#include "wx/osx/uma.h"
489468fe
SC
23
24
25IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
26
27
28wxMessageDialog::wxMessageDialog(wxWindow *parent,
29 const wxString& message,
30 const wxString& caption,
31 long style,
32 const wxPoint& WXUNUSED(pos))
23e00c55 33 : wxMessageDialogWithCustomLabels(parent, message, caption, style)
489468fe 34{
489468fe
SC
35}
36
37int wxMessageDialog::ShowModal()
38{
39 int resultbutton = wxID_CANCEL;
40
41 const long style = GetMessageDialogStyle();
42
a4578b0c
VZ
43 wxASSERT_MSG( (style & 0x3F) != wxYES,
44 "this style is not supported on Mac" );
489468fe
SC
45
46 AlertType alertType = kAlertPlainAlert;
a4578b0c
VZ
47
48 switch ( GetEffectiveIcon() )
49 {
50 case wxICON_ERROR:
51 alertType = kAlertStopAlert;
52 break;
53
54 case wxICON_WARNING:
55 alertType = kAlertCautionAlert;
56 break;
57
58 case wxICON_QUESTION:
59 case wxICON_INFORMATION:
60 alertType = kAlertNoteAlert;
61 break;
62 }
489468fe
SC
63
64
65 // work out what to display
66 // if the extended text is empty then we use the caption as the title
67 // and the message as the text (for backwards compatibility)
68 // but if the extended message is not empty then we use the message as the title
69 // and the extended message as the text because that makes more sense
70
71 wxString msgtitle,msgtext;
72 if(m_extendedMessage.IsEmpty())
73 {
74 msgtitle = m_caption;
75 msgtext = m_message;
76 }
77 else
78 {
79 msgtitle = m_message;
80 msgtext = m_extendedMessage;
81 }
82
83
84 if ( !wxIsMainThread() )
85 {
86 CFStringRef defaultButtonTitle = NULL;
87 CFStringRef alternateButtonTitle = NULL;
88 CFStringRef otherButtonTitle = NULL;
89
90 wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
91 wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
92
23e00c55
VZ
93 wxCFStringRef cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
94 wxCFStringRef cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
95 wxCFStringRef cfOKString( GetOKLabel().c_str() , GetFont().GetEncoding()) ;
96 wxCFStringRef cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
489468fe
SC
97
98 int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ };
99
100 if (style & wxYES_NO)
101 {
102 if ( style & wxNO_DEFAULT )
103 {
104 defaultButtonTitle = cfNoString;
105 alternateButtonTitle = cfYesString;
106 buttonId[0] = wxID_NO;
107 buttonId[1] = wxID_YES;
108 }
109 else
110 {
111 defaultButtonTitle = cfYesString;
112 alternateButtonTitle = cfNoString;
113 buttonId[0] = wxID_YES;
114 buttonId[1] = wxID_NO;
115 }
116 if (style & wxCANCEL)
117 {
118 otherButtonTitle = cfCancelString;
119 buttonId[2] = wxID_CANCEL;
120 }
121 }
122 else
123 {
124 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
125 buttonId[0] = wxID_OK;
126 // using null as default title does not work on earlier systems
127 defaultButtonTitle = cfOKString;
128 if (style & wxCANCEL)
129 {
130 alternateButtonTitle = cfCancelString;
131 buttonId[1] = wxID_CANCEL;
132 }
133 }
134
135 CFOptionFlags exitButton;
136 OSStatus err = CFUserNotificationDisplayAlert(
137 0, alertType, NULL, NULL, NULL, cfTitle, cfText,
138 defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton );
139 if (err == noErr)
140 resultbutton = buttonId[exitButton];
141 }
142 else
143 {
144 short result;
145
146 AlertStdCFStringAlertParamRec param;
23e00c55
VZ
147 wxCFStringRef cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() );
148 wxCFStringRef cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() );
149 wxCFStringRef cfOKString( GetOKLabel().c_str(), GetFont().GetEncoding() );
150 wxCFStringRef cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() );
489468fe
SC
151
152 wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() );
153 wxCFStringRef cfText( msgtext, GetFont().GetEncoding() );
154
155 param.movable = true;
156 param.flags = 0;
157 param.version = kStdCFStringAlertVersionOne;
158
159 bool skipDialog = false;
160
161 if (style & wxYES_NO)
162 {
163 if (style & wxCANCEL)
164 {
165 param.defaultText = cfYesString;
166 param.cancelText = cfCancelString;
167 param.otherText = cfNoString;
168 param.helpButton = false;
169 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
170 param.cancelButton = kAlertStdAlertCancelButton;
171 }
172 else
173 {
174 param.defaultText = cfYesString;
175 param.cancelText = NULL;
176 param.otherText = cfNoString;
177 param.helpButton = false;
178 param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton;
179 param.cancelButton = 0;
180 }
181 }
182 // the MSW implementation even shows an OK button if it is not specified, we'll do the same
183 else
184 {
185 if (style & wxCANCEL)
186 {
187 // that's a cancel missing
188 param.defaultText = cfOKString;
189 param.cancelText = cfCancelString;
190 param.otherText = NULL;
191 param.helpButton = false;
192 param.defaultButton = kAlertStdAlertOKButton;
193 param.cancelButton = 0;
194 }
195 else
196 {
197 param.defaultText = cfOKString;
198 param.cancelText = NULL;
199 param.otherText = NULL;
200 param.helpButton = false;
201 param.defaultButton = kAlertStdAlertOKButton;
202 param.cancelButton = 0;
203 }
204 }
205
206 param.position = kWindowDefaultPosition;
207 if ( !skipDialog )
208 {
209 DialogRef alertRef;
210 CreateStandardAlert( alertType, cfTitle, cfText, &param, &alertRef );
211 RunStandardAlert( alertRef, NULL, &result );
212 }
213 else
214 {
215 return wxID_CANCEL;
216 }
217
218 if (style & wxOK)
219 {
220 switch ( result )
221 {
222 case 1:
223 resultbutton = wxID_OK;
224 break;
225
226 case 2:
227 // TODO: add Cancel button
228 // if (style & wxCANCEL)
229 // resultbutton = wxID_CANCEL;
230 break;
231
232 case 3:
233 default:
234 break;
235 }
236 }
237 else if (style & wxYES_NO)
238 {
239 switch ( result )
240 {
241 case 1:
242 resultbutton = wxID_YES;
243 break;
244
245 case 2:
246 if (!(style & wxCANCEL))
247 resultbutton = wxID_CANCEL;
248 break;
249
250 case 3:
251 resultbutton = wxID_NO;
252 break;
253
254 default:
255 break;
256 }
257 }
258 }
f135deaa
SC
259
260 SetReturnCode(resultbutton);
489468fe
SC
261
262 return resultbutton;
263}