vfs: check userland buffers before reading them.
[haiku.git] / src / apps / screenshot / ScreenshotApp.cpp
blob0b5449d57aaa7ee674d6d3c36b922409986ce1ee
1 /*
2 * Copyright 2010 Wim van der Meer <WPJvanderMeer@gmail.com>
3 * All rights reserved. Distributed under the terms of the MIT license.
5 * Authors:
6 * Wim van der Meer
7 */
10 #include "ScreenshotApp.h"
12 #include <stdlib.h>
14 #include <Bitmap.h>
15 #include <Catalog.h>
16 #include <Locale.h>
17 #include <Roster.h>
19 #include "ScreenshotWindow.h"
20 #include "Utility.h"
23 ScreenshotApp::ScreenshotApp()
25 BApplication("application/x-vnd.haiku-screenshot"),
26 fUtility(new Utility),
27 fSilent(false),
28 fClipboard(false)
33 ScreenshotApp::~ScreenshotApp()
35 delete fUtility;
39 void
40 ScreenshotApp::MessageReceived(BMessage* message)
42 status_t status = B_OK;
43 switch (message->what) {
44 case SS_UTILITY_DATA:
46 BMessage bitmap;
47 status = message->FindMessage("wholeScreen", &bitmap);
48 if (status != B_OK)
49 break;
51 fUtility->wholeScreen = new BBitmap(&bitmap);
53 status = message->FindMessage("cursorBitmap", &bitmap);
54 if (status != B_OK)
55 break;
57 fUtility->cursorBitmap = new BBitmap(&bitmap);
59 status = message->FindMessage("cursorAreaBitmap", &bitmap);
60 if (status != B_OK)
61 break;
63 fUtility->cursorAreaBitmap = new BBitmap(&bitmap);
65 status = message->FindPoint("cursorPosition",
66 &fUtility->cursorPosition);
67 if (status != B_OK)
68 break;
70 status = message->FindRect("activeWindowFrame",
71 &fUtility->activeWindowFrame);
72 if (status != B_OK)
73 break;
75 status = message->FindRect("tabFrame", &fUtility->tabFrame);
76 if (status != B_OK)
77 break;
79 status = message->FindFloat("borderSize", &fUtility->borderSize);
80 if (status != B_OK)
81 break;
83 break;
86 default:
87 BApplication::MessageReceived(message);
88 break;
91 if (status != B_OK)
92 be_app->PostMessage(B_QUIT_REQUESTED);
96 void
97 ScreenshotApp::ArgvReceived(int32 argc, char** argv)
99 for (int32 i = 0; i < argc; i++) {
100 if (strcmp(argv[i], "-s") == 0
101 || strcmp(argv[i], "--silent") == 0)
102 fSilent = true;
103 else if (strcmp(argv[i], "-c") == 0
104 || strcmp(argv[i], "--clipboard") == 0)
105 fClipboard = true;
110 void
111 ScreenshotApp::ReadyToRun()
113 new ScreenshotWindow(*fUtility, fSilent, fClipboard);
118 main()
120 ScreenshotApp app;
121 return app.Run();