Author: wim Date: 2010-06-05 13:23:22 +0200 (Sat, 05 Jun 2010) New Revision: 37017 Changeset: http://dev.haiku-os.org/changeset/37017/haiku Ticket: http://dev.haiku-os.org/ticket/3831 Ticket: http://dev.haiku-os.org/ticket/3831 Ticket: http://dev.haiku-os.org/ticket/4100 Ticket: http://dev.haiku-os.org/ticket/4100 Ticket: http://dev.haiku-os.org/ticket/3112 Ticket: http://dev.haiku-os.org/ticket/4878 Ticket: http://dev.haiku-os.org/ticket/4423 Ticket: http://dev.haiku-os.org/ticket/2988 Ticket: http://dev.haiku-os.org/ticket/2997 Added: haiku/trunk/src/apps/screenshot/ScreenshotApp.cpp haiku/trunk/src/apps/screenshot/ScreenshotApp.h haiku/trunk/src/apps/screenshot/ScreenshotApp.rdef haiku/trunk/src/apps/screenshot/Utility.cpp haiku/trunk/src/apps/screenshot/Utility.h Removed: haiku/trunk/src/apps/screenshot/main.cpp Modified: haiku/trunk/build/jam/HaikuImage haiku/trunk/src/apps/screenshot/Jamfile haiku/trunk/src/apps/screenshot/Screenshot.cpp haiku/trunk/src/apps/screenshot/Screenshot.h haiku/trunk/src/apps/screenshot/Screenshot.rdef haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp haiku/trunk/src/apps/screenshot/ScreenshotWindow.h Log: Screenshot application enhancements: - Remove the options panel, and the "-o, --options" switch, put all options inside the main panel as discussed in ticket #3831. - Add a "Copy to clipboard" button, as discussed in ticket #3831. - Add a "-c, --clipboard" switch to quickly copy a screenshot to the clipboard without launching the GUI. - All settings apply directly to the current schreenshot as well as new Screenshots, as discussed in ticket #4100. - Separate executables for the CLI (Screenshot) and GUI (ScreenshotApp). When "Screenshot" is launched it runs in the background, and launches the GUI (if not run with the -s or -c switch) before quiting itself. When a new screenshot is requested through the ScreenshotApp GUI interface, ScreenshotApp launches Screenshot before quiting itself, after which Screenshot re-launches ScreenshotApp. This fixes ticket #4100. Note that because of this change the deskbar entry will show "ScreenshotApp" and not "Screenshot" as might be expected. I am not sure if this is a problem. - Fixed the code that determines the active window because it was just finding the top most window. This change fixes tickets #3112, #4878, and #4423. - Hide the cursor by calling BApplication::HideCursor(). This fixes ticket #2988 (but *not* #2997). Modified: haiku/trunk/build/jam/HaikuImage =================================================================== --- haiku/trunk/build/jam/HaikuImage 2010-06-05 02:10:14 UTC (rev 37016) +++ haiku/trunk/build/jam/HaikuImage 2010-06-05 11:23:22 UTC (rev 37017) @@ -66,7 +66,8 @@ DiskProbe DiskUsage DriveSetup CDPlayer Expander Icon-O-Matic Installer LaunchBox Magnify Mail MediaConverter MediaPlayer MidiPlayer NetworkStatus PackageInstaller People PoorMan PowerStatus ProcessController Screenshot - ShowImage SoundRecorder StyledEdit Terminal TextSearch TV Workspaces + ScreenshotApp ShowImage SoundRecorder StyledEdit Terminal TextSearch TV + Workspaces ; SYSTEM_PREFERENCES = Appearance Backgrounds CPUFrequency DataTranslations <preference>Deskbar E-mail FileTypes Fonts Keyboard Keymap Locale Media Modified: haiku/trunk/src/apps/screenshot/Jamfile =================================================================== --- haiku/trunk/src/apps/screenshot/Jamfile 2010-06-05 02:10:14 UTC (rev 37016) +++ haiku/trunk/src/apps/screenshot/Jamfile 2010-06-05 11:23:22 UTC (rev 37017) @@ -1,19 +1,26 @@ SubDir HAIKU_TOP src apps screenshot ; -UseLibraryHeaders zlib ; UsePrivateHeaders interface ; -Application Screenshot : - main.cpp +Application ScreenshotApp : + ScreenshotApp.cpp + ScreenshotWindow.cpp PreviewView.cpp - Screenshot.cpp - ScreenshotWindow.cpp - : be tracker translation libz.so liblocale.so $(TARGET_LIBSUPC++) - : Screenshot.rdef + Utility.cpp + : be locale tracker translation $(TARGET_LIBSUPC++) + : ScreenshotApp.rdef ; -DoCatalogs Screenshot : - x-vnd.Haiku-Screenshot +DoCatalogs ScreenshotApp : + x-vnd.Haiku-ScreenshotApp : - ScreenshotWindow.cpp + ScreenshotWindow.cpp + Utility.cpp ; + +Application Screenshot : + Screenshot.cpp + Utility.cpp + : be locale translation $(TARGET_LIBSUPC++) + : Screenshot.rdef +; Modified: haiku/trunk/src/apps/screenshot/Screenshot.cpp =================================================================== --- haiku/trunk/src/apps/screenshot/Screenshot.cpp 2010-06-05 02:10:14 UTC (rev 37016) +++ haiku/trunk/src/apps/screenshot/Screenshot.cpp 2010-06-05 11:23:22 UTC (rev 37017) @@ -1,35 +1,39 @@ /* + * Copyright 2010 Wim van der Meer <WPJvanderMeer@xxxxxxxxx> * Copyright Karsten Heimrich, host.haiku@xxxxxxx All rights reserved. * Distributed under the terms of the MIT License. * * Authors: * Karsten Heimrich * Fredrik Modéen + * Christophe Huriaux + * Wim van der Meer */ #include "Screenshot.h" - #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <Catalog.h> + +#include <AppDefs.h> +#include <Bitmap.h> #include <Locale.h> - - +#include <Roster.h> +#include <Screen.h> #include <TranslatorFormats.h> +#include <WindowInfo.h> -#include "ScreenshotWindow.h" +#include "Utility.h" Screenshot::Screenshot() : BApplication("application/x-vnd.Haiku-Screenshot"), - fArgvReceived(false), - fRefsReceived(false), - fImageFileType(B_PNG_FORMAT) + fUtility(new Utility()), + fLaunchGui(true) { be_locale->GetAppCatalog(&fCatalog); } @@ -37,59 +41,21 @@ Screenshot::~Screenshot() { + delete fUtility; } void -Screenshot::ReadyToRun() -{ - if (!fArgvReceived && !fRefsReceived) - new ScreenshotWindow(); - - fArgvReceived = false; - fRefsReceived = false; -} - - -void -Screenshot::RefsReceived(BMessage* message) -{ - int32 delay = 0; - message->FindInt32("delay", &delay); - - bool includeBorder = false; - message->FindBool("border", &includeBorder); - - bool includeMouse = false; - message->FindBool("border", &includeMouse); - - bool grabActiveWindow = false; - message->FindBool("window", &grabActiveWindow); - - bool saveScreenshotSilent = false; - message->FindBool("silent", &saveScreenshotSilent); - - bool showConfigureWindow = false; - message->FindBool("configure", &showConfigureWindow); - - new ScreenshotWindow(delay * 1000000, includeBorder, includeMouse, - grabActiveWindow, showConfigureWindow, saveScreenshotSilent); - - fRefsReceived = true; -} - - -void Screenshot::ArgvReceived(int32 argc, char** argv) { bigtime_t delay = 0; - const char* outputFilename = NULL; bool includeBorder = false; - bool includeMouse = false; + bool includeCursor = false; bool grabActiveWindow = false; - bool showConfigureWindow = false; bool saveScreenshotSilent = false; + bool copyToClipboard = false; + uint32 imageFileType = B_PNG_FORMAT; for (int32 i = 0; i < argc; i++) { if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) @@ -99,21 +65,18 @@ includeBorder = true; else if (strcmp(argv[i], "-m") == 0 || strcmp(argv[i], "--mouse-pointer") == 0) - includeMouse = true; + includeCursor = true; else if (strcmp(argv[i], "-w") == 0 || strcmp(argv[i], "--window") == 0) grabActiveWindow = true; else if (strcmp(argv[i], "-s") == 0 || strcmp(argv[i], "--silent") == 0) saveScreenshotSilent = true; - else if (strcmp(argv[i], "-o") == 0 - || strcmp(argv[i], "--options") == 0) - showConfigureWindow = true; else if (strcmp(argv[i], "-f") == 0 || strncmp(argv[i], "--format", 6) == 0 - || strncmp(argv[i], "--format=", 7) == 0) { - _SetImageTypeSilence(argv[i + 1]); - } else if (strcmp(argv[i], "-d") == 0 + || strncmp(argv[i], "--format=", 7) == 0) + imageFileType = _GetImageType(argv[i + 1]); + else if (strcmp(argv[i], "-d") == 0 || strncmp(argv[i], "--delay", 7) == 0 || strncmp(argv[i], "--delay=", 8) == 0) { int32 seconds = -1; @@ -123,60 +86,306 @@ delay = seconds * 1000000; i++; } else { - printf("Screenshot: option requires an argument -- %s\n" - , argv[i]); - exit(0); + printf("Screenshot: option requires an argument -- %s\n", + argv[i]); + fLaunchGui = false; + return; } - } else if (i == argc - 1) + } else if (strcmp(argv[i], "-c") == 0 + || strcmp(argv[i], "--clipboard") == 0) + copyToClipboard = true; + else if (i == argc - 1) outputFilename = argv[i]; } + + if (argc > 1) + _New(delay); + + if (copyToClipboard || saveScreenshotSilent) { + fLaunchGui = false; + + BBitmap* screenshot = fUtility->MakeScreenshot(includeCursor, + grabActiveWindow, includeBorder); + + if (screenshot == NULL) + return; + + if (copyToClipboard) + fUtility->CopyToClipboard(*screenshot); - fArgvReceived = true; - - new ScreenshotWindow(delay, includeBorder, includeMouse, grabActiveWindow, - showConfigureWindow, saveScreenshotSilent, fImageFileType, - outputFilename); + if (saveScreenshotSilent) + fUtility->Save(&screenshot, outputFilename, imageFileType); + + delete screenshot; + } } void -Screenshot::_ShowHelp() const +Screenshot::ReadyToRun() { - printf("Screenshot [OPTIONS] [FILE] Creates a bitmap of the current screen\n\n"); - printf("FILE is the optional output path / filename used in silent mode. If FILE is not given, a default filename will be generated in the prefered directory.\n\n"); + if (fLaunchGui) { + // Launch the GUI application + if (fUtility->wholeScreen == NULL) { + // No command line parameters were given + be_roster->Launch("application/x-vnd.Haiku-ScreenshotApp"); + } else { + // Send the utility data and the command line settings to the GUI + BMessage message; + message.what = SS_UTILITY_DATA; + + BMessage* bitmap = new BMessage(); + fUtility->wholeScreen->Archive(bitmap); + message.AddMessage("wholeScreen", bitmap); + + bitmap = new BMessage(); + fUtility->cursorBitmap->Archive(bitmap); + message.AddMessage("cursorBitmap", bitmap); + + bitmap = new BMessage(); + fUtility->cursorAreaBitmap->Archive(bitmap); + message.AddMessage("cursorAreaBitmap", bitmap); + + message.AddPoint("cursorPosition", fUtility->cursorPosition); + message.AddRect("activeWindowFrame", fUtility->activeWindowFrame); + message.AddRect("tabFrame", fUtility->tabFrame); + message.AddFloat("borderSize", fUtility->borderSize); + + be_roster->Launch("application/x-vnd.Haiku-ScreenshotApp", + &message); + } + } + + be_app->PostMessage(B_QUIT_REQUESTED); +} + + +void +Screenshot::_ShowHelp() +{ + printf("Screenshot [OPTIONS] [FILE] Creates a bitmap of the current " + "screen\n\n"); + printf("FILE is the optional output path / filename used in silent mode. " + "An exisiting\nfile with the same name will be overwritten without " + "warning. If FILE is not\ngiven the screenshot will be saved to a " + "file with the default filename in the\nuser's home directory.\n\n"); printf("OPTIONS\n"); - printf(" -o, --options Show options window first\n"); printf(" -m, --mouse-pointer Include the mouse pointer\n"); printf(" -b, --border Include the window border\n"); - printf(" -w, --window Capture the active window instead of the entire screen\n"); - printf(" -d, --delay=seconds Take screenshot after specified delay [in seconds]\n"); - printf(" -s, --silent Saves the screenshot without showing the app window\n"); - printf(" overrides --options\n"); - printf(" -f, --format=image Write the image format you like to save as\n"); - printf(" [bmp], [gif], [jpg], [png], [ppm], [targa], [tiff]\n"); + printf(" -w, --window Capture the active window instead of the " + "entire screen\n"); + printf(" -d, --delay=seconds Take screenshot after the specified delay " + "[in seconds]\n"); + printf(" -s, --silent Saves the screenshot without showing the " + "application\n window\n"); + printf(" -f, --format=image Give the image format you like to save " + "as\n"); + printf(" [bmp], [gif], [jpg], [png], [ppm], " + "[tga], [tif]\n"); + printf(" -c, --clipboard Copies the screenshot to the system " + "clipboard without\n showing the application " + "window\n"); printf("\n"); - printf("Note: OPTION -b, --border takes only effect when used with -w, --window\n"); - exit(0); + printf("Note: OPTION -b, --border takes only effect when used with -w, " + "--window\n"); + + fLaunchGui = false; } void -Screenshot::_SetImageTypeSilence(const char* name) +Screenshot::_New(bigtime_t delay) { + delete fUtility->wholeScreen; + delete fUtility->cursorBitmap; + delete fUtility->cursorAreaBitmap; + + if (delay > 0) + snooze(delay); + + _GetActiveWindowFrame(); + + // There is a bug in the drawEngine code that prevents the drawCursor + // flag from hiding the cursor when GetBitmap is called, so we need to hide + // the cursor by ourselves. Refer to trac tickets #2988 and #2997 + bool cursorIsHidden = IsCursorHidden(); + if (!cursorIsHidden) + HideCursor(); + if (BScreen().GetBitmap(&fUtility->wholeScreen, false) != B_OK) + return; + if (!cursorIsHidden) + ShowCursor(); + + // Get the current cursor position, bitmap, and hotspot + BPoint cursorHotSpot; + get_mouse(&fUtility->cursorPosition, NULL); + get_mouse_bitmap(&fUtility->cursorBitmap, &cursorHotSpot); + fUtility->cursorPosition -= cursorHotSpot; + + // Put the mouse area in a bitmap + BRect bounds = fUtility->cursorBitmap->Bounds(); + int cursorWidth = bounds.IntegerWidth() + 1; + int cursorHeight = bounds.IntegerHeight() + 1; + fUtility->cursorAreaBitmap = new BBitmap(bounds, B_RGBA32); + + fUtility->cursorAreaBitmap->ImportBits(fUtility->wholeScreen->Bits(), + fUtility->wholeScreen->BitsLength(), + fUtility->wholeScreen->BytesPerRow(), + fUtility->wholeScreen->ColorSpace(), + fUtility->cursorPosition, BPoint(0, 0), + cursorWidth, cursorHeight); + + // Fill in the background of the mouse bitmap + uint8* bits = (uint8*)fUtility->cursorBitmap->Bits(); + uint8* areaBits = (uint8*)fUtility->cursorAreaBitmap->Bits(); + for (int32 i = 0; i < cursorHeight; i++) { + for (int32 j = 0; j < cursorWidth; j++) { + uint8 alpha = 255 - bits[3]; + bits[0] = ((areaBits[0] * alpha) >> 8) + bits[0]; + bits[1] = ((areaBits[1] * alpha) >> 8) + bits[1]; + bits[2] = ((areaBits[2] * alpha) >> 8) + bits[2]; + bits[3] = 255; + areaBits += 4; + bits += 4; + } + } +} + + +status_t +Screenshot::_GetActiveWindowFrame() +{ + fUtility->activeWindowFrame.Set(0, 0, -1, -1); + + // Create a messenger to communicate with the active application + app_info appInfo; + status_t status = be_roster->GetActiveAppInfo(&appInfo); + if (status != B_OK) + return status; + BMessenger messenger(appInfo.signature, appInfo.team); + if (!messenger.IsValid()) + return B_ERROR; + + // Loop through the windows of the active application to find out which + // window is active + int32 tokenCount; + int32* tokens = get_token_list(appInfo.team, &tokenCount); + bool foundActiveWindow = false; + BMessage message; + BMessage reply; + int32 index = 0; + int32 token = -1; + client_window_info* windowInfo = NULL; + bool modalWindow = false; + while (true) { + message.MakeEmpty(); + reply.MakeEmpty(); + + message.what = B_GET_PROPERTY; + message.AddSpecifier("Active"); + message.AddSpecifier("Window", index); + messenger.SendMessage(&message, &reply, B_INFINITE_TIMEOUT, 50000); + + if (reply.what == B_MESSAGE_NOT_UNDERSTOOD) + break; + + if (!reply.what) { + // Reply timout, this probably means that we have a modal window + // so we'll just get the window frame of the top most window + modalWindow = true; + free(tokens); + status_t status = BPrivate::get_window_order(current_workspace(), + &tokens, &tokenCount); + if (status != B_OK || !tokens || tokenCount < 1) + return B_ERROR; + foundActiveWindow = true; + } else if (reply.FindBool("result", &foundActiveWindow) != B_OK) + foundActiveWindow = false; + + if (foundActiveWindow) { + // Get the client_window_info of the active window + foundActiveWindow = false; + for (int i = 0; i < tokenCount; i++) { + token = tokens[i]; + windowInfo = get_window_info(token); + if (!windowInfo->is_mini && !windowInfo->show_hide_level > 0) { + foundActiveWindow = true; + break; + } + free(windowInfo); + } + if (foundActiveWindow) + break; + } + index++; + } + free(tokens); + + if (!foundActiveWindow) + return B_ERROR; + + // Get the TabFrame using the scripting interface + if (!modalWindow) { + message.MakeEmpty(); + message.what = B_GET_PROPERTY; + message.AddSpecifier("TabFrame"); + message.AddSpecifier("Window", index); + reply.MakeEmpty(); + messenger.SendMessage(&message, &reply); + + if (reply.FindRect("result", &fUtility->tabFrame) != B_OK) + return B_ERROR; + } else + fUtility->tabFrame.Set(0, 0, 0, 0); + + // Get the active window frame from the client_window_info + fUtility->activeWindowFrame.left = windowInfo->window_left; + fUtility->activeWindowFrame.top = windowInfo->window_top; + fUtility->activeWindowFrame.right = windowInfo->window_right; + fUtility->activeWindowFrame.bottom = windowInfo->window_bottom; + fUtility->borderSize = windowInfo->border_size; + + free(windowInfo); + + // Make sure that fActiveWindowFrame doesn't extend beyond the screen frame + BRect screenFrame(BScreen().Frame()); + if (fUtility->activeWindowFrame.left < screenFrame.left) + fUtility->activeWindowFrame.left = screenFrame.left; + if (fUtility->activeWindowFrame.top < screenFrame.top) + fUtility->activeWindowFrame.top = screenFrame.top; + if (fUtility->activeWindowFrame.right > screenFrame.right) + fUtility->activeWindowFrame.right = screenFrame.right; + if (fUtility->activeWindowFrame.bottom > screenFrame.bottom) + fUtility->activeWindowFrame.bottom = screenFrame.bottom; + + return B_OK; +} + + +int32 +Screenshot::_GetImageType(const char* name) const +{ if (strcmp(name, "bmp") == 0) - fImageFileType = B_BMP_FORMAT; + return B_BMP_FORMAT; else if (strcmp(name, "gif") == 0) - fImageFileType = B_GIF_FORMAT; + return B_GIF_FORMAT; else if (strcmp(name, "jpg") == 0 || strcmp(name, "jpeg") == 0) - fImageFileType = B_JPEG_FORMAT; + return B_JPEG_FORMAT; else if (strcmp(name, "ppm") == 0) - fImageFileType = B_PPM_FORMAT; - else if (strcmp(name, "targa") == 0 || strcmp(name, "tga") == 0) - fImageFileType = B_TGA_FORMAT; + return B_PPM_FORMAT; + else if (strcmp(name, "tga") == 0 || strcmp(name, "targa") == 0) + return B_TGA_FORMAT; else if (strcmp(name, "tif") == 0 || strcmp(name, "tiff") == 0) - fImageFileType = B_TIFF_FORMAT; + return B_TIFF_FORMAT; else { - // Default to PNG. - fImageFileType = B_PNG_FORMAT; + return B_PNG_FORMAT; } } + + +int +main() +{ + Screenshot screenshot; + return screenshot.Run(); +} Modified: haiku/trunk/src/apps/screenshot/Screenshot.h =================================================================== --- haiku/trunk/src/apps/screenshot/Screenshot.h 2010-06-05 02:10:14 UTC (rev 37016) +++ haiku/trunk/src/apps/screenshot/Screenshot.h 2010-06-05 11:23:22 UTC (rev 37017) @@ -1,10 +1,6 @@ /* - * Copyright Karsten Heimrich, host.haiku@xxxxxxx All rights reserved. + * Copyright 2010 Wim van der Meer <WPJvanderMeer@xxxxxxxxx> * Distributed under the terms of the MIT License. - * - * Authors: - * Karsten Heimrich - * Fredrik Modéen */ #ifndef SCREENSHOT_H #define SCREENSHOT_H @@ -14,23 +10,29 @@ #include <Catalog.h> +class BBitmap; +class Utility; + + class Screenshot : public BApplication { public: Screenshot(); - virtual ~Screenshot(); + ~Screenshot(); - virtual void ReadyToRun(); - virtual void RefsReceived(BMessage* message); - virtual void ArgvReceived(int32 argc, char** argv); + void ReadyToRun(); + void ArgvReceived(int32 argc, char** argv); private: - void _ShowHelp() const; - void _SetImageTypeSilence(const char* name); + void _ShowHelp(); + void _New(bigtime_t delay); + status_t _GetActiveWindowFrame(); + int32 _GetImageType(const char* name) const; - bool fArgvReceived; - bool fRefsReceived; - int32 fImageFileType; - BCatalog fCatalog; + Utility* fUtility; + BCatalog fCatalog; + + bool fLaunchGui; }; -#endif /* SCREENSHOT_H */ + +#endif // SCREENSHOT_H Modified: haiku/trunk/src/apps/screenshot/Screenshot.rdef =================================================================== --- haiku/trunk/src/apps/screenshot/Screenshot.rdef 2010-06-05 02:10:14 UTC (rev 37016) +++ haiku/trunk/src/apps/screenshot/Screenshot.rdef 2010-06-05 11:23:22 UTC (rev 37017) @@ -1,20 +1,15 @@ - resource app_signature "application/x-vnd.Haiku-Screenshot"; -resource app_flags B_MULTIPLE_LAUNCH; +resource app_flags B_MULTIPLE_LAUNCH | B_BACKGROUND_APP; resource app_version { major = 1, middle = 0, minor = 0, - - /* 0 = development 1 = alpha 2 = beta - 3 = gamma 4 = golden master 5 = final */ - variety = 2, + variety = B_APPV_BETA, internal = 0, - short_info = "Screenshot", - long_info = "Screenshot ©2008-2009 Haiku" + long_info = "Screenshot ©2008-2010 Haiku" }; resource vector_icon { @@ -48,4 +43,3 @@ $"0B73BD11333F6C1B4A6724C968940A0D010D02B8307E3A7163BA7600B82C644A" $"AAA84832F80A0D010E023EE2433C8C01BC90D03EDCDB4A6EE0C86667" }; - Added: haiku/trunk/src/apps/screenshot/ScreenshotApp.cpp =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotApp.cpp (rev 0) +++ haiku/trunk/src/apps/screenshot/ScreenshotApp.cpp 2010-06-05 11:23:22 UTC (rev 37017) @@ -0,0 +1,106 @@ +/* + * Copyright 2010 Wim van der Meer <WPJvanderMeer@xxxxxxxxx> + * All rights reserved. Distributed under the terms of the MIT license. + * + * Authors: + * Wim van der Meer + */ + + +#include "ScreenshotApp.h" + +#include <stdlib.h> + +#include <Bitmap.h> +#include <Locale.h> +#include <Roster.h> + +#include "ScreenshotWindow.h" +#include "Utility.h" + + +ScreenshotApp::ScreenshotApp() + : + BApplication("application/x-vnd.Haiku-ScreenshotApp"), + fUtility(new Utility) +{ + be_locale->GetAppCatalog(&fCatalog); +} + + +ScreenshotApp::~ScreenshotApp() +{ + delete fUtility; +} + + +void +ScreenshotApp::MessageReceived(BMessage* message) +{ + status_t status = B_OK; + switch (message->what) { + case SS_UTILITY_DATA: + { + BMessage bitmap; + status = message->FindMessage("wholeScreen", &bitmap); + if (status != B_OK) + break; + + fUtility->wholeScreen = new BBitmap(&bitmap); + + status = message->FindMessage("cursorBitmap", &bitmap); + if (status != B_OK) + break; + + fUtility->cursorBitmap = new BBitmap(&bitmap); + + status = message->FindMessage("cursorAreaBitmap", &bitmap); + if (status != B_OK) + break; + + fUtility->cursorAreaBitmap = new BBitmap(&bitmap); + + status = message->FindPoint("cursorPosition", + &fUtility->cursorPosition); + if (status != B_OK) + break; + + status = message->FindRect("activeWindowFrame", + &fUtility->activeWindowFrame); + if (status != B_OK) + break; + + status = message->FindRect("tabFrame", &fUtility->tabFrame); + if (status != B_OK) + break; + + status = message->FindFloat("borderSize", &fUtility->borderSize); + if (status != B_OK) + break; + + break; + } + + default: + BApplication::MessageReceived(message); + break; + } + + if (status != B_OK) + be_app->PostMessage(B_QUIT_REQUESTED); +} + + +void +ScreenshotApp::ReadyToRun() +{ + new ScreenshotWindow(*fUtility); +} + + +int +main() +{ + ScreenshotApp app; + return app.Run(); +} Added: haiku/trunk/src/apps/screenshot/ScreenshotApp.h =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotApp.h (rev 0) +++ haiku/trunk/src/apps/screenshot/ScreenshotApp.h 2010-06-05 11:23:22 UTC (rev 37017) @@ -0,0 +1,33 @@ +/* + * Copyright 2010 Wim van der Meer <WPJvanderMeer@xxxxxxxxx> + * Distributed under the terms of the MIT License. + * + * Authors: + * Wim van der Meer + */ +#ifndef SCREENSHOT_APP_H +#define SCREENSHOT_APP_H + + +#include <Application.h> +#include <Catalog.h> + + +class Utility; + + +class ScreenshotApp : public BApplication { +public: + ScreenshotApp(); + ~ScreenshotApp(); + + void MessageReceived(BMessage* message); + void ReadyToRun(); + +private: + BCatalog fCatalog; + Utility* fUtility; +}; + + +#endif // SCREENSHOT_APP_H Added: haiku/trunk/src/apps/screenshot/ScreenshotApp.rdef =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotApp.rdef (rev 0) +++ haiku/trunk/src/apps/screenshot/ScreenshotApp.rdef 2010-06-05 11:23:22 UTC (rev 37017) @@ -0,0 +1,45 @@ +resource app_signature "application/x-vnd.Haiku-ScreenshotApp"; + +resource app_flags B_MULTIPLE_LAUNCH; + +resource app_version { + major = 1, + middle = 0, + minor = 0, + variety = B_APPV_BETA, + internal = 0, + short_info = "ScreenshotApp", + long_info = "ScreenshotApp ©2008-2010 Haiku" +}; + +resource vector_icon { + $"6E6369660E050102000603399E0F3D9C0ABF82B23B84A84B88504910C900A5B1" + $"FFBCEAF1FFFFB3B8FF020106023E49240000000000003CAAAA4940004A80007C" + $"896EFFFFC0D5FF0401920332669805D803FFCB0005FF020016023CC7ED389BBF" + $"BA16553E39B04A41E44546E300FFFFD3020016023C529D3753A2B8966F3D9D07" + $"4AF244490EAF005EFFC502001602BCDCFABCCC663C90D9BCA00D47B5864B0A2A" + $"0090FFF4020006023CC0000000000000003D000047C00048A0001F010101FFC1" + $"ACAC020106023A26EC38CA29B828213953DA48968D4B2BC600434A68FF0F1238" + $"05FF0F0606AE0BB40BC14A33C5ACB75CC370BDEFC804C13ECA02CA27BF80C117" + $"BB1EC51BBD3EBF06BA053AB8BA0606AE0BB40BC14A33C5ACB75CC370BDEFC804" + $"C13ECA02CA27BF80C117BB1EC51BBD3EBF06BA053AB8BA0605AE02B57D43B9B9" + $"C5EDB7BB49BBB756BD75CB34CA8DC3AE40340605AE02B57D43B9B9C5EDB7BB49" + $"BBB756BD75CB34CA8DC3AE40340A093B5E3D60BFCDCB3B4560C516C7EE604B5B" + $"485D4A44560606AA0B27444054523FC074BC08C072BC07C073BC07BEE7BB113A" + $"3208022E4733420A062C3E2C50485E4E584E44323C0A042C3E48484E44323C0A" + $"044848485E4E584E440A042C3E2C50485E48480A04363E54505E43393A0204C0" + $"80C3B945C4F0BF41C281BC4DC353BD60C254BB39C452BC9BC754BB5DC61DBDDA" + $"C88CC0CEC7BABFBBC8B9C1E2C6BB0204B7E1C43BB8D9C34DB6EAC52BB893C86B" + $"B73BC70BB9EAC9CEBCBFC936BBC7CA26BDB5C848BC0FC507BD66C668BAB7C3A6" + $"0604EE3355BC43C7D1BBDDC837BCA9C76B3851BC83C828BCE9C7C2BC1DC88E17" + $"0A030104000A0001021001178400040A020103000A0001001001178400040A01" + $"0101000A0001051001178200040A040105000A050105023E2E8B000000000000" + $"3E2E8B472E8B48945D0A06010630212001178300040A070106123FFC76B8A84F" + $"38A84F3FFC7642069D437F0F01178200040A07010630282401178200040A0701" + $"06302B2601178200040A070106302E2801178200040A03010B000A0001073028" + $"A92301178400040A0801082028A9230A0901092028A9230A0A010A2028A9230A" + $"070106123CE1EA3F79B7BE878F3DF5DD4ADA30C89CFA01178200040A0B010D12" + $"BEE243BC8C013C90D0BEDCDB4A31144BF5A201178400040A0C010D023F72923D" + $"0B73BD11333F6C1B4A6724C968940A0D010D02B8307E3A7163BA7600B82C644A" + $"AAA84832F80A0D010E023EE2433C8C01BC90D03EDCDB4A6EE0C86667" +}; Modified: haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp =================================================================== --- haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp 2010-06-05 02:10:14 UTC (rev 37016) +++ haiku/trunk/src/apps/screenshot/ScreenshotWindow.cpp 2010-06-05 11:23:22 UTC (rev 37017) @@ -1,81 +1,58 @@ /* - * Copyright Karsten Heimrich, host.haiku@xxxxxxx All rights reserved. - * Distributed under the terms of the MIT License. + * Copyright 2010 Wim van der Meer <WPJvanderMeer@xxxxxxxxx> + * Copyright Karsten Heimrich, host.haiku@xxxxxxx + * All rights reserved. Distributed under the terms of the MIT License. * * Authors: * Karsten Heimrich * Fredrik Modéen * Christophe Huriaux - * Wim van der Meer, WPJvanderMeer@xxxxxxxxx + * Wim van der Meer */ #include "ScreenshotWindow.h" - -#include <stdio.h> #include <stdlib.h> - #include <Alert.h> #include <Application.h> #include <Bitmap.h> #include <Box.h> -#include <BitmapStream.h> #include <Button.h> -#include <CardLayout.h> #include <Catalog.h> #include <CheckBox.h> -#include <Directory.h> -#include <Entry.h> #include <File.h> -#include <FindDirectory.h> #include <FilePanel.h> +#include <FindDirectory.h> #include <GridLayoutBuilder.h> #include <GroupLayoutBuilder.h> -#include <LayoutItem.h> -#include <Locale.h> #include <Menu.h> #include <MenuField.h> #include <MenuItem.h> -#include <Message.h> -#include <NodeInfo.h> #include <Path.h> -#include <RadioButton.h> -#include <Region.h> #include <Roster.h> -#include <Screen.h> #include <String.h> #include <StringView.h> -#include <SpaceLayoutItem.h> #include <TextControl.h> -#include <TranslatorFormats.h> #include <TranslationUtils.h> -#include <TranslatorRoster.h> -#include <View.h> -#include <WindowInfo.h> - #include "PreviewView.h" +#include "Utility.h" enum { - kScreenshotType, + kActiveWindow, kIncludeBorder, - kShowMouse, - kBackToSave, - kTakeScreenshot, - kImageOutputFormat, + kIncludeCursor, + kNewScreenshot, + kImageFormat, kLocationChanged, kChooseLocation, - kFinishScreenshot, - kShowOptions + kSaveScreenshot }; -// #pragma mark - DirectoryRefFilter - - class DirectoryRefFilter : public BRefFilter { public: virtual ~DirectoryRefFilter() @@ -90,142 +67,191 @@ }; -// #pragma mark - ScreenshotWindow - - #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "ScreenshotWindow" -ScreenshotWindow::ScreenshotWindow() +ScreenshotWindow::ScreenshotWindow(const Utility& utility) : - BWindow(BRect(0, 0, 200.0, 100.0), B_TRANSLATE("Retake screenshot"), - B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE - | B_QUIT_ON_WINDOW_CLOSE | B_AVOID_FRONT - | B_AUTO_UPDATE_SIZE_LIMITS | B_CLOSE_ON_ESCAPE), + BWindow(BRect(0, 0, 200.0, 100.0), B_TRANSLATE("Screenshot"), + B_TITLED_WINDOW, B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_AVOID_FRONT + | B_QUIT_ON_WINDOW_CLOSE | B_AUTO_UPDATE_SIZE_LIMITS + | B_CLOSE_ON_ESCAPE), + fUtility(utility), fDelayControl(NULL), fScreenshot(NULL), fOutputPathPanel(NULL), fLastSelectedPath(NULL), fDelay(0), - fTabHeight(0), fIncludeBorder(false), - fIncludeMouse(false), + fIncludeCursor(false), fGrabActiveWindow(false), - fShowConfigWindow(false), - fSaveScreenshotSilent(false), fOutputFilename(NULL), fExtension(""), fImageFileType(B_PNG_FORMAT) { - BMessage settings = _ReadSettings(); + // Check if fUtility contains valid data + if (fUtility.wholeScreen == NULL) { + // New screenshot using zero delay + _NewScreenshot(); + return; + } + + // _ReadSettings() needs a valid fOutputPathMenu + fOutputPathMenu = new BMenu(B_TRANSLATE("Please select")); + _ReadSettings(); - if (settings.FindInt32("type", &fImageFileType) != B_OK) - fImageFileType = B_PNG_FORMAT; - settings.FindBool("includeBorder", &fIncludeBorder); - settings.FindBool("includeMouse", &fIncludeMouse); - settings.FindBool("grabActiveWindow", &fGrabActiveWindow); - settings.FindInt64("delay", &fDelay); - settings.FindString("outputFilename", &fOutputFilename); + fScreenshot = fUtility.MakeScreenshot(fIncludeCursor, fGrabActiveWindow, + fIncludeBorder); - _TakeScreenshot(0); - _InitWindow(settings); + fActiveWindow = new BCheckBox(B_TRANSLATE("Capture active window"), + new BMessage(kActiveWindow)); + if (fGrabActiveWindow) + fActiveWindow->SetValue(B_CONTROL_ON); + + fWindowBorder = new BCheckBox(B_TRANSLATE("Include window border"), + new BMessage(kIncludeBorder)); + if (fIncludeBorder) [... truncated: 1526 lines follow ...]