vfs: check userland buffers before reading them.
[haiku.git] / src / tests / servers / app / hide_and_show / HideAndShow.cpp
blobed5df99cdfd1ac92a37335398470ba82df5b2bac
1 /*
2 * Copyright 2005-2009, Haiku Inc.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Axel Dörfler, axeld@pinc-software.de
7 */
10 #include <stdio.h>
12 #include <Application.h>
13 #include <MessageRunner.h>
14 #include <TextView.h>
15 #include <Window.h>
18 static const uint32 kMsgToggleShow = 'tgsh';
20 class Window : public BWindow {
21 public:
22 Window();
23 virtual ~Window();
25 virtual void MessageReceived(BMessage* message);
26 virtual void FrameResized(float width, float height);
27 virtual bool QuitRequested();
29 private:
30 BMessageRunner* fRunner;
34 Window::Window()
35 : BWindow(BRect(100, 100, 400, 400), "HideAndShow-Test",
36 B_TITLED_WINDOW, B_ASYNCHRONOUS_CONTROLS)
38 BRect rect(Bounds());
39 rect.left += 20;
40 rect.right -= 20;
41 rect.top = 100;
42 rect.bottom = 200;
43 BTextView* view = new BTextView(Bounds(), "", rect, B_FOLLOW_ALL,
44 B_FRAME_EVENTS | B_WILL_DRAW);
45 view->MakeEditable(false);
46 view->SetAlignment(B_ALIGN_CENTER);
47 view->SetViewUIColor(B_PANEL_BACKGROUND_COLOR);
48 view->SetText("The window will be hidden and shown every 2 seconds.");
49 AddChild(view);
51 BMessage showAndHide(kMsgToggleShow);
52 fRunner = new BMessageRunner(this, &showAndHide, 2000000);
55 Window::~Window()
57 delete fRunner;
61 void
62 Window::MessageReceived(BMessage* message)
64 switch (message->what) {
65 case kMsgToggleShow:
66 if (IsHidden())
67 Show();
68 else
69 Hide();
70 break;
72 default:
73 BWindow::MessageReceived(message);
74 break;
79 void
80 Window::FrameResized(float width, float height)
82 BTextView* view = dynamic_cast<BTextView*>(ChildAt(0));
83 if (view == NULL)
84 return;
86 BRect rect = Bounds();
87 rect.left += 20;
88 rect.right -= 20;
89 rect.top = 100;
90 rect.bottom = 200;
91 view->SetTextRect(rect);
95 bool
96 Window::QuitRequested()
98 be_app->PostMessage(B_QUIT_REQUESTED);
99 return true;
103 // #pragma mark -
106 class Application : public BApplication {
107 public:
108 Application();
110 virtual void ReadyToRun();
114 Application::Application()
115 : BApplication("application/x-vnd.haiku-hide_and_show")
120 void
121 Application::ReadyToRun(void)
123 Window* window = new Window();
124 window->Show();
128 // #pragma mark -
132 main(int argc, char** argv)
134 Application app;
136 app.Run();
137 return 0;