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 <Catalog.h> 16 #include <Locale.h> 17 #include <Roster.h> 18 19 #include "ScreenshotWindow.h" 20 #include "Utility.h" 21 22 23 ScreenshotApp::ScreenshotApp() 24 : 25 BApplication("application/x-vnd.haiku-screenshot"), 26 fUtility(new Utility), 27 fSilent(false), 28 fClipboard(false) 29 { 30 be_locale->GetAppCatalog(&fCatalog); 31 } 32 33 34 ScreenshotApp::~ScreenshotApp() 35 { 36 delete fUtility; 37 } 38 39 40 void 41 ScreenshotApp::MessageReceived(BMessage* message) 42 { 43 status_t status = B_OK; 44 switch (message->what) { 45 case SS_UTILITY_DATA: 46 { 47 BMessage bitmap; 48 status = message->FindMessage("wholeScreen", &bitmap); 49 if (status != B_OK) 50 break; 51 52 fUtility->wholeScreen = new BBitmap(&bitmap); 53 54 status = message->FindMessage("cursorBitmap", &bitmap); 55 if (status != B_OK) 56 break; 57 58 fUtility->cursorBitmap = new BBitmap(&bitmap); 59 60 status = message->FindMessage("cursorAreaBitmap", &bitmap); 61 if (status != B_OK) 62 break; 63 64 fUtility->cursorAreaBitmap = new BBitmap(&bitmap); 65 66 status = message->FindPoint("cursorPosition", 67 &fUtility->cursorPosition); 68 if (status != B_OK) 69 break; 70 71 status = message->FindRect("activeWindowFrame", 72 &fUtility->activeWindowFrame); 73 if (status != B_OK) 74 break; 75 76 status = message->FindRect("tabFrame", &fUtility->tabFrame); 77 if (status != B_OK) 78 break; 79 80 status = message->FindFloat("borderSize", &fUtility->borderSize); 81 if (status != B_OK) 82 break; 83 84 break; 85 } 86 87 default: 88 BApplication::MessageReceived(message); 89 break; 90 } 91 92 if (status != B_OK) 93 be_app->PostMessage(B_QUIT_REQUESTED); 94 } 95 96 97 void 98 ScreenshotApp::ArgvReceived(int32 argc, char** argv) 99 { 100 for (int32 i = 0; i < argc; i++) { 101 if (strcmp(argv[i], "-s") == 0 102 || strcmp(argv[i], "--silent") == 0) 103 fSilent = true; 104 else if (strcmp(argv[i], "-c") == 0 105 || strcmp(argv[i], "--clipboard") == 0) 106 fClipboard = true; 107 } 108 } 109 110 111 void 112 ScreenshotApp::ReadyToRun() 113 { 114 new ScreenshotWindow(*fUtility, fSilent, fClipboard); 115 } 116 117 118 int 119 main() 120 { 121 ScreenshotApp app; 122 return app.Run(); 123 } 124