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 // the msw implementation even shows an ok button if it is not specified, we'll do the same
126 if (m_dialogStyle
& wxCANCEL
)
128 // thats a cancel missing
129 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
130 param
.cancelText
= NULL
;
131 param
.otherText
= NULL
;
132 param
.helpButton
= false ;
133 param
.defaultButton
= kAlertStdAlertOKButton
;
134 param
.cancelButton
= 0;
138 param
.defaultText
= (CFStringRef
) kAlertDefaultOKText
;
139 param
.cancelText
= NULL
;
140 param
.otherText
= NULL
;
141 param
.helpButton
= false ;
142 param
.defaultButton
= kAlertStdAlertOKButton
;
143 param
.cancelButton
= 0;
153 param
.position
= kWindowDefaultPosition
;
157 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
) ;
158 RunStandardAlert( alertRef
, NULL
, &result
) ;
164 if(cfNoString
!= NULL
)
165 CFRelease(cfNoString
);
166 if(cfYesString
!= NULL
)
167 CFRelease(cfYesString
);
174 AlertStdAlertParamRec param
;
177 if (wxApp::s_macDefaultEncodingIsPC
)
179 strcpy(cText
, wxMacMakeMacStringFromPC( m_message
) ) ;
183 strcpy( cText
, m_message
) ;
185 wxMacConvertNewlines( cText
, cText
) ;
192 wxMacStringToPascal( m_caption
, pascalTitle
) ;
193 wxMacStringToPascal( _("Yes") , yesPString
) ;
194 wxMacStringToPascal( _("No") , noPString
) ;
195 CopyCStringToPascal( cText
, pascalText
) ;
197 param
.movable
= true;
198 param
.filterProc
= NULL
;
199 if (m_dialogStyle
& wxYES_NO
)
201 if (m_dialogStyle
& wxCANCEL
)
203 param
.defaultText
= yesPString
;
204 param
.cancelText
= (StringPtr
) kAlertDefaultCancelText
;
205 param
.otherText
= noPString
;
206 param
.helpButton
= false ;
207 param
.defaultButton
= kAlertStdAlertOKButton
;
208 param
.cancelButton
= kAlertStdAlertCancelButton
;
212 param
.defaultText
= yesPString
;
213 param
.cancelText
= NULL
;
214 param
.otherText
= noPString
;
215 param
.helpButton
= false ;
216 param
.defaultButton
= kAlertStdAlertOKButton
;
217 param
.cancelButton
= 0;
220 else if (m_dialogStyle
& wxOK
)
222 if (m_dialogStyle
& wxCANCEL
)
224 // thats a cancel missing
225 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
226 param
.cancelText
= NULL
;
227 param
.otherText
= NULL
;
228 param
.helpButton
= false ;
229 param
.defaultButton
= kAlertStdAlertOKButton
;
230 param
.cancelButton
= 0;
234 param
.defaultText
= (StringPtr
) kAlertDefaultOKText
;
235 param
.cancelText
= NULL
;
236 param
.otherText
= NULL
;
237 param
.helpButton
= false ;
238 param
.defaultButton
= kAlertStdAlertOKButton
;
239 param
.cancelButton
= 0;
244 return resultbutton
;
249 StandardAlert( alertType
, pascalTitle
, pascalText
, ¶m
, &result
);
252 if (m_dialogStyle
& wxOK
)
254 if (m_dialogStyle
& wxCANCEL
)
256 //TODO add Cancelbutton
260 resultbutton
= wxID_OK
;
273 resultbutton
= wxID_OK
;
282 else if (m_dialogStyle
& wxYES_NO
)
284 if (m_dialogStyle
& wxCANCEL
)
289 resultbutton
= wxID_YES
;
292 resultbutton
= wxID_CANCEL
;
295 resultbutton
= wxID_NO
;
304 resultbutton
= wxID_YES
;
309 resultbutton
= wxID_NO
;
315 return resultbutton
;