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 // default copy ctor and dtor are ok
51 // get the string label, whether it was originally specified directly
52 // or as a stock id -- this is only useful for platforms without native
53 // stock items id support
54 wxString
GetAsString() const
56 return m_stockId
== wxID_NONE
? m_label
57 : wxGetStockLabel(m_stockId
);
60 // return the stock id or wxID_NONE if this is not a stock label
61 int GetStockId() const { return m_stockId
; }
64 // the label if explicitly given or empty if this is a stock item
65 const wxString m_label
;
67 // the stock item id or wxID_NONE if m_label should be used
73 wxMessageDialogBase() { m_dialogStyle
= 0; }
74 wxMessageDialogBase(wxWindow
*parent
,
75 const wxString
& message
,
76 const wxString
& caption
,
82 SetMessageDialogStyle(style
);
85 // virtual dtor for the base class
86 virtual ~wxMessageDialogBase() { }
89 // methods for setting up more custom message dialogs -- all functions
90 // return false if they're not implemented
91 virtual bool SetYesNoLabels(const ButtonLabel
& WXUNUSED(yes
),
92 const ButtonLabel
& WXUNUSED(no
))
97 virtual bool SetYesNoCancelLabels(const ButtonLabel
& WXUNUSED(yes
),
98 const ButtonLabel
& WXUNUSED(no
),
99 const ButtonLabel
& WXUNUSED(cancel
))
104 virtual bool SetOKLabel(const ButtonLabel
& WXUNUSED(ok
))
109 virtual bool SetOKCancelLabels(const ButtonLabel
& WXUNUSED(ok
),
110 const ButtonLabel
& WXUNUSED(cancel
))
115 virtual void SetMessage(const wxString
& message
)
120 virtual void SetExtendedMessage(const wxString
& extendedMessage
)
122 m_extendedMessage
= extendedMessage
;
126 // common validation of wxMessageDialog style
127 void SetMessageDialogStyle(long style
)
129 wxASSERT_MSG( ((style
& wxYES_NO
) == wxYES_NO
) || !(style
& wxYES_NO
),
130 "wxYES and wxNO may only be used together" );
132 wxASSERT_MSG( (style
& wxID_OK
) != wxID_OK
,
133 "wxMessageBox: Did you mean wxOK (and not wxID_OK)?" );
135 m_dialogStyle
= style
;
138 long GetMessageDialogStyle() const { return m_dialogStyle
; }
141 // for the platforms not supporting separate main and extended messages
142 // this function should be used to combine both of them in a single string
143 wxString
GetFullMessage() const
145 wxString msg
= m_message
;
146 if ( !m_extendedMessage
.empty() )
147 msg
<< "\n\n" << m_extendedMessage
;
157 DECLARE_NO_COPY_CLASS(wxMessageDialogBase
)
160 // this is a helper class for native wxMessageDialog implementations which need
161 // to store the custom button labels as member variables and then use them in
162 // ShowModal() (there could conceivably be a port which would have some native
163 // functions for setting these labels immediately and we also don't need to
164 // store them at all if custom labels are not supported, which is why we do
165 // this in a separate class and not wxMessageDialogBase itself)
166 #if defined(__WXCOCOA__) || \
167 defined(__WXGTK20__) || \
168 defined(__WXMAC__) || \
171 class WXDLLIMPEXP_CORE wxMessageDialogWithCustomLabels
172 : public wxMessageDialogBase
176 wxMessageDialogWithCustomLabels() { }
177 wxMessageDialogWithCustomLabels(wxWindow
*parent
,
178 const wxString
& message
,
179 const wxString
& caption
,
181 : wxMessageDialogBase(parent
, message
, caption
, style
)
185 // customization of the message box buttons
186 virtual bool SetYesNoLabels(const ButtonLabel
& yes
,const ButtonLabel
& no
)
188 DoSetCustomLabel(m_yes
, yes
);
189 DoSetCustomLabel(m_no
, no
);
193 virtual bool SetYesNoCancelLabels(const ButtonLabel
& yes
,
194 const ButtonLabel
& no
,
195 const ButtonLabel
& cancel
)
197 DoSetCustomLabel(m_yes
, yes
);
198 DoSetCustomLabel(m_no
, no
);
199 DoSetCustomLabel(m_cancel
, cancel
);
203 virtual bool SetOKLabel(const ButtonLabel
& ok
)
205 DoSetCustomLabel(m_ok
, ok
);
209 virtual bool SetOKCancelLabels(const ButtonLabel
& ok
,
210 const ButtonLabel
& cancel
)
212 DoSetCustomLabel(m_ok
, ok
);
213 DoSetCustomLabel(m_cancel
, cancel
);
218 // test if any custom labels were set
219 bool HasCustomLabels() const
221 return !(m_ok
.empty() && m_cancel
.empty() &&
222 m_yes
.empty() && m_no
.empty());
225 // these functions return the label to be used for the button which is
226 // either a custom label explicitly set by the user or the default label,
227 // i.e. they always return a valid string
228 wxString
GetYesLabel() const
229 { return m_yes
.empty() ? GetDefaultYesLabel() : m_yes
; }
230 wxString
GetNoLabel() const
231 { return m_no
.empty() ? GetDefaultNoLabel() : m_no
; }
232 wxString
GetOKLabel() const
233 { return m_ok
.empty() ? GetDefaultOKLabel() : m_ok
; }
234 wxString
GetCancelLabel() const
235 { return m_cancel
.empty() ? GetDefaultCancelLabel() : m_cancel
; }
237 // this function is called by our public SetXXXLabels() and should assign
238 // the value to var with possibly some transformation (e.g. Cocoa version
239 // currently uses this to remove any accelerators from the button strings
240 // while GTK+ one handles stock items specifically here)
241 virtual void DoSetCustomLabel(wxString
& var
, const ButtonLabel
& label
)
243 var
= label
.GetAsString();
247 // these functions may be overridden to provide different defaults for the
248 // default button labels (this is used by wxGTK)
249 virtual wxString
GetDefaultYesLabel() const { return _("Yes"); }
250 virtual wxString
GetDefaultNoLabel() const { return _("No"); }
251 virtual wxString
GetDefaultOKLabel() const { return _("OK"); }
252 virtual wxString
GetDefaultCancelLabel() const { return _("Cancel"); }
254 // labels for the buttons, initially empty meaning that the defaults should
255 // be used, use GetYes/No/OK/CancelLabel() to access them
261 DECLARE_NO_COPY_CLASS(wxMessageDialogWithCustomLabels
)
264 #endif // ports needing wxMessageDialogWithCustomLabels
266 #if defined(__WX_COMPILING_MSGDLGG_CPP__) || \
267 defined(__WXUNIVERSAL__) || defined(__WXGPE__) || \
268 (defined(__WXGTK__) && !defined(__WXGTK20__))
269 #include "wx/generic/msgdlgg.h"
271 #define wxMessageDialog wxGenericMessageDialog
272 #elif defined(__WXCOCOA__)
273 #include "wx/cocoa/msgdlg.h"
274 #elif defined(__WXPALMOS__)
275 #include "wx/palmos/msgdlg.h"
276 #elif defined(__WXMSW__)
277 #include "wx/msw/msgdlg.h"
278 #elif defined(__WXMOTIF__)
279 #include "wx/motif/msgdlg.h"
280 #elif defined(__WXGTK20__)
281 #include "wx/gtk/msgdlg.h"
282 #elif defined(__WXMAC__)
283 #include "wx/osx/msgdlg.h"
284 #elif defined(__WXPM__)
285 #include "wx/os2/msgdlg.h"
288 // ----------------------------------------------------------------------------
289 // wxMessageBox: the simplest way to use wxMessageDialog
290 // ----------------------------------------------------------------------------
292 int WXDLLIMPEXP_CORE
wxMessageBox(const wxString
& message
,
293 const wxString
& caption
= wxMessageBoxCaptionStr
,
294 long style
= wxOK
| wxCENTRE
,
295 wxWindow
*parent
= NULL
,
296 int x
= wxDefaultCoord
, int y
= wxDefaultCoord
);
298 #endif // wxUSE_MSGDLG
300 #endif // _WX_MSGDLG_H_BASE_