xref: /haiku/src/tests/servers/app/scrollbar/main.cpp (revision b35b070b5940433d125d18253929f5dc08dfed66)
1 #include <stdio.h>
2 
3 #include <Application.h>
4 #include <ScrollBar.h>
5 #include <ScrollView.h>
6 #include <Window.h>
7 
8 class View : public BView {
9 public:
View(BRect frame)10 	View(BRect frame)
11 		: BView(frame, "target view", B_FOLLOW_ALL,
12 			B_WILL_DRAW | B_FRAME_EVENTS)
13 	{
14 	}
15 
Draw(BRect updateRect)16 	virtual void Draw(BRect updateRect)
17 	{
18 		BRect b = Bounds().OffsetToCopy(B_ORIGIN);
19 		b.bottom = b.bottom * 2.0;
20 		StrokeLine(b.LeftTop(), b.RightBottom());
21 	}
22 
AttachedToWindow()23 	virtual	void AttachedToWindow()
24 	{
25 		UpdateScrollbar(Bounds().Height());
26 	}
27 
FrameResized(float width,float height)28 	virtual void FrameResized(float width, float height)
29 	{
30 		UpdateScrollbar(height);
31 	}
32 
UpdateScrollbar(float height)33 	void UpdateScrollbar(float height)
34 	{
35 		BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
36 		if (!scrollBar) {
37 			printf("no vertical scroll bar\n");
38 			return;
39 		}
40 		float smallStep, bigStep;
41 		scrollBar->GetSteps(&smallStep, &bigStep);
42 		printf("scrollbar steps: %.1f, %.1f, proportion: %.1f\n",
43 			smallStep, bigStep, scrollBar->Proportion());
44 
45 		scrollBar->SetRange(0.0, height);
46 		scrollBar->SetSteps(5.0, height / 2);
47 
48 		scrollBar->GetSteps(&smallStep, &bigStep);
49 		printf("scrollbar steps: %.1f, %.1f, proportion: %.1f, "
50 			"range: %.1f\n",
51 			smallStep, bigStep, scrollBar->Proportion(),
52 			height);
53 	}
54 };
55 
56 
57 int
main(int argc,char * argv[])58 main(int argc, char* argv[])
59 {
60 	BApplication app("application/x-vnd.stippi.scrollbar_test");
61 
62 	BRect frame(50, 50, 350, 350);
63 	BWindow* window = new BWindow(frame, "BScrollBar Test",
64 		B_TITLED_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
65 		B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
66 
67 	frame = window->Bounds();
68 	frame.right -= B_V_SCROLL_BAR_WIDTH;
69 	View* view = new View(frame);
70 
71 	BScrollView* scrollView = new BScrollView("scroll view", view,
72 		B_FOLLOW_ALL, 0, false, true, B_NO_BORDER);
73 
74 	window->AddChild(scrollView);
75 	window->Show();
76 
77 	app.Run();
78 	return 0;
79 }
80 
81 
82