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 16 CheckBox::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 23 BSize 24 CheckBox::MinSize() 25 { 26 return BSize(12, 12); 27 } 28 29 30 BSize 31 CheckBox::MaxSize() 32 { 33 return MinSize(); 34 } 35 36 37 void 38 CheckBox::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 60 LabeledCheckBox::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 73 void 74 LabeledCheckBox::SetTarget(BMessenger messenger) 75 { 76 fCheckBox->SetTarget(messenger); 77 } 78 79 80 void 81 LabeledCheckBox::SetSelected(bool selected) 82 { 83 fCheckBox->SetSelected(selected); 84 } 85 86 87 bool 88 LabeledCheckBox::IsSelected() const 89 { 90 return fCheckBox->IsSelected(); 91 } 92