1/*
2 * Copyright 2008, Stephan A��mus <superstippi@gmx.de>.
3 * All rights reserved. Distributed under the terms of the MIT License.
4 */
5
6#include "ScrollBarTest.h"
7
8#include <Message.h>
9#include <ScrollBar.h>
10
11#include "RadioButton.h"
12#include "TestView.h"
13
14
15// messages
16enum {
17	MSG_ORIENTATION_CHANGED			= 'orch'
18};
19
20
21// OrientationRadioButton
22class ScrollBarTest::OrientationRadioButton : public LabeledRadioButton {
23public:
24	OrientationRadioButton(const char* label, enum orientation orientation)
25		: LabeledRadioButton(label),
26		  fOrientation(orientation)
27	{
28	}
29
30	enum orientation fOrientation;
31};
32
33
34ScrollBarTest::ScrollBarTest()
35	: Test("ScrollBar", NULL),
36	  fScrollBar(new BScrollBar("scroll bar", NULL, 0, 100, B_HORIZONTAL)),
37	  fOrientationRadioGroup(NULL)
38{
39	SetView(fScrollBar);
40}
41
42
43ScrollBarTest::~ScrollBarTest()
44{
45	delete fOrientationRadioGroup;
46}
47
48
49Test*
50ScrollBarTest::CreateTest()
51{
52	return new ScrollBarTest;
53}
54
55
56void
57ScrollBarTest::ActivateTest(View* controls)
58{
59	// the radio button group for selecting the orientation
60
61	GroupView* vGroup = new GroupView(B_VERTICAL);
62	vGroup->SetFrame(controls->Bounds());
63	vGroup->SetSpacing(0, 4);
64	controls->AddChild(vGroup);
65
66	fOrientationRadioGroup = new RadioButtonGroup(
67		new BMessage(MSG_ORIENTATION_CHANGED), this);
68
69	// horizontal
70	LabeledRadioButton* button = new OrientationRadioButton("Horizontal",
71		B_HORIZONTAL);
72	vGroup->AddChild(button);
73	fOrientationRadioGroup->AddButton(button->GetRadioButton());
74
75	// vertical
76	button = new OrientationRadioButton("Vertical", B_VERTICAL);
77	vGroup->AddChild(button);
78	fOrientationRadioGroup->AddButton(button->GetRadioButton());
79
80	// default to horizontal
81	fOrientationRadioGroup->SelectButton((int32)0);
82
83	// glue
84	vGroup->AddChild(new Glue());
85}
86
87
88void
89ScrollBarTest::DectivateTest()
90{
91}
92
93
94void
95ScrollBarTest::MessageReceived(BMessage* message)
96{
97	switch (message->what) {
98		case MSG_ORIENTATION_CHANGED:
99			_UpdateOrientation();
100			break;
101		default:
102			Test::MessageReceived(message);
103			break;
104	}
105}
106
107
108void
109ScrollBarTest::_UpdateOrientation()
110{
111	if (fOrientationRadioGroup == NULL)
112		return;
113
114	// We need to get the parent of the actually selected button, since
115	// that is the labeled radio button we've derived our
116	// BorderStyleRadioButton from.
117	AbstractButton* selectedButton
118		= fOrientationRadioGroup->SelectedButton();
119	View* parent = (selectedButton ? selectedButton->Parent() : NULL);
120	OrientationRadioButton* button = dynamic_cast<OrientationRadioButton*>(
121		parent);
122	if (button)
123		fScrollBar->SetOrientation(button->fOrientation);
124}
125
126
127
128
129
130