xref: /haiku/docs/user/interface/CheckBox.dox (revision 44b874666af6b25da6311e5a1c506ee3761f4268)
16ac7032dSJohn Scipione/*
2819863d8SJohn Scipione * Copyright 2011-2014 Haiku, Inc. All rights reserved.
3820dca4dSJohn Scipione * Distributed under the terms of the MIT License.
46ac7032dSJohn Scipione *
5820dca4dSJohn Scipione * Authors:
66ac7032dSJohn Scipione *		Stephan Aßmus, superstippi@gmx.de
76ac7032dSJohn Scipione *		Marc Flerackers, mflerackers@androme.be
86ac7032dSJohn Scipione *		John Scipione, jscipione@gmail.com
9820dca4dSJohn Scipione *
106ac7032dSJohn Scipione * Corresponds to:
11274571d8SJohn Scipione *		headers/os/interface/CheckBox.h	 hrev47274
12274571d8SJohn Scipione *		src/kits/interface/CheckBox.cpp	 hrev47274
136ac7032dSJohn Scipione */
146ac7032dSJohn Scipione
15820dca4dSJohn Scipione
166ac7032dSJohn Scipione/*!
176ac7032dSJohn Scipione	\file CheckBox.h
18820dca4dSJohn Scipione	\ingroup interface
19820dca4dSJohn Scipione	\ingroup libbe
206ac7032dSJohn Scipione	\brief Defines the BCheckBox class
216ac7032dSJohn Scipione*/
226ac7032dSJohn Scipione
236ac7032dSJohn Scipione
246ac7032dSJohn Scipione/*!
256ac7032dSJohn Scipione	\class BCheckBox
266ac7032dSJohn Scipione	\ingroup interface
276ac7032dSJohn Scipione	\ingroup libbe
28274571d8SJohn Scipione	\brief A user interface element used to make a binary decision.
296ac7032dSJohn Scipione
30274571d8SJohn Scipione	A BCheckBox is used to draw a check box UI control. This simple control
316ac7032dSJohn Scipione	has 2 states, \c B_CONTROL_OFF when the check box is unchecked and
326ac7032dSJohn Scipione	\c B_CONTROL_ON when the check box is checked. A check box can also have a
336ac7032dSJohn Scipione	descriptive label drawn to the right of the check box.
346ac7032dSJohn Scipione
356ac7032dSJohn Scipione	When the check box is checked it has an X drawn inside of it. The check box
366ac7032dSJohn Scipione	can be checked by a mouse click or by pushing \key{Space} on the
376ac7032dSJohn Scipione	keyboard when the check box has focus. A check box object with focus
386ac7032dSJohn Scipione	is surrounded by a blue border. A check box can also be set
396ac7032dSJohn Scipione	programmatically by calling the SetValue() method.
406ac7032dSJohn Scipione
416ac7032dSJohn Scipione	A few check box examples can be seen below in unchecked state, checked
426ac7032dSJohn Scipione	state, and another unchecked check box with focus on it.
436ac7032dSJohn Scipione
446ac7032dSJohn Scipione	\image html BCheckBox_example.png
4547852bffSJohn Scipione
4647852bffSJohn Scipione	\since BeOS R3
476ac7032dSJohn Scipione*/
486ac7032dSJohn Scipione
496ac7032dSJohn Scipione
506ac7032dSJohn Scipione/*!
516ac7032dSJohn Scipione	\fn BCheckBox::BCheckBox(BRect frame, const char* name, const char* label,
52274571d8SJohn Scipione		BMessage* message, uint32 resizingMode, uint32 flags)
536ac7032dSJohn Scipione	\brief Construct a check box in the \a frame with a \a name, \a label,
546ac7032dSJohn Scipione		model \a message, \a resizingMode, and creation \a flags.
556ac7032dSJohn Scipione
56*44b87466SJohn Scipione	\note This constructor will resize the control to its minimum height if needed
57274571d8SJohn Scipione	      for compatibility with BeOS R5.
58274571d8SJohn Scipione
59274571d8SJohn Scipione	The initial value of the check box is 0 (\c B_CONTROL_OFF).
606ac7032dSJohn Scipione	The \a label and the \a message parameters can be set to \c NULL.
616ac7032dSJohn Scipione
62274571d8SJohn Scipione	\param frame The \a frame to draw the check box in.
63274571d8SJohn Scipione	\param name The \a name of the check box.
64274571d8SJohn Scipione	\param label The \a label displayed along with the check box control.
65274571d8SJohn Scipione	\param message The \a message to send when the check box is activated.
666ac7032dSJohn Scipione	\param resizingMode Defines the behavior of the check box as the parent
67274571d8SJohn Scipione		view resizes. See BView for details.
68274571d8SJohn Scipione	\param flags Behavior \a flags for the check box. See BView for details.
6947852bffSJohn Scipione
7047852bffSJohn Scipione	\since BeOS R3
716ac7032dSJohn Scipione*/
726ac7032dSJohn Scipione
736ac7032dSJohn Scipione
746ac7032dSJohn Scipione/*!
756ac7032dSJohn Scipione	\fn BCheckBox::BCheckBox(const char* name, const char* label,
766ac7032dSJohn Scipione		BMessage* message, uint32 flags)
776ac7032dSJohn Scipione	\brief Construct a check box with a \a name, \a label, model \a message,
786ac7032dSJohn Scipione		and creation \a flags suitable for use with the Layout API.
796ac7032dSJohn Scipione
80274571d8SJohn Scipione	The initial value of the check box is 0 (\c B_CONTROL_OFF).
816ac7032dSJohn Scipione	The \a label and the \a message parameters can be set to \c NULL.
826ac7032dSJohn Scipione
83274571d8SJohn Scipione	\param name The \a name of the check box.
84274571d8SJohn Scipione	\param label The \a label displayed along with the check box control.
85274571d8SJohn Scipione	\param message The \a message to send when the check box is activated.
86274571d8SJohn Scipione	       See BView for details.
87274571d8SJohn Scipione	\param flags Behavior \a flags for the check box. See BView for details.
8847852bffSJohn Scipione
8947852bffSJohn Scipione	\since Haiku R1
906ac7032dSJohn Scipione*/
916ac7032dSJohn Scipione
926ac7032dSJohn Scipione
936ac7032dSJohn Scipione/*!
946ac7032dSJohn Scipione	\fn BCheckBox::BCheckBox(const char* label, BMessage* message)
956ac7032dSJohn Scipione	\brief Constructs a BCheckBox object with just a \a label and model
966ac7032dSJohn Scipione		\a message.
976ac7032dSJohn Scipione
986ac7032dSJohn Scipione	The initial value of the check box is set to 0 (\c B_CONTROL_OFF).
996ac7032dSJohn Scipione	The \a label and the \a message parameters can be set to \c NULL.
1006ac7032dSJohn Scipione
101274571d8SJohn Scipione	\param label The \a label displayed along with the check box.
102274571d8SJohn Scipione	\param message The \a message to send when the check box is activated.
10347852bffSJohn Scipione
10447852bffSJohn Scipione	\since Haiku R1
1056ac7032dSJohn Scipione*/
1066ac7032dSJohn Scipione
1076ac7032dSJohn Scipione
1086ac7032dSJohn Scipione/*!
1096ac7032dSJohn Scipione	\fn BCheckBox::BCheckBox(BMessage* archive)
1106ac7032dSJohn Scipione	\brief Constructs a BCheckBox object from an \a archive message.
1116ac7032dSJohn Scipione
112274571d8SJohn Scipione	This method is usually not called directly, if you want to build a
113274571d8SJohn Scipione	check box from an archived message you should call Instantiate() instead
114274571d8SJohn Scipione	because it can handle errors properly.
1156ac7032dSJohn Scipione
116274571d8SJohn Scipione	\param archive The message to construct the BCheckBox object from.
11747852bffSJohn Scipione
11847852bffSJohn Scipione	\since BeOS R3
1196ac7032dSJohn Scipione*/
1206ac7032dSJohn Scipione
1216ac7032dSJohn Scipione
1226ac7032dSJohn Scipione/*!
1236ac7032dSJohn Scipione	\fn BCheckBox::~BCheckBox()
124274571d8SJohn Scipione	\brief Destructor, does nothing.
12547852bffSJohn Scipione
12647852bffSJohn Scipione	\since BeOS R3
127274571d8SJohn Scipione*/
128274571d8SJohn Scipione
129274571d8SJohn Scipione
130274571d8SJohn Scipione/*!
131274571d8SJohn Scipione	\name Archiving
132274571d8SJohn Scipione*/
133274571d8SJohn Scipione
134274571d8SJohn Scipione
135274571d8SJohn Scipione//! @{
136274571d8SJohn Scipione
137274571d8SJohn Scipione
138274571d8SJohn Scipione/*!
139274571d8SJohn Scipione	\fn BArchivable* BCheckBox::Instantiate(BMessage* archive)
140274571d8SJohn Scipione	\brief Creates a new BCheckBox object from the \a archive message.
141274571d8SJohn Scipione
14247852bffSJohn Scipione	\param archive The \a archive message to restore from.
14347852bffSJohn Scipione
144274571d8SJohn Scipione	\return A newly created check box or \c NULL if the message doesn't
145274571d8SJohn Scipione	        contain an archived BCheckBox.
14647852bffSJohn Scipione
14747852bffSJohn Scipione	\since BeOS R3
148274571d8SJohn Scipione*/
149274571d8SJohn Scipione
150274571d8SJohn Scipione
151274571d8SJohn Scipione/*!
152274571d8SJohn Scipione	\fn status_t BCheckBox::Archive(BMessage* data, bool deep) const
153274571d8SJohn Scipione	\brief Archives the object into the \a data message.
154274571d8SJohn Scipione
15547852bffSJohn Scipione	\copydetails BControl::Archive()
156274571d8SJohn Scipione*/
157274571d8SJohn Scipione
158274571d8SJohn Scipione
159274571d8SJohn Scipione//! @}
160274571d8SJohn Scipione
161274571d8SJohn Scipione
162274571d8SJohn Scipione/*!
163274571d8SJohn Scipione	\name Hook Methods
164274571d8SJohn Scipione*/
165274571d8SJohn Scipione
166274571d8SJohn Scipione
167274571d8SJohn Scipione//! @{
168274571d8SJohn Scipione
169274571d8SJohn Scipione
170274571d8SJohn Scipione/*!
171274571d8SJohn Scipione	\fn void BCheckBox::AttachedToWindow()
172274571d8SJohn Scipione	\brief Hook method called when the control is attached to a window.
173274571d8SJohn Scipione
17447852bffSJohn Scipione	\copydetails BControl::AttachedToWindow()
175274571d8SJohn Scipione*/
176274571d8SJohn Scipione
177274571d8SJohn Scipione
178274571d8SJohn Scipione/*!
179274571d8SJohn Scipione	\fn void BCheckBox::DetachedFromWindow()
180274571d8SJohn Scipione	\brief Hook method called when the control is detached from a window.
181274571d8SJohn Scipione
18247852bffSJohn Scipione	\copydetails BControl::DetachedFromWindow()
183274571d8SJohn Scipione*/
184274571d8SJohn Scipione
185274571d8SJohn Scipione
186274571d8SJohn Scipione/*!
187274571d8SJohn Scipione	\fn void BCheckBox::AllAttached()
188274571d8SJohn Scipione	\brief Similar to AttachedToWindow() but this method is triggered after
189274571d8SJohn Scipione	       all child views have already been attached to a window.
190274571d8SJohn Scipione
19147852bffSJohn Scipione	\copydetails BView::AllAttached()
192274571d8SJohn Scipione*/
193274571d8SJohn Scipione
194274571d8SJohn Scipione
195274571d8SJohn Scipione/*!
196274571d8SJohn Scipione	\fn void BCheckBox::AllDetached()
197274571d8SJohn Scipione	\brief Similar to AttachedToWindow() but this method is triggered after
198274571d8SJohn Scipione	       all child views have already been detached from a window.
199274571d8SJohn Scipione
20047852bffSJohn Scipione	\copydetails BView::AllDetached()
2016ac7032dSJohn Scipione*/
2026ac7032dSJohn Scipione
2036ac7032dSJohn Scipione
2046ac7032dSJohn Scipione/*!
2056ac7032dSJohn Scipione	\fn void BCheckBox::Draw(BRect updateRect)
2066ac7032dSJohn Scipione	\brief Draws the area of the check box that intersects \a updateRect.
2076ac7032dSJohn Scipione
2086ac7032dSJohn Scipione	\note This is an hook method called by the Interface Kit, you don't
209274571d8SJohn Scipione	      have to call it yourself. If you need to forcefully redraw a
210274571d8SJohn Scipione	      check box consider calling Invalidate() instead.
2116ac7032dSJohn Scipione
2126ac7032dSJohn Scipione	\param updateRect The rectangular area to be drawn.
2136ac7032dSJohn Scipione
2146ac7032dSJohn Scipione	\sa BView::Draw()
21547852bffSJohn Scipione
21647852bffSJohn Scipione	\since BeOS R3
2176ac7032dSJohn Scipione*/
2186ac7032dSJohn Scipione
2196ac7032dSJohn Scipione
2206ac7032dSJohn Scipione/*!
221274571d8SJohn Scipione	\fn void BCheckBox::FrameMoved(BPoint newPosition)
222274571d8SJohn Scipione	\brief Hook method called when the check box is moved.
223274571d8SJohn Scipione
22447852bffSJohn Scipione	\copydetails BView::FrameMoved()
225274571d8SJohn Scipione*/
226274571d8SJohn Scipione
227274571d8SJohn Scipione
228274571d8SJohn Scipione/*!
22947852bffSJohn Scipione	\fn void BCheckBox::FrameResized(float newWidth, float newHeight)
230274571d8SJohn Scipione	\brief Hook method called when the check box is resized.
231274571d8SJohn Scipione
23247852bffSJohn Scipione	\copydetails BView::FrameResized()
233274571d8SJohn Scipione*/
234274571d8SJohn Scipione
235274571d8SJohn Scipione
236274571d8SJohn Scipione/*!
2376ac7032dSJohn Scipione	\fn void BCheckBox::GetPreferredSize(float* _width, float* _height)
2386ac7032dSJohn Scipione	\brief Fill out the preferred width and height of the check box
2396ac7032dSJohn Scipione	       into the \a _width and \a _height parameters.
2406ac7032dSJohn Scipione
24147852bffSJohn Scipione	\copydetails BView::GetPreferredSize()
2426ac7032dSJohn Scipione*/
2436ac7032dSJohn Scipione
2446ac7032dSJohn Scipione
2456ac7032dSJohn Scipione/*!
246274571d8SJohn Scipione	\fn status_t BCheckBox::GetSupportedSuites(BMessage* message)
247274571d8SJohn Scipione	\brief Report the suites of messages this control understands.
248274571d8SJohn Scipione
249274571d8SJohn Scipione	\param message Allows you to add the names of the suites the check box
250274571d8SJohn Scipione	       implements to the suites array.
251274571d8SJohn Scipione
252274571d8SJohn Scipione	\return \c B_OK if all went well or an error code otherwise.
253274571d8SJohn Scipione
254274571d8SJohn Scipione	\sa BControl::GetSupportedSuites();
255274571d8SJohn Scipione
25647852bffSJohn Scipione	\since BeOS R3
25747852bffSJohn Scipione*/
258274571d8SJohn Scipione
259274571d8SJohn Scipione
260274571d8SJohn Scipione/*!
261274571d8SJohn Scipione	\fn void BCheckBox::KeyDown(const char* bytes, int32 numBytes)
262274571d8SJohn Scipione	\brief Hook method called when a keyboard key is pressed.
263274571d8SJohn Scipione
264274571d8SJohn Scipione	Inverts the value on \a B_ENTER or \a B_SPACE.
265274571d8SJohn Scipione
26647852bffSJohn Scipione	\copydetails BControl::KeyDown()
267274571d8SJohn Scipione*/
268274571d8SJohn Scipione
269274571d8SJohn Scipione
270274571d8SJohn Scipione/*!
271274571d8SJohn Scipione	\fn void BCheckBox::MessageReceived(BMessage* message)
272274571d8SJohn Scipione	\brief Handle \a message received by the associated looper.
273274571d8SJohn Scipione
27447852bffSJohn Scipione	\copydetails BControl::MessageReceived()
275274571d8SJohn Scipione*/
276274571d8SJohn Scipione
277274571d8SJohn Scipione
278274571d8SJohn Scipione/*!
279274571d8SJohn Scipione	\fn void BCheckBox::MouseDown(BPoint where)
280274571d8SJohn Scipione	\brief Hook method called when a mouse button is pressed.
281274571d8SJohn Scipione
282274571d8SJohn Scipione	Begins tracking the mouse cursor.
283274571d8SJohn Scipione
28447852bffSJohn Scipione	\copydetails BControl::MouseDown()
285274571d8SJohn Scipione*/
286274571d8SJohn Scipione
287274571d8SJohn Scipione
288274571d8SJohn Scipione/*!
289274571d8SJohn Scipione	\fn void BCheckBox::MouseMoved(BPoint where, uint32 code,
290274571d8SJohn Scipione		const BMessage* dragMessage)
291274571d8SJohn Scipione	\brief Hook method called when the mouse is moved.
292274571d8SJohn Scipione
293274571d8SJohn Scipione	Once MouseDown() has been called on a check box this method updates
294274571d8SJohn Scipione	the outline when the cursor is inside the control redrawing as necessary.
295274571d8SJohn Scipione
29647852bffSJohn Scipione	\copydetails BControl::MouseMoved()
297274571d8SJohn Scipione*/
298274571d8SJohn Scipione
299274571d8SJohn Scipione
300274571d8SJohn Scipione/*!
301274571d8SJohn Scipione	\fn void BCheckBox::MouseUp(BPoint where)
302274571d8SJohn Scipione	\brief Hook method called when a mouse button is released.
303274571d8SJohn Scipione
304274571d8SJohn Scipione	Inverts the check box value.
305274571d8SJohn Scipione
30647852bffSJohn Scipione	\copydetails BControl::MouseUp()
307274571d8SJohn Scipione*/
308274571d8SJohn Scipione
309274571d8SJohn Scipione
310274571d8SJohn Scipione
311274571d8SJohn Scipione/*!
312274571d8SJohn Scipione	\fn void BCheckBox::WindowActivated(bool active)
313274571d8SJohn Scipione	\brief Hook method called when the attached window is activated or
314274571d8SJohn Scipione	       deactivated.
315274571d8SJohn Scipione
31647852bffSJohn Scipione	\copydetails BControl::WindowActivated()
317274571d8SJohn Scipione*/
318274571d8SJohn Scipione
319274571d8SJohn Scipione
320274571d8SJohn Scipione//! @}
321274571d8SJohn Scipione
322274571d8SJohn Scipione
323274571d8SJohn Scipione/*!
3246ac7032dSJohn Scipione	\fn void BCheckBox::SetValue(int32 value)
3256ac7032dSJohn Scipione	\brief Turn the check box on or off.
3266ac7032dSJohn Scipione
3276ac7032dSJohn Scipione	\param value The value to set the check box to, should be
3286ac7032dSJohn Scipione		either \c B_CONTROL_ON or \c B_CONTROL_OFF.
3296ac7032dSJohn Scipione
3306ac7032dSJohn Scipione	\sa BControl::SetValue()
33147852bffSJohn Scipione
33247852bffSJohn Scipione	\since BeOS R3
33347852bffSJohn Scipione*/
33447852bffSJohn Scipione
33547852bffSJohn Scipione
33647852bffSJohn Scipione/*!
33747852bffSJohn Scipione	\fn BHandler* BCheckBox::ResolveSpecifier(BMessage* message, int32 index,
33847852bffSJohn Scipione		BMessage* specifier, int32 what, const char* property)
33947852bffSJohn Scipione	\copydoc BHandler::ResolveSpecifier()
3406ac7032dSJohn Scipione*/
341