1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMessageDialog
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "msgdlg.h"
17 #include "wx/msgdlg.h"
19 #include "wx/mac/uma.h"
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
27 void wxMacConvertNewlines( const char *source
, char * destination
) ;
28 void wxMacConvertNewlines( const char *source
, char * destination
)
30 const char *s
= source
;
31 char *d
= destination
;
55 wxMessageDialog::wxMessageDialog(wxWindow
*parent
, const wxString
& message
, const wxString
& caption
,
56 long style
, const wxPoint
& pos
)
60 m_dialogStyle
= style
;
64 int wxMessageDialog::ShowModal()
66 int resultbutton
= wxID_CANCEL
;
70 wxASSERT_MSG( ( m_dialogStyle
& 0x3F ) != wxYES
, "this style is not supported on mac" ) ;
72 AlertType alertType
= kAlertPlainAlert
;
73 if (m_dialogStyle
& wxICON_EXCLAMATION
)
74 alertType
= kAlertNoteAlert
;
75 else if (m_dialogStyle
& wxICON_HAND
)
76 alertType
= kAlertStopAlert
;
77 else if (m_dialogStyle
& wxICON_INFORMATION
)
78 alertType
= kAlertNoteAlert
;
79 else if (m_dialogStyle
& wxICON_QUESTION
)
80 alertType
= kAlertCautionAlert
;
83 if ( UMAGetSystemVersion() >= 0x1000 )
85 AlertStdCFStringAlertParamRec param
;
86 CFStringRef cfNoString
= NULL
;
87 CFStringRef cfYesString
= NULL
;
89 CFStringRef cfTitle
= NULL
;
90 CFStringRef cfText
= NULL
;
92 cfTitle
= wxMacCreateCFString( m_caption
) ;
93 cfText
= wxMacCreateCFString( m_message
) ;
94 cfNoString
= wxMacCreateCFString( _("No") ) ;
95 cfYesString
= wxMacCreateCFString( _("Yes") ) ;
100 bool skipDialog
= false ;
102 if (m_dialogStyle
& wxYES_NO
)
104 if (m_dialogStyle
& wxCANCEL
)
106 param
.defaultText
= cfYesString
;
107 param
.cancelText
= (CFStringRef
) kAlertDefaultCancelText
;
108 param
.otherText
= cfNoString
;
109 param
.helpButton
= false ;
110 param
.defaultButton
= kAlertStdAlertOKButton
;
111 param
.cancelButton
= kAlertStdAlertCancelButton
;
115 param
.defaultText
= cfYesString
;
116 param
.cancelText
= NULL
;
117 param
.otherText
= cfNoString
;
118 param
.helpButton
= false ;
119 param
.defaultButton
= kAlertStdAlertOKButton
;
120 param
.cancelButton
= 0;
123 else if (m_dialogStyle
& wxOK
)
125 if (m_dialogStyle
& wxCANCEL
)
127 // thats a cancel missing
128 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
129 param
.cancelText
= NULL
;
130 param
.otherText
= NULL
;
131 param
.helpButton
= false ;
132 param
.defaultButton
= kAlertStdAlertOKButton
;
133 param
.cancelButton
= 0;
137 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
138 param
.cancelText
= NULL
;
139 param
.otherText
= NULL
;
140 param
.helpButton
= false ;
141 param
.defaultButton
= kAlertStdAlertOKButton
;
142 param
.cancelButton
= 0;
150 param
.position
= kWindowDefaultPosition
;
154 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
) ;
155 RunStandardAlert( alertRef
, NULL
, &result
) ;
161 if(cfNoString
!= NULL
)
162 CFRelease(cfNoString
);
163 if(cfYesString
!= NULL
)
164 CFRelease(cfYesString
);
171 AlertStdAlertParamRec param
;
174 if (wxApp::s_macDefaultEncodingIsPC
)
176 strcpy(cText
, wxMacMakeMacStringFromPC( m_message
) ) ;
180 strcpy( cText
, m_message
) ;
182 wxMacConvertNewlines( cText
, cText
) ;
189 wxMacStringToPascal( m_caption
, pascalTitle
) ;
190 wxMacStringToPascal( _("Yes") , yesPString
) ;
191 wxMacStringToPascal( _("No") , noPString
) ;
192 CopyCStringToPascal( cText
, pascalText
) ;
194 param
.movable
= true;
195 param
.filterProc
= NULL
;
196 if (m_dialogStyle
& wxYES_NO
)
198 if (m_dialogStyle
& wxCANCEL
)
200 param
.defaultText
= yesPString
;
201 param
.cancelText
= (StringPtr
) kAlertDefaultCancelText
;
202 param
.otherText
= noPString
;
203 param
.helpButton
= false ;
204 param
.defaultButton
= kAlertStdAlertOKButton
;
205 param
.cancelButton
= kAlertStdAlertCancelButton
;
209 param
.defaultText
= yesPString
;
210 param
.cancelText
= NULL
;
211 param
.otherText
= noPString
;
212 param
.helpButton
= false ;
213 param
.defaultButton
= kAlertStdAlertOKButton
;
214 param
.cancelButton
= 0;
217 else if (m_dialogStyle
& wxOK
)
219 if (m_dialogStyle
& wxCANCEL
)
221 // thats a cancel missing
222 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
223 param
.cancelText
= NULL
;
224 param
.otherText
= NULL
;
225 param
.helpButton
= false ;
226 param
.defaultButton
= kAlertStdAlertOKButton
;
227 param
.cancelButton
= 0;
231 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
232 param
.cancelText
= NULL
;
233 param
.otherText
= NULL
;
234 param
.helpButton
= false ;
235 param
.defaultButton
= kAlertStdAlertOKButton
;
236 param
.cancelButton
= 0;
241 return resultbutton
;
246 StandardAlert( alertType
, pascalTitle
, pascalText
, ¶m
, &result
);
249 if (m_dialogStyle
& wxOK
)
251 if (m_dialogStyle
& wxCANCEL
)
253 //TODO add Cancelbutton
257 resultbutton
= wxID_OK
;
270 resultbutton
= wxID_OK
;
279 else if (m_dialogStyle
& wxYES_NO
)
281 if (m_dialogStyle
& wxCANCEL
)
286 resultbutton
= wxID_YES
;
289 resultbutton
= wxID_CANCEL
;
292 resultbutton
= wxID_NO
;
301 resultbutton
= wxID_YES
;
306 resultbutton
= wxID_NO
;
312 return resultbutton
;