From fa635377e0a6d0982d7be3e6ec45a52f73830b14 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 8 Jun 2007 23:48:08 +0000 Subject: [PATCH] Extended the BBox test. One can now play with label and child view. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21361 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../layout/widget_layout_test/BoxTest.cpp | 142 +++++++++++++++++- .../layout/widget_layout_test/BoxTest.h | 9 ++ 2 files changed, 148 insertions(+), 3 deletions(-) diff --git a/src/tests/kits/interface/layout/widget_layout_test/BoxTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/BoxTest.cpp index 23f6d0cc56..f4c13b2d63 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/BoxTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/BoxTest.cpp @@ -8,15 +8,21 @@ #include #include +#include #include +#include "CheckBox.h" #include "GroupView.h" #include "RadioButton.h" +#include "TestView.h" // messages enum { MSG_BORDER_STYLE_CHANGED = 'bstc', + MSG_LABEL_CHANGED = 'lbch', + MSG_LONG_LABEL_CHANGED = 'llch', + MSG_CHILD_CHANGED = 'chch' }; @@ -33,12 +39,31 @@ public: }; +// LabelRadioButton +class BoxTest::LabelRadioButton : public LabeledRadioButton { +public: + LabelRadioButton(const char* label, const char* boxLabel, + bool labelView = false) + : LabeledRadioButton(label), + fLabel(boxLabel), + fLabelView(labelView) + { + } + + const char* fLabel; + bool fLabelView; +}; + + // constructor BoxTest::BoxTest() : Test("Box", NULL), - fBox(new BBox(BRect(0, 0, 9, 9), "test box", B_FOLLOW_NONE)), - fBorderStyleRadioGroup(NULL) -// TODO: Layout-friendly constructor + fBox(new BBox("test box")), + fChild(NULL), + fBorderStyleRadioGroup(NULL), + fLabelRadioGroup(NULL), + fLongLabelCheckBox(NULL), + fChildCheckBox(NULL) { SetView(fBox); } @@ -48,6 +73,7 @@ BoxTest::BoxTest() BoxTest::~BoxTest() { delete fBorderStyleRadioGroup; + delete fLabelRadioGroup; } @@ -67,6 +93,7 @@ BoxTest::ActivateTest(View* controls) controls->AddChild(group); // the radio button group for selecting the border style + fBorderStyleRadioGroup = new RadioButtonGroup( new BMessage(MSG_BORDER_STYLE_CHANGED), this); @@ -89,6 +116,47 @@ BoxTest::ActivateTest(View* controls) // default to no border fBorderStyleRadioGroup->SelectButton(0L); + // spacing + group->AddChild(new VStrut(10)); + + // the radio button group for selecting the label + + fLabelRadioGroup = new RadioButtonGroup(new BMessage(MSG_LABEL_CHANGED), + this); + + // no label + button = new LabelRadioButton("No label", NULL); + group->AddChild(button); + fLabelRadioGroup->AddButton(button->GetRadioButton()); + + // label string + button = new LabelRadioButton("Label string", ""); + group->AddChild(button); + fLabelRadioGroup->AddButton(button->GetRadioButton()); + + // label view + button = new LabelRadioButton("Label view", NULL, true); + group->AddChild(button); + fLabelRadioGroup->AddButton(button->GetRadioButton()); + + // default to no border + fLabelRadioGroup->SelectButton(0L); + + // spacing + group->AddChild(new VStrut(10)); + + // long label + fLongLabelCheckBox = new LabeledCheckBox("Long label", + new BMessage(MSG_LONG_LABEL_CHANGED), this); + group->AddChild(fLongLabelCheckBox); + + // child + fChildCheckBox = new LabeledCheckBox("Child", + new BMessage(MSG_CHILD_CHANGED), this); + group->AddChild(fChildCheckBox); + + + // glue group->AddChild(new Glue()); } @@ -108,6 +176,15 @@ BoxTest::MessageReceived(BMessage* message) case MSG_BORDER_STYLE_CHANGED: _UpdateBorderStyle(); break; + case MSG_LABEL_CHANGED: + _UpdateLabel(); + break; + case MSG_LONG_LABEL_CHANGED: + _UpdateLongLabel(); + break; + case MSG_CHILD_CHANGED: + _UpdateChild(); + break; default: Test::MessageReceived(message); break; @@ -132,3 +209,62 @@ BoxTest::_UpdateBorderStyle() fBox->SetBorder(button->fBorderStyle); } } + + +// _UpdateLabel +void +BoxTest::_UpdateLabel() +{ + if (fLabelRadioGroup) { + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton = fLabelRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + LabelRadioButton* button = dynamic_cast(parent); + if (button) { + if (button->fLabelView) + fBox->SetLabel(new BButton("", NULL)); + else + fBox->SetLabel(button->fLabel); + + _UpdateLongLabel(); + } + } +} + + +// _UpdateLongLabel +void +BoxTest::_UpdateLongLabel() +{ + if (!fLongLabelCheckBox) + return; + + const char* label = (fLongLabelCheckBox->IsSelected() + ? "Quite Long Label for a BBox" + : "Label"); + + if (BView* labelView = fBox->LabelView()) { + if (BButton* button = dynamic_cast(labelView)) + button->SetLabel(label); + } else if (fBox->Label()) + fBox->SetLabel(label); +} + + +// _UpdateChild +void +BoxTest::_UpdateChild() +{ + if (!fChildCheckBox || fChildCheckBox->IsSelected() == (fChild != NULL)) + return; + + if (fChild) { + fBox->RemoveChild(fChild); + fChild = NULL; + } else { + fChild = new TestView(BSize(20, 10), BSize(350, 200), BSize(100, 70)); + fBox->AddChild(fChild); + } +} diff --git a/src/tests/kits/interface/layout/widget_layout_test/BoxTest.h b/src/tests/kits/interface/layout/widget_layout_test/BoxTest.h index 61913d6dfc..ac81993777 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/BoxTest.h +++ b/src/tests/kits/interface/layout/widget_layout_test/BoxTest.h @@ -10,6 +10,7 @@ class BBox; +class LabeledCheckBox; class RadioButtonGroup; @@ -25,12 +26,20 @@ public: private: void _UpdateBorderStyle(); + void _UpdateLabel(); + void _UpdateLongLabel(); + void _UpdateChild(); private: class BorderStyleRadioButton; + class LabelRadioButton; BBox* fBox; + BView* fChild; RadioButtonGroup* fBorderStyleRadioGroup; + RadioButtonGroup* fLabelRadioGroup; + LabeledCheckBox* fLongLabelCheckBox; + LabeledCheckBox* fChildCheckBox; };