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 bool useClipping, const BMessenger& target) 12 : 13 BView(frame, "test view", B_FOLLOW_ALL, B_WILL_DRAW), 14 fTest(test), 15 fTarget(target), 16 fUseClipping(useClipping) 17 { 18 SetDrawingMode(mode); 19 } 20 21 22 void 23 TestView::AttachedToWindow() 24 { 25 fTest->Prepare(this); 26 if (fUseClipping) 27 fTest->SetupClipping(this); 28 } 29 30 31 void 32 TestView::Draw(BRect updateRect) 33 { 34 if (fTest->RunIteration(this)) { 35 Invalidate(); 36 return; 37 } 38 39 fTarget.SendMessage(MSG_TEST_FINISHED); 40 } 41 42 43 TestWindow::TestWindow(BRect frame, Test* test, drawing_mode mode, 44 bool useClipping, const BMessenger& target) 45 : BWindow(frame, "Test Window", B_TITLED_WINDOW_LOOK, 46 B_FLOATING_ALL_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE), 47 fTarget(target), 48 fAllowedToQuit(false) 49 { 50 fTestView = new TestView(Bounds(), test, mode, useClipping, target); 51 AddChild(fTestView); 52 Show(); 53 } 54 55 56 bool 57 TestWindow::QuitRequested() 58 { 59 if (fAllowedToQuit) 60 return true; 61 62 fTarget.SendMessage(MSG_TEST_CANCELED); 63 return false; 64 } 65 66 67 void 68 TestWindow::SetAllowedToQuit(bool allowed) 69 { 70 fAllowedToQuit = allowed; 71 } 72 73