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
16 enum {
17 MSG_ORIENTATION_CHANGED = 'orch'
18 };
19
20
21 // OrientationRadioButton
22 class ScrollBarTest::OrientationRadioButton : public LabeledRadioButton {
23 public:
OrientationRadioButton(const char * label,enum orientation orientation)24 OrientationRadioButton(const char* label, enum orientation orientation)
25 : LabeledRadioButton(label),
26 fOrientation(orientation)
27 {
28 }
29
30 enum orientation fOrientation;
31 };
32
33
ScrollBarTest()34 ScrollBarTest::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
~ScrollBarTest()43 ScrollBarTest::~ScrollBarTest()
44 {
45 delete fOrientationRadioGroup;
46 }
47
48
49 Test*
CreateTest()50 ScrollBarTest::CreateTest()
51 {
52 return new ScrollBarTest;
53 }
54
55
56 void
ActivateTest(View * controls)57 ScrollBarTest::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
88 void
DectivateTest()89 ScrollBarTest::DectivateTest()
90 {
91 }
92
93
94 void
MessageReceived(BMessage * message)95 ScrollBarTest::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
108 void
_UpdateOrientation()109 ScrollBarTest::_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