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
)
25 wxMessageDialog::wxMessageDialog(wxWindow
*parent
, const wxString
& message
, const wxString
& caption
,
26 long style
, const wxPoint
& pos
)
30 m_dialogStyle
= style
;
34 int wxMessageDialog::ShowModal()
36 int resultbutton
= wxID_CANCEL
;
40 wxASSERT_MSG( ( m_dialogStyle
& 0x3F ) != wxYES
, wxT("this style is not supported on mac") ) ;
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
;
53 if ( UMAGetSystemVersion() >= 0x1000 )
55 AlertStdCFStringAlertParamRec param
;
56 wxMacCFStringHolder
cfNoString(_("No") , m_font
.GetEncoding()) ;
57 wxMacCFStringHolder
cfYesString( _("Yes") , m_font
.GetEncoding()) ;
59 wxMacCFStringHolder
cfTitle(m_caption
, m_font
.GetEncoding());
60 wxMacCFStringHolder
cfText(m_message
, m_font
.GetEncoding());
64 param
.version
= kStdCFStringAlertVersionOne
;
66 bool skipDialog
= false ;
68 if (m_dialogStyle
& wxYES_NO
)
70 if (m_dialogStyle
& wxCANCEL
)
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
;
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;
89 // the msw implementation even shows an ok button if it is not specified, we'll do the same
92 if (m_dialogStyle
& wxCANCEL
)
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;
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;
119 param
.position
= kWindowDefaultPosition
;
123 CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef
) ;
124 RunStandardAlert( alertRef
, NULL
, &result
) ;
132 AlertStdAlertParamRec param
;
139 wxMacStringToPascal( m_caption
, pascalTitle
) ;
140 wxMacStringToPascal( _("Yes") , yesPString
) ;
141 wxMacStringToPascal( _("No") , noPString
) ;
142 wxMacStringToPascal( m_message
, pascalText
) ;
144 param
.movable
= true;
145 param
.filterProc
= NULL
;
146 if (m_dialogStyle
& wxYES_NO
)
148 if (m_dialogStyle
& wxCANCEL
)
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
;
159 param
.defaultText
= yesPString
;
160 param
.cancelText
= NULL
;
161 param
.otherText
= noPString
;
162 param
.helpButton
= false ;
163 param
.defaultButton
= kAlertStdAlertOKButton
;
164 param
.cancelButton
= 0;
167 else if (m_dialogStyle
& wxOK
)
169 if (m_dialogStyle
& wxCANCEL
)
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;
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;
190 return resultbutton
;
195 StandardAlert( alertType
, pascalTitle
, pascalText
, ¶m
, &result
);
198 if (m_dialogStyle
& wxOK
)
200 if (m_dialogStyle
& wxCANCEL
)
202 //TODO add Cancelbutton
206 resultbutton
= wxID_OK
;
219 resultbutton
= wxID_OK
;
228 else if (m_dialogStyle
& wxYES_NO
)
230 if (m_dialogStyle
& wxCANCEL
)
235 resultbutton
= wxID_YES
;
238 resultbutton
= wxID_CANCEL
;
241 resultbutton
= wxID_NO
;
250 resultbutton
= wxID_YES
;
255 resultbutton
= wxID_NO
;
261 return resultbutton
;