From 21527c4e77cb6db8533b7c75ca444de1a7f9204a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sat, 13 Sep 2008 19:21:55 +0000 Subject: [PATCH] Added BScrollBar test. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27495 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../layout/widget_layout_test/Jamfile | 1 + .../widget_layout_test/WidgetLayoutTest.cpp | 2 + .../tests/ScrollBarTest.cpp | 129 ++++++++++++++++++ .../widget_layout_test/tests/ScrollBarTest.h | 39 ++++++ .../layout/widget_layout_test/tests/TODO | 1 - 5 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.cpp create mode 100644 src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.h diff --git a/src/tests/kits/interface/layout/widget_layout_test/Jamfile b/src/tests/kits/interface/layout/widget_layout_test/Jamfile index 80b484f746..ae7555ff8c 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/Jamfile +++ b/src/tests/kits/interface/layout/widget_layout_test/Jamfile @@ -27,6 +27,7 @@ SimpleTest WidgetLayoutTest : MenuBarTest.cpp MenuFieldTest.cpp MenuTest.cpp + ScrollBarTest.cpp SliderTest.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 ff054b90f0..c9db384755 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp +++ b/src/tests/kits/interface/layout/widget_layout_test/WidgetLayoutTest.cpp @@ -17,6 +17,7 @@ #include "MenuBarTest.h" #include "MenuFieldTest.h" #include "MenuTest.h" +#include "ScrollBarTest.h" #include "SliderTest.h" #include "StringView.h" #include "Test.h" @@ -46,6 +47,7 @@ const test_info kTestInfos[] = { { "BMenu", MenuTest::CreateTest }, { "BMenuBar", MenuBarTest::CreateTest }, { "BMenuField", MenuFieldTest::CreateTest }, + { "BScrollBar", ScrollBarTest::CreateTest }, { "BSlider", SliderTest::CreateTest }, { NULL, NULL } }; diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.cpp b/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.cpp new file mode 100644 index 0000000000..bd1ac21357 --- /dev/null +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.cpp @@ -0,0 +1,129 @@ +/* + * Copyright 2008, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ + +#include "ScrollBarTest.h" + +#include +#include + +#include "RadioButton.h" +#include "TestView.h" + + +// messages +enum { + MSG_ORIENTATION_CHANGED = 'orch' +}; + + +// OrientationRadioButton +class ScrollBarTest::OrientationRadioButton : public LabeledRadioButton { +public: + OrientationRadioButton(const char* label, enum orientation orientation) + : LabeledRadioButton(label), + fOrientation(orientation) + { + } + + enum orientation fOrientation; +}; + + +ScrollBarTest::ScrollBarTest() + : Test("ScrollBar", NULL), + fScrollBar(new BScrollBar("scroll bar", NULL, 0, 100, B_HORIZONTAL)), + fOrientationRadioGroup(NULL) +{ + SetView(fScrollBar); +} + + +ScrollBarTest::~ScrollBarTest() +{ + delete fOrientationRadioGroup; +} + + +Test* +ScrollBarTest::CreateTest() +{ + return new ScrollBarTest; +} + + +void +ScrollBarTest::ActivateTest(View* controls) +{ + // the radio button group for selecting the orientation + + GroupView* vGroup = new GroupView(B_VERTICAL); + vGroup->SetFrame(controls->Bounds()); + vGroup->SetSpacing(0, 4); + controls->AddChild(vGroup); + + fOrientationRadioGroup = new RadioButtonGroup( + new BMessage(MSG_ORIENTATION_CHANGED), this); + + // horizontal + LabeledRadioButton* button = new OrientationRadioButton("Horizontal", + B_HORIZONTAL); + vGroup->AddChild(button); + fOrientationRadioGroup->AddButton(button->GetRadioButton()); + + // vertical + button = new OrientationRadioButton("Vertical", B_VERTICAL); + vGroup->AddChild(button); + fOrientationRadioGroup->AddButton(button->GetRadioButton()); + + // default to horizontal + fOrientationRadioGroup->SelectButton(0L); + + // glue + vGroup->AddChild(new Glue()); +} + + +void +ScrollBarTest::DectivateTest() +{ +} + + +void +ScrollBarTest::MessageReceived(BMessage* message) +{ + switch (message->what) { + case MSG_ORIENTATION_CHANGED: + _UpdateOrientation(); + break; + default: + Test::MessageReceived(message); + break; + } +} + + +void +ScrollBarTest::_UpdateOrientation() +{ + if (fOrientationRadioGroup == NULL) + return; + + // We need to get the parent of the actually selected button, since + // that is the labeled radio button we've derived our + // BorderStyleRadioButton from. + AbstractButton* selectedButton + = fOrientationRadioGroup->SelectedButton(); + View* parent = (selectedButton ? selectedButton->Parent() : NULL); + OrientationRadioButton* button = dynamic_cast( + parent); + if (button) + fScrollBar->SetOrientation(button->fOrientation); +} + + + + + diff --git a/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.h b/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.h new file mode 100644 index 0000000000..3b0fb31107 --- /dev/null +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/ScrollBarTest.h @@ -0,0 +1,39 @@ +/* + * Copyright 2008, Stephan Aßmus . + * All rights reserved. Distributed under the terms of the MIT License. + */ +#ifndef WIDGET_LAYOUT_TEST_SCROLL_BAR_TEST_H +#define WIDGET_LAYOUT_TEST_SCROLL_BAR_TEST_H + + +#include "Test.h" + + +class BScrollBar; +class RadioButtonGroup; + + +class ScrollBarTest : public Test { +public: + ScrollBarTest(); + virtual ~ScrollBarTest(); + + static Test* CreateTest(); + + virtual void ActivateTest(View* controls); + virtual void DectivateTest(); + + virtual void MessageReceived(BMessage* message); + +private: + void _UpdateOrientation(); + +private: + class OrientationRadioButton; + + BScrollBar* fScrollBar; + RadioButtonGroup* fOrientationRadioGroup; +}; + + +#endif // WIDGET_LAYOUT_TEST_SCROLL_BAR_TEST_H 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 a36b082075..55892d1ae2 100644 --- a/src/tests/kits/interface/layout/widget_layout_test/tests/TODO +++ b/src/tests/kits/interface/layout/widget_layout_test/tests/TODO @@ -1,7 +1,6 @@ ChannelSlider OptionPopup (covered by MenuField ?) RadioButton -ScrollBar ScrollView StringView TabView