xref: /haiku/src/apps/screenshot/ScreenshotApp.cpp (revision a5bf12376daeded4049521eb17a6cc41192250d9)
1 /*
2  * Copyright 2010 Wim van der Meer <WPJvanderMeer@gmail.com>
3  * All rights reserved. Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Wim van der Meer
7  */
8 
9 
10 #include "ScreenshotApp.h"
11 
12 #include <stdlib.h>
13 
14 #include <Bitmap.h>
15 #include <Locale.h>
16 #include <Roster.h>
17 
18 #include "ScreenshotWindow.h"
19 #include "Utility.h"
20 
21 
22 ScreenshotApp::ScreenshotApp()
23 	:
24 	BApplication("application/x-vnd.haiku-screenshot"),
25 	fUtility(new Utility)
26 {
27 	be_locale->GetAppCatalog(&fCatalog);
28 }
29 
30 
31 ScreenshotApp::~ScreenshotApp()
32 {
33 	delete fUtility;
34 }
35 
36 
37 void
38 ScreenshotApp::MessageReceived(BMessage* message)
39 {
40 	status_t status = B_OK;
41 	switch (message->what) {
42 		case SS_UTILITY_DATA:
43 		{
44 			BMessage bitmap;
45 			status = message->FindMessage("wholeScreen", &bitmap);
46 			if (status != B_OK)
47 				break;
48 
49 			fUtility->wholeScreen = new BBitmap(&bitmap);
50 
51 			status = message->FindMessage("cursorBitmap", &bitmap);
52 			if (status != B_OK)
53 				break;
54 
55 			fUtility->cursorBitmap = new BBitmap(&bitmap);
56 
57 			status = message->FindMessage("cursorAreaBitmap", &bitmap);
58 			if (status != B_OK)
59 				break;
60 
61 			fUtility->cursorAreaBitmap = new BBitmap(&bitmap);
62 
63 			status = message->FindPoint("cursorPosition",
64 				&fUtility->cursorPosition);
65 			if (status != B_OK)
66 				break;
67 
68 			status = message->FindRect("activeWindowFrame",
69 				&fUtility->activeWindowFrame);
70 			if (status != B_OK)
71 				break;
72 
73 			status = message->FindRect("tabFrame", &fUtility->tabFrame);
74 			if (status != B_OK)
75 				break;
76 
77 			status = message->FindFloat("borderSize", &fUtility->borderSize);
78 			if (status != B_OK)
79 				break;
80 
81 			break;
82 		}
83 
84 		default:
85 			BApplication::MessageReceived(message);
86 			break;
87 	}
88 
89 	if (status != B_OK)
90 		be_app->PostMessage(B_QUIT_REQUESTED);
91 }
92 
93 
94 void
95 ScreenshotApp::ReadyToRun()
96 {
97 	new ScreenshotWindow(*fUtility);
98 }
99 
100 
101 int
102 main()
103 {
104 	ScreenshotApp app;
105 	return app.Run();
106 }
107