#include "ControlTest.h"
#include <stdio.h>
#include <Control.h>
#include <Font.h>
#include <Message.h>
#include "CheckBox.h"
#include "GroupView.h"
#include "StringView.h"
ControlTest::ControlTest(const char* name)
: Test(name, NULL),
fControl(NULL),
fLongTextCheckBox(NULL),
fBigFontCheckBox(NULL),
fDefaultFont(NULL),
fBigFont(NULL)
{
}
ControlTest::~ControlTest()
{
delete fDefaultFont;
delete fBigFont;
}
void
ControlTest::SetView(BView* view)
{
Test::SetView(view);
fControl = dynamic_cast<BControl*>(view);
}
void
ControlTest::ActivateTest(View* controls)
{
GroupView* group = new GroupView(B_VERTICAL);
group->SetFrame(controls->Bounds());
group->SetSpacing(0, 8);
controls->AddChild(group);
fLongTextCheckBox = new LabeledCheckBox("Long label text",
new BMessage(MSG_CHANGE_CONTROL_TEXT), this);
group->AddChild(fLongTextCheckBox);
fBigFontCheckBox = new LabeledCheckBox("Big label font",
new BMessage(MSG_CHANGE_CONTROL_FONT), this);
group->AddChild(fBigFontCheckBox);
UpdateControlText();
UpdateControlFont();
}
void
ControlTest::DectivateTest()
{
}
void
ControlTest::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_CHANGE_CONTROL_TEXT:
UpdateControlText();
break;
case MSG_CHANGE_CONTROL_FONT:
UpdateControlFont();
break;
default:
Test::MessageReceived(message);
break;
}
}
void
ControlTest::UpdateControlText()
{
if (!fLongTextCheckBox || !fControl)
return;
fControl->SetLabel(fLongTextCheckBox->IsSelected()
? "Very long label for a simple control"
: "Short label");
}
void
ControlTest::UpdateControlFont()
{
if (!fBigFontCheckBox || !fControl || !fControl->Window())
return;
if (!fDefaultFont) {
fDefaultFont = new BFont;
fControl->GetFont(fDefaultFont);
fBigFont = new BFont(fDefaultFont);
fBigFont->SetSize(20);
}
fControl->SetFont(fBigFontCheckBox->IsSelected()
? fBigFont : fDefaultFont);
fControl->InvalidateLayout();
fControl->Invalidate();
}