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