1/*
2 * Copyright 2007, Ingo Weinhold <bonefish@cs.tu-berlin.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6#include "CheckBox.h"
7
8#include <View.h>
9
10#include "StringView.h"
11
12
13// #pragma mark - CheckBox
14
15
16CheckBox::CheckBox(BMessage* message, BMessenger target)
17	: AbstractButton(BUTTON_POLICY_TOGGLE_ON_RELEASE, message, target)
18{
19	SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
20}
21
22
23BSize
24CheckBox::MinSize()
25{
26	return BSize(12, 12);
27}
28
29
30BSize
31CheckBox::MaxSize()
32{
33	return MinSize();
34}
35
36
37void
38CheckBox::Draw(BView* container, BRect updateRect)
39{
40	BRect rect(Bounds());
41
42	if (IsPressed())
43		container->SetHighColor((rgb_color){ 120, 0, 0, 255 });
44	else
45		container->SetHighColor((rgb_color){ 0, 0, 0, 255 });
46
47	container->StrokeRect(rect);
48
49	if (IsSelected()) {
50		rect.InsetBy(2, 2);
51		container->StrokeLine(rect.LeftTop(), rect.RightBottom());
52		container->StrokeLine(rect.RightTop(), rect.LeftBottom());
53	}
54}
55
56
57// #pragma mark - LabeledCheckBox
58
59
60LabeledCheckBox::LabeledCheckBox(const char* label, BMessage* message,
61	BMessenger target)
62	: GroupView(B_HORIZONTAL),
63	  fCheckBox(new CheckBox(message, target))
64{
65	SetSpacing(8, 0);
66
67	AddChild(fCheckBox);
68	if (label)
69		AddChild(new StringView(label));
70}
71
72
73void
74LabeledCheckBox::SetTarget(BMessenger messenger)
75{
76	fCheckBox->SetTarget(messenger);
77}
78
79
80void
81LabeledCheckBox::SetSelected(bool selected)
82{
83	fCheckBox->SetSelected(selected);
84}
85
86
87bool
88LabeledCheckBox::IsSelected() const
89{
90	return fCheckBox->IsSelected();
91}
92