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"
20 #include "wx/stockitem.h"
22 WXDLLIMPEXP_DATA_CORE(extern const char) wxMessageBoxCaptionStr
[];
24 // ----------------------------------------------------------------------------
25 // wxMessageDialogBase: base class defining wxMessageDialog interface
26 // ----------------------------------------------------------------------------
28 class WXDLLIMPEXP_CORE wxMessageDialogBase
: public wxDialog
31 // helper class for SetXXXLabels() methods: it makes it possible to pass
32 // either a stock id (wxID_CLOSE) or a string ("&Close") to them
36 // ctors are not explicit, objects of this class can be implicitly
37 // constructed from either stock ids or strings
38 ButtonLabel(int stockId
)
41 wxASSERT_MSG( wxIsStockID(stockId
), "invalid stock id" );
44 ButtonLabel(const wxString
& label
)
45 : m_label(label
), m_stockId(wxID_NONE
)
49 ButtonLabel(const char *label
)
50 : m_label(label
), m_stockId(wxID_NONE
)
54 ButtonLabel(const wchar_t *label
)
55 : m_label(label
), m_stockId(wxID_NONE
)
59 ButtonLabel(const wxCStrData
& label
)
60 : m_label(label
), m_stockId(wxID_NONE
)
64 // default copy ctor and dtor are ok
66 // get the string label, whether it was originally specified directly
67 // or as a stock id -- this is only useful for platforms without native
68 // stock items id support
69 wxString
GetAsString() const
71 return m_stockId
== wxID_NONE
? m_label
72 : wxGetStockLabel(m_stockId
);
75 // return the stock id or wxID_NONE if this is not a stock label
76 int GetStockId() const { return m_stockId
; }
79 // the label if explicitly given or empty if this is a stock item
80 const wxString m_label
;
82 // the stock item id or wxID_NONE if m_label should be used
88 wxMessageDialogBase() { m_dialogStyle
= 0; }
89 wxMessageDialogBase(wxWindow
*parent
,
90 const wxString
& message
,
91 const wxString
& caption
,
97 SetMessageDialogStyle(style
);
100 // virtual dtor for the base class
101 virtual ~wxMessageDialogBase() { }
104 // methods for setting up more custom message dialogs -- all functions
105 // return false if they're not implemented
106 virtual bool SetYesNoLabels(const ButtonLabel
& WXUNUSED(yes
),
107 const ButtonLabel
& WXUNUSED(no
))
112 virtual bool SetYesNoCancelLabels(const ButtonLabel
& WXUNUSED(yes
),
113 const ButtonLabel
& WXUNUSED(no
),
114 const ButtonLabel
& WXUNUSED(cancel
))
119 virtual bool SetOKLabel(const ButtonLabel
& WXUNUSED(ok
))
124 virtual bool SetOKCancelLabels(const ButtonLabel
& WXUNUSED(ok
),
125 const ButtonLabel
& WXUNUSED(cancel
))
130 virtual void SetMessage(const wxString
& message
)
135 virtual void SetExtendedMessage(const wxString
& extendedMessage
)
137 m_extendedMessage
= extendedMessage
;
140 // change the dialog style flag
141 void SetMessageDialogStyle(long style
)
143 wxASSERT_MSG( ((style
& wxYES_NO
) == wxYES_NO
) || !(style
& wxYES_NO
),
144 "wxYES and wxNO may only be used together" );
146 wxASSERT_MSG( (style
& wxID_OK
) != wxID_OK
,
147 "wxMessageBox: Did you mean wxOK (and not wxID_OK)?" );
149 m_dialogStyle
= style
;
153 long GetMessageDialogStyle() const { return m_dialogStyle
; }
156 // for the platforms not supporting separate main and extended messages
157 // this function should be used to combine both of them in a single string
158 wxString
GetFullMessage() const
160 wxString msg
= m_message
;
161 if ( !m_extendedMessage
.empty() )
162 msg
<< "\n\n" << m_extendedMessage
;
172 DECLARE_NO_COPY_CLASS(wxMessageDialogBase
)
175 // this is a helper class for native wxMessageDialog implementations which need
176 // to store the custom button labels as member variables and then use them in
177 // ShowModal() (there could conceivably be a port which would have some native
178 // functions for setting these labels immediately and we also don't need to
179 // store them at all if custom labels are not supported, which is why we do
180 // this in a separate class and not wxMessageDialogBase itself)
181 #if defined(__WXCOCOA__) || \
182 defined(__WXGTK20__) || \
183 defined(__WXMAC__) || \
186 class WXDLLIMPEXP_CORE wxMessageDialogWithCustomLabels
187 : public wxMessageDialogBase
191 wxMessageDialogWithCustomLabels() { }
192 wxMessageDialogWithCustomLabels(wxWindow
*parent
,
193 const wxString
& message
,
194 const wxString
& caption
,
196 : wxMessageDialogBase(parent
, message
, caption
, style
)
200 // customization of the message box buttons
201 virtual bool SetYesNoLabels(const ButtonLabel
& yes
,const ButtonLabel
& no
)
203 DoSetCustomLabel(m_yes
, yes
);
204 DoSetCustomLabel(m_no
, no
);
208 virtual bool SetYesNoCancelLabels(const ButtonLabel
& yes
,
209 const ButtonLabel
& no
,
210 const ButtonLabel
& cancel
)
212 DoSetCustomLabel(m_yes
, yes
);
213 DoSetCustomLabel(m_no
, no
);
214 DoSetCustomLabel(m_cancel
, cancel
);
218 virtual bool SetOKLabel(const ButtonLabel
& ok
)
220 DoSetCustomLabel(m_ok
, ok
);
224 virtual bool SetOKCancelLabels(const ButtonLabel
& ok
,
225 const ButtonLabel
& cancel
)
227 DoSetCustomLabel(m_ok
, ok
);
228 DoSetCustomLabel(m_cancel
, cancel
);
233 // test if any custom labels were set
234 bool HasCustomLabels() const
236 return !(m_ok
.empty() && m_cancel
.empty() &&
237 m_yes
.empty() && m_no
.empty());
240 // these functions return the label to be used for the button which is
241 // either a custom label explicitly set by the user or the default label,
242 // i.e. they always return a valid string
243 wxString
GetYesLabel() const
244 { return m_yes
.empty() ? GetDefaultYesLabel() : m_yes
; }
245 wxString
GetNoLabel() const
246 { return m_no
.empty() ? GetDefaultNoLabel() : m_no
; }
247 wxString
GetOKLabel() const
248 { return m_ok
.empty() ? GetDefaultOKLabel() : m_ok
; }
249 wxString
GetCancelLabel() const
250 { return m_cancel
.empty() ? GetDefaultCancelLabel() : m_cancel
; }
252 // this function is called by our public SetXXXLabels() and should assign
253 // the value to var with possibly some transformation (e.g. Cocoa version
254 // currently uses this to remove any accelerators from the button strings
255 // while GTK+ one handles stock items specifically here)
256 virtual void DoSetCustomLabel(wxString
& var
, const ButtonLabel
& label
)
258 var
= label
.GetAsString();
262 // these functions may be overridden to provide different defaults for the
263 // default button labels (this is used by wxGTK)
264 virtual wxString
GetDefaultYesLabel() const { return _("Yes"); }
265 virtual wxString
GetDefaultNoLabel() const { return _("No"); }
266 virtual wxString
GetDefaultOKLabel() const { return _("OK"); }
267 virtual wxString
GetDefaultCancelLabel() const { return _("Cancel"); }
269 // labels for the buttons, initially empty meaning that the defaults should
270 // be used, use GetYes/No/OK/CancelLabel() to access them
276 DECLARE_NO_COPY_CLASS(wxMessageDialogWithCustomLabels
)
279 #endif // ports needing wxMessageDialogWithCustomLabels
281 #if defined(__WX_COMPILING_MSGDLGG_CPP__) || \
282 defined(__WXUNIVERSAL__) || defined(__WXGPE__) || \
283 (defined(__WXGTK__) && !defined(__WXGTK20__))
284 #include "wx/generic/msgdlgg.h"
286 #define wxMessageDialog wxGenericMessageDialog
287 #elif defined(__WXCOCOA__)
288 #include "wx/cocoa/msgdlg.h"
289 #elif defined(__WXPALMOS__)
290 #include "wx/palmos/msgdlg.h"
291 #elif defined(__WXMSW__)
292 #include "wx/msw/msgdlg.h"
293 #elif defined(__WXMOTIF__)
294 #include "wx/motif/msgdlg.h"
295 #elif defined(__WXGTK20__)
296 #include "wx/gtk/msgdlg.h"
297 #elif defined(__WXMAC__)
298 #include "wx/osx/msgdlg.h"
299 #elif defined(__WXPM__)
300 #include "wx/os2/msgdlg.h"
303 // ----------------------------------------------------------------------------
304 // wxMessageBox: the simplest way to use wxMessageDialog
305 // ----------------------------------------------------------------------------
307 int WXDLLIMPEXP_CORE
wxMessageBox(const wxString
& message
,
308 const wxString
& caption
= wxMessageBoxCaptionStr
,
309 long style
= wxOK
| wxCENTRE
,
310 wxWindow
*parent
= NULL
,
311 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
313 #endif // wxUSE_MSGDLG
315 #endif // _WX_MSGDLG_H_BASE_