1/* 2Open Tracker License 3 4Terms and Conditions 5 6Copyright (c) 1991-2000, Be Incorporated. All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a copy of 9this software and associated documentation files (the "Software"), to deal in 10the Software without restriction, including without limitation the rights to 11use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 12of the Software, and to permit persons to whom the Software is furnished to do 13so, subject to the following conditions: 14 15The above copyright notice and this permission notice applies to all licensees 16and shall be included in all copies or substantial portions of the Software. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF TITLE, MERCHANTABILITY, 20FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21BE INCORPORATED BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 22AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF, OR IN CONNECTION 23WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 25Except as contained in this notice, the name of Be Incorporated shall not be 26used in advertising or otherwise to promote the sale, use or other dealings in 27this Software without prior written authorization from Be Incorporated. 28 29Tracker(TM), Be(R), BeOS(R), and BeIA(TM) are trademarks or registered trademarks 30of Be Incorporated in the United States and other countries. Other brand product 31names are registered trademarks or trademarks of their respective holders. 32All rights reserved. 33*/ 34 35// Classes used for setting up and managing background images 36// 37 38#ifndef __BACKGROUND_IMAGE__ 39#define __BACKGROUND_IMAGE__ 40 41 42#include <GraphicsDefs.h> 43#include <Node.h> 44#include <Path.h> 45 46#include "ObjectList.h" 47#include "String.h" 48 49 50class BView; 51class BBitmap; 52 53class BackgroundImage; 54class Image; 55class BackgroundsView; 56 57extern const char* kBackgroundImageInfo; 58extern const char* kBackgroundImageInfoOffset; 59extern const char* kBackgroundImageInfoEraseText; 60extern const char* kBackgroundImageInfoMode; 61extern const char* kBackgroundImageInfoWorkspaces; 62extern const char* kBackgroundImageInfoPath; 63extern const char* kBackgroundImageInfoSet; 64extern const char* kBackgroundImageInfoSetPeriod; 65 66const uint32 kRestoreBackgroundImage = 'Tbgr'; 67const uint32 kChangeBackgroundImage = 'Cbgr'; 68 69class BackgroundImage { 70 // This class knows everything about which bitmap to use for a given 71 // view and how. 72 // Unlike other windows, the Desktop window can have different backgrounds 73 // for each workspace 74public: 75 76 enum Mode { 77 kAtOffset, 78 kCentered, // only works on Desktop 79 kScaledToFit, // only works on Desktop 80 kTiled 81 }; 82 83 class BackgroundImageInfo { 84 // element of the per-workspace list 85 public: 86 BackgroundImageInfo(uint32 workspace, int32 imageIndex, Mode mode, 87 BPoint offset, bool textWidgetLabelOutline, uint32 imageSet, 88 uint32 cacheMode); 89 ~BackgroundImageInfo(); 90 91 void LoadBitmap(); 92 void UnloadBitmap(uint32 globalCacheMode); 93 94 uint32 fWorkspace; 95 int32 fImageIndex; 96 Mode fMode; 97 BPoint fOffset; 98 bool fTextWidgetLabelOutline; 99 uint32 fImageSet; 100 uint32 fCacheMode; // image cache strategy (0 cache , 1 no cache) 101 }; 102 103 static BackgroundImage* GetBackgroundImage(const BNode* node, 104 bool isDesktop, BackgroundsView* view); 105 // create a BackgroundImage object by reading it from a node 106 107 virtual ~BackgroundImage(); 108 109 void Show(BView* view, int32 workspace); 110 // display the right background for a given workspace 111 void Remove(); 112 // remove the background from it's current view 113 114 void WorkspaceActivated(BView* view, int32 workspace, bool state); 115 // respond to a workspace change 116 void ScreenChanged(BRect rect, color_space space); 117 // respond to a screen size change 118 /*static BackgroundImage* Refresh(BackgroundImage* oldBackgroundImage, 119 const BNode* fromNode, bool desktop, BPoseView* poseView); 120 // respond to a background image setting change 121 void ChangeImageSet(BPoseView* poseView); 122 // change to the next imageSet if any, no refresh*/ 123 BackgroundImageInfo* ImageInfoForWorkspace(int32) const; 124 125 bool IsDesktop() { return fIsDesktop;} 126 127 status_t SetBackgroundImage(BNode* node); 128 129 void Show(BackgroundImageInfo*, BView* view); 130 131 uint32 GetShowingImageSet() { return fShowingImageSet; } 132 133 void Add(BackgroundImageInfo*); 134 void Remove(BackgroundImageInfo*); 135 void RemoveAll(); 136 137private: 138 BackgroundImage(const BNode* node, bool isDesktop, BackgroundsView* view); 139 // no public constructor, GetBackgroundImage factory function is 140 // used instead 141 142 float BRectRatio(BRect rect); 143 float BRectHorizontalOverlap(BRect hostRect, BRect resizedRect); 144 float BRectVerticalOverlap(BRect hostRect, BRect resizedRect); 145 146 bool fIsDesktop; 147 BNode fDefinedByNode; 148 BView* fView; 149 BackgroundsView* fBackgroundsView; 150 BackgroundImageInfo* fShowingBitmap; 151 152 BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList; 153 154 uint32 fImageSetPeriod; // period between imagesets, 0 if none 155 uint32 fShowingImageSet; // current imageset 156 uint32 fImageSetCount; // imageset count 157 uint32 fCacheMode;// image cache strategy (0 all, 1 none, 2 own strategy) 158 bool fRandomChange; // random or sequential change 159}; 160 161class Image { 162 // element for each image 163public: 164 Image(BPath path); 165 ~Image(); 166 167 void UnloadBitmap(); 168 const char* GetName() { return fName.String(); } 169 BBitmap* GetBitmap(); 170 BPath GetPath() { return fPath; } 171private: 172 BBitmap* fBitmap; 173 BPath fPath; 174 BString fName; 175}; 176 177#endif 178 179