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
This commit is contained in:
@@ -8,15 +8,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include <Box.h>
|
||||
#include <Button.h>
|
||||
#include <Message.h>
|
||||
|
||||
#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<LabelRadioButton*>(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<BButton*>(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user