]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msgdlg.h | |
e54c96f1 | 3 | // Purpose: interface of wxMessageDialog |
23324ae1 | 4 | // Author: wxWidgets team |
526954c5 | 5 | // Licence: wxWindows licence |
23324ae1 FM |
6 | ///////////////////////////////////////////////////////////////////////////// |
7 | ||
0b59366f VZ |
8 | /** |
9 | Default message box caption string. | |
10 | */ | |
11 | const char wxMessageBoxCaptionStr[] = "Message"; | |
12 | ||
13 | ||
23324ae1 FM |
14 | /** |
15 | @class wxMessageDialog | |
7c913512 | 16 | |
23324ae1 FM |
17 | This class represents a dialog that shows a single or multi-line message, |
18 | with a choice of OK, Yes, No and Cancel buttons. | |
7c913512 | 19 | |
11dd61cb FM |
20 | @beginStyleTable |
21 | @style{wxOK} | |
22 | Puts an Ok button in the message box. May be combined with @c wxCANCEL. | |
23 | @style{wxCANCEL} | |
24 | Puts a Cancel button in the message box. Must be combined with | |
25 | either @c wxOK or @c wxYES_NO. | |
26 | @style{wxYES_NO} | |
8bd410eb VZ |
27 | Puts Yes and No buttons in the message box. It is recommended to always |
28 | use @c wxCANCEL with this style as otherwise the message box won't have | |
29 | a close button under wxMSW and the user will be forced to answer it. | |
7112cdd1 VZ |
30 | @style{wxHELP} |
31 | Puts a Help button to the message box. This button can have special | |
32 | appearance or be specially positioned if its label is not changed from | |
33 | the default one. Notice that using this button is not supported when | |
34 | showing a message box from non-main thread in wxOSX/Cocoa and it is not | |
5ea01cd4 | 35 | supported in wxOSX/Carbon at all. Available since wxWidgets 2.9.3. |
11dd61cb FM |
36 | @style{wxNO_DEFAULT} |
37 | Makes the "No" button default, can only be used with @c wxYES_NO. | |
38 | @style{wxCANCEL_DEFAULT} | |
39 | Makes the "Cancel" button default, can only be used with @c wxCANCEL | |
40 | @style{wxYES_DEFAULT} | |
41 | Makes the "Yes" button default, this is the default behaviour and | |
42 | this flag exists solely for symmetry with @c wxNO_DEFAULT. | |
43 | @style{wxOK_DEFAULT} | |
44 | Makes the "OK" button default, this is the default behaviour and | |
45 | this flag exists solely for symmetry with @c wxCANCEL_DEFAULT. | |
7e3204b4 VZ |
46 | @style{wxICON_NONE} |
47 | Displays no icon in the dialog if possible (an icon might still be | |
48 | displayed if the current platform mandates its use). This style may be | |
49 | used to prevent the dialog from using the default icon based on @c | |
50 | wxYES_NO presence as explained in @c wxICON_QUESTION and @c | |
51 | wxICON_INFORMATION documentation below. | |
11dd61cb | 52 | @style{wxICON_EXCLAMATION} |
7e3204b4 | 53 | Displays an exclamation, or warning, icon in the dialog. |
11dd61cb | 54 | @style{wxICON_ERROR} |
7e3204b4 | 55 | Displays an error icon in the dialog. |
11dd61cb FM |
56 | @style{wxICON_HAND} |
57 | Displays an error symbol, this is a MSW-inspired synonym for @c wxICON_ERROR. | |
58 | @style{wxICON_QUESTION} | |
59 | Displays a question mark symbol. This icon is automatically used | |
60 | with @c wxYES_NO so it's usually unnecessary to specify it explicitly. | |
b8737371 VZ |
61 | This style is not supported for message dialogs under wxMSW when a task |
62 | dialog is used to implement them (i.e. when running under Windows Vista | |
63 | or later) because <a href="http://msdn.microsoft.com/en-us/library/aa511273.aspx">Microsoft | |
64 | guidelines</a> indicate that no icon should be used for routine | |
65 | confirmations. If it is specified, no icon will be displayed. | |
11dd61cb FM |
66 | @style{wxICON_INFORMATION} |
67 | Displays an information symbol. This icon is used by default if | |
68 | @c wxYES_NO is not given so it is usually unnecessary to specify it | |
69 | explicitly. | |
67315c8b VZ |
70 | @style{wxICON_AUTH_NEEDED} |
71 | Displays an authentication needed symbol. This style is only supported | |
72 | for message dialogs under wxMSW when a task dialog is used to implement | |
73 | them (i.e. when running under Windows Vista or later). In other cases | |
74 | the default icon selection logic will be used. Note this can be | |
75 | combined with other styles to provide a fallback. For instance, using | |
76 | wxICON_AUTH_NEEDED | wxICON_QUESTION will show a shield symbol on | |
77 | Windows Vista or above and a question symbol on other platforms. | |
5ea01cd4 | 78 | Available since wxWidgets 2.9.5 |
11dd61cb | 79 | @style{wxSTAY_ON_TOP} |
4566dcbe VZ |
80 | Makes the message box stay on top of all other windows and not only |
81 | just its parent (currently implemented only under MSW and GTK). | |
7981d340 VZ |
82 | @style{wxCENTRE} |
83 | Centre the message box on its parent or on the screen if parent is not | |
ede7b017 VZ |
84 | specified. |
85 | Setting this style under MSW makes no differences as the dialog is | |
86 | always centered on the parent. | |
11dd61cb FM |
87 | @endStyleTable |
88 | ||
23324ae1 FM |
89 | @library{wxcore} |
90 | @category{cmndlg} | |
7c913512 | 91 | |
ba1d7a6c | 92 | @see @ref overview_cmndlg_msg |
0800eb84 | 93 | @see wxRichMessageDialog |
23324ae1 FM |
94 | */ |
95 | class wxMessageDialog : public wxDialog | |
96 | { | |
97 | public: | |
1f165e74 VZ |
98 | /** |
99 | Helper class allowing to use either stock id or string labels. | |
100 | ||
101 | This class should never be used explicitly and is not really part of | |
102 | wxWidgets API but rather is just an implementation helper allowing the | |
103 | methods such as SetYesNoLabels() and SetOKCancelLabels() below to be | |
104 | callable with either stock ids (e.g. ::wxID_CLOSE) or strings | |
105 | ("&Close"). | |
106 | */ | |
107 | class ButtonLabel | |
108 | { | |
109 | public: | |
110 | /// Construct the label from a stock id. | |
111 | ButtonLabel(int stockId); | |
112 | ||
113 | /// Construct the label from the specified string. | |
114 | ButtonLabel(const wxString& label); | |
115 | ||
116 | /** | |
117 | Return the associated label as string. | |
118 | ||
119 | Get the string label, whether it was originally specified directly | |
120 | or as a stock id -- this is only useful for platforms without native | |
121 | stock items id support | |
122 | */ | |
123 | wxString GetAsString() const; | |
124 | ||
125 | /** | |
126 | Return the stock id or wxID_NONE if this is not a stock label. | |
127 | */ | |
128 | int GetStockId() const; | |
129 | }; | |
130 | ||
23324ae1 | 131 | /** |
8ad89211 | 132 | Constructor specifying the message box properties. |
8ad89211 VZ |
133 | Use ShowModal() to show the dialog. |
134 | ||
11dd61cb | 135 | @a style may be a bit list of the identifiers described above. |
3c4f71cc | 136 | |
ba1d7a6c FM |
137 | Notice that not all styles are compatible: only one of @c wxOK and |
138 | @c wxYES_NO may be specified (and one of them must be specified) and at | |
f45d6ade VZ |
139 | most one default button style can be used and it is only valid if the |
140 | corresponding button is shown in the message box. | |
141 | ||
7c913512 | 142 | @param parent |
4cc4bfaf | 143 | Parent window. |
7c913512 | 144 | @param message |
8ad89211 | 145 | Message to show in the dialog. |
7c913512 | 146 | @param caption |
8ad89211 | 147 | The dialog title. |
7c913512 | 148 | @param style |
8ad89211 | 149 | Combination of style flags described above. |
7c913512 | 150 | @param pos |
8ad89211 | 151 | Dialog position (ignored under MSW). |
23324ae1 FM |
152 | */ |
153 | wxMessageDialog(wxWindow* parent, const wxString& message, | |
0a98423e | 154 | const wxString& caption = wxMessageBoxCaptionStr, |
f45d6ade | 155 | long style = wxOK | wxCENTRE, |
23324ae1 FM |
156 | const wxPoint& pos = wxDefaultPosition); |
157 | ||
158 | /** | |
8ad89211 VZ |
159 | Sets the extended message for the dialog: this message is usually an |
160 | extension of the short message specified in the constructor or set with | |
161 | SetMessage(). | |
162 | ||
163 | If it is set, the main message appears highlighted -- if supported -- | |
164 | and this message appears beneath it in normal font. On the platforms | |
165 | which don't support extended messages, it is simply appended to the | |
b9b2c695 VS |
166 | normal message with an empty line separating them. |
167 | ||
168 | @since 2.9.0 | |
23324ae1 | 169 | */ |
43c48e1e | 170 | virtual void SetExtendedMessage(const wxString& extendedMessage); |
23324ae1 | 171 | |
7112cdd1 VZ |
172 | /** |
173 | Sets the label for the Help button. | |
174 | ||
175 | Please see the remarks in SetYesNoLabels() documentation. | |
176 | ||
177 | Notice that changing the label of the help button resets its special | |
178 | status (if any, this depends on the platform) and it will be treated | |
179 | just like another button in this case. | |
180 | ||
181 | @since 2.9.3 | |
182 | */ | |
183 | virtual bool SetHelpLabel(const ButtonLabel& help); | |
184 | ||
23324ae1 FM |
185 | /** |
186 | Sets the message shown by the dialog. | |
b9b2c695 VS |
187 | |
188 | @since 2.9.0 | |
23324ae1 | 189 | */ |
43c48e1e | 190 | virtual void SetMessage(const wxString& message); |
23324ae1 FM |
191 | |
192 | /** | |
193 | Overrides the default labels of the OK and Cancel buttons. | |
8ad89211 VZ |
194 | |
195 | Please see the remarks in SetYesNoLabels() documentation. | |
b9b2c695 VS |
196 | |
197 | @since 2.9.0 | |
23324ae1 | 198 | */ |
adaaa686 FM |
199 | virtual bool SetOKCancelLabels(const ButtonLabel& ok, |
200 | const ButtonLabel& cancel); | |
23324ae1 FM |
201 | |
202 | /** | |
203 | Overrides the default label of the OK button. | |
8ad89211 VZ |
204 | |
205 | Please see the remarks in SetYesNoLabels() documentation. | |
b9b2c695 VS |
206 | |
207 | @since 2.9.0 | |
23324ae1 | 208 | */ |
adaaa686 | 209 | virtual bool SetOKLabel(const ButtonLabel& ok); |
23324ae1 FM |
210 | |
211 | /** | |
212 | Overrides the default labels of the Yes, No and Cancel buttons. | |
8ad89211 VZ |
213 | |
214 | Please see the remarks in SetYesNoLabels() documentation. | |
b9b2c695 VS |
215 | |
216 | @since 2.9.0 | |
23324ae1 | 217 | */ |
fadc2df6 FM |
218 | virtual bool SetYesNoCancelLabels(const ButtonLabel& yes, |
219 | const ButtonLabel& no, | |
220 | const ButtonLabel& cancel); | |
23324ae1 FM |
221 | |
222 | /** | |
223 | Overrides the default labels of the Yes and No buttons. | |
8ad89211 | 224 | |
e08931c0 VZ |
225 | The arguments of this function can be either strings or one of the |
226 | standard identifiers, such as @c wxID_APPLY or @c wxID_OPEN. Notice | |
227 | that even if the label is specified as an identifier, the return value | |
228 | of the dialog ShowModal() method still remains one of @c wxID_OK, @c | |
229 | wxID_CANCEL, @c wxID_YES or @c wxID_NO values, i.e. this identifier | |
230 | changes only the label appearance but not the return code generated by | |
231 | the button. It is possible to mix stock identifiers and string labels | |
232 | in the same function call, for example: | |
233 | @code | |
234 | wxMessageDialog dlg(...); | |
235 | dlg.SetYesNoLabels(wxID_SAVE, _("&Don't save")); | |
236 | @endcode | |
237 | ||
238 | Also notice that this function is not currently available on all | |
239 | platforms (although as of wxWidgets 2.9.0 it is implemented in all | |
240 | major ports), so it may return @false to indicate that the labels | |
461cd115 VZ |
241 | couldn't be changed. If it returns @true, the labels were set |
242 | successfully. | |
243 | ||
244 | Typically, if the function was used successfully, the main dialog | |
245 | message may need to be changed, e.g.: | |
8ad89211 VZ |
246 | @code |
247 | wxMessageDialog dlg(...); | |
248 | if ( dlg.SetYesNoLabels(_("&Quit"), _("&Don't quit")) ) | |
249 | dlg.SetMessage(_("What do you want to do?")); | |
250 | else // buttons have standard "Yes"/"No" values, so rephrase the question | |
251 | dlg.SetMessage(_("Do you really want to quit?")); | |
252 | @endcode | |
b9b2c695 VS |
253 | |
254 | @since 2.9.0 | |
23324ae1 | 255 | */ |
adaaa686 | 256 | virtual bool SetYesNoLabels(const ButtonLabel& yes, const ButtonLabel& no); |
23324ae1 FM |
257 | |
258 | /** | |
7112cdd1 VZ |
259 | Shows the dialog, returning one of wxID_OK, wxID_CANCEL, wxID_YES, |
260 | wxID_NO or wxID_HELP. | |
8ad89211 VZ |
261 | |
262 | Notice that this method returns the identifier of the button which was | |
263 | clicked unlike wxMessageBox() function. | |
23324ae1 | 264 | */ |
adaaa686 | 265 | virtual int ShowModal(); |
8f199edf RD |
266 | |
267 | ||
268 | wxString GetCaption() const; | |
269 | wxString GetMessage() const; | |
270 | wxString GetExtendedMessage() const; | |
271 | long GetMessageDialogStyle() const; | |
272 | bool HasCustomLabels() const; | |
273 | wxString GetYesLabel() const; | |
274 | wxString GetNoLabel() const; | |
275 | wxString GetOKLabel() const; | |
276 | wxString GetCancelLabel() const; | |
277 | wxString GetHelpLabel() const; | |
278 | long GetEffectiveIcon() const; | |
279 | ||
23324ae1 FM |
280 | }; |
281 | ||
282 | ||
e54c96f1 | 283 | |
23324ae1 FM |
284 | // ============================================================================ |
285 | // Global functions/macros | |
286 | // ============================================================================ | |
287 | ||
b21126db | 288 | /** @addtogroup group_funcmacro_dialog */ |
ba2874ff BP |
289 | //@{ |
290 | ||
23324ae1 | 291 | /** |
8ad89211 VZ |
292 | Show a general purpose message dialog. |
293 | ||
294 | This is a convenient function which is usually used instead of using | |
295 | wxMessageDialog directly. Notice however that some of the features, such as | |
296 | extended text and custom labels for the message box buttons, are not | |
297 | provided by this function but only by wxMessageDialog. | |
298 | ||
7112cdd1 VZ |
299 | The return value is one of: @c wxYES, @c wxNO, @c wxCANCEL, @c wxOK or @c |
300 | wxHELP (notice that this return value is @b different from the return value | |
301 | of wxMessageDialog::ShowModal()). | |
4cc4bfaf | 302 | |
8ad89211 | 303 | For example: |
23324ae1 | 304 | @code |
ba2874ff BP |
305 | int answer = wxMessageBox("Quit program?", "Confirm", |
306 | wxYES_NO | wxCANCEL, main_frame); | |
307 | if (answer == wxYES) | |
308 | main_frame->Close(); | |
23324ae1 | 309 | @endcode |
7c913512 | 310 | |
ba2874ff BP |
311 | @a message may contain newline characters, in which case the message will |
312 | be split into separate lines, to cater for large messages. | |
313 | ||
8ad89211 VZ |
314 | @param message |
315 | Message to show in the dialog. | |
316 | @param caption | |
317 | The dialog title. | |
318 | @param parent | |
319 | Parent window. | |
320 | @param style | |
321 | Combination of style flags described in wxMessageDialog documentation. | |
322 | @param x | |
76e2b570 | 323 | Horizontal dialog position (ignored under MSW). Use ::wxDefaultCoord |
8ad89211 VZ |
324 | for @a x and @a y to let the system position the window. |
325 | @param y | |
326 | Vertical dialog position (ignored under MSW). | |
89041b25 | 327 | |
ba2874ff | 328 | @header{wx/msgdlg.h} |
23324ae1 FM |
329 | */ |
330 | int wxMessageBox(const wxString& message, | |
fe9b5698 VZ |
331 | const wxString& caption = wxMessageBoxCaptionStr, |
332 | int style = wxOK | wxCENTRE, | |
4cc4bfaf | 333 | wxWindow* parent = NULL, |
8ad89211 VZ |
334 | int x = wxDefaultCoord, |
335 | int y = wxDefaultCoord); | |
23324ae1 | 336 | |
ba2874ff BP |
337 | //@} |
338 |