xref: /haiku/src/tests/servers/app/benchmark/TestWindow.cpp (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
1 /*
2  * Copyright (C) 2008 Stephan Aßmus <superstippi@gmx.de>
3  * All rights reserved. Distributed under the terms of the MIT license.
4  */
5 #include "TestWindow.h"
6 
7 #include "Test.h"
8 
9 
10 TestView::TestView(BRect frame, Test* test, drawing_mode mode,
11 		const BMessenger& target)
12 	: BView(frame, "test view", B_FOLLOW_ALL, B_WILL_DRAW),
13 	  fTest(test),
14 	  fTarget(target)
15 {
16 	SetDrawingMode(mode);
17 }
18 
19 
20 void
21 TestView::AttachedToWindow()
22 {
23 	fTest->Prepare(this);
24 }
25 
26 
27 void
28 TestView::Draw(BRect updateRect)
29 {
30 	if (fTest->RunIteration(this)) {
31 		Invalidate();
32 		return;
33 	}
34 
35 	fTarget.SendMessage(MSG_TEST_FINISHED);
36 }
37 
38 
39 TestWindow::TestWindow(BRect frame, Test* test, drawing_mode mode,
40 		const BMessenger& target)
41 	: BWindow(frame, "Test Window", B_TITLED_WINDOW_LOOK,
42 		B_FLOATING_ALL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE),
43 	  fTarget(target),
44 	  fAllowedToQuit(false)
45 {
46 	TestView* view = new TestView(Bounds(), test, mode, target);
47 	AddChild(view);
48 	Show();
49 }
50 
51 
52 bool
53 TestWindow::QuitRequested()
54 {
55 	if (fAllowedToQuit)
56 		return true;
57 
58 	fTarget.SendMessage(MSG_TEST_CANCELED);
59 	return false;
60 }
61 
62 
63 void
64 TestWindow::SetAllowedToQuit(bool allowed)
65 {
66 	fAllowedToQuit = allowed;
67 }
68 
69