xref: /haiku/src/tests/kits/interface/layout/widget_layout_test/CheckBox.cpp (revision 884412df8e67a4f2546b46722ab18868d7439202)
1a5b50d1fSIngo Weinhold /*
2a5b50d1fSIngo Weinhold  * Copyright 2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3a5b50d1fSIngo Weinhold  * All rights reserved. Distributed under the terms of the MIT License.
4a5b50d1fSIngo Weinhold  */
5a5b50d1fSIngo Weinhold 
6a5b50d1fSIngo Weinhold #include "CheckBox.h"
7a5b50d1fSIngo Weinhold 
8a5b50d1fSIngo Weinhold #include <View.h>
9a5b50d1fSIngo Weinhold 
108dbedf90SIngo Weinhold #include "StringView.h"
118dbedf90SIngo Weinhold 
128dbedf90SIngo Weinhold 
138dbedf90SIngo Weinhold // #pragma mark - CheckBox
148dbedf90SIngo Weinhold 
15a5b50d1fSIngo Weinhold 
CheckBox(BMessage * message,BMessenger target)16a5b50d1fSIngo Weinhold CheckBox::CheckBox(BMessage* message, BMessenger target)
170ce9bc68SIngo Weinhold 	: AbstractButton(BUTTON_POLICY_TOGGLE_ON_RELEASE, message, target)
18a5b50d1fSIngo Weinhold {
19*884412dfSAdrien Destugues 	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
20a5b50d1fSIngo Weinhold }
21a5b50d1fSIngo Weinhold 
22a5b50d1fSIngo Weinhold 
23a5b50d1fSIngo Weinhold BSize
MinSize()24a5b50d1fSIngo Weinhold CheckBox::MinSize()
25a5b50d1fSIngo Weinhold {
26a5b50d1fSIngo Weinhold 	return BSize(12, 12);
27a5b50d1fSIngo Weinhold }
28a5b50d1fSIngo Weinhold 
29a5b50d1fSIngo Weinhold 
30a5b50d1fSIngo Weinhold BSize
MaxSize()31a5b50d1fSIngo Weinhold CheckBox::MaxSize()
32a5b50d1fSIngo Weinhold {
33a5b50d1fSIngo Weinhold 	return MinSize();
34a5b50d1fSIngo Weinhold }
35a5b50d1fSIngo Weinhold 
36a5b50d1fSIngo Weinhold 
37a5b50d1fSIngo Weinhold void
Draw(BView * container,BRect updateRect)38a5b50d1fSIngo Weinhold CheckBox::Draw(BView* container, BRect updateRect)
39a5b50d1fSIngo Weinhold {
40a5b50d1fSIngo Weinhold 	BRect rect(Bounds());
41a5b50d1fSIngo Weinhold 
420ce9bc68SIngo Weinhold 	if (IsPressed())
43a5b50d1fSIngo Weinhold 		container->SetHighColor((rgb_color){ 120, 0, 0, 255 });
44a5b50d1fSIngo Weinhold 	else
45a5b50d1fSIngo Weinhold 		container->SetHighColor((rgb_color){ 0, 0, 0, 255 });
46a5b50d1fSIngo Weinhold 
47a5b50d1fSIngo Weinhold 	container->StrokeRect(rect);
48a5b50d1fSIngo Weinhold 
490ce9bc68SIngo Weinhold 	if (IsSelected()) {
50a5b50d1fSIngo Weinhold 		rect.InsetBy(2, 2);
51a5b50d1fSIngo Weinhold 		container->StrokeLine(rect.LeftTop(), rect.RightBottom());
52a5b50d1fSIngo Weinhold 		container->StrokeLine(rect.RightTop(), rect.LeftBottom());
53a5b50d1fSIngo Weinhold 	}
54a5b50d1fSIngo Weinhold }
55a5b50d1fSIngo Weinhold 
56a5b50d1fSIngo Weinhold 
578dbedf90SIngo Weinhold // #pragma mark - LabeledCheckBox
588dbedf90SIngo Weinhold 
598dbedf90SIngo Weinhold 
LabeledCheckBox(const char * label,BMessage * message,BMessenger target)608dbedf90SIngo Weinhold LabeledCheckBox::LabeledCheckBox(const char* label, BMessage* message,
618dbedf90SIngo Weinhold 	BMessenger target)
628dbedf90SIngo Weinhold 	: GroupView(B_HORIZONTAL),
638dbedf90SIngo Weinhold 	  fCheckBox(new CheckBox(message, target))
648dbedf90SIngo Weinhold {
658dbedf90SIngo Weinhold 	SetSpacing(8, 0);
668dbedf90SIngo Weinhold 
678dbedf90SIngo Weinhold 	AddChild(fCheckBox);
688dbedf90SIngo Weinhold 	if (label)
698dbedf90SIngo Weinhold 		AddChild(new StringView(label));
708dbedf90SIngo Weinhold }
718dbedf90SIngo Weinhold 
728dbedf90SIngo Weinhold 
738dbedf90SIngo Weinhold void
SetTarget(BMessenger messenger)748dbedf90SIngo Weinhold LabeledCheckBox::SetTarget(BMessenger messenger)
758dbedf90SIngo Weinhold {
768dbedf90SIngo Weinhold 	fCheckBox->SetTarget(messenger);
778dbedf90SIngo Weinhold }
788dbedf90SIngo Weinhold 
798dbedf90SIngo Weinhold 
808dbedf90SIngo Weinhold void
SetSelected(bool selected)818dbedf90SIngo Weinhold LabeledCheckBox::SetSelected(bool selected)
828dbedf90SIngo Weinhold {
838dbedf90SIngo Weinhold 	fCheckBox->SetSelected(selected);
848dbedf90SIngo Weinhold }
858dbedf90SIngo Weinhold 
868dbedf90SIngo Weinhold 
878dbedf90SIngo Weinhold bool
IsSelected() const888dbedf90SIngo Weinhold LabeledCheckBox::IsSelected() const
898dbedf90SIngo Weinhold {
908dbedf90SIngo Weinhold 	return fCheckBox->IsSelected();
918dbedf90SIngo Weinhold }
92