From 7302e28d1ba8b5539004e6a939945c5010b07ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 13 Sep 2008 19:50:01 +0000 Subject: [PATCH] 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 --- .../layout/widget_layout_test/Jamfile | 1 + .../widget_layout_test/WidgetLayoutTest.cpp | 2 + .../layout/widget_layout_test/tests/TODO | 1 - .../tests/TextControlTest.cpp | 144 ++++++++++++++++++ .../tests/TextControlTest.h | 43 ++++++ 5 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.cpp create mode 100644 src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.h diff --git a/src/tests/kits/interface/layout/widget_layout_test/Jamfile b/src/tests/kits/interface/layout/widget_layout_test/Jamfile index ae7555ff8c..790a4069ec 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/Jamfile +++ b/src/tests/kits/interface/layout/widget_layout_test/Jamfile @@ -29,6 +29,7 @@ SimpleTest WidgetLayoutTest : MenuTest.cpp ScrollBarTest.cpp SliderTest.cpp + TextControlTest.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 c9db384755..1721adc997 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp @@ -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 } }; diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/TODO b/src/tests/kits/interface/layout/widget_layout_test/tests/TODO index 55892d1ae2..5809c7c0d0 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/TODO +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/TODO @@ -4,5 +4,4 @@ RadioButton ScrollView StringView TabView -TextControl TextView diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.cpp new file mode 100644 index 0000000000..78a105f2f9 --- /dev/null +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.cpp @@ -0,0 +1,144 @@ +/* + * Copyright 2008, Stephan Aßmus . + * Copyright 2007, Ingo Weinhold . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "TextControlTest.h" + +#include + +#include + +#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(); +} diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.h b/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.h new file mode 100644 index 0000000000..51854566b4 --- /dev/null +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/TextControlTest.h @@ -0,0 +1,43 @@ +/* + * 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_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