Added BTextControl test. BTextControl seems to need some love.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27498 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stephan Aßmus
2008-09-13 19:50:01 +00:00
parent 28f362c129
commit 7302e28d1b
5 changed files with 190 additions and 1 deletions
@@ -29,6 +29,7 @@ SimpleTest WidgetLayoutTest :
MenuTest.cpp
ScrollBarTest.cpp
SliderTest.cpp
TextControlTest.cpp
:
be
;
@@ -21,6 +21,7 @@
#include "SliderTest.h"
#include "StringView.h"
#include "Test.h"
#include "TextControlTest.h"
#include "TwoDimensionalSliderView.h"
#include "View.h"
#include "ViewContainer.h"
@@ -49,6 +50,7 @@ const test_info kTestInfos[] = {
{ "BMenuField", MenuFieldTest::CreateTest },
{ "BScrollBar", ScrollBarTest::CreateTest },
{ "BSlider", SliderTest::CreateTest },
{ "BTextControl", TextControlTest::CreateTest },
{ NULL, NULL }
};
@@ -4,5 +4,4 @@ RadioButton
ScrollView
StringView
TabView
TextControl
TextView
@@ -0,0 +1,144 @@
/*
* Copyright 2008, Stephan Aßmus <[email protected]>.
* Copyright 2007, Ingo Weinhold <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "TextControlTest.h"
#include <stdio.h>
#include <TextControl.h>
#include "CheckBox.h"
#include "GroupView.h"
enum {
MSG_CHANGE_LABEL_TEXT = 'chlt',
MSG_CHANGE_LABEL_FONT = 'chlf'
};
// constructor
TextControlTest::TextControlTest()
: ControlTest("TextControl"),
fLongTextCheckBox(NULL),
fBigFontCheckBox(NULL),
fDefaultFont(NULL),
fBigFont(NULL)
{
fTextControl = new BTextControl("Label", "Some Text", NULL);
SetView(fTextControl);
}
// destructor
TextControlTest::~TextControlTest()
{
delete fDefaultFont;
delete fBigFont;
}
// CreateTest
Test*
TextControlTest::CreateTest()
{
return new TextControlTest;
}
// ActivateTest
void
TextControlTest::ActivateTest(View* controls)
{
GroupView* group = new GroupView(B_VERTICAL);
group->SetFrame(controls->Bounds());
group->SetSpacing(0, 8);
controls->AddChild(group);
// BMenuField sets its background color to that of its parent in
// AttachedToWindow(). Override.
rgb_color background = ui_color(B_PANEL_BACKGROUND_COLOR);
fTextControl->SetViewColor(background);
fTextControl->SetLowColor(background);
// long text
fLongTextCheckBox = new LabeledCheckBox("Long label text",
new BMessage(MSG_CHANGE_LABEL_TEXT), this);
group->AddChild(fLongTextCheckBox);
// big font
fBigFontCheckBox = new LabeledCheckBox("Big label font",
new BMessage(MSG_CHANGE_LABEL_FONT), this);
group->AddChild(fBigFontCheckBox);
_UpdateLabelText();
_UpdateLabelFont();
group->AddChild(new Glue());
}
// DectivateTest
void
TextControlTest::DectivateTest()
{
}
// MessageReceived
void
TextControlTest::MessageReceived(BMessage* message)
{
switch (message->what) {
case MSG_CHANGE_LABEL_TEXT:
_UpdateLabelText();
break;
case MSG_CHANGE_LABEL_FONT:
_UpdateLabelFont();
break;
default:
Test::MessageReceived(message);
break;
}
}
// _UpdateLabelText
void
TextControlTest::_UpdateLabelText()
{
if (!fLongTextCheckBox || !fTextControl)
return;
fTextControl->SetLabel(fLongTextCheckBox->IsSelected()
? "Pretty long menu field label"
: "Short label");
}
// _UpdateLabelFont
void
TextControlTest::_UpdateLabelFont()
{
if (!fBigFontCheckBox || !fTextControl || !fTextControl->Window())
return;
// get default font lazily
if (!fDefaultFont) {
fDefaultFont = new BFont;
fTextControl->GetFont(fDefaultFont);
fBigFont = new BFont(fDefaultFont);
fBigFont->SetSize(20);
}
// set font
fTextControl->SetFont(fBigFontCheckBox->IsSelected()
? fBigFont : fDefaultFont);
fTextControl->InvalidateLayout();
fTextControl->Invalidate();
}
@@ -0,0 +1,43 @@
/*
* Copyright 2008, Stephan Aßmus <[email protected]>.
* Copyright 2007, Ingo Weinhold <[email protected]>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef WIDGET_LAYOUT_TEST_TEXT_CONTROL_TEST_H
#define WIDGET_LAYOUT_TEST_TEXT_CONTROL_TEST_H
#include "ControlTest.h"
class BFont;
class BTextControl;
class LabeledCheckBox;
class TextControlTest : public ControlTest {
public:
TextControlTest();
virtual ~TextControlTest();
static Test* CreateTest();
virtual void ActivateTest(View* controls);
virtual void DectivateTest();
virtual void MessageReceived(BMessage* message);
private:
void _UpdateLabelText();
void _UpdateLabelFont();
private:
BTextControl* fTextControl;
LabeledCheckBox* fLongTextCheckBox;
LabeledCheckBox* fBigFontCheckBox;
BFont* fDefaultFont;
BFont* fBigFont;
};
#endif // WIDGET_LAYOUT_TEST_TEXT_CONTROL_TEST_H