vfs: check userland buffers before reading them.
[haiku.git] / src / tests / servers / app / scrolling / main.cpp
blob8b80e23fe5b627d839b542548092849b16b344e7
1 // main.cpp
3 #include <stdio.h>
5 #include "Application.h"
6 #include "Message.h"
7 #include "Button.h"
8 #include "View.h"
9 #include "Window.h"
11 enum {
12 MSG_RESET = 'rset'
15 class TestView : public BView {
17 public:
18 TestView(BRect frame, const char* name,
19 uint32 resizeFlags, uint32 flags)
20 : BView(frame, name, resizeFlags, flags),
21 fTracking(false),
22 fLastMousePos(0.0, 0.0)
24 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
25 SetLowUIColor(ViewUIColor());
28 virtual void MessageReceived(BMessage* message);
30 virtual void Draw(BRect updateRect);
32 virtual void MouseDown(BPoint where);
33 virtual void MouseUp(BPoint where);
34 virtual void MouseMoved(BPoint where, uint32 transit,
35 const BMessage* dragMessage);
37 private:
38 bool fTracking;
40 BPoint fLastMousePos;
43 // MessageReceived
44 void
45 TestView::MessageReceived(BMessage* message)
47 if (message->what == MSG_RESET)
48 ScrollTo(0.0, 0.0);
49 else
50 BView::MessageReceived(message);
53 // Draw
54 void
55 TestView::Draw(BRect updateRect)
57 // ellipses
58 SetHighColor(200, 90, 0, 100);
59 StrokeEllipse(BPoint(80.0, 50.0), 70.0, 40.0);
61 SetDrawingMode(B_OP_ALPHA);
63 SetPenSize(2.0);
64 SetHighColor(20, 40, 180, 150);
65 StrokeEllipse(BPoint(230.0, 90.0), 14.0, 60.0);
67 SetPenSize(5.0);
68 SetHighColor(60, 20, 110, 100);
69 StrokeEllipse(BPoint(100.0, 180.0), 35.0, 25.0);
71 // text
72 SetHighColor(0, 0, 0, 255);
73 SetDrawingMode(B_OP_OVER);
74 const char* message = "Click and drag to scroll this view!";
75 DrawString(message, BPoint(0.0, 30.0));
78 // MouseDown
79 void
80 TestView::MouseDown(BPoint where)
82 fTracking = true;
83 fLastMousePos = where;
84 SetMouseEventMask(B_POINTER_EVENTS);
87 // MouseUp
88 void
89 TestView::MouseUp(BPoint where)
91 fTracking = false;
94 // MouseMoved
95 void
96 TestView::MouseMoved(BPoint where, uint32 transit,
97 const BMessage* dragMessage)
99 if (fTracking) {
100 BPoint offset = fLastMousePos - where;
101 ScrollBy(offset.x, offset.y);
102 fLastMousePos = where + offset;
108 // show_window
109 void
110 show_window(BRect frame, const char* name)
112 BWindow* window = new BWindow(frame, name,
113 B_TITLED_WINDOW,
114 B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
116 BView* view = new TestView(window->Bounds(), "test", B_FOLLOW_ALL,
117 B_WILL_DRAW/* | B_FULL_UPDATE_ON_RESIZE*/);
119 window->AddChild(view);
120 BRect b(0.0, 0.0, 60.0, 15.0);
121 b.OffsetTo(5.0, view->Bounds().bottom - (b.Height() + 15.0));
122 BButton* control = new BButton(b, "button", "Reset", new BMessage(MSG_RESET));
123 view->AddChild(control);
124 control->SetTarget(view);
126 window->Show();
129 // main
131 main(int argc, char** argv)
133 BApplication* app = new BApplication("application/x.vnd-Haiku.Scrolling");
135 BRect frame(50.0, 50.0, 300.0, 250.0);
136 show_window(frame, "Scrolling Test");
138 app->Run();
140 delete app;
141 return 0;