1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: common header and base class for wxMessageDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_MSGDLG_H_BASE_
13 #define _WX_MSGDLG_H_BASE_
19 #include "wx/dialog.h"
21 WXDLLIMPEXP_DATA_CORE(extern const char) wxMessageBoxCaptionStr
[];
23 class WXDLLIMPEXP_CORE wxMessageDialogBase
: public wxDialog
27 wxMessageDialogBase() { m_dialogStyle
= 0; }
28 wxMessageDialogBase(wxWindow
*parent
,
29 const wxString
& message
,
30 const wxString
& caption
,
36 SetMessageDialogStyle(style
);
39 // virtual dtor for the base class
40 virtual ~wxMessageDialogBase() { }
43 // methods for setting up more custom message dialogs -- all functions
44 // return false if they're not implemented
45 virtual bool SetYesNoLabels(const wxString
& WXUNUSED(yes
),
46 const wxString
& WXUNUSED(no
))
51 virtual bool SetYesNoCancelLabels(const wxString
& WXUNUSED(yes
),
52 const wxString
& WXUNUSED(no
),
53 const wxString
& WXUNUSED(cancel
))
58 virtual bool SetOKLabel(const wxString
& WXUNUSED(ok
))
63 virtual bool SetOKCancelLabels(const wxString
& WXUNUSED(ok
),
64 const wxString
& WXUNUSED(cancel
))
69 virtual void SetMessage(const wxString
& message
)
74 virtual void SetExtendedMessage(const wxString
& extendedMessage
)
76 m_extendedMessage
= extendedMessage
;
80 // common validation of wxMessageDialog style
81 void SetMessageDialogStyle(long style
)
83 wxASSERT_MSG( ((style
& wxYES_NO
) == wxYES_NO
) || ((style
& wxYES_NO
) == 0),
84 _T("wxYES and wxNO may only be used together in wxMessageDialog") );
86 wxASSERT_MSG( (style
& wxID_OK
) != wxID_OK
,
87 _T("wxMessageBox: Did you mean wxOK (and not wxID_OK)?") );
89 m_dialogStyle
= style
;
92 long GetMessageDialogStyle() const { return m_dialogStyle
; }
95 // for the platforms not supporting separate main and extended messages
96 // this function should be used to combine both of them in a single string
97 wxString
GetFullMessage() const
99 wxString msg
= m_message
;
100 if ( !m_extendedMessage
.empty() )
101 msg
<< "\n\n" << m_extendedMessage
;
111 DECLARE_NO_COPY_CLASS(wxMessageDialogBase
)
114 // this is a helper class for native wxMessageDialog implementations which need
115 // to store the custom button labels as member variables and then use them in
116 // ShowModal() (there could conceivably be a port which would have some native
117 // functions for setting these labels immediately and we also don't need to
118 // store them at all if custom labels are not supported, which is why we do
119 // this in a separate class and not wxMessageDialogBase itself)
120 #if defined(__WXCOCOA__) || defined(__WXMAC__) || defined(__WXMSW__)
122 class WXDLLIMPEXP_CORE wxMessageDialogWithCustomLabels
123 : public wxMessageDialogBase
127 wxMessageDialogWithCustomLabels() { }
128 wxMessageDialogWithCustomLabels(wxWindow
*parent
,
129 const wxString
& message
,
130 const wxString
& caption
,
132 : wxMessageDialogBase(parent
, message
, caption
, style
)
136 // customization of the message box buttons
137 virtual bool SetYesNoLabels(const wxString
& yes
,const wxString
& no
)
139 DoSetCustomLabel(m_yes
, yes
);
140 DoSetCustomLabel(m_no
, no
);
144 virtual bool SetYesNoCancelLabels(const wxString
& yes
,
146 const wxString
& cancel
)
148 DoSetCustomLabel(m_yes
, yes
);
149 DoSetCustomLabel(m_no
, no
);
150 DoSetCustomLabel(m_cancel
, cancel
);
154 virtual bool SetOKLabel(const wxString
& ok
)
156 DoSetCustomLabel(m_ok
, ok
);
160 virtual bool SetOKCancelLabels(const wxString
& ok
, const wxString
& cancel
)
162 DoSetCustomLabel(m_ok
, ok
);
163 DoSetCustomLabel(m_cancel
, cancel
);
168 // test if any custom labels were set
169 bool HasCustomLabels() const
171 return !(m_ok
.empty() && m_cancel
.empty() &&
172 m_yes
.empty() && m_no
.empty());
175 // these functions return the label to be used for the button which is
176 // either a custom label explicitly set by the user or the default label,
177 // i.e. they always return a valid string
178 wxString
GetYesLabel() const { return m_yes
.empty() ? _("Yes") : m_yes
; }
179 wxString
GetNoLabel() const { return m_no
.empty() ? _("No") : m_no
; }
180 wxString
GetOKLabel() const { return m_ok
.empty() ? _("OK") : m_ok
; }
181 wxString
GetCancelLabel() const
182 { return m_cancel
.empty() ? _("Cancel") : m_cancel
; }
185 // this function is called by our public SetXXXLabels() and should assign
186 // the value to var with possibly some transformation (e.g. Cocoa version
187 // currently uses this to remove any accelerators from the button strings)
188 virtual void DoSetCustomLabel(wxString
& var
, const wxString
& value
)
193 // labels for the buttons, initially empty meaning that the defaults should
194 // be used, use GetYes/No/OK/CancelLabel() to access them
200 DECLARE_NO_COPY_CLASS(wxMessageDialogWithCustomLabels
)
203 #endif // ports needing wxMessageDialogWithCustomLabels
205 #if defined(__WX_COMPILING_MSGDLGG_CPP__) || \
206 defined(__WXUNIVERSAL__) || defined(__WXGPE__) || \
207 (defined(__WXGTK__) && !defined(__WXGTK20__))
208 #include "wx/generic/msgdlgg.h"
210 #define wxMessageDialog wxGenericMessageDialog
211 #elif defined(__WXCOCOA__)
212 #include "wx/cocoa/msgdlg.h"
213 #elif defined(__WXPALMOS__)
214 #include "wx/palmos/msgdlg.h"
215 #elif defined(__WXMSW__)
216 #include "wx/msw/msgdlg.h"
217 #elif defined(__WXMOTIF__)
218 #include "wx/motif/msgdlg.h"
219 #elif defined(__WXGTK20__)
220 #include "wx/gtk/msgdlg.h"
221 #elif defined(__WXMAC__)
222 #include "wx/osx/msgdlg.h"
223 #elif defined(__WXPM__)
224 #include "wx/os2/msgdlg.h"
227 // ----------------------------------------------------------------------------
228 // wxMessageBox: the simplest way to use wxMessageDialog
229 // ----------------------------------------------------------------------------
231 int WXDLLIMPEXP_CORE
wxMessageBox(const wxString
& message
,
232 const wxString
& caption
= wxMessageBoxCaptionStr
,
233 long style
= wxOK
| wxCENTRE
,
234 wxWindow
*parent
= NULL
,
235 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
237 #endif // wxUSE_MSGDLG
239 #endif // _WX_MSGDLG_H_BASE_