diff --git a/src/tests/kits/interface/layout/widget_layout_test/Jamfile b/src/tests/kits/interface/layout/widget_layout_test/Jamfile index 1f56954afe..b74b2831e9 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/Jamfile +++ b/src/tests/kits/interface/layout/widget_layout_test/Jamfile @@ -31,6 +31,7 @@ SimpleTest WidgetLayoutTest : ScrollBarTest.cpp SliderTest.cpp TextControlTest.cpp + TextViewTest.cpp : be ; diff --git a/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp index 9b74d82b1e..edf4b185b6 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp @@ -23,6 +23,7 @@ #include "StringView.h" #include "Test.h" #include "TextControlTest.h" +#include "TextViewTest.h" #include "TwoDimensionalSliderView.h" #include "View.h" #include "ViewContainer.h" @@ -53,6 +54,7 @@ const test_info kTestInfos[] = { { "BScrollBar", ScrollBarTest::CreateTest }, { "BSlider", SliderTest::CreateTest }, { "BTextControl", TextControlTest::CreateTest }, + { "BTextView", TextViewTest::CreateTest }, { NULL, NULL } }; diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/TextViewTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/tests/TextViewTest.cpp new file mode 100644 index 0000000000..6d3baf5f57 --- /dev/null +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/TextViewTest.cpp @@ -0,0 +1,155 @@ +/* + * Copyright 2008, Stephan Aßmus . + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "TextViewTest.h" + +#include + +#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); + } +} + + + diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/TextViewTest.h b/src/tests/kits/interface/layout/widget_layout_test/tests/TextViewTest.h new file mode 100644 index 0000000000..6dacd77eaa --- /dev/null +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/TextViewTest.h @@ -0,0 +1,42 @@ +/* + * Copyright 2008, Stephan Aßmus . + * Copyright 2007, Ingo Weinhold . + * 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