18afcf72aSAxel Dörfler /* 28afcf72aSAxel Dörfler ** Copyright 2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 38afcf72aSAxel Dörfler ** Distributed under the terms of the OpenBeOS License. 48afcf72aSAxel Dörfler */ 58afcf72aSAxel Dörfler 68afcf72aSAxel Dörfler 78afcf72aSAxel Dörfler #include <ScrollView.h> 88afcf72aSAxel Dörfler 98afcf72aSAxel Dörfler #include <Application.h> 108afcf72aSAxel Dörfler #include <Window.h> 118afcf72aSAxel Dörfler #include <Box.h> 128afcf72aSAxel Dörfler 13c81fdc88SAxel Dörfler #include <stdio.h> 14c81fdc88SAxel Dörfler 15c81fdc88SAxel Dörfler 16*a8c4af5aSAxel Dörfler //#define ARCHIVE_TEST 17*a8c4af5aSAxel Dörfler //#define CHANGE_BORDER_TEST 18*a8c4af5aSAxel Dörfler //#define SIZE_TEST 19c81fdc88SAxel Dörfler 208afcf72aSAxel Dörfler 218afcf72aSAxel Dörfler class Window : public BWindow { 228afcf72aSAxel Dörfler public: 238afcf72aSAxel Dörfler Window(); 248afcf72aSAxel Dörfler virtual ~Window(); 258afcf72aSAxel Dörfler 268afcf72aSAxel Dörfler virtual bool QuitRequested(); 278afcf72aSAxel Dörfler }; 288afcf72aSAxel Dörfler 298afcf72aSAxel Dörfler 308afcf72aSAxel Dörfler Window::Window() 318afcf72aSAxel Dörfler : BWindow(BRect(100, 100, 580, 580), "Scroll-Test", 32*a8c4af5aSAxel Dörfler B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS) 338afcf72aSAxel Dörfler { 348afcf72aSAxel Dörfler const bool horiz[] = {false, true, false, true}; 358afcf72aSAxel Dörfler const bool vert[] = {false, false, true, true}; 368afcf72aSAxel Dörfler const border_style border[] = {B_NO_BORDER, B_PLAIN_BORDER, B_FANCY_BORDER, B_FANCY_BORDER}; 378afcf72aSAxel Dörfler BRect rect(1, 1, 119, 119); 388afcf72aSAxel Dörfler BRect frame = rect.InsetByCopy(20, 20); 398afcf72aSAxel Dörfler 408afcf72aSAxel Dörfler for (int32 i = 0; i < 16; i++) { 418afcf72aSAxel Dörfler if (i > 0 && (i % 4) == 0) 428afcf72aSAxel Dörfler rect.OffsetBy(-480, 120); 438afcf72aSAxel Dörfler 44*a8c4af5aSAxel Dörfler int32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP; 45*a8c4af5aSAxel Dörfler if (i % 4 == 3) { 46*a8c4af5aSAxel Dörfler if (i == 15) 47*a8c4af5aSAxel Dörfler resizingMode = B_FOLLOW_ALL; 48*a8c4af5aSAxel Dörfler else 49*a8c4af5aSAxel Dörfler resizingMode = B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP; 50*a8c4af5aSAxel Dörfler } else if (i > 11) 51*a8c4af5aSAxel Dörfler resizingMode = B_FOLLOW_TOP_BOTTOM | B_FOLLOW_LEFT; 52*a8c4af5aSAxel Dörfler 53*a8c4af5aSAxel Dörfler BBox *box = new BBox(rect, "box", resizingMode); 548afcf72aSAxel Dörfler AddChild(box); 558afcf72aSAxel Dörfler 568afcf72aSAxel Dörfler BView *view = new BView(frame, "main view", B_FOLLOW_ALL, B_WILL_DRAW); 57*a8c4af5aSAxel Dörfler view->SetViewColor(200, 200, 21); 58*a8c4af5aSAxel Dörfler BView *inner = new BView(frame.OffsetToCopy(B_ORIGIN).InsetBySelf(3, 3), 598afcf72aSAxel Dörfler "inner", B_FOLLOW_ALL, B_WILL_DRAW); 608afcf72aSAxel Dörfler inner->SetViewColor(200, 42, 42); 618afcf72aSAxel Dörfler view->AddChild(inner); 628afcf72aSAxel Dörfler 63*a8c4af5aSAxel Dörfler BScrollView *scroller = new BScrollView("scroller", view, resizingMode, 648afcf72aSAxel Dörfler 0, horiz[i % 4], vert[i % 4], border[i / 4]); 658afcf72aSAxel Dörfler if (i >= 12) 668afcf72aSAxel Dörfler scroller->SetBorderHighlighted(true); 678afcf72aSAxel Dörfler box->AddChild(scroller); 688afcf72aSAxel Dörfler 69*a8c4af5aSAxel Dörfler #ifdef ARCHIVE_TEST 70c81fdc88SAxel Dörfler if (i == 7) { 71c81fdc88SAxel Dörfler BMessage archive; 72c81fdc88SAxel Dörfler if (scroller->Archive(&archive/*, false*/) == B_OK) { 73c81fdc88SAxel Dörfler puts("BScrollView archived:"); 74c81fdc88SAxel Dörfler archive.PrintToStream(); 75c81fdc88SAxel Dörfler } else 76c81fdc88SAxel Dörfler puts("archiving failed!"); 77c81fdc88SAxel Dörfler 78c81fdc88SAxel Dörfler BScrollView *second = (BScrollView *)BScrollView::Instantiate(&archive); 79c81fdc88SAxel Dörfler archive.MakeEmpty(); 80c81fdc88SAxel Dörfler if (second != NULL && second->Archive(&archive) == B_OK) { 81c81fdc88SAxel Dörfler puts("2. BScrollView archived:"); 82c81fdc88SAxel Dörfler archive.PrintToStream(); 83c81fdc88SAxel Dörfler } 84c81fdc88SAxel Dörfler } 85*a8c4af5aSAxel Dörfler #endif 86c81fdc88SAxel Dörfler 87*a8c4af5aSAxel Dörfler #ifdef CHANGE_BORDER_TEST 88*a8c4af5aSAxel Dörfler if (i % 4 == 1) 89c81fdc88SAxel Dörfler scroller->SetBorder(B_FANCY_BORDER); 90*a8c4af5aSAxel Dörfler else if (i % 4 == 2) 91*a8c4af5aSAxel Dörfler scroller->SetBorder(B_PLAIN_BORDER); 92*a8c4af5aSAxel Dörfler else if (i % 4 == 3) 93*a8c4af5aSAxel Dörfler scroller->SetBorder(B_NO_BORDER); 94c81fdc88SAxel Dörfler #endif 95c81fdc88SAxel Dörfler 968afcf72aSAxel Dörfler rect.OffsetBy(120, 0); 978afcf72aSAxel Dörfler } 98c81fdc88SAxel Dörfler 99*a8c4af5aSAxel Dörfler #ifdef SIZE_TEST 100*a8c4af5aSAxel Dörfler printf("sizeof = %lu (R5 == 212)\n", sizeof(BScrollView)); 101c81fdc88SAxel Dörfler #endif 1028afcf72aSAxel Dörfler } 1038afcf72aSAxel Dörfler 1048afcf72aSAxel Dörfler 1058afcf72aSAxel Dörfler Window::~Window() 1068afcf72aSAxel Dörfler { 1078afcf72aSAxel Dörfler } 1088afcf72aSAxel Dörfler 1098afcf72aSAxel Dörfler 1108afcf72aSAxel Dörfler bool 1118afcf72aSAxel Dörfler Window::QuitRequested() 1128afcf72aSAxel Dörfler { 1138afcf72aSAxel Dörfler be_app->PostMessage(B_QUIT_REQUESTED); 1148afcf72aSAxel Dörfler return true; 1158afcf72aSAxel Dörfler } 1168afcf72aSAxel Dörfler 1178afcf72aSAxel Dörfler 1188afcf72aSAxel Dörfler // #pragma mark - 1198afcf72aSAxel Dörfler 1208afcf72aSAxel Dörfler 1218afcf72aSAxel Dörfler class Application : public BApplication { 1228afcf72aSAxel Dörfler public: 1238afcf72aSAxel Dörfler Application(); 1248afcf72aSAxel Dörfler 1258afcf72aSAxel Dörfler virtual void ReadyToRun(void); 1268afcf72aSAxel Dörfler }; 1278afcf72aSAxel Dörfler 1288afcf72aSAxel Dörfler 1298afcf72aSAxel Dörfler Application::Application() 1308afcf72aSAxel Dörfler : BApplication("application/x-vnd.obos-test") 1318afcf72aSAxel Dörfler { 1328afcf72aSAxel Dörfler } 1338afcf72aSAxel Dörfler 1348afcf72aSAxel Dörfler 1358afcf72aSAxel Dörfler void 1368afcf72aSAxel Dörfler Application::ReadyToRun(void) 1378afcf72aSAxel Dörfler { 1388afcf72aSAxel Dörfler Window *window = new Window(); 1398afcf72aSAxel Dörfler window->Show(); 1408afcf72aSAxel Dörfler } 1418afcf72aSAxel Dörfler 1428afcf72aSAxel Dörfler 1438afcf72aSAxel Dörfler // #pragma mark - 1448afcf72aSAxel Dörfler 1458afcf72aSAxel Dörfler 1468afcf72aSAxel Dörfler int 1478afcf72aSAxel Dörfler main(int argc, char **argv) 1488afcf72aSAxel Dörfler { 1498afcf72aSAxel Dörfler Application app; 1508afcf72aSAxel Dörfler 1518afcf72aSAxel Dörfler app.Run(); 1528afcf72aSAxel Dörfler return 0; 1538afcf72aSAxel Dörfler } 1548afcf72aSAxel Dörfler 155