Derived from: public BControl
Declared in: <interface/CheckBox.h>
A BCheckBox object draws a labeled check box on-screen and responds to a keyboard action or a click by changing the state of the device. A check box has two states: An " X" is displayed in the box when the object's value is 1 (B_CONTROL_ON), and is absent when the value is 0 (B_CONTROL_OFF). The BCheckBox is invoked (it posts a message to the target receiver) whenever its value changes in either direction--when it's turned on and when it's turned off.
A check box is an appropriate control device for setting a state-- turning a value on and off. Use menu items or buttons to initiate actions within the application.
BCheckBox(BRect frame, const char *name, const char *label, BMessage *message, ulong resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, ulong flags = B_WILL_DRAW | B_NAVIGABLE)
Initializes the BCheckBox by passing all arguments to the BControl constructor. BControl initializes the label of the check box and assigns it a model message that encapsulates the action that should be taken when the state of the check box changes.
The frame, name, resizingMode, and flags arguments are the same as those declared for the BView class and are passed unchanged to the BView constructor.
When the BCheckBox is attached to a window, the height of its frame rectangle will be adjusted so that it has exactly the right amount of room to display the check box icon and the label, given its current font. The object draws at the vertical center of its frame rectangle beginning at the left side.
See also: the BControl and BView constructors, AttachedToWindow()
virtual void AttachedToWindow(void)
Augments the BControl version of AttachedToWindow() to set the view and low colors of the BCheckbox to the match its parent's view color, and to resize the view vertically to fit the height of the label it displays. The height of the label depends on the BCheckBox's font, which the BControl constructor sets to the Emily bitmap font.
See also: BControl::AttachedToWindow()
virtual void Draw(BRect updateRect)
Draws the check box and its label. If the current value of the BCheckBox is 1 (B_CONTROL_ON ), it's marked with an "X". If the value is 0 (B_CONTROL_OFF), it's empty.
See also: BView::Draw()
virtual void MouseDown(BPoint point)
Responds to a mouse-down event within the check box by tracking the cursor while the user holds the mouse button down. If the cursor is inside the bounds rectangle when the user releases the mouse button, this function toggles the value of the BCheckBox and calls Draw() to redisplay it. If the box was empty before the mouse-down event, it will be marked afterward; if marked before, it will be empty afterwards.
When the value of the BCheckBox changes, a copy of the model BMessage is posted so that it can be delivered to the object's target handler. See BControl's Invoke() and SetTarget() functions for more information. The message is dispatched by calling the target's MessageReceived() virtual function.
The target object can get a pointer to the BCheckBox from the message, and use it to discover the object's new value. For example:
void MyHandler::MessageReceived(BMessage *msg) { . . . BCheckBox *box = (BCheckBox *)msg->FindObject("source"); if ( message->Error() == B_NO_ERROR ) { long value = box->Value(); . . . } . . . }
See also: BControl::Invoke(), BControl::SetTarget(), and BControl::SetValue()
The Be Book, HTML Edition, for Developer Release 8 of the Be Operating System.
Copyright © 1996 Be, Inc. All rights reserved.
Be, the Be logo, BeBox, BeOS, BeWare, and GeekPort are trademarks of Be, Inc.
Last modified September 6, 1996.