xref: /haiku/docs/user/interface/Box.dox (revision 6ec25bba48828d6d3e51e768d766aed4d97a08c5)
1*6ec25bbaSAdrien Destugues/*
2*6ec25bbaSAdrien Destugues * Copyright 2010, Haiku inc.
3*6ec25bbaSAdrien Destugues * Distributed under the terms of the MIT Licence.
4*6ec25bbaSAdrien Destugues *
5*6ec25bbaSAdrien Destugues * Documentation by:
6*6ec25bbaSAdrien Destugues *  Clark Gaeble
7*6ec25bbaSAdrien Destugues *  Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
8*6ec25bbaSAdrien Destugues * Corresponds to:
9*6ec25bbaSAdrien Destugues *  /trunk/headers/os/interface/Box.h  rev 39685
10*6ec25bbaSAdrien Destugues *  /trunk/src/kits/interface/Box.cpp  rev 39685
11*6ec25bbaSAdrien Destugues
12*6ec25bbaSAdrien Destugues/*!
13*6ec25bbaSAdrien Destugues\file Box.h
14*6ec25bbaSAdrien Destugues\brief Defines the BBox class
15*6ec25bbaSAdrien Destugues*/
16*6ec25bbaSAdrien Destugues
17*6ec25bbaSAdrien Destugues/*! \class BBox
18*6ec25bbaSAdrien Destugues	\ingroup interface
19*6ec25bbaSAdrien Destugues	\brief Class just drawing a square box with a label in a window.
20*6ec25bbaSAdrien Destugues
21*6ec25bbaSAdrien Destugues	A Box represents a square on the interface with dimensions, an optional
22*6ec25bbaSAdrien Destugues	name, and no interactivity.
23*6ec25bbaSAdrien Destugues
24*6ec25bbaSAdrien Destugues	This would be used to visually group elements together.
25*6ec25bbaSAdrien Destugues*/
26*6ec25bbaSAdrien Destugues
27*6ec25bbaSAdrien 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)
28*6ec25bbaSAdrien Destugues	\brief Constructs a Box from a set of dimensions.
29*6ec25bbaSAdrien Destugues
30*6ec25bbaSAdrien Destugues	This is the only constructor that can be used if the box is to be inserted
31*6ec25bbaSAdrien Destugues	in a window that doesn't use the layout system.
32*6ec25bbaSAdrien Destugues
33*6ec25bbaSAdrien Destugues	\param frame        The bounds of the box.
34*6ec25bbaSAdrien Destugues	\param name         The name of the box.
35*6ec25bbaSAdrien Destugues	\param resizingMode Defines the behavior of the box as the window resizes.
36*6ec25bbaSAdrien Destugues	\param flags        Behavior flags for the box.
37*6ec25bbaSAdrien Destugues	\param border       Sets the initial style of the border.
38*6ec25bbaSAdrien Destugues*/
39*6ec25bbaSAdrien Destugues
40*6ec25bbaSAdrien Destugues
41*6ec25bbaSAdrien 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)
42*6ec25bbaSAdrien Destugues \brief Constructs a named Box, with dimensions defined automatically by the Layout Kit.
43*6ec25bbaSAdrien Destugues
44*6ec25bbaSAdrien Destugues \param name   The name of the box.
45*6ec25bbaSAdrien Destugues \param flags  Behavior flags for the box.
46*6ec25bbaSAdrien Destugues \param border Defines the initial border style.
47*6ec25bbaSAdrien Destugues \param child  Adds an initial child to the box. See: Layout Kit
48*6ec25bbaSAdrien Destugues*/
49*6ec25bbaSAdrien Destugues
50*6ec25bbaSAdrien Destugues
51*6ec25bbaSAdrien Destugues/*! \fn BBox::BBox(border_style border, BView* child)
52*6ec25bbaSAdrien Destugues	\brief Constructs an anonymous Box, with a defined border style and a child.
53*6ec25bbaSAdrien Destugues
54*6ec25bbaSAdrien Destugues	There can only be a single child view in the box. This view can, however,
55*6ec25bbaSAdrien Destugues	act as a nesting container if you need more things to show inside the box.
56*6ec25bbaSAdrien Destugues
57*6ec25bbaSAdrien Destugues	\param border The initial border style of the box.
58*6ec25bbaSAdrien Destugues	\param child  The child of the Box.
59*6ec25bbaSAdrien Destugues*/
60*6ec25bbaSAdrien Destugues
61*6ec25bbaSAdrien Destugues
62*6ec25bbaSAdrien Destugues/*! \fn BBox::BBox(BMessage* archive)
63*6ec25bbaSAdrien Destugues	\brief For archive restoration, allows a box to be constructed from an
64*6ec25bbaSAdrien Destugues		archive message.
65*6ec25bbaSAdrien Destugues
66*6ec25bbaSAdrien Destugues	You don't usually call this directly, if you want to build a BBox from a
67*6ec25bbaSAdrien Destugues	message, prefer calling Instanciate, which can properly handle errors.
68*6ec25bbaSAdrien Destugues
69*6ec25bbaSAdrien Destugues	If the archive is a deep one, the box will also unarchive all of its
70*6ec25bbaSAdrien Destugues	children recursively.
71*6ec25bbaSAdrien Destugues
72*6ec25bbaSAdrien Destugues	\param archive  The archive to restore from.
73*6ec25bbaSAdrien Destugues*/
74*6ec25bbaSAdrien Destugues
75*6ec25bbaSAdrien Destugues
76*6ec25bbaSAdrien Destugues/*! \fn static BArchivable*	BBox::Instantiate(BMessage* archive)
77*6ec25bbaSAdrien Destugues	\brief Creates a new BBox from an archive.
78*6ec25bbaSAdrien Destugues
79*6ec25bbaSAdrien Destugues	If the message is a valid box, an instance of BBox (created from the
80*6ec25bbaSAdrien Destugues	archive) will be returned. Otherwise, this function will return NULL.
81*6ec25bbaSAdrien Destugues*/
82*6ec25bbaSAdrien Destugues
83*6ec25bbaSAdrien Destugues
84*6ec25bbaSAdrien Destugues/*! \fn virtual	status_t BBox::Archive(BMessage* archive, bool deep = true) const;
85*6ec25bbaSAdrien Destugues	\brief Archives the box into archive.
86*6ec25bbaSAdrien Destugues
87*6ec25bbaSAdrien Destugues	\param   archive The target archive which the box data will go into.
88*6ec25bbaSAdrien Destugues	\param   deep    Whether or not to recursively archive the children.
89*6ec25bbaSAdrien Destugues	\returns B_OK if the archive was successful.
90*6ec25bbaSAdrien Destugues*/
91*6ec25bbaSAdrien Destugues
92*6ec25bbaSAdrien Destugues
93*6ec25bbaSAdrien Destugues/*! \fn virtual	void BBox::SetBorder(border_style border)
94*6ec25bbaSAdrien Destugues	\brief Sets the border style.
95*6ec25bbaSAdrien Destugues*/
96*6ec25bbaSAdrien Destugues
97*6ec25bbaSAdrien Destugues
98*6ec25bbaSAdrien Destugues/*! \fn border_style BBox::Border() const
99*6ec25bbaSAdrien Destugues	\brief Gets the border style.
100*6ec25bbaSAdrien Destugues*/
101*6ec25bbaSAdrien Destugues
102*6ec25bbaSAdrien Destugues
103*6ec25bbaSAdrien Destugues/*! \fn float BBox::TopBorderOffset()
104*6ec25bbaSAdrien Destugues	\brief Gets the label's distance from the very top of the Box, in pixels.
105*6ec25bbaSAdrien Destugues*/
106*6ec25bbaSAdrien Destugues
107*6ec25bbaSAdrien Destugues
108*6ec25bbaSAdrien Destugues/*! \fn BRect BBox::InnerFrame()
109*6ec25bbaSAdrien Destugues	\brief Returns the rectangle just inside the border.
110*6ec25bbaSAdrien Destugues*/
111*6ec25bbaSAdrien Destugues
112*6ec25bbaSAdrien Destugues
113*6ec25bbaSAdrien Destugues/*! \fn void BBox::SetLabel(const char* string)
114*6ec25bbaSAdrien Destugues	\brief Sets the label's text.
115*6ec25bbaSAdrien Destugues
116*6ec25bbaSAdrien Destugues	This text is shown as the box title on screen, so the user can identify the
117*6ec25bbaSAdrien Destugues	purpose of it.
118*6ec25bbaSAdrien Destugues*/
119*6ec25bbaSAdrien Destugues
120*6ec25bbaSAdrien Destugues
121*6ec25bbaSAdrien Destugues/*! \fn status_t BBox::SetLabel(BView* viewLabel)
122*6ec25bbaSAdrien Destugues	\brief Sets the label from a pre-existing BView.
123*6ec25bbaSAdrien Destugues
124*6ec25bbaSAdrien Destugues 	You can use any type of BView for this, such as a BPopupMenu.
125*6ec25bbaSAdrien Destugues	This version of SetLabel is much more powerful than
126*6ec25bbaSAdrien Destugues	SetLabel(const char* string). It allows building a box which contents can
127*6ec25bbaSAdrien Destugues	be changed depending on the label widget.
128*6ec25bbaSAdrien Destugues*/
129*6ec25bbaSAdrien Destugues
130*6ec25bbaSAdrien Destugues
131*6ec25bbaSAdrien Destugues/*! \fn const char*	BBox::Label() const
132*6ec25bbaSAdrien Destugues	\brief Gets the label's text.
133*6ec25bbaSAdrien Destugues
134*6ec25bbaSAdrien Destugues	This only works if the label view is a BTextView.
135*6ec25bbaSAdrien Destugues*/
136*6ec25bbaSAdrien Destugues
137*6ec25bbaSAdrien Destugues
138*6ec25bbaSAdrien Destugues/*! \fn BView*	BBox::LabelView() const
139*6ec25bbaSAdrien Destugues	\brief Gets the BView representing the label.
140*6ec25bbaSAdrien Destugues*/
141*6ec25bbaSAdrien Destugues
142*6ec25bbaSAdrien Destugues
143*6ec25bbaSAdrien Destugues/*! \fn virtual	void BBox::Draw(BRect updateRect)
144*6ec25bbaSAdrien Destugues	\brief Draws onto the parent window the part of the box that intersects
145*6ec25bbaSAdrien Destugues		the dirty area.
146*6ec25bbaSAdrien Destugues
147*6ec25bbaSAdrien Destugues	\param updateRect The area that needs to be redrawn. Note the box may draw
148*6ec25bbaSAdrien Destugues		more than asked.
149*6ec25bbaSAdrien Destugues*/
150*6ec25bbaSAdrien Destugues
151*6ec25bbaSAdrien Destugues
152*6ec25bbaSAdrien Destugues/*! \fn virtual	void BBox::AttachedToWindow()
153*6ec25bbaSAdrien Destugues	\brief Hook called when the box is attached to a window.
154*6ec25bbaSAdrien Destugues
155*6ec25bbaSAdrien Destugues	This function sets the box background color to the parent's one.
156*6ec25bbaSAdrien Destugues
157*6ec25bbaSAdrien Destugues	If you are using the layout system, the box is also resized depending
158*6ec25bbaSAdrien Destugues	on the layout of the parent view.
159*6ec25bbaSAdrien Destugues*/
160*6ec25bbaSAdrien Destugues
161*6ec25bbaSAdrien Destugues
162*6ec25bbaSAdrien Destugues/*! \fn virtual void BBox::FrameResized(float width, float height)
163*6ec25bbaSAdrien Destugues	\brief Called when the box needs to change its size.
164*6ec25bbaSAdrien Destugues
165*6ec25bbaSAdrien Destugues	This function may be called either because the window in which the box is
166*6ec25bbaSAdrien Destugues	was resized, or because the window layout was otherwise altered.
167*6ec25bbaSAdrien Destugues
168*6ec25bbaSAdrien Destugues	It recomputes the bounds of the box and makes it redraw itself as needed.
169*6ec25bbaSAdrien Destugues*/
170*6ec25bbaSAdrien Destugues
171*6ec25bbaSAdrien Destugues
172*6ec25bbaSAdrien Destugues/*! \fn 	virtual void BBox::ResizeToPreferred()
173*6ec25bbaSAdrien Destugues	\brief Resizes the box to its preferred dimensions.
174*6ec25bbaSAdrien Destugues
175*6ec25bbaSAdrien Destugues	This only works in the layout system mode.
176*6ec25bbaSAdrien Destugues*/
177*6ec25bbaSAdrien Destugues
178*6ec25bbaSAdrien Destugues
179*6ec25bbaSAdrien Destugues/*!	virtual void BBox::GetPreferredSize(float* _width, float* _height)
180*6ec25bbaSAdrien Destugues	\brief Gets the dimensions the box would prefer to be.
181*6ec25bbaSAdrien Destugues
182*6ec25bbaSAdrien Destugues	The size is computed from the children sizes, unless it was explicitly set
183*6ec25bbaSAdrien Destugues	for the box.
184*6ec25bbaSAdrien Destugues
185*6ec25bbaSAdrien Destugues	\param _width  An output parameter. The width of the preferred size is placed in here.
186*6ec25bbaSAdrien Destugues	\param _height An output parameter. The height of the preferred size is placed in here.
187*6ec25bbaSAdrien Destugues*/
188*6ec25bbaSAdrien Destugues
189*6ec25bbaSAdrien Destugues
190*6ec25bbaSAdrien Destugues/*! \fn virtual	BSize BBox::MinSize()
191*6ec25bbaSAdrien Destugues	\brief Gets the minimum possible size of the Box.
192*6ec25bbaSAdrien Destugues
193*6ec25bbaSAdrien Destugues	This size ensures the label and all the childs are visible.
194*6ec25bbaSAdrien Destugues*/
195*6ec25bbaSAdrien Destugues
196*6ec25bbaSAdrien Destugues
197*6ec25bbaSAdrien Destugues/*!	\fn virtual	BSize BBox::MaxSize()
198*6ec25bbaSAdrien Destugues	\brief Gets the maximum possible size of the Box.
199*6ec25bbaSAdrien Destugues
200*6ec25bbaSAdrien Destugues	The maximum size depends on the children.
201*6ec25bbaSAdrien Destugues*/
202*6ec25bbaSAdrien Destugues
203*6ec25bbaSAdrien Destugues
204*6ec25bbaSAdrien Destugues/*! \fn virtual	BSize BBox::PreferredSize()
205*6ec25bbaSAdrien Destugues	\brief Returns the box's preferred size.
206*6ec25bbaSAdrien Destugues
207*6ec25bbaSAdrien Destugues	This is the same as GetPreferredSize, but using the more convenient BSize
208*6ec25bbaSAdrien Destugues	struct.
209*6ec25bbaSAdrien Destugues*/
210*6ec25bbaSAdrien Destugues
211*6ec25bbaSAdrien Destugues
212*6ec25bbaSAdrien Destugues/*! \fn virtual	void BBox::DoLayout()
213*6ec25bbaSAdrien Destugues	\brief Lays out the box. Moves everything to its appropriate position.
214*6ec25bbaSAdrien Destugues
215*6ec25bbaSAdrien Destugues	This only works if the box uses the layout system, ie., was created with
216*6ec25bbaSAdrien Destugues	one of the BRect-less constructors.
217*6ec25bbaSAdrien Destugues*/
218