#include "ScrollBarTest.h"
#include <Message.h>
#include <ScrollBar.h>
#include "RadioButton.h"
#include "TestView.h"
enum {
MSG_ORIENTATION_CHANGED = 'orch'
};
class ScrollBarTest::OrientationRadioButton : public LabeledRadioButton {
public:
OrientationRadioButton(const char* label, enum orientation orientation)
: LabeledRadioButton(label),
fOrientation(orientation)
{
}
enum orientation fOrientation;
};
ScrollBarTest::ScrollBarTest()
: Test("ScrollBar", NULL),
fScrollBar(new BScrollBar("scroll bar", NULL, 0, 100, B_HORIZONTAL)),
fOrientationRadioGroup(NULL)
{
SetView(fScrollBar);
}
ScrollBarTest::~ScrollBarTest()
{
delete fOrientationRadioGroup;
}
Test*
ScrollBarTest::CreateTest()
{
return new ScrollBarTest;
}
void
ScrollBarTest::ActivateTest(View* controls)
{
GroupView* vGroup = new GroupView(B_VERTICAL);
vGroup->SetFrame(controls->Bounds());
vGroup->SetSpacing(0, 4);
controls->AddChild(vGroup);
fOrientationRadioGroup = new RadioButtonGroup(
new BMessage(MSG_ORIENTATION_CHANGED), this);
LabeledRadioButton* button = new OrientationRadioButton("Horizontal",
B_HORIZONTAL);
vGroup->AddChild(button);
fOrientationRadioGroup->AddButton(button->GetRadioButton());
button = new OrientationRadioButton("Vertical", B_VERTICAL);
vGroup->AddChild(button);
fOrientationRadioGroup->AddButton(button->GetRadioButton());
fOrientationRadioGroup->SelectButton((int32)0);
vGroup->AddChild(new Glue());
}
void
ScrollBarTest::DectivateTest()
{
}
void
ScrollBarTest::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_ORIENTATION_CHANGED:
_UpdateOrientation();
break;
default:
Test::MessageReceived(message);
break;
}
}
void
ScrollBarTest::_UpdateOrientation()
{
if (fOrientationRadioGroup == NULL)
return;
AbstractButton* selectedButton
= fOrientationRadioGroup->SelectedButton();
View* parent = (selectedButton ? selectedButton->Parent() : NULL);
OrientationRadioButton* button = dynamic_cast<OrientationRadioButton*>(
parent);
if (button)
fScrollBar->SetOrientation(button->fOrientation);
}