#include "TextViewTest.h"
#include <TextView.h>
#include "CheckBox.h"
#include "GroupView.h"
#include "TestView.h"
enum {
MSG_UPDATE_INSETS = 'upin',
MSG_UPDATE_TEXT = 'uptx',
MSG_UPDATE_FONT = 'upfn',
};
static const char* kNormalText = "Some text to get something on the screen.\n"
"There is even a line break to see that as well.";
static const char* kAlternativeText = "This is some different Text to "
"check out what happens when the text changes.";
TextViewTest::TextViewTest()
: Test("TextView", NULL),
fTextView(new BTextView("text view")),
fUseInsetsCheckBox(NULL),
fTextCheckBox(NULL),
fFontCheckBox(NULL)
{
SetView(fTextView);
fTextView->SetText(kNormalText);
}
Test*
TextViewTest::CreateTest()
{
return new TextViewTest;
}
void
TextViewTest::ActivateTest(View* controls)
{
GroupView* group = new GroupView(B_VERTICAL);
group->SetFrame(controls->Bounds());
group->SetSpacing(0, 4);
controls->AddChild(group);
fUseInsetsCheckBox = new LabeledCheckBox("Use text rect insets",
new BMessage(MSG_UPDATE_INSETS), this);
group->AddChild(fUseInsetsCheckBox);
fTextCheckBox = new LabeledCheckBox("Use alternative text",
new BMessage(MSG_UPDATE_TEXT), this);
group->AddChild(fTextCheckBox);
fFontCheckBox = new LabeledCheckBox("Use large font",
new BMessage(MSG_UPDATE_FONT), this);
group->AddChild(fFontCheckBox);
group->AddChild(new Glue());
}
void
TextViewTest::DectivateTest()
{
}
void
TextViewTest::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_UPDATE_INSETS:
_UpdateInsets();
break;
case MSG_UPDATE_TEXT:
_UpdateText();
break;
case MSG_UPDATE_FONT:
_UpdateFont();
break;
default:
Test::MessageReceived(message);
break;
}
}
void
TextViewTest::_UpdateInsets()
{
if (fUseInsetsCheckBox == NULL)
return;
if (fUseInsetsCheckBox->IsSelected())
fTextView->SetInsets(10, 10, 10, 10);
else
fTextView->SetInsets(0, 0, 0, 0);
}
void
TextViewTest::_UpdateText()
{
if (fTextCheckBox == NULL)
return;
if (fTextCheckBox->IsSelected())
fTextView->SetText(kAlternativeText);
else
fTextView->SetText(kNormalText);
}
void
TextViewTest::_UpdateFont()
{
if (fFontCheckBox == NULL)
return;
BFont font(be_plain_font);
if (fFontCheckBox->IsSelected()) {
font.SetSize(ceilf(font.Size() * 1.5));
fTextView->SetFontAndColor(&font);
} else {
fTextView->SetFontAndColor(&font);
}
}