2 * Copyright 2014 Stephan Aßmus <superstippi@gmx.de>
3 * All rights reserved. Distributed under the terms of the MIT license.
10 #include <Application.h>
12 #include <LayoutBuilder.h>
14 #include <PopUpMenu.h>
15 #include <ScrollView.h>
18 Test::Test(const char* name
)
30 // #pragma mark - TestView
33 class TestView
: public BView
{
38 virtual void Draw(BRect updateRect
);
40 void SetTest(Test
* test
);
49 BView(NULL
, B_WILL_DRAW
| B_FULL_UPDATE_ON_RESIZE
),
61 TestView::Draw(BRect updateRect
)
64 fTest
->Draw(this, updateRect
);
69 TestView::SetTest(Test
* test
)
76 // #pragma mark - TestWindow
80 MSG_SELECT_TEST
= 'stst'
84 TestWindow::TestWindow(const char* title
)
86 BWindow(BRect(50.0, 50.0, 450.0, 250.0), title
,
87 B_DOCUMENT_WINDOW
, B_ASYNCHRONOUS_CONTROLS
| B_QUIT_ON_WINDOW_CLOSE
88 | B_AUTO_UPDATE_SIZE_LIMITS
)
90 fTestView
= new TestView();
92 BScrollView
* scrollView
= new BScrollView("scroll", fTestView
, 0, true,
95 fTestSelectionField
= new BMenuField("test selection",
96 "Select test:", new BPopUpMenu("select"));
98 BLayoutBuilder::Group
<>(this, B_VERTICAL
, 0.0f
)
99 .AddGroup(B_HORIZONTAL
)
100 .Add(fTestSelectionField
)
102 .SetInsets(B_USE_DEFAULT_SPACING
)
109 TestWindow::~TestWindow()
111 for (int32 i
= fTests
.CountItems() - 1; i
>= 0; i
++)
112 delete (Test
*)fTests
.ItemAt(i
);
117 TestWindow::MessageReceived(BMessage
* message
)
119 switch (message
->what
) {
120 case MSG_SELECT_TEST
:
123 if (message
->FindInt32("index", &index
) == B_OK
)
129 BWindow::MessageReceived(message
);
135 TestWindow::AddTest(Test
* test
)
137 if (test
== NULL
|| fTests
.HasItem(test
))
140 if (!fTests
.AddItem(test
)) {
145 BMessage
* message
= new BMessage(MSG_SELECT_TEST
);
146 message
->AddInt32("index", fTests
.CountItems() - 1);
148 BMenuItem
* item
= new BMenuItem(test
->Name(), message
);
149 if (!fTestSelectionField
->Menu()->AddItem(item
)) {
150 fTests
.RemoveItem(fTests
.CountItems() - 1);
156 if (fTests
.CountItems() == 1)
162 TestWindow::SetToTest(int32 index
)
164 Test
* test
= (Test
*)fTests
.ItemAt(index
);
168 fTestSelectionField
->Menu()->ItemAt(index
)->SetMarked(true);
170 fTestView
->SetTest(test
);