xref: /haiku/docs/user/interface/Box.dox (revision 01c2a7f38f935041dc7f0afc15c108ee55fd870d)
16ec25bbaSAdrien Destugues/*
26ec25bbaSAdrien Destugues * Copyright 2010, Haiku inc.
36ec25bbaSAdrien Destugues * Distributed under the terms of the MIT Licence.
46ec25bbaSAdrien Destugues *
56ec25bbaSAdrien Destugues * Documentation by:
66ec25bbaSAdrien Destugues *  Clark Gaeble
76ec25bbaSAdrien Destugues *  Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
86ec25bbaSAdrien Destugues * Corresponds to:
96ec25bbaSAdrien Destugues *  /trunk/headers/os/interface/Box.h  rev 39685
106ec25bbaSAdrien Destugues *  /trunk/src/kits/interface/Box.cpp  rev 39685
116ec25bbaSAdrien Destugues
126ec25bbaSAdrien Destugues/*!
136ec25bbaSAdrien Destugues\file Box.h
146ec25bbaSAdrien Destugues\brief Defines the BBox class
156ec25bbaSAdrien Destugues*/
166ec25bbaSAdrien Destugues
176ec25bbaSAdrien Destugues/*! \class BBox
186ec25bbaSAdrien Destugues	\ingroup interface
196ec25bbaSAdrien Destugues	\brief Class just drawing a square box with a label in a window.
206ec25bbaSAdrien Destugues
216ec25bbaSAdrien Destugues	A Box represents a square on the interface with dimensions, an optional
226ec25bbaSAdrien Destugues	name, and no interactivity.
236ec25bbaSAdrien Destugues
246ec25bbaSAdrien Destugues	This would be used to visually group elements together.
256ec25bbaSAdrien Destugues*/
266ec25bbaSAdrien Destugues
276ec25bbaSAdrien Destugues/*! \fn BBox::BBox(BRect frame, const char *name = NULL, uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, border_style border = B_FANCY_BORDER)
286ec25bbaSAdrien Destugues	\brief Constructs a Box from a set of dimensions.
296ec25bbaSAdrien Destugues
306ec25bbaSAdrien Destugues	This is the only constructor that can be used if the box is to be inserted
316ec25bbaSAdrien Destugues	in a window that doesn't use the layout system.
326ec25bbaSAdrien Destugues
336ec25bbaSAdrien Destugues	\param frame        The bounds of the box.
346ec25bbaSAdrien Destugues	\param name         The name of the box.
35*01c2a7f3SAdrien Destugues	\param resizingMode Defines the behavior of the box as the parent view
36*01c2a7f3SAdrien Destugues		resizes.
37*01c2a7f3SAdrien Destugues	\param flags        Behavior flags for the box. See BView page for more
38*01c2a7f3SAdrien Destugues		info.
39*01c2a7f3SAdrien Destugues	\param border       Sets the initial style of the border. See SetBorder for
40*01c2a7f3SAdrien Destugues		more details.
416ec25bbaSAdrien Destugues*/
426ec25bbaSAdrien Destugues
436ec25bbaSAdrien Destugues
446ec25bbaSAdrien Destugues/*! \fn BBox::BBox(const char* name, uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, border_style border = B_FANCY_BORDER, BView* child = NULL)
45*01c2a7f3SAdrien Destugues	\brief Constructs a named Box, with dimensions defined automatically by the
46*01c2a7f3SAdrien Destugues		Layout Kit.
476ec25bbaSAdrien Destugues
486ec25bbaSAdrien Destugues	\param name   The name of the box.
496ec25bbaSAdrien Destugues	\param flags  Behavior flags for the box.
506ec25bbaSAdrien Destugues	\param border Defines the initial border style.
516ec25bbaSAdrien Destugues	\param child  Adds an initial child to the box. See: Layout Kit
526ec25bbaSAdrien Destugues*/
536ec25bbaSAdrien Destugues
546ec25bbaSAdrien Destugues
556ec25bbaSAdrien Destugues/*! \fn BBox::BBox(border_style border, BView* child)
566ec25bbaSAdrien Destugues	\brief Constructs an anonymous Box, with a defined border style and a child.
576ec25bbaSAdrien Destugues
586ec25bbaSAdrien Destugues	There can only be a single child view in the box. This view can, however,
596ec25bbaSAdrien Destugues	act as a nesting container if you need more things to show inside the box.
606ec25bbaSAdrien Destugues
616ec25bbaSAdrien Destugues	\param border The initial border style of the box.
626ec25bbaSAdrien Destugues	\param child  The child of the Box.
636ec25bbaSAdrien Destugues*/
646ec25bbaSAdrien Destugues
656ec25bbaSAdrien Destugues
666ec25bbaSAdrien Destugues/*! \fn BBox::BBox(BMessage* archive)
676ec25bbaSAdrien Destugues	\brief For archive restoration, allows a box to be constructed from an
686ec25bbaSAdrien Destugues		archive message.
696ec25bbaSAdrien Destugues
706ec25bbaSAdrien Destugues	You don't usually call this directly, if you want to build a BBox from a
71*01c2a7f3SAdrien Destugues	message, prefer calling Instantiate, which can properly handle errors.
726ec25bbaSAdrien Destugues
736ec25bbaSAdrien Destugues	If the archive is a deep one, the box will also unarchive all of its
746ec25bbaSAdrien Destugues	children recursively.
756ec25bbaSAdrien Destugues
766ec25bbaSAdrien Destugues	\param archive  The archive to restore from.
776ec25bbaSAdrien Destugues*/
786ec25bbaSAdrien Destugues
796ec25bbaSAdrien Destugues
806ec25bbaSAdrien Destugues/*! \fn static BArchivable*	BBox::Instantiate(BMessage* archive)
816ec25bbaSAdrien Destugues	\brief Creates a new BBox from an archive.
826ec25bbaSAdrien Destugues
836ec25bbaSAdrien Destugues	If the message is a valid box, an instance of BBox (created from the
846ec25bbaSAdrien Destugues	archive) will be returned. Otherwise, this function will return NULL.
856ec25bbaSAdrien Destugues*/
866ec25bbaSAdrien Destugues
876ec25bbaSAdrien Destugues
886ec25bbaSAdrien Destugues/*! \fn virtual	status_t BBox::Archive(BMessage* archive, bool deep = true) const;
896ec25bbaSAdrien Destugues	\brief Archives the box into archive.
906ec25bbaSAdrien Destugues
916ec25bbaSAdrien Destugues	\param   archive The target archive which the box data will go into.
926ec25bbaSAdrien Destugues	\param   deep    Whether or not to recursively archive the children.
936ec25bbaSAdrien Destugues	\returns B_OK if the archive was successful.
946ec25bbaSAdrien Destugues*/
956ec25bbaSAdrien Destugues
966ec25bbaSAdrien Destugues
976ec25bbaSAdrien Destugues/*! \fn virtual	void BBox::SetBorder(border_style border)
986ec25bbaSAdrien Destugues	\brief Sets the border style.
99*01c2a7f3SAdrien Destugues
100*01c2a7f3SAdrien Destugues	Possible values are B_PLAIN_BORDER (a single 1-pixel line border),
101*01c2a7f3SAdrien Destugues	B_FANCY_BORDER (the default, slightly beveled look), and B_NO_BORDER, which
102*01c2a7f3SAdrien Destugues	is used to make an invisible box.
1036ec25bbaSAdrien Destugues*/
1046ec25bbaSAdrien Destugues
1056ec25bbaSAdrien Destugues
1066ec25bbaSAdrien Destugues/*! \fn border_style BBox::Border() const
1076ec25bbaSAdrien Destugues	\brief Gets the border style.
1086ec25bbaSAdrien Destugues*/
1096ec25bbaSAdrien Destugues
1106ec25bbaSAdrien Destugues
1116ec25bbaSAdrien Destugues/*! \fn float BBox::TopBorderOffset()
112*01c2a7f3SAdrien Destugues	\brief Gets the distance from the very top of the Box to the top border
113*01c2a7f3SAdrien Destugues		line, in pixels.
114*01c2a7f3SAdrien Destugues
115*01c2a7f3SAdrien Destugues	The distance may vary depending on the text or view used as label, and the
116*01c2a7f3SAdrien Destugues	font settings. The border is drawn center aligned with the label.
117*01c2a7f3SAdrien Destugues
118*01c2a7f3SAdrien Destugues	You can use this value to line up two boxes visually, if one has a label and
119*01c2a7f3SAdrien Destugues	the other has not.
1206ec25bbaSAdrien Destugues*/
1216ec25bbaSAdrien Destugues
1226ec25bbaSAdrien Destugues
1236ec25bbaSAdrien Destugues/*! \fn BRect BBox::InnerFrame()
1246ec25bbaSAdrien Destugues	\brief Returns the rectangle just inside the border.
1256ec25bbaSAdrien Destugues*/
1266ec25bbaSAdrien Destugues
1276ec25bbaSAdrien Destugues
1286ec25bbaSAdrien Destugues/*! \fn void BBox::SetLabel(const char* string)
1296ec25bbaSAdrien Destugues	\brief Sets the label's text.
1306ec25bbaSAdrien Destugues
1316ec25bbaSAdrien Destugues	This text is shown as the box title on screen, so the user can identify the
1326ec25bbaSAdrien Destugues	purpose of it.
1336ec25bbaSAdrien Destugues*/
1346ec25bbaSAdrien Destugues
1356ec25bbaSAdrien Destugues
1366ec25bbaSAdrien Destugues/*! \fn status_t BBox::SetLabel(BView* viewLabel)
1376ec25bbaSAdrien Destugues	\brief Sets the label from a pre-existing BView.
1386ec25bbaSAdrien Destugues
1396ec25bbaSAdrien Destugues	You can use any type of BView for this, such as a BPopupMenu.
1406ec25bbaSAdrien Destugues	This version of SetLabel is much more powerful than
1416ec25bbaSAdrien Destugues	SetLabel(const char* string). It allows building a box which contents can
1426ec25bbaSAdrien Destugues	be changed depending on the label widget.
1436ec25bbaSAdrien Destugues*/
1446ec25bbaSAdrien Destugues
1456ec25bbaSAdrien Destugues
1466ec25bbaSAdrien Destugues/*! \fn const char*	BBox::Label() const
1476ec25bbaSAdrien Destugues	\brief Gets the label's text.
1486ec25bbaSAdrien Destugues
149*01c2a7f3SAdrien Destugues	This only works if the label was set as text. If you set another view as the
150*01c2a7f3SAdrien Destugues	label, you have to get its text by other means, likely starting with
151*01c2a7f3SAdrien Destugues	LabelView.
1526ec25bbaSAdrien Destugues*/
1536ec25bbaSAdrien Destugues
1546ec25bbaSAdrien Destugues
1556ec25bbaSAdrien Destugues/*! \fn BView*	BBox::LabelView() const
1566ec25bbaSAdrien Destugues	\brief Gets the BView representing the label.
1576ec25bbaSAdrien Destugues*/
1586ec25bbaSAdrien Destugues
1596ec25bbaSAdrien Destugues
1606ec25bbaSAdrien Destugues/*! \fn virtual	void BBox::Draw(BRect updateRect)
1616ec25bbaSAdrien Destugues	\brief Draws onto the parent window the part of the box that intersects
1626ec25bbaSAdrien Destugues		the dirty area.
1636ec25bbaSAdrien Destugues
164*01c2a7f3SAdrien Destugues	This is an hook function called by the interface kit. You don't have to call
165*01c2a7f3SAdrien Destugues	it yourself. If you need to force redrawing of (part of) the box, consider
166*01c2a7f3SAdrien Destugues	using Invalidate instead.
167*01c2a7f3SAdrien Destugues
1686ec25bbaSAdrien Destugues	\param updateRect The area that needs to be redrawn. Note the box may draw
169*01c2a7f3SAdrien Destugues		more around the rectangle.
1706ec25bbaSAdrien Destugues*/
1716ec25bbaSAdrien Destugues
1726ec25bbaSAdrien Destugues
1736ec25bbaSAdrien Destugues/*! \fn virtual	void BBox::AttachedToWindow()
1746ec25bbaSAdrien Destugues	\brief Hook called when the box is attached to a window.
1756ec25bbaSAdrien Destugues
1766ec25bbaSAdrien Destugues	This function sets the box background color to the parent's one.
1776ec25bbaSAdrien Destugues
1786ec25bbaSAdrien Destugues	If you are using the layout system, the box is also resized depending
1796ec25bbaSAdrien Destugues	on the layout of the parent view.
1806ec25bbaSAdrien Destugues*/
1816ec25bbaSAdrien Destugues
1826ec25bbaSAdrien Destugues
1836ec25bbaSAdrien Destugues/*! \fn virtual void BBox::FrameResized(float width, float height)
1846ec25bbaSAdrien Destugues	\brief Called when the box needs to change its size.
1856ec25bbaSAdrien Destugues
1866ec25bbaSAdrien Destugues	This function may be called either because the window in which the box is
1876ec25bbaSAdrien Destugues	was resized, or because the window layout was otherwise altered.
1886ec25bbaSAdrien Destugues
189*01c2a7f3SAdrien Destugues	It recomputes the layouting of the box (including label and contents) and
190*01c2a7f3SAdrien Destugues	makes it redraw itself as needed.
1916ec25bbaSAdrien Destugues*/
1926ec25bbaSAdrien Destugues
1936ec25bbaSAdrien Destugues
1946ec25bbaSAdrien Destugues/*! \fn 	virtual void BBox::ResizeToPreferred()
1956ec25bbaSAdrien Destugues	\brief Resizes the box to its preferred dimensions.
1966ec25bbaSAdrien Destugues
197*01c2a7f3SAdrien Destugues	This only works in the non-layout mode, as it forces the resizing.
1986ec25bbaSAdrien Destugues*/
1996ec25bbaSAdrien Destugues
2006ec25bbaSAdrien Destugues
2016ec25bbaSAdrien Destugues/*!	virtual void BBox::GetPreferredSize(float* _width, float* _height)
2026ec25bbaSAdrien Destugues	\brief Gets the dimensions the box would prefer to be.
2036ec25bbaSAdrien Destugues
2046ec25bbaSAdrien Destugues	The size is computed from the children sizes, unless it was explicitly set
205*01c2a7f3SAdrien Destugues	for the box (which canbe done only in layouted mode).
2066ec25bbaSAdrien Destugues
207*01c2a7f3SAdrien Destugues	\note Either one of the parameters may be set to NULL if you only want to
208*01c2a7f3SAdrien Destugues		get the other one.
209*01c2a7f3SAdrien Destugues
210*01c2a7f3SAdrien Destugues	\param _width  An output parameter. The width of the preferred size is
211*01c2a7f3SAdrien Destugues		placed in here.
212*01c2a7f3SAdrien Destugues	\param _height An output parameter. The height of the preferred size is
213*01c2a7f3SAdrien Destugues		placed in here.
2146ec25bbaSAdrien Destugues*/
2156ec25bbaSAdrien Destugues
2166ec25bbaSAdrien Destugues
2176ec25bbaSAdrien Destugues/*! \fn virtual	BSize BBox::MinSize()
2186ec25bbaSAdrien Destugues	\brief Gets the minimum possible size of the Box.
2196ec25bbaSAdrien Destugues
220*01c2a7f3SAdrien Destugues	Drawing the box at this size ensures the label and the child view are
221*01c2a7f3SAdrien Destugues	visible. Going smaller means something may get invisible on screen for lack
222*01c2a7f3SAdrien Destugues	of space.
2236ec25bbaSAdrien Destugues*/
2246ec25bbaSAdrien Destugues
2256ec25bbaSAdrien Destugues
2266ec25bbaSAdrien Destugues/*!	\fn virtual	BSize BBox::MaxSize()
2276ec25bbaSAdrien Destugues	\brief Gets the maximum possible size of the Box.
2286ec25bbaSAdrien Destugues
229*01c2a7f3SAdrien Destugues	The maximum size depends on the child view's one.
2306ec25bbaSAdrien Destugues*/
2316ec25bbaSAdrien Destugues
2326ec25bbaSAdrien Destugues
2336ec25bbaSAdrien Destugues/*! \fn virtual	BSize BBox::PreferredSize()
2346ec25bbaSAdrien Destugues	\brief Returns the box's preferred size.
2356ec25bbaSAdrien Destugues
2366ec25bbaSAdrien Destugues	This is the same as GetPreferredSize, but using the more convenient BSize
2376ec25bbaSAdrien Destugues	struct.
2386ec25bbaSAdrien Destugues*/
2396ec25bbaSAdrien Destugues
2406ec25bbaSAdrien Destugues
2416ec25bbaSAdrien Destugues/*! \fn virtual	void BBox::DoLayout()
2426ec25bbaSAdrien Destugues	\brief Lays out the box. Moves everything to its appropriate position.
2436ec25bbaSAdrien Destugues
2446ec25bbaSAdrien Destugues	This only works if the box uses the layout system, ie., was created with
2456ec25bbaSAdrien Destugues	one of the BRect-less constructors.
246*01c2a7f3SAdrien Destugues
247*01c2a7f3SAdrien Destugues	Once the size of the box is known, from layouting of the parent views, this
248*01c2a7f3SAdrien Destugues	function is called so the box can adjust the position and size of the label,
249*01c2a7f3SAdrien Destugues	eventually truncating the text if there is not enough space. The exact
250*01c2a7f3SAdrien Destugues	border positions are also computed, then the child view is also layouted if
251*01c2a7f3SAdrien Destugues	its size constraints changed.
2526ec25bbaSAdrien Destugues*/
253