]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msgdlg.h
1dbd69e3afe7a2aeb0182fcba26c1833c4ad11b3
[wxWidgets.git] / include / wx / msgdlg.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msgdlgg.h
3 // Purpose: common header and base class for wxMessageDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created:
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_MSGDLG_H_BASE_
13 #define _WX_MSGDLG_H_BASE_
14
15 #include "wx/defs.h"
16
17 #if wxUSE_MSGDLG
18
19 #include "wx/dialog.h"
20
21 WXDLLIMPEXP_DATA_CORE(extern const char) wxMessageBoxCaptionStr[];
22
23 class WXDLLIMPEXP_CORE wxMessageDialogBase : public wxDialog
24 {
25 public:
26 // ctors
27 wxMessageDialogBase() { m_dialogStyle = 0; }
28 wxMessageDialogBase(wxWindow *parent,
29 const wxString& message,
30 const wxString& caption,
31 long style)
32 : m_message(message),
33 m_caption(caption)
34 {
35 m_parent = parent;
36 SetMessageDialogStyle(style);
37 }
38
39 // virtual dtor for the base class
40 virtual ~wxMessageDialogBase() { }
41
42
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))
47 {
48 return false;
49 }
50
51 virtual bool SetYesNoCancelLabels(const wxString& WXUNUSED(yes),
52 const wxString& WXUNUSED(no),
53 const wxString& WXUNUSED(cancel))
54 {
55 return false;
56 }
57
58 virtual bool SetOKLabel(const wxString& WXUNUSED(ok))
59 {
60 return false;
61 }
62
63 virtual bool SetOKCancelLabels(const wxString& WXUNUSED(ok),
64 const wxString& WXUNUSED(cancel))
65 {
66 return false;
67 }
68
69 virtual void SetMessage(const wxString& message)
70 {
71 m_message = message;
72 }
73
74 virtual void SetExtendedMessage(const wxString& extendedMessage)
75 {
76 m_extendedMessage = extendedMessage;
77 }
78
79 protected:
80 // common validation of wxMessageDialog style
81 void SetMessageDialogStyle(long style)
82 {
83 wxASSERT_MSG( ((style & wxYES_NO) == wxYES_NO) || ((style & wxYES_NO) == 0),
84 _T("wxYES and wxNO may only be used together in wxMessageDialog") );
85
86 wxASSERT_MSG( (style & wxID_OK) != wxID_OK,
87 _T("wxMessageBox: Did you mean wxOK (and not wxID_OK)?") );
88
89 m_dialogStyle = style;
90 }
91
92 long GetMessageDialogStyle() const { return m_dialogStyle; }
93
94
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
98 {
99 wxString msg = m_message;
100 if ( !m_extendedMessage.empty() )
101 msg << "\n\n" << m_extendedMessage;
102
103 return msg;
104 }
105
106 wxString m_message,
107 m_extendedMessage,
108 m_caption;
109 long m_dialogStyle;
110
111 DECLARE_NO_COPY_CLASS(wxMessageDialogBase)
112 };
113
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__) || \
121 defined(__WXGTK20__) || \
122 defined(__WXMAC__) || \
123 defined(__WXMSW__)
124
125 class WXDLLIMPEXP_CORE wxMessageDialogWithCustomLabels
126 : public wxMessageDialogBase
127 {
128 public:
129 // ctors
130 wxMessageDialogWithCustomLabels() { }
131 wxMessageDialogWithCustomLabels(wxWindow *parent,
132 const wxString& message,
133 const wxString& caption,
134 long style)
135 : wxMessageDialogBase(parent, message, caption, style)
136 {
137 }
138
139 // customization of the message box buttons
140 virtual bool SetYesNoLabels(const wxString& yes,const wxString& no)
141 {
142 DoSetCustomLabel(m_yes, yes);
143 DoSetCustomLabel(m_no, no);
144 return true;
145 }
146
147 virtual bool SetYesNoCancelLabels(const wxString& yes,
148 const wxString& no,
149 const wxString& cancel)
150 {
151 DoSetCustomLabel(m_yes, yes);
152 DoSetCustomLabel(m_no, no);
153 DoSetCustomLabel(m_cancel, cancel);
154 return true;
155 }
156
157 virtual bool SetOKLabel(const wxString& ok)
158 {
159 DoSetCustomLabel(m_ok, ok);
160 return true;
161 }
162
163 virtual bool SetOKCancelLabels(const wxString& ok, const wxString& cancel)
164 {
165 DoSetCustomLabel(m_ok, ok);
166 DoSetCustomLabel(m_cancel, cancel);
167 return true;
168 }
169
170 protected:
171 // test if any custom labels were set
172 bool HasCustomLabels() const
173 {
174 return !(m_ok.empty() && m_cancel.empty() &&
175 m_yes.empty() && m_no.empty());
176 }
177
178 // these functions return the label to be used for the button which is
179 // either a custom label explicitly set by the user or the default label,
180 // i.e. they always return a valid string
181 wxString GetYesLabel() const
182 { return m_yes.empty() ? GetDefaultYesLabel() : m_yes; }
183 wxString GetNoLabel() const
184 { return m_no.empty() ? GetDefaultNoLabel() : m_no; }
185 wxString GetOKLabel() const
186 { return m_ok.empty() ? GetDefaultOKLabel() : m_ok; }
187 wxString GetCancelLabel() const
188 { return m_cancel.empty() ? GetDefaultCancelLabel() : m_cancel; }
189
190 private:
191 // this function is called by our public SetXXXLabels() and should assign
192 // the value to var with possibly some transformation (e.g. Cocoa version
193 // currently uses this to remove any accelerators from the button strings)
194 virtual void DoSetCustomLabel(wxString& var, const wxString& value)
195 {
196 var = value;
197 }
198
199 // these functions may be overridden to provide different defaults for the
200 // default button labels (this is used by wxGTK)
201 virtual wxString GetDefaultYesLabel() const { return _("Yes"); }
202 virtual wxString GetDefaultNoLabel() const { return _("No"); }
203 virtual wxString GetDefaultOKLabel() const { return _("OK"); }
204 virtual wxString GetDefaultCancelLabel() const { return _("Cancel"); }
205
206 // labels for the buttons, initially empty meaning that the defaults should
207 // be used, use GetYes/No/OK/CancelLabel() to access them
208 wxString m_yes,
209 m_no,
210 m_ok,
211 m_cancel;
212
213 DECLARE_NO_COPY_CLASS(wxMessageDialogWithCustomLabels)
214 };
215
216 #endif // ports needing wxMessageDialogWithCustomLabels
217
218 #if defined(__WX_COMPILING_MSGDLGG_CPP__) || \
219 defined(__WXUNIVERSAL__) || defined(__WXGPE__) || \
220 (defined(__WXGTK__) && !defined(__WXGTK20__))
221 #include "wx/generic/msgdlgg.h"
222
223 #define wxMessageDialog wxGenericMessageDialog
224 #elif defined(__WXCOCOA__)
225 #include "wx/cocoa/msgdlg.h"
226 #elif defined(__WXPALMOS__)
227 #include "wx/palmos/msgdlg.h"
228 #elif defined(__WXMSW__)
229 #include "wx/msw/msgdlg.h"
230 #elif defined(__WXMOTIF__)
231 #include "wx/motif/msgdlg.h"
232 #elif defined(__WXGTK20__)
233 #include "wx/gtk/msgdlg.h"
234 #elif defined(__WXMAC__)
235 #include "wx/osx/msgdlg.h"
236 #elif defined(__WXPM__)
237 #include "wx/os2/msgdlg.h"
238 #endif
239
240 // ----------------------------------------------------------------------------
241 // wxMessageBox: the simplest way to use wxMessageDialog
242 // ----------------------------------------------------------------------------
243
244 int WXDLLIMPEXP_CORE wxMessageBox(const wxString& message,
245 const wxString& caption = wxMessageBoxCaptionStr,
246 long style = wxOK | wxCENTRE,
247 wxWindow *parent = NULL,
248 int x = wxDefaultCoord, int y = wxDefaultCoord);
249
250 #endif // wxUSE_MSGDLG
251
252 #endif // _WX_MSGDLG_H_BASE_