xref: /haiku/docs/user/interface/Box.dox (revision 37fedaf8494b34aad811abcc49e79aa32943f880)
1/*
2 * Copyright 2011 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Clark Gaeble
7 *		Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
8 *		John Scipione <jscipione@gmail.com>
9 *
10 * Corresponds to:
11 *		headers/os/interface/Box.h	 rev 42274
12 *		src/kits/interface/Box.cpp	 rev 42274
13
14
15/*!
16	\file Box.h
17	\ingroup interface
18	\ingroup libbe
19	\brief Defines the BBox class
20*/
21
22
23/*!
24	\class BBox
25	\ingroup interface
26	\ingroup libbe
27	\brief A rectangular view with a border and an optional label to group
28		related subviews visually.
29
30	A basic BBox looks like this:
31	\image html B_FANCY_BORDER.png
32
33	A box's label can either be composed of text or it can be a view such
34	as a checkbox or dropdown box. See SetLabel() for more details on setting
35	the box's label.
36*/
37
38
39/*!
40	\fn BBox::BBox(BRect frame, const char *name = NULL,
41		uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
42		uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
43		border_style border = B_FANCY_BORDER)
44	\brief Constructs a named BBox object from a set of dimensions.
45
46	\note This is the only constructor that can be used if the box is to be
47		inserted in a window that doesn't use the layout system.
48
49	\param frame The bounds of the box.
50	\param name The name of the box.
51	\param resizingMode Defines the behavior of the box as the parent view
52		resizes. See BView for details.
53	\param flags Behavior flags for the box. See BView for details.
54	\param border The border_style of the box.
55*/
56
57
58/*!
59	\fn BBox::BBox(const char* name,
60		uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP,
61		border_style border = B_FANCY_BORDER, BView* child = NULL)
62	\brief Constructs a named BBox object with its dimensions defined
63		automatically by the Layout API.
64
65	\param name The name of the box.
66	\param flags Behavior flags for the box. See BView for details.
67	\param border The border_style of the box.
68	\param child Adds an initial child to the Box object. See the Layout
69		API for details.
70*/
71
72
73/*!
74	\fn BBox::BBox(border_style border, BView* child)
75	\brief Constructs an anonymous BBox object with a defined border style
76		and child view.
77
78	There can only be a single child view. This view can, however, act as a
79	nesting container if you need to show more items inside the box.
80*/
81
82
83/*!
84	\fn BBox::BBox(BMessage* archive)
85	\brief Constructs a BBox object from an \a archive message.
86
87	This method is usually not called directly. If you want to build a BBox
88	object from a message you should call Instantiate() which can
89	handle errors properly.
90
91	If the \a archive deep, the BBox object will also unarchive each of its
92	child views recursively.
93
94	\param archive The \a archive message to restore from.
95*/
96
97
98/*!
99	\fn BBox::~BBox()
100	\brief Destructor method.
101
102	Calling the destructor will also free the memory used by the box's label
103	if it has one.
104*/
105
106
107/*!
108	\fn static BArchivable* BBox::Instantiate(BMessage* archive)
109	\brief Creates a new object from an \a archive.
110
111	If the message is a valid object then the instance created from the
112	passed in \a archive will be returned. Otherwise this method will
113	return \c NULL.
114
115	\param archive The \a archive message.
116
117	\returns An instance of the object if \a archive is valid or \c NULL.
118
119	\sa BArchivable::Instantiate()
120*/
121
122
123/*!
124	\fn virtual	status_t BBox::Archive(BMessage* archive,
125		bool deep = true) const;
126	\brief Archives the object into \a archive.
127
128	\param archive The target \a archive that the data will go into.
129	\param deep Whether or not to recursively archive child views.
130
131	\retval B_OK The archive operation was successful.
132	\retval B_BAD_VALUE \c NULL \a archive message.
133	\retval B_ERROR The archive operation failed.
134
135	\sa BArchivable::Archive()
136*/
137
138
139/*!
140	\fn virtual void BBox::SetBorder(border_style border)
141	\brief Sets the #border_style.
142
143	Possible #border_style values include:
144		- \c B_PLAIN_BORDER A single 1-pixel line border.
145		- \c B_FANCY_BORDER The default, beveled look.
146		- \c B_NO_BORDER Used to make a borderless box.
147
148	\param border The #border_style to set.
149*/
150
151
152/*!
153	\fn border_style BBox::Border() const
154	\brief Gets the current #border_style.
155
156	Possible #border_style values include:
157		- \c B_PLAIN_BORDER A single 1-pixel line border.
158		- \c B_FANCY_BORDER The default, beveled look.
159		- \c B_NO_BORDER Used to make a borderless box.
160
161	\returns The #border_style of the box.
162*/
163
164
165/*!
166	\fn float BBox::TopBorderOffset()
167	\brief Gets the distance from the very top of the box to the top border
168		line in pixels.
169
170	\warning This method is not part of the BeOS R5 API and is not yet
171		finalized.
172
173	The distance may vary depending on the text or view used as label and the
174	font settings. The border is drawn center-aligned with the label. This
175	method can be used to line up two boxes visually if one has a label and
176	the other does not.
177
178	\returns The distance from the very top of the box to the top border
179		line in pixels as a \c float.
180*/
181
182
183/*!
184	\fn BRect BBox::InnerFrame()
185	\brief Gets the frame rectangle just inside the border of the box.
186
187	\warning This method is not part of the BeOS R5 API and is not yet
188		finalized.
189
190	\returns A BRect set to the dimensions of the box's inside border.
191*/
192
193
194/*!
195	\fn void BBox::SetLabel(const char* string)
196	\brief Sets the box's label text.
197
198	Below is an example of a box with some simple text label:
199
200	\image html BBox_example.png
201
202	The code to create a box with a text label looks like this:
203	\code
204fIconBox = new BBox("Icon Box");
205fIconBox->SetLabel("Icon");
206	\endcode
207
208	\param string The label text string to set as the box's title.
209*/
210
211
212/*!
213	\fn status_t BBox::SetLabel(BView* viewLabel)
214	\brief Sets the label from a BView.
215
216	This version of SetLabel() provides for building a BBox object with a
217	control used in place of the text label. You can pass in any type of
218	BView derived control for this such as a BPopupMenu or BCheckBox.
219
220	An example of a box with a checkbox view is shown below:
221	\image html BBox_with_checkbox.png
222
223	The code to create such a box looks like this:
224	\code
225fVirtualMemoryEnabledCheckBox = new BCheckBox("Virtual memory check box",
226	"Enable virtual memory", new BMessage(kVirtualMemoryEnabled));
227
228BBox* fVirtualMemoryBox = new BBox("Virtual memory box");
229fVirtualMemoryBox->SetLabel(fVirtualMemoryEnabledCheckBox);
230	\endcode
231
232	\param viewLabel A BView.
233
234	\returns \c B_OK
235*/
236
237
238/*!
239	\fn const char* BBox::Label() const
240	\brief Gets the text of the box's label.
241
242	This only works if the label is set as text. If you set the label to a
243	BView, you have to get the text by other means, likely starting with
244	LabelView.
245
246	\returns The label text of the BBox if the box has a text label or
247		\c NULL otherwise.
248*/
249
250
251/*!
252	\fn BView* BBox::LabelView() const
253	\brief Gets the BView representing the label.
254
255	\returns a pointer to a BView object.
256*/
257
258
259/*!
260	\fn virtual void BBox::Draw(BRect updateRect)
261	\brief Draws the area of the box that intersects \a updateRect.
262
263	This is an hook method called by the Interface Kit, you don't have to
264	call it yourself. If you need to forcefully redraw the view,
265	consider calling Invalidate() instead.
266
267	\param updateRect The rectangular area to be drawn.
268*/
269
270
271/*!
272	\fn virtual void BBox::AttachedToWindow()
273	\brief Hook method that is called when the object is attached to a
274		window.
275
276	This method overrides BView::AttachedToWindow() to set the background
277	color of the box to the background of its parent view.
278
279	If you are using the layout system, the BBox is also resized according to
280	the layout of the parent view.
281
282	\sa BView::AttachedToWindow()
283*/
284
285
286/*!
287	\fn virtual void BBox::FrameResized(float width, float height)
288	\brief Hook method that gets called when the BBox object is resized.
289
290	This method may be called either because the window in which the BBox
291	object was resized, or because the window layout was otherwise altered.
292
293	This method recomputes the layout of the BBox (including label and
294	contents) and makes it redraw as necessary.
295*/
296
297
298/*!
299	\fn virtual void BBox::ResizeToPreferred()
300	\brief Resizes the box to its preferred dimensions.
301
302	\note This only works in the non-layout mode, as it forces the resizing.
303*/
304
305
306/*!
307	\fn virtual void BBox::GetPreferredSize(float* _width, float* _height)
308	\brief Fill out the preferred width and height of the box
309		into the \a _width and \a _height parameters.
310
311	\note Either the \a _width or \a _height parameter may be set to \c NULL
312		if you only want to get the other one.
313
314	The size is computed from the child view sizes, unless it was explicitly
315	set for the BBox (which can be done only if the BBox is configured to
316	use the Layout API).
317
318	\param[out] _width Pointer to a \c float to store the width of the view.
319	\param[out] _height Pointer to a \c float to store the height of the view.
320*/
321
322
323/*!
324	\fn virtual BSize BBox::MinSize()
325	\brief Gets the minimum possible size of the BBox object.
326
327	Drawing the box at this size ensures the label and the child view are
328	visible. Reducing the size even more would mean that a view would not
329	be visible.
330*/
331
332
333/*!
334	\fn virtual BSize BBox::MaxSize()
335	\brief Gets the maximum possible size of the BBox object.
336
337	The maximum size depends on the maximize size of the child views.
338
339	\returns The maximum possible size of the BBox as a BSize.
340*/
341
342
343/*!
344	\fn virtual BSize BBox::PreferredSize()
345	\brief Returns the preferred size of the box.
346
347	This method works the same as GetPreferredSize, but uses the more
348	convenient BSize object.
349
350	\returns The minimum possible size of the BBox as a BSize.
351*/
352
353
354/*!
355	\fn virtual void BBox::DoLayout()
356	\brief Lays out the box moving everything into its appropriate position.
357
358	This only works if the BBox object was constructed using the Layout API,
359	i.e. it was created with one of the BRect-less constructors.
360
361	Once the size of the box is known from laying out its parent views,
362	this method is called so the box can adjust the position and size of the
363	label, eventually truncating the label text if there is not enough space.
364	The exact border positions are also computed, then the child view is also
365	laid out if its size constraints change.
366*/
367