Added a test for BTextView. It is quite basic yet.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27678 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -31,6 +31,7 @@ SimpleTest WidgetLayoutTest :
|
|||||||
ScrollBarTest.cpp
|
ScrollBarTest.cpp
|
||||||
SliderTest.cpp
|
SliderTest.cpp
|
||||||
TextControlTest.cpp
|
TextControlTest.cpp
|
||||||
|
TextViewTest.cpp
|
||||||
:
|
:
|
||||||
be
|
be
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "StringView.h"
|
#include "StringView.h"
|
||||||
#include "Test.h"
|
#include "Test.h"
|
||||||
#include "TextControlTest.h"
|
#include "TextControlTest.h"
|
||||||
|
#include "TextViewTest.h"
|
||||||
#include "TwoDimensionalSliderView.h"
|
#include "TwoDimensionalSliderView.h"
|
||||||
#include "View.h"
|
#include "View.h"
|
||||||
#include "ViewContainer.h"
|
#include "ViewContainer.h"
|
||||||
@@ -53,6 +54,7 @@ const test_info kTestInfos[] = {
|
|||||||
{ "BScrollBar", ScrollBarTest::CreateTest },
|
{ "BScrollBar", ScrollBarTest::CreateTest },
|
||||||
{ "BSlider", SliderTest::CreateTest },
|
{ "BSlider", SliderTest::CreateTest },
|
||||||
{ "BTextControl", TextControlTest::CreateTest },
|
{ "BTextControl", TextControlTest::CreateTest },
|
||||||
|
{ "BTextView", TextViewTest::CreateTest },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,155 @@
|
|||||||
|
/*
|
||||||
|
* 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 "TextViewTest.h"
|
||||||
|
|
||||||
|
#include <TextView.h>
|
||||||
|
|
||||||
|
#include "CheckBox.h"
|
||||||
|
#include "GroupView.h"
|
||||||
|
#include "TestView.h"
|
||||||
|
|
||||||
|
|
||||||
|
// messages
|
||||||
|
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")),
|
||||||
|
|
||||||
|
// fTextView(new BTextView(BRect(0, 0, 49, 49), "name",
|
||||||
|
// BRect(0, 0, 49, 49), B_FOLLOW_NONE, B_WILL_DRAW | B_PULSE_NEEDED
|
||||||
|
// | B_SUPPORTS_LAYOUT)),
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// insets
|
||||||
|
fUseInsetsCheckBox = new LabeledCheckBox("Use text rect insets",
|
||||||
|
new BMessage(MSG_UPDATE_INSETS), this);
|
||||||
|
group->AddChild(fUseInsetsCheckBox);
|
||||||
|
|
||||||
|
// text
|
||||||
|
fTextCheckBox = new LabeledCheckBox("Use alternative text",
|
||||||
|
new BMessage(MSG_UPDATE_TEXT), this);
|
||||||
|
group->AddChild(fTextCheckBox);
|
||||||
|
|
||||||
|
// font
|
||||||
|
fFontCheckBox = new LabeledCheckBox("Use large font",
|
||||||
|
new BMessage(MSG_UPDATE_FONT), this);
|
||||||
|
group->AddChild(fFontCheckBox);
|
||||||
|
|
||||||
|
// glue
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// #pragma mark - private
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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_VIEW_TEST_H
|
||||||
|
#define WIDGET_LAYOUT_TEST_TEXT_VIEW_TEST_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "Test.h"
|
||||||
|
|
||||||
|
|
||||||
|
class BTextView;
|
||||||
|
class LabeledCheckBox;
|
||||||
|
|
||||||
|
|
||||||
|
class TextViewTest : public Test {
|
||||||
|
public:
|
||||||
|
TextViewTest();
|
||||||
|
|
||||||
|
static Test* CreateTest();
|
||||||
|
|
||||||
|
virtual void ActivateTest(View* controls);
|
||||||
|
virtual void DectivateTest();
|
||||||
|
|
||||||
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
void _UpdateInsets();
|
||||||
|
void _UpdateText();
|
||||||
|
void _UpdateFont();
|
||||||
|
|
||||||
|
private:
|
||||||
|
BTextView* fTextView;
|
||||||
|
LabeledCheckBox* fUseInsetsCheckBox;
|
||||||
|
LabeledCheckBox* fTextCheckBox;
|
||||||
|
LabeledCheckBox* fFontCheckBox;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // WIDGET_LAYOUT_TEST_TEXT_VIEW_TEST_H
|
||||||
Reference in New Issue
Block a user