xref: /haiku/src/kits/tracker/BackgroundImage.h (revision 25a7b01d15612846f332751841da3579db313082)
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 #ifndef __BACKGROUND_IMAGE__
35 #define __BACKGROUND_IMAGE__
36 
37 
38 //  Classes used for setting up and managing background images
39 
40 
41 #include <String.h>
42 #include "ObjectList.h"
43 
44 
45 class BNode;
46 class BView;
47 class BBitmap;
48 
49 namespace BPrivate {
50 
51 class BackgroundImage;
52 class BPoseView;
53 
54 extern const char* kBackgroundImageInfo;
55 extern const char* kBackgroundImageInfoOffset;
56 extern const char* kBackgroundImageInfoTextOutline;
57 extern const char* kBackgroundImageInfoMode;
58 extern const char* kBackgroundImageInfoWorkspaces;
59 extern const char* kBackgroundImageInfoPath;
60 
61 const uint32 kRestoreBackgroundImage = 'Tbgr';
62 
63 class BackgroundImage {
64 	// This class knows everything about which bitmap to use for a given
65 	// view and how.
66 	// Unlike other windows, the Desktop window can have different backgrounds
67 	// for each workspace
68 public:
69 
70 	enum Mode {
71 		kAtOffset,
72 		kCentered,			// only works on Desktop
73 		kScaledToFit,		// only works on Desktop
74 		kTiled
75 	};
76 
77 	class BackgroundImageInfo {
78 		// element of the per-workspace list
79 	public:
80 		BackgroundImageInfo(uint32 workspace, BBitmap* bitmap, Mode mode,
81 			BPoint offset, bool textWidgetOutline);
82 		~BackgroundImageInfo();
83 
84 		uint32 fWorkspace;
85 		BBitmap* fBitmap;
86 		Mode fMode;
87 		BPoint fOffset;
88 		bool fTextWidgetOutline;
89 	};
90 
91 	static BackgroundImage* GetBackgroundImage(const BNode* node,
92 		bool isDesktop);
93 		// create a BackgroundImage object by reading it from a node
94 	virtual ~BackgroundImage();
95 
96 	void Show(BView* view, int32 workspace);
97 		// display the right background for a given workspace
98 	void Remove();
99 		// remove the background from it's current view
100 
101 	void WorkspaceActivated(BView* view, int32 workspace, bool state);
102 		// respond to a workspace change
103 	void ScreenChanged(BRect rect, color_space space);
104 		// respond to a screen size change
105 	static BackgroundImage* Refresh(BackgroundImage* oldBackgroundImage,
106 		const BNode* fromNode, bool desktop, BPoseView* poseView);
107 		// respond to a background image setting change
108 
109 private:
110 	BackgroundImageInfo* ImageInfoForWorkspace(int32) const;
111 	void Show(BackgroundImageInfo*, BView* view);
112 
113 	BackgroundImage(const BNode*, bool);
114 		// no public constructor, GetBackgroundImage factory function is
115 		// used instead
116 
117 	void Add(BackgroundImageInfo*);
118 
119 	float BRectRatio(BRect rect);
120 	float BRectHorizontalOverlap(BRect hostRect, BRect resizedRect);
121 	float BRectVerticalOverlap(BRect hostRect, BRect resizedRect);
122 
123 	bool fIsDesktop;
124 	BNode fDefinedByNode;
125 	BView* fView;
126 	BackgroundImageInfo* fShowingBitmap;
127 
128 	BObjectList<BackgroundImageInfo> fBitmapForWorkspaceList;
129 };
130 
131 } // namespace BPrivate
132 
133 using namespace BPrivate;
134 
135 #endif
136