From a60adbf9b400d4f8d586c3acb7ff34034e89fb6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 7 Feb 2006 10:28:27 +0000 Subject: [PATCH] * Added a "Set as desktop background" option with an easy to use engine based on the OpenTracker's BackgroundImage implementation. * It's currently placed in the "View" menu, even though it doesn't fit that good, I think it should definitely be part of the right click menu. * Some more cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16273 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/BackgroundImage.cpp | 256 ++++++++++++++ src/apps/showimage/BackgroundImage.h | 70 ++++ src/apps/showimage/Jamfile | 1 + src/apps/showimage/ShowImageConstants.h | 1 + src/apps/showimage/ShowImageView.h | 445 ++++++++++++------------ src/apps/showimage/ShowImageWindow.cpp | 48 ++- src/apps/showimage/ShowImageWindow.h | 20 +- 7 files changed, 592 insertions(+), 249 deletions(-) create mode 100644 src/apps/showimage/BackgroundImage.cpp create mode 100644 src/apps/showimage/BackgroundImage.h diff --git a/src/apps/showimage/BackgroundImage.cpp b/src/apps/showimage/BackgroundImage.cpp new file mode 100644 index 0000000000..59e157a69e --- /dev/null +++ b/src/apps/showimage/BackgroundImage.cpp @@ -0,0 +1,256 @@ +/* +Open Tracker License + +Terms and Conditions + +Copyright (c) 1991-2000, Be Incorporated. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice applies to all licensees +and shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of Be Incorporated shall not be +used in advertising or otherwise to promote the sale, use or other dealings in +this Software without prior written authorization from Be Incorporated. + +Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks +of Be Incorporated in the United States and other countries. Other brand product +names are registered trademarks or trademarks of their respective holders. +All rights reserved. +*/ + + +#include "BackgroundImage.h" + +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + + +const char *kBackgroundImageInfoSet = "be:bgndimginfoset"; + + +/*static*/ +status_t +BackgroundImage::_NotifyTracker(BDirectory& directory, bool desktop) +{ + BMessenger tracker("application/x-vnd.Be-TRAK"); + + if (desktop) { + tracker.SendMessage(new BMessage(B_RESTORE_BACKGROUND_IMAGE)); + } else { + BEntry entry; + status_t status = directory.GetEntry(&entry); + if (status < B_OK) + return status; + + BPath folderPath(&entry); + int32 i = -1; + + while (true) { + BMessage msg(B_GET_PROPERTY); + BMessage reply; + i++; + + // look at the "Poses" in every Tracker window + msg.AddSpecifier("Poses"); + msg.AddSpecifier("Window", i); + + reply.MakeEmpty(); + tracker.SendMessage(&msg, &reply); + + // break out of the loop when we're at the end of + // the windows + int32 err; + if (reply.what == B_MESSAGE_NOT_UNDERSTOOD + && reply.FindInt32("error", &err) == B_OK + && err == B_BAD_INDEX) + break; + + // don't stop for windows that don't understand + // a request for "Poses"; they're not displaying + // folders + if (reply.what == B_MESSAGE_NOT_UNDERSTOOD + && reply.FindInt32("error", &err) == B_OK + && err != B_BAD_SCRIPT_SYNTAX) + continue; + + BMessenger trackerWindow; + if (reply.FindMessenger("result", &trackerWindow) != B_OK) + continue; + + // found a window with poses, ask for its path + msg.MakeEmpty(); + msg.what = B_GET_PROPERTY; + msg.AddSpecifier("Path"); + msg.AddSpecifier("Poses"); + msg.AddSpecifier("Window", i); + + reply.MakeEmpty(); + tracker.SendMessage(&msg, &reply); + + // go on with the next if this din't have a path + if (reply.what == B_MESSAGE_NOT_UNDERSTOOD) + continue; + + entry_ref ref; + if (reply.FindRef("result", &ref) == B_OK) { + BEntry entry(&ref); + BPath path(&entry); + + // these are not the paths you're looking for + if (folderPath != path) + continue; + } + + trackerWindow.SendMessage(B_RESTORE_BACKGROUND_IMAGE); + } + } + + return B_OK; +} + + +/*static*/ +status_t +BackgroundImage::_GetImages(BDirectory& directory, BMessage& container) +{ + attr_info info; + status_t status = directory.GetAttrInfo(B_BACKGROUND_INFO, &info); + if (status != B_OK) + return status; + + char *buffer = new (nothrow) char [info.size]; + if (buffer == NULL) + return NULL; + + status = directory.ReadAttr(B_BACKGROUND_INFO, info.type, + 0, buffer, (size_t)info.size); + if (status == info.size) + status = container.Unflatten(buffer); + else + status = B_ERROR; + + delete[] buffer; + + return status; +} + + +/*static*/ +status_t +BackgroundImage::_SetImage(BDirectory& directory, bool desktop, uint32 workspaces, + const char* path, Mode mode, BPoint offset, bool eraseIconBackground) +{ + BMessage images; + if (desktop) { + status_t status = _GetImages(directory, images); + if (status != B_OK) + return status; + + if (workspaces == B_CURRENT_WORKSPACE) + workspaces = 1UL << current_workspace(); + + // Find old image and replace it + + uint32 imageWorkspaces; + int32 found = -1; + int32 i = 0; + while (images.FindInt32(B_BACKGROUND_WORKSPACES, i, + (int32 *)&imageWorkspaces) == B_OK) { + // we don't care about masks that are similar to ours + if (imageWorkspaces == workspaces) { + found = i; + break; + } + + i++; + } + + // Remove old image, if any + + if (found == i) { + images.RemoveData(B_BACKGROUND_ERASE_TEXT, i); + images.RemoveData(B_BACKGROUND_IMAGE, i); + images.RemoveData(B_BACKGROUND_WORKSPACES, i); + images.RemoveData(B_BACKGROUND_ORIGIN, i); + images.RemoveData(B_BACKGROUND_MODE, i); + if (desktop) + images.RemoveData(kBackgroundImageInfoSet, i); + } + } + + // Insert new image + + images.AddBool(B_BACKGROUND_ERASE_TEXT, eraseIconBackground); + images.AddString(B_BACKGROUND_IMAGE, path); + images.AddInt32(B_BACKGROUND_WORKSPACES, workspaces); + images.AddPoint(B_BACKGROUND_ORIGIN, offset); + images.AddInt32(B_BACKGROUND_MODE, mode); + if (desktop) + images.AddInt32(kBackgroundImageInfoSet, 0); + + // Write back new image info + + size_t flattenedSize = images.FlattenedSize(); + char* buffer = new (std::nothrow) char[flattenedSize]; + if (buffer == NULL) + return B_NO_MEMORY; + + status_t status = images.Flatten(buffer, flattenedSize); + if (status != B_OK) + return status; + + ssize_t written = directory.WriteAttr(B_BACKGROUND_INFO, B_MESSAGE_TYPE, + 0, buffer, flattenedSize); + + delete[] buffer; + + if (written < B_OK) + return written; + if ((size_t)written != flattenedSize) + return B_ERROR; + + _NotifyTracker(directory, desktop); + return B_OK; +} + + +/*static*/ +status_t +BackgroundImage::SetImage(BDirectory& directory, const char* path, Mode mode, + BPoint offset, bool eraseIconBackground) +{ + return _SetImage(directory, false, 0, path, mode, offset, eraseIconBackground); +} + + +/*static*/ +status_t +BackgroundImage::SetDesktopImage(BDirectory& directory, uint32 workspaces, const char* path, + Mode mode, BPoint offset, bool eraseIconBackground) +{ + return _SetImage(directory, true, workspaces, path, mode, offset, eraseIconBackground); +} + diff --git a/src/apps/showimage/BackgroundImage.h b/src/apps/showimage/BackgroundImage.h new file mode 100644 index 0000000000..b368ffe60e --- /dev/null +++ b/src/apps/showimage/BackgroundImage.h @@ -0,0 +1,70 @@ +/* +Open Tracker License + +Terms and Conditions + +Copyright (c) 1991-2000, Be Incorporated. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice applies to all licensees +and shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of Be Incorporated shall not be +used in advertising or otherwise to promote the sale, use or other dealings in +this Software without prior written authorization from Be Incorporated. + +Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks +of Be Incorporated in the United States and other countries. Other brand product +names are registered trademarks or trademarks of their respective holders. +All rights reserved. +*/ +#ifndef BACKGROUND_IMAGE_H +#define BACKGROUND_IMAGE_H + + +#include + +class BDirectory; + + +class BackgroundImage { + // This class knows everything about which bitmap to use for a given + // view and how. + // Unlike other windows, the Desktop window can have different backgrounds + // for each workspace + public: + enum Mode { + kAtOffset, + kCentered, // only works on Desktop + kScaledToFit, // only works on Desktop + kTiled + }; + + static status_t SetImage(BDirectory& directory, const char* path, Mode mode, + BPoint offset, bool eraseIconBackground = false); + static status_t SetDesktopImage(BDirectory& directory, uint32 workspaces, + const char* path, Mode mode, BPoint offset, + bool eraseIconBackground = false); + + private: + static status_t _SetImage(BDirectory& directory, bool desktop, uint32 workspaces, + const char* path, Mode mode, BPoint offset, + bool eraseIconBackground); + static status_t _GetImages(BDirectory& directory, BMessage& images); + static status_t _NotifyTracker(BDirectory& directory, bool desktop); +}; + +#endif // BACKGROUND_IMAGE_H diff --git a/src/apps/showimage/Jamfile b/src/apps/showimage/Jamfile index 80be181c7e..cdccbca509 100644 --- a/src/apps/showimage/Jamfile +++ b/src/apps/showimage/Jamfile @@ -12,6 +12,7 @@ Application ShowImage : ShowImageApp.cpp PrintOptionsWindow.cpp Filter.cpp EntryMenuItem.cpp + BackgroundImage.cpp : be tracker translation : ShowImage.rdef ; diff --git a/src/apps/showimage/ShowImageConstants.h b/src/apps/showimage/ShowImageConstants.h index d7b27c4215..380658edb2 100644 --- a/src/apps/showimage/ShowImageConstants.h +++ b/src/apps/showimage/ShowImageConstants.h @@ -56,5 +56,6 @@ const uint32 MSG_ZOOM_OUT = 'mZOU'; const uint32 MSG_ORIGINAL_SIZE = 'mOSZ'; const uint32 MSG_INVALIDATE = 'mIVD'; const uint32 MSG_SCALE_BILINEAR = 'mSBL'; +const uint32 MSG_DESKTOP_BACKGROUND = 'mDBG'; #endif // SHOW_IMAGE_CONSTANTS_H diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index f144f4bc6f..24a60d9b7b 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -1,43 +1,26 @@ -/*****************************************************************************/ -// ShowImageView -// Written by Fernando Francisco de Oliveira, Michael Wilber, Michael Pfeiffer -// -// ShowImageView.h -// -// -// Copyright (c) 2003 OpenBeOS Project -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included -// in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL -// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. -/*****************************************************************************/ +/* + * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Fernando Francisco de Oliveira + * Michael Wilber + * Michael Pfeiffer + */ +#ifndef SHOW_IMAGE_VIEW_H +#define SHOW_IMAGE_VIEW_H -#ifndef _ShowImageView_h -#define _ShowImageView_h -#include +#include "Filter.h" +#include "ShowImageUndo.h" + #include #include #include #include #include +#include -#include "Filter.h" -#include "ShowImageUndo.h" // delay scaling operation, so that a sequence of zoom in/out operations works smoother #define DELAYED_SCALING 1 @@ -45,206 +28,214 @@ #define PEN_SIZE 1.0f class ShowImageView : public BView { -public: - ShowImageView(BRect rect, const char *name, uint32 resizingMode, - uint32 flags); - ~ShowImageView(); - - void Pulse(); - - void SetTrackerMessenger(const BMessenger& trackerMessenger); - status_t SetImage(const entry_ref *pref); - void SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap, const translation_format* format); - void SetDither(bool dither); - bool GetDither() const { return fDither; } - void SetShowCaption(bool show); - void SetShrinkToBounds(bool enable); - bool GetShrinkToBounds() const { return fShrinkToBounds; } - void SetZoomToBounds(bool enable); - bool GetZoomToBounds() const { return fZoomToBounds; } - void SetBorder(bool hasBorder); - bool HasBorder() const { return fHasBorder; } - void SetAlignment(alignment horizontal, vertical_alignment vertical); - BBitmap *GetBitmap(); - void GetName(BString *name); - void GetPath(BString *name); - void FlushToLeftTop(); - void SetScaleBilinear(bool b); - bool GetScaleBilinear() { return fScaleBilinear; } - - virtual void AttachedToWindow(); - virtual void Draw(BRect updateRect); - virtual void FrameResized(float width, float height); - virtual void MouseDown(BPoint point); - virtual void MouseMoved(BPoint point, uint32 state, const BMessage *pmsg); - virtual void MouseUp(BPoint point); - virtual void KeyDown(const char *bytes, int32 numBytes); + public: + ShowImageView(BRect rect, const char *name, uint32 resizingMode, + uint32 flags); + virtual ~ShowImageView(); - virtual void MessageReceived(BMessage *pmsg); + virtual void AttachedToWindow(); + virtual void Draw(BRect updateRect); + virtual void FrameResized(float width, float height); + virtual void MouseDown(BPoint point); + virtual void MouseMoved(BPoint point, uint32 state, const BMessage *pmsg); + virtual void MouseUp(BPoint point); + virtual void KeyDown(const char *bytes, int32 numBytes); + virtual void Pulse(); + + virtual void MessageReceived(BMessage *pmsg); + + void SetTrackerMessenger(const BMessenger& trackerMessenger); + status_t SetImage(const entry_ref *ref); + const entry_ref* Image() const { return &fCurrentRef; } + + void SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap, + const translation_format* format); + void SetDither(bool dither); + bool GetDither() const { return fDither; } + void SetShowCaption(bool show); + void SetShrinkToBounds(bool enable); + bool GetShrinkToBounds() const { return fShrinkToBounds; } + void SetZoomToBounds(bool enable); + bool GetZoomToBounds() const { return fZoomToBounds; } + void SetBorder(bool hasBorder); + bool HasBorder() const { return fHasBorder; } + void SetAlignment(alignment horizontal, vertical_alignment vertical); + BBitmap *GetBitmap(); + void GetName(BString *name); + void GetPath(BString *name); + void FlushToLeftTop(); + void SetScaleBilinear(bool b); + bool GetScaleBilinear() { return fScaleBilinear; } + + void FixupScrollBar(orientation o, float bitmapLength, float viewLength); + void FixupScrollBars(); + + int32 CurrentPage(); + int32 PageCount(); + + void Undo(); + void Cut(); + void Paste(); + void SelectAll(); + void ClearSelection(); + + void CopySelectionToClipboard(); + + void FirstPage(); + void LastPage(); + void NextPage(); + void PrevPage(); + void GoToPage(int32 page); + bool NextFile(); + bool PrevFile(); + bool HasNextFile(); + bool HasPrevFile(); + void SetSlideShowDelay(float seconds); + float GetSlideShowDelay() const { return fSlideShowDelay / 10.0; } + bool SlideShowStarted() const { return fSlideShow; } + void StartSlideShow(); + void StopSlideShow(); + void SetZoom(float zoom); + void ZoomIn(); + void ZoomOut(); + + // Image manipulation + void Rotate(int degree); // 90 and 270 only + void Mirror(bool vertical); + void Invert(); + + void SetIcon(bool clear); + + private: + ShowImageUndo fUndo; + enum image_orientation { + k0, // 0 + k90, // 1 + k180, // 2 + k270, // 3 + k0V, // 4 + k90V, // 5 + k0H, // 6 + k270V, // 7 + kNumberOfOrientations, + }; + void InitPatterns(); + void RotatePatterns(); + void RemoveSelection(bool bToClipboard); + bool HasSelection() { return fHasSelection; } + void SetHasSelection(bool bHasSelection); + void AnimateSelection(bool a); + void Notify(const char* status); + void AddToRecentDocuments(); + void AddWhiteRect(BRect &rect); + void GetMergeRects(BBitmap *merge, BRect selection, BRect &srcBits, BRect &destRect); + void GetSelMergeRects(BRect &srcBits, BRect &destRect); + status_t SetSelection(const entry_ref *pref, BPoint point); + status_t PasteBitmap(BBitmap *bitmap, BPoint point); + void MergeWithBitmap(BBitmap *merge, BRect selection); + void MergeSelection(); + void DeleteScaler(); + void DeleteBitmap(); + void DeleteSelBitmap(); + int32 BytesPerPixel(color_space cs) const; + void CopyPixel(uchar* dest, int32 destX, int32 destY, int32 destBPR, + uchar* src, int32 x, int32 y, int32 bpr, int32 bpp); + void InvertPixel(int32 x, int32 y, uchar* dest, int32 destBPR, uchar* src, + int32 bpr, int32 bpp); + void DoImageOperation(enum ImageProcessor::operation op, bool quiet = false); + void UserDoImageOperation(enum ImageProcessor::operation op, bool quiet = false); + BRect AlignBitmap(); + void Setup(BRect r); + BPoint ImageToView(BPoint p) const; + BPoint ViewToImage(BPoint p) const; + BRect ImageToView(BRect r) const; + bool IsImage(const entry_ref* pref); + static int CompareEntries(const void* a, const void* b); + void FreeEntries(BList* entries); + void SetTrackerSelectionToCurrent(); + bool FindNextImageByDir(entry_ref *in_current, entry_ref *out_image, + bool next, bool rewind); + bool FindNextImage(entry_ref *in_current, entry_ref *out_image, + bool next, bool rewind); + bool ShowNextImage(bool next, bool rewind); + bool FirstFile(); + void ConstrainToImage(BPoint &point); + void ConstrainToImage(BRect &rect); + BBitmap* CopyFromRect(BRect srcRect); + BBitmap* CopySelection(uchar alpha = 255, bool imageSize = true); + bool AddSupportedTypes(BMessage* msg, BBitmap* bitmap); + void BeginDrag(BPoint sourcePoint); + void SendInMessage(BMessage* msg, BBitmap* bitmap, translation_format* format); + bool OutputFormatForType(BBitmap* bitmap, const char* type, + translation_format* format); + void HandleDrop(BMessage* msg); + void MoveImage(); + uint32 GetMouseButtons(); + void UpdateSelectionRect(BPoint point, bool final); + void DrawBorder(BRect border); + void LayoutCaption(BFont &font, BPoint &textPos, BRect &background); + void DrawCaption(); + void UpdateCaption(); + void DrawSelectionBox(); + Scaler* GetScaler(BRect rect); + void DrawImage(BRect rect); + float LimitToRange(float v, orientation o, bool absolute); + void ScrollRestricted(float x, float y, bool absolute); + void ScrollRestrictedTo(float x, float y); + void ScrollRestrictedBy(float x, float y); + void MouseWheelChanged(BMessage* msg); + void ShowPopUpMenu(BPoint screen); + void SettingsSetBool(const char* name, bool value); + void SetIcon(bool clear, icon_size which); + void ToggleSlideShow(); + void ExitFullScreen(); + + BMessenger fTrackerMessenger; // of the window that this was launched from + entry_ref fCurrentRef; // of the image + bool fDither; // dither the image + int32 fDocumentIndex; // of the image in the file + int32 fDocumentCount; // number of images in the file + BBitmap *fBitmap; // the original image + BBitmap *fDisplayBitmap; + // the image to be displayed + // (== fBitmap if the bitmap can be displayed as is) + BBitmap *fSelBitmap; // the bitmap in the selection + float fZoom; // factor to be used to display the image + bool fScaleBilinear; // use bilinear scaling? + Scaler* fScaler; // holds the scaled image if bilinear scaling is enabled + bool fShrinkToBounds; + bool fZoomToBounds; + bool fShrinkOrZoomToBounds; + bool fHasBorder; // should the image have a border? + alignment fHAlignment; // horizontal alignment (left and centered only) + vertical_alignment fVAlignment; // vertical alignment (left and centered only) + float fLeft; // the origin of the image in the view + float fTop; + float fScaleX; // to convert image from/to view coordinates + float fScaleY; + bool fMovesImage; // is the image being moved with the mouse + bool fMakesSelection; // is a selection being made + BPoint fFirstPoint; // first point in image space of selection + bool fAnimateSelection; // marching ants + bool fHasSelection; // is fSelectionRect valid + BRect fSelectionRect; // the current location of the selection rectangle + BRect fCopyFromRect; + // the portion of the background bitmap the selection is made from + pattern fPatternUp, fPatternDown, fPatternLeft, fPatternRight; - void FixupScrollBar(orientation o, float bitmapLength, float viewLength); - void FixupScrollBars(); - - int32 CurrentPage(); - int32 PageCount(); - - void Undo(); - void Cut(); - void Paste(); - void SelectAll(); - void ClearSelection(); - - void CopySelectionToClipboard(); - - void FirstPage(); - void LastPage(); - void NextPage(); - void PrevPage(); - void GoToPage(int32 page); - bool NextFile(); - bool PrevFile(); - bool HasNextFile(); - bool HasPrevFile(); - void SetSlideShowDelay(float seconds); - float GetSlideShowDelay() const { return fSlideShowDelay / 10.0; } - bool SlideShowStarted() const { return fSlideShow; } - void StartSlideShow(); - void StopSlideShow(); - void SetZoom(float zoom); - void ZoomIn(); - void ZoomOut(); - - // Image manipulation - void Rotate(int degree); // 90 and 270 only - void Mirror(bool vertical); - void Invert(); - - void SetIcon(bool clear); - -private: - ShowImageUndo fUndo; - enum image_orientation { - k0, // 0 - k90, // 1 - k180, // 2 - k270, // 3 - k0V, // 4 - k90V, // 5 - k0H, // 6 - k270V, // 7 - kNumberOfOrientations, - }; - void InitPatterns(); - void RotatePatterns(); - void RemoveSelection(bool bToClipboard); - bool HasSelection() { return fHasSelection; } - void SetHasSelection(bool bHasSelection); - void AnimateSelection(bool a); - void Notify(const char* status); - void AddToRecentDocuments(); - void AddWhiteRect(BRect &rect); - void GetMergeRects(BBitmap *merge, BRect selection, BRect &srcBits, BRect &destRect); - void GetSelMergeRects(BRect &srcBits, BRect &destRect); - status_t SetSelection(const entry_ref *pref, BPoint point); - status_t PasteBitmap(BBitmap *bitmap, BPoint point); - void MergeWithBitmap(BBitmap *merge, BRect selection); - void MergeSelection(); - void DeleteScaler(); - void DeleteBitmap(); - void DeleteSelBitmap(); - int32 BytesPerPixel(color_space cs) const; - inline void CopyPixel(uchar* dest, int32 destX, int32 destY, int32 destBPR, uchar* src, int32 x, int32 y, int32 bpr, int32 bpp); - inline void InvertPixel(int32 x, int32 y, uchar* dest, int32 destBPR, uchar* src, int32 bpr, int32 bpp); - void DoImageOperation(enum ImageProcessor::operation op, bool quiet = false); - void UserDoImageOperation(enum ImageProcessor::operation op, bool quiet = false); - BRect AlignBitmap(); - void Setup(BRect r); - BPoint ImageToView(BPoint p) const; - BPoint ViewToImage(BPoint p) const; - BRect ImageToView(BRect r) const; - bool IsImage(const entry_ref* pref); - static int CompareEntries(const void* a, const void* b); - void FreeEntries(BList* entries); - void SetTrackerSelectionToCurrent(); - bool FindNextImageByDir(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind); - bool FindNextImage(entry_ref *in_current, entry_ref *out_image, bool next, bool rewind); - bool ShowNextImage(bool next, bool rewind); - bool FirstFile(); - void ConstrainToImage(BPoint &point); - void ConstrainToImage(BRect &rect); - BBitmap* CopyFromRect(BRect srcRect); - BBitmap* CopySelection(uchar alpha = 255, bool imageSize = true); - bool AddSupportedTypes(BMessage* msg, BBitmap* bitmap); - void BeginDrag(BPoint sourcePoint); - void SendInMessage(BMessage* msg, BBitmap* bitmap, translation_format* format); - bool OutputFormatForType(BBitmap* bitmap, const char* type, translation_format* format); - void HandleDrop(BMessage* msg); - void MoveImage(); - uint32 GetMouseButtons(); - void UpdateSelectionRect(BPoint point, bool final); - void DrawBorder(BRect border); - void LayoutCaption(BFont &font, BPoint &textPos, BRect &background); - void DrawCaption(); - void UpdateCaption(); - void DrawSelectionBox(); - Scaler* GetScaler(BRect rect); - void DrawImage(BRect rect); - float LimitToRange(float v, orientation o, bool absolute); - void ScrollRestricted(float x, float y, bool absolute); - void ScrollRestrictedTo(float x, float y); - void ScrollRestrictedBy(float x, float y); - void MouseWheelChanged(BMessage* msg); - void ShowPopUpMenu(BPoint screen); - void SettingsSetBool(const char* name, bool value); - void SetIcon(bool clear, icon_size which); - void ToggleSlideShow(); - void ExitFullScreen(); - - BMessenger fTrackerMessenger; // of the window that this was launched from - entry_ref fCurrentRef; // of the image - bool fDither; // dither the image - int32 fDocumentIndex; // of the image in the file - int32 fDocumentCount; // number of images in the file - BBitmap *fBitmap; // the original image - BBitmap *fDisplayBitmap; // the image to be displayed - // (== fBitmap if the bitmap can be displayed as is) - BBitmap *fSelBitmap; // the bitmap in the selection - float fZoom; // factor to be used to display the image - bool fScaleBilinear; // use bilinear scaling? - Scaler* fScaler; // holds the scaled image if bilinear scaling is enabled - bool fShrinkToBounds; // shrink images to view bounds that are larger than the view - bool fZoomToBounds; // zoom images to view bounds that are smaller than the view - bool fShrinkOrZoomToBounds; - bool fHasBorder; // should the image have a border? - alignment fHAlignment; // horizontal alignment (left and centered only) - vertical_alignment fVAlignment; // vertical alignment (left and centered only) - float fLeft; // the origin of the image in the view - float fTop; - float fScaleX; // to convert image from/to view coordinates - float fScaleY; - bool fMovesImage; // is the image being moved with the mouse - bool fMakesSelection; // is a selection being made - BPoint fFirstPoint; // first point in image space of selection - bool fAnimateSelection; // marching ants - bool fHasSelection; // is fSelectionRect valid - BRect fSelectionRect; // the current location of the selection rectangle - BRect fCopyFromRect; - // the portion of the background bitmap the selection is made from - pattern fPatternUp, fPatternDown, fPatternLeft, fPatternRight; - - bool fSlideShow; // is slide show enabled? - int fSlideShowDelay; // in pulse rate units - int fSlideShowCountDown; // shows next image if it reaches zero + bool fSlideShow; // is slide show enabled? + int fSlideShowDelay; // in pulse rate units + int fSlideShowCountDown; // shows next image if it reaches zero #if DELAYED_SCALING - int fScalingCountDown; + int fScalingCountDown; #endif - bool fShowCaption; // display caption? - BString fCaption; // caption text + bool fShowCaption; // display caption? + BString fCaption; // caption text - bool fInverted; - enum image_orientation fImageOrientation; - static enum image_orientation fTransformation[ImageProcessor::kNumberOfAffineTransformations][kNumberOfOrientations]; + bool fInverted; + enum image_orientation fImageOrientation; + static enum image_orientation fTransformation[ImageProcessor::kNumberOfAffineTransformations][kNumberOfOrientations]; }; -#endif /* _ShowImageView_h */ +#endif // SHOW_IMAGE_VIEW_H diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index e5d7dc168e..dff4f9d316 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -9,6 +9,7 @@ */ +#include "BackgroundImage.h" #include "EntryMenuItem.h" #include "ShowImageApp.h" #include "ShowImageConstants.h" @@ -23,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -46,9 +48,9 @@ RecentDocumentsMenu::RecentDocumentsMenu(const char *title, menu_layout layout) bool -RecentDocumentsMenu::AddDynamicItem(add_state s) +RecentDocumentsMenu::AddDynamicItem(add_state addState) { - if (s != B_INITIAL_ADD) + if (addState != B_INITIAL_ADD) return false; BMenuItem *item; @@ -264,6 +266,11 @@ ShowImageWindow::BuildViewMenu(BMenu *menu) EnableMenuItem(menu, MSG_ORIGINAL_SIZE, enabled); EnableMenuItem(menu, MSG_ZOOM_IN, enabled); EnableMenuItem(menu, MSG_ZOOM_OUT, enabled); + + menu->AddSeparatorItem(); + + AddItemMenu(menu, "As Desktop Background", MSG_DESKTOP_BACKGROUND, 0, 0, 'W', + true); } @@ -292,7 +299,7 @@ ShowImageWindow::AddMenus(BMenuBar *bar) menu->AddSeparatorItem(); AddItemMenu(menu, "Quit", B_QUIT_REQUESTED, 'Q', 0, 'A', true); bar->AddItem(menu); - + menu = new BMenu("Edit"); AddItemMenu(menu, "Undo", B_UNDO, 'Z', 0, 'W', false); menu->AddSeparatorItem(); @@ -313,7 +320,7 @@ ShowImageWindow::AddMenus(BMenuBar *bar) fGoToPageMenu->SetRadioMode(true); menu->AddItem(fGoToPageMenu); menu->AddSeparatorItem(); - AddItemMenu(menu, "Previous File", MSG_FILE_PREV, B_UP_ARROW, 0, 'W', true); + AddItemMenu(menu, "Previous File", MSG_FILE_PREV, B_UP_ARROW, 0, 'W', true); AddItemMenu(menu, "Next File", MSG_FILE_NEXT, B_DOWN_ARROW, 0, 'W', true); bar->AddItem(menu); @@ -321,21 +328,21 @@ ShowImageWindow::AddMenus(BMenuBar *bar) AddItemMenu(menu, "Dither Image", MSG_DITHER_IMAGE, 0, 0, 'W', true); menu->AddSeparatorItem(); AddItemMenu(menu, "Rotate -90°", MSG_ROTATE_270, '[', 0, 'W', true); - AddItemMenu(menu, "Rotate +90°", MSG_ROTATE_90, ']', 0, 'W', true); + AddItemMenu(menu, "Rotate +90°", MSG_ROTATE_90, ']', 0, 'W', true); menu->AddSeparatorItem(); AddItemMenu(menu, "Mirror Vertical", MSG_MIRROR_VERTICAL, 0, 0, 'W', true); AddItemMenu(menu, "Mirror Horizontal", MSG_MIRROR_HORIZONTAL, 0, 0, 'W', true); menu->AddSeparatorItem(); - AddItemMenu(menu, "Invert", MSG_INVERT, 0, 0, 'W', true); + AddItemMenu(menu, "Invert", MSG_INVERT, 0, 0, 'W', true); bar->AddItem(menu); } BMenuItem * -ShowImageWindow::AddItemMenu(BMenu *menu, char *caption, long unsigned int msg, +ShowImageWindow::AddItemMenu(BMenu *menu, char *caption, uint32 command, char shortcut, uint32 modifier, char target, bool enabled) { - BMenuItem* item = new BMenuItem(caption, new BMessage(msg), shortcut, modifier); + BMenuItem* item = new BMenuItem(caption, new BMessage(command), shortcut, modifier); if (target == 'A') item->SetTarget(be_app); @@ -791,6 +798,22 @@ ShowImageWindow::MessageReceived(BMessage *message) fImageView->SetScaleBilinear(ToggleMenuItem(message->what)); break; + case MSG_DESKTOP_BACKGROUND: + { + BPath path; + if (find_directory(B_DESKTOP_DIRECTORY, &path) == B_OK) { + BDirectory directory(path.Path()); + if (directory.InitCheck() == B_OK) { + if (path.SetTo(fImageView->Image()) == B_OK) { + BackgroundImage::SetDesktopImage(directory, B_CURRENT_WORKSPACE, + path.Path(), BackgroundImage::kScaledToFit, BPoint(0, 0), + false); + } + } + } + break; + } + default: BWindow::MessageReceived(message); break; @@ -812,15 +835,16 @@ ShowImageWindow::SaveAs(BMessage *message) // Add the chosen translator and output type to the // message that the save panel will send back - BMessage *ppanelMsg = new BMessage(MSG_SAVE_PANEL); - ppanelMsg->AddInt32(TRANSLATOR_FLD, outTranslator); - ppanelMsg->AddInt32(TYPE_FLD, outType); + BMessage *panelMsg = new BMessage(MSG_SAVE_PANEL); + panelMsg->AddInt32(TRANSLATOR_FLD, outTranslator); + panelMsg->AddInt32(TYPE_FLD, outType); // Create save panel and show it fSavePanel = new (std::nothrow) BFilePanel(B_SAVE_PANEL, - new BMessenger(this), NULL, 0, false, ppanelMsg); + new BMessenger(this), NULL, 0, false, panelMsg); if (!fSavePanel) return; + fSavePanel->Window()->SetWorkspaces(B_CURRENT_WORKSPACE); fSavePanel->Show(); } diff --git a/src/apps/showimage/ShowImageWindow.h b/src/apps/showimage/ShowImageWindow.h index fc1f395ad2..c122851e54 100644 --- a/src/apps/showimage/ShowImageWindow.h +++ b/src/apps/showimage/ShowImageWindow.h @@ -29,7 +29,7 @@ class ShowImageStatusView; class RecentDocumentsMenu : public BMenu { public: RecentDocumentsMenu(const char *title, menu_layout layout = B_ITEMS_IN_COLUMN); - bool AddDynamicItem(add_state s); + bool AddDynamicItem(add_state addState); private: void UpdateRecentDocumentsMenu(); @@ -37,11 +37,11 @@ class RecentDocumentsMenu : public BMenu { class ShowImageWindow : public BWindow { public: - ShowImageWindow(const entry_ref *pref, const BMessenger& trackerMessenger); + ShowImageWindow(const entry_ref *ref, const BMessenger& trackerMessenger); virtual ~ShowImageWindow(); virtual void FrameResized(float width, float height); - virtual void MessageReceived(BMessage *pmsg); + virtual void MessageReceived(BMessage *message); virtual bool QuitRequested(); virtual void Zoom(BPoint origin, float width, float height); @@ -50,14 +50,14 @@ class ShowImageWindow : public BWindow { void UpdateTitle(); void BuildViewMenu(BMenu *menu); - void AddMenus(BMenuBar *pbar); - void WindowRedimension(BBitmap *pbitmap); + void AddMenus(BMenuBar *bar); + void WindowRedimension(BBitmap *bitmap); private: - BMenuItem *AddItemMenu(BMenu *pmenu, char *caption, - long unsigned int msg, char shortcut, uint32 modifier, + BMenuItem *AddItemMenu(BMenu *menu, char *caption, + uint32 command, char shortcut, uint32 modifier, char target, bool enabled); - BMenuItem* AddDelayItem(BMenu *pmenu, char *caption, float value); + BMenuItem* AddDelayItem(BMenu *menu, char *caption, float value); bool ToggleMenuItem(uint32 what); void EnableMenuItem(BMenu *menu, uint32 what, bool enable); @@ -65,9 +65,9 @@ class ShowImageWindow : public BWindow { void MarkSlideShowDelay(float value); void ResizeToWindow(bool shrink, uint32 what); - void SaveAs(BMessage *pmsg); + void SaveAs(BMessage *message); // Handle Save As submenu choice - void SaveToFile(BMessage *pmsg); + void SaveToFile(BMessage *message); // Handle save file panel message bool ClosePrompt(); void ToggleFullScreen();