xref: /haiku/docs/user/interface/Alert.dox (revision 0044a8c39ab5721051b6279506d1a8c511e20453)
1/*
2 * Copyright 2011, Haiku inc.
3 * Distributed under the terms of the MIT Licence.
4 *
5 * Documentation by:
6 *  John Scipione <jscipione@gmail.com>
7 * Corresponds to:
8 *  /trunk/headers/os/interface/Alert.h	 rev 42274
9 *  /trunk/src/kits/interface/Alert.cpp	 rev 42274
10 */
11
12
13/*!
14	\file Alert.h
15	\brief BAlert class definition and support enums.
16*/
17
18
19/*!
20	\enum alert_type
21	Determines which icon (if any) is displayed in the alert dialog.
22	Choose one option. If the constructor doesn't include an
23	alert_type argument than \c B_EMPTY_ALERT is used.
24*/
25
26/*!
27	\var alert_type B_EMPTY_ALERT
28	No icon
29*/
30
31/*!
32	\var alert_type B_INFO_ALERT
33	\image html http://api.haiku-os.org/images/alert_info_32.png
34	Info icon
35*/
36
37/*!
38	\var alert_type B_IDEA_ALERT
39	\image html http://api.haiku-os.org/images/alert_idea_32.png
40	Idea icon
41*/
42
43/*!
44	\var alert_type B_WARNING_ALERT
45	\image html http://api.haiku-os.org/images/alert_warning_32.png
46	Warning icon
47*/
48
49/*!
50	\var alert_type B_STOP_ALERT
51	\image html http://api.haiku-os.org/images/alert_stop_32.png
52	Stop icon
53*/
54
55/*!
56	\enum button_spacing
57	Determines how the buttons on the alert dialog are spaced relative
58	to each other. Choose one option. If the constructor doesn't include a
59	button_spacing argument than \c B_EVEN_SPACING is used.
60*/
61
62/*!
63	\var button_spacing B_EVEN_SPACING
64	If the alert dialog has more than one button than the buttons are
65	spaced evenly across the bottom of the alert dialog.
66*/
67
68/*!
69	\var button_spacing B_OFFSET_SPACING
70	If the alert dialog has more than one button than the leftmost button
71	is offset to the left-hand side of the dialog while the rest of the
72	buttons are grouped on the right. This is useful to separate off a
73	leftmost "Cancel" or "Delete" button.
74*/
75
76
77/*!
78	\class BAlert
79	\ingroup interface
80	\brief The BAlert class defines a modal alert dialog which displays a short
81		message and provides a set of labeled buttons that allow the user to
82		respond.
83
84	The alert can be configured with a set of one to three buttons. These
85	buttons are assigned indexes 0, 1, and 2 from right-to-left respectively
86	and are automatically positioned by the system. The user can either click
87	on one of the buttons or use a shortcut key to select a button.
88
89	The layout of the buttons can be configured by setting the #button_width
90	and #button_spacing properties in the BAlert constructor. The icon displayed
91	in the alert can also be configured by setting the #alert_type property. The
92	right-most button (index 0) is the default button which can be activated
93	by pushing the \key{Enter} key.
94
95	Below is an example of an unsaved changes alert dialog:
96
97	\image html BAlert_example.png
98
99	When the user responds by selecting one of the buttons the alert window is
100	removed from the screen. The index of the selected button is returned to
101	the calling application and the BAlert object is deleted.
102
103	The code used to create and display an alert dialog like the one shown
104	above is shown below:
105
106	\code
107BAlert* alert = new BAlert("Close and save dialog", "Save changes to...",
108	"Cancel", "Don't save", "Save", B_WIDTH_AS_USUAL, B_OFFSET_SPACING,
109	B_WARNING_ALERT);
110alert->SetShortcut(0, B_ESCAPE);
111int32 button_index = alert->Go();
112	\endcode
113
114	The messaged displayed in the dialog window along with the button labels
115	are set by the strings in the contructor. The Cancel button is offset to
116	the left relative to the other buttons by setting the \c B_OFFSET_SPACING
117	flag.  The \c B_WARNING_ALERT flag displays the exclamation mark icon in
118	the dialog.
119
120	Any alert with a Cancel button should map the \key{Escape} key as shown in
121	the example above. You can setup additional shortcut keys for the buttons
122	with the SetShortcut() method.
123
124	The Go() method does the work of loading up and removing the alert
125	window and returns the index of the button that the user selected.
126*/
127
128
129/*!
130	\fn BAlert::BAlert(const char *title, const char *text,
131		const char *button1, const char *button2, const char *button3,
132		button_width width, alert_type type)
133	\brief Creates and initializes a BAlert dialog.
134
135	\param title The title of the window. Since the alert window doesn't have
136		   a title tab, the title is not actually displayed anywhere but is
137		   useful for debugging purposes.
138	\param text The text that is displayed at the top of the window.
139	\param button1 Button 1 label
140	\param button2 Button 2 label
141	\param button3 Button 3 label
142	\param width A constant that describes how the button should be sized.
143		Options are
144		\li \c B_WIDTH_AS_USUAL
145		\li \c B_WIDTH_FROM_WIDEST
146		\li \c B_WIDTH_FROM_LABEL
147
148		See button_width for details.
149	\param type Constant that determines which alert icon is displayed.
150		Options are
151		\li \c B_EMPTY_ALERT
152		\li \c B_INFO_ALERT
153		\li \c B_IDEA_ALERT
154		\li \c B_WARNING_ALERT
155		\li \c B_STOP_ALERT
156
157		See alert_type for details.
158*/
159
160/*!
161	\fn BAlert::BAlert(const char *title, const char *text, const char *button1,
162		const char *button2, const char *button3, button_width width,
163		button_spacing spacing, alert_type type)
164	\brief Creates and initializes a BAlert dialog.
165
166	You can also set the \a spacing with this constructor.
167
168	\param title The title of the window. Since the alert window doesn't have
169		   a title tab, the title is not actually displayed anywhere but is
170		   useful for debugging purposes.
171	\param text The text that is displayed at the top of the window.
172	\param button1 Button 1 label
173	\param button2 Button 2 label
174	\param button3 Button 3 label
175	\param width A constant that describes how the button should be sized.
176		Options are
177		\li \c B_WIDTH_AS_USUAL
178		\li \c B_WIDTH_FROM_WIDEST
179		\li \c B_WIDTH_FROM_LABEL
180
181		See button_width for details.
182	\param spacing Determines how the buttons are spaced. Options are
183		\li \c B_EVEN_SPACING
184		\li \c B_OFFSET_SPACING
185
186		See button_spacing for details.
187	\param type Constant that determines which alert icon is displayed.
188		Options are
189		\li \c B_EMPTY_ALERT
190		\li \c B_INFO_ALERT
191		\li \c B_IDEA_ALERT
192		\li \c B_WARNING_ALERT
193		\li \c B_STOP_ALERT
194
195		See alert_type for details.
196*/
197
198/*!
199	\fn BAlert::BAlert(BMessage* data)
200	\brief Unarchives an alert from a BMessage.
201
202	\param data The archive.
203*/
204
205/*!
206	\fn BAlert::~BAlert()
207	\brief Destructor method.
208
209	Standard Destructor method to delete a BAlert.
210*/
211
212/*!
213	\fn BArchivable* BAlert::Instantiate(BMessage* data)
214	\brief Instantiates a BAlert from a BMessage.
215	\param data The message to instantiate the BAlert.
216	\returns a BArchivable object of the BAlert.
217*/
218
219/*!
220	\fn status_t BAlert::Archive(BMessage* data, bool deep) const
221	\brief Archives the BAlert into \a archive.
222
223	\param data The target archive which the BAlert \a data will go into.
224	\param deep Whether or not to recursively archive the BAlert's children.
225	\retval B_OK The archive operation was successful.
226	\retval B_BAD_VALUE The archive operation failed.
227*/
228
229/*!
230	\fn void BAlert::SetShortcut(int32 index, char key)
231	\brief Sets the shortcut character which is mapped to a button at the
232	specified \a index.
233
234	A button can only have one shortcut except for the rightmost button which,
235	in addition to the shortcut you set, is always mapped to \c B_ENTER.
236
237	If you create a "Cancel" button then you should set its shortcut to
238	\c B_ESCAPE.
239
240	\param index The \a index of the button to set the shortcut to.
241	\param key The shortcut character to set.
242*/
243
244/*!
245	\fn char BAlert::Shortcut(int32 index) const
246	\brief Gets the shortcut character which is mapped to a button at the
247	specified \a index.
248
249	\param index The \a index of the button to get the shortcut of.
250
251	\return The shortcut character mapped to the button at the specified
252		\a index.
253*/
254
255/*!
256	\fn int32 BAlert::Go()
257	\brief Displays the alert window.
258
259	This version of Go() that does not include an invoker is
260	synchronous. Go() returns once the user has clicked a button and
261	the panel has been removed from the screen. The BAlert object is
262	deleted before the method returns.
263
264	If the BAlert is sent a \c B_QUIT_REQUESTED message while the alert
265	window is still on screen then Go() returns -1.
266
267	\returns The index of the button clicked.
268*/
269
270/*!
271	\fn status_t BAlert::Go(BInvoker* invoker)
272	\brief Displays the alert window from a specified \a invoker.
273
274	This version of Go() with an \a invoker is asynchronous. It returns
275	immediately with \c B_OK and the button \a index is set to the field
276	of the BMessage that is sent to the target of the \a invoker.
277
278	Go() deletes the BAlert object after the message is sent.
279
280	If you call Go() with a \c NULL invoker argument than the BMessage
281	is not sent.
282
283	If the BAlert is sent a \c B_QUIT_REQUESTED method while the alert
284	window is still on screen then the message is not sent.
285
286	\returns A status code.
287*/
288
289/*!
290	\fn void BAlert::MessageReceived(BMessage* msg)
291	\brief Initiates an action from a received message.
292
293	\param msg The message
294
295	\see BWindow::MessagedReceived()
296*/
297
298/*!
299	\fn void BAlert::FrameResized(float newWidth, float newHeight)
300	\brief Resizes the alert dialog.
301
302	\param newWidth The new alert dialog width.
303	\param newHeight The new alert dialog height.
304
305	\see BWindow::FrameResized()
306*/
307
308/*!
309	\fn BButton* BAlert::ButtonAt(int32 index) const
310	\brief Returns a pointer to the BButton at the specified \a index.
311
312	The \a index of the buttons begins at \c 0 and counts from left to right.
313	If a BButton does not exist for the specified \a index then \c NULL is
314	returned.
315
316	\param index The \a index of the desired button.
317
318	\return A pointer to the BButton at the specified \a index.
319*/
320
321/*!
322	\fn BTextView* BAlert::TextView() const
323	\brief Returns a TextView containing the text of the Alert.
324*/
325
326/*!
327	\fn BHandler* BAlert::ResolveSpecifier(BMessage* msg, int32 index,
328		BMessage* specifier, int32 form, const char* property)
329	\brief Resolves specifiers for properties.
330	\see BHandler::ResolveSpecifier()
331*/
332
333/*!
334	\fn status_t BAlert::GetSupportedSuites(BMessage* data)
335	\brief Reports the suites of messages and specifiers that derived classes
336		understand.
337
338	\param data The message to report the suite of messages and specifiers.
339
340	\see BWindow::GetSupportedSuites()
341*/
342
343/*!
344	\fn void BAlert::DispatchMessage(BMessage* msg, BHandler* handler)
345	\brief Sends out a message.
346
347	\see BWindow::DispatchMessage()
348*/
349
350/*!
351	\fn void BAlert::Quit()
352	\brief Quits the window closing it.
353
354	\see BWindow::Quit()
355*/
356
357/*!
358	\fn bool BAlert::QuitRequested()
359	\brief Hook method that gets called with the window is closed.
360
361	\returns \c true if the window closes.
362
363	\see BWindow::QuitRequested()
364*/
365
366/*!
367	\fn BPoint BAlert::AlertPosition(float width, float height)
368	\brief Resizes the Alert window to the width and height specified and
369	return the Point of the top-left corner of the Alert window.
370
371	\param width The desired \a width of the alert window.
372	\param height The desired \a height of the alert window.
373
374	\returns The BPoint of the top-left corner of the Alert window.
375*/
376
377/*!
378	\fn status_t BAlert::Perform(perform_code code, void* _data)
379	\brief Performs an action give a perform_code and data
380
381	Currently the only perform code available is \c PERFORM_CODE_SET_LAYOUT.
382
383	\param code The perform code
384	\param _data A pointer to some data to perform on
385
386	\return A status code.
387
388	\see BWindow::Perform().
389*/
390