vfs: check userland buffers before reading them.
[haiku.git] / src / tests / servers / app / view_transit / ViewTransit.cpp
blob4481417739878531d88f1f7636567a937758aa98
1 /*
2 * Copyright 2008, Stephan Aßmus <superstippi@gmx.de>
3 * Distributed under the terms of the MIT License.
4 */
7 #include <Application.h>
8 #include <Window.h>
9 #include <View.h>
11 #include <stdio.h>
14 class View : public BView {
15 public:
16 View(BRect rect, const char* name, uint32 followMode,
17 uint8 red, uint8 green, uint8 blue);
18 virtual ~View();
20 virtual void Draw(BRect updateRect);
22 virtual void MouseDown(BPoint where);
23 virtual void MouseMoved(BPoint where, uint32 transit,
24 const BMessage* dragMessage);
26 private:
27 void _SetTransit(uint32 transit);
29 uint32 fLastTransit;
33 View::View(BRect rect, const char* name, uint32 followMode,
34 uint8 red, uint8 green, uint8 blue)
35 : BView(rect, name, followMode, B_WILL_DRAW),
36 fLastTransit(B_OUTSIDE_VIEW)
38 SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
39 SetHighColor(red, green, blue);
43 View::~View()
48 void
49 View::Draw(BRect updateRect)
51 if (fLastTransit == B_INSIDE_VIEW || fLastTransit == B_ENTERED_VIEW)
52 FillRect(updateRect);
56 void
57 View::MouseDown(BPoint where)
59 uint32 buttons;
60 do {
61 GetMouse(&where, &buttons);
62 } while (buttons != 0);
66 void
67 View::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
69 _SetTransit(transit);
73 void
74 View::_SetTransit(uint32 transit)
76 if (transit == fLastTransit)
77 return;
79 switch (transit) {
80 case B_ENTERED_VIEW:
81 if (fLastTransit == B_INSIDE_VIEW)
82 printf("%s, B_ENTERED_VIEW, but already inside!\n", Name());
83 break;
85 case B_EXITED_VIEW:
86 if (fLastTransit == B_OUTSIDE_VIEW)
87 printf("%s, B_EXITED_VIEW, but already outside!\n", Name());
88 break;
90 case B_INSIDE_VIEW:
91 if (fLastTransit == B_OUTSIDE_VIEW)
92 printf("%s, B_INSIDE_VIEW, but never entered!\n", Name());
93 if (fLastTransit == B_EXITED_VIEW)
94 printf("%s, B_INSIDE_VIEW, but just exited!\n", Name());
95 break;
97 case B_OUTSIDE_VIEW:
98 if (fLastTransit == B_INSIDE_VIEW)
99 printf("%s, B_OUTSIDE_VIEW, but never exited!\n", Name());
100 if (fLastTransit == B_ENTERED_VIEW)
101 printf("%s, B_OUTSIDE_VIEW, but just entered!\n", Name());
102 break;
105 fLastTransit = transit;
106 Invalidate();
110 // #pragma mark -
113 int
114 main(int argc, char **argv)
116 BApplication app("application/x-vnd.haiku-view_transit");
118 BWindow* window = new BWindow(BRect(100, 100, 400, 400),
119 "ViewTransit-Test", B_TITLED_WINDOW,
120 B_ASYNCHRONOUS_CONTROLS | B_QUIT_ON_WINDOW_CLOSE);
122 BRect frame = window->Bounds();
123 frame.right /= 2;
124 window->AddChild(new View(frame, "L ", B_FOLLOW_ALL, 255, 0, 0));
125 frame.left = frame.right + 1;
126 frame.right = window->Bounds().right;
127 View* view = new View(frame, "R", B_FOLLOW_TOP_BOTTOM | B_FOLLOW_RIGHT,
128 0, 255, 0);
129 window->AddChild(view);
130 view->SetEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
132 window->Show();
134 app.Run();
135 return 0;