headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / servers / app / scrollbar / main.cpp
blob7633367322de3f02cdd475200f4c37b7dcdfb99b
1 #include <stdio.h>
3 #include <Application.h>
4 #include <ScrollBar.h>
5 #include <ScrollView.h>
6 #include <Window.h>
8 class View : public BView {
9 public:
10 View(BRect frame)
11 : BView(frame, "target view", B_FOLLOW_ALL,
12 B_WILL_DRAW | B_FRAME_EVENTS)
16 virtual void Draw(BRect updateRect)
18 BRect b = Bounds().OffsetToCopy(B_ORIGIN);
19 b.bottom = b.bottom * 2.0;
20 StrokeLine(b.LeftTop(), b.RightBottom());
23 virtual void AttachedToWindow()
25 UpdateScrollbar(Bounds().Height());
28 virtual void FrameResized(float width, float height)
30 UpdateScrollbar(height);
33 void UpdateScrollbar(float height)
35 BScrollBar* scrollBar = ScrollBar(B_VERTICAL);
36 if (!scrollBar) {
37 printf("no vertical scroll bar\n");
38 return;
40 float smallStep, bigStep;
41 scrollBar->GetSteps(&smallStep, &bigStep);
42 printf("scrollbar steps: %.1f, %.1f, proportion: %.1f\n",
43 smallStep, bigStep, scrollBar->Proportion());
45 scrollBar->SetRange(0.0, height);
46 scrollBar->SetSteps(5.0, height / 2);
48 scrollBar->GetSteps(&smallStep, &bigStep);
49 printf("scrollbar steps: %.1f, %.1f, proportion: %.1f, "
50 "range: %.1f\n",
51 smallStep, bigStep, scrollBar->Proportion(),
52 height);
57 int
58 main(int argc, char* argv[])
60 BApplication app("application/x-vnd.stippi.scrollbar_test");
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);
67 frame = window->Bounds();
68 frame.right -= B_V_SCROLL_BAR_WIDTH;
69 View* view = new View(frame);
71 BScrollView* scrollView = new BScrollView("scroll view", view,
72 B_FOLLOW_ALL, 0, false, true, B_NO_BORDER);
74 window->AddChild(scrollView);
75 window->Show();
77 app.Run();
78 return 0;