xref: /haiku/src/servers/app/View.h (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
1 /*
2  * Copyright (c) 2001-2008, Haiku, Inc.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		DarkWyrm <bpmagic@columbus.rr.com>
7  *		Adi Oanca <adioanca@gmail.com>
8  *		Axel Dörfler, axeld@pinc-software.de
9  *		Stephan Aßmus <superstippi@gmx.de>
10  *		Marcus Overhagen <marcus@overhagen.de>
11  */
12 #ifndef	VIEW_H
13 #define VIEW_H
14 
15 
16 #include "IntRect.h"
17 
18 #include <GraphicsDefs.h>
19 #include <ObjectList.h>
20 #include <Region.h>
21 #include <String.h>
22 
23 class BList;
24 class BMessage;
25 
26 namespace BPrivate {
27 	class PortLink;
28 };
29 
30 class DrawState;
31 class DrawingEngine;
32 class Overlay;
33 class Window;
34 class ServerBitmap;
35 class ServerCursor;
36 class ServerPicture;
37 
38 class View {
39  public:
40 							View(IntRect frame, IntPoint scrollingOffset,
41 								const char* name, int32 token,
42 								uint32 resizeMode, uint32 flags);
43 	virtual					~View();
44 
45 			int32			Token() const
46 								{ return fToken; }
47 
48 			IntRect			Frame() const
49 								{ return fFrame; }
50 			IntRect			Bounds() const;
51 
52 			void			SetResizeMode(uint32 resizeMode)
53 								{ fResizeMode = resizeMode; }
54 
55 			void			SetName(const char* string);
56 			const char*		Name() const
57 								{ return fName.String(); }
58 
59 			void			SetFlags(uint32 flags);
60 			uint32			Flags() const
61 								{ return fFlags; }
62 
63 	inline	IntPoint		ScrollingOffset() const
64 								{ return fScrollingOffset; }
65 
66 			void			SetDrawingOrigin(BPoint origin);
67 			BPoint			DrawingOrigin() const;
68 
69 			void			SetScale(float scale);
70 			float			Scale() const;
71 
72 			void			SetUserClipping(const BRegion* region);
73 				// region is expected in view coordinates
74 
75 			// converts the given frame up the view hierarchy and
76 			// clips to each views bounds
77 			void			ConvertToVisibleInTopView(IntRect* bounds) const;
78 
79 	virtual	void			AttachedToWindow(::Window* window);
80 	virtual void			DetachedFromWindow();
81 			::Window*		Window() const { return fWindow; }
82 
83 			// tree stuff
84 			void			AddChild(View* view);
85 			bool			RemoveChild(View* view);
86 
87 	inline	View*			Parent() const
88 								{ return fParent; }
89 
90 	inline	View*			FirstChild() const
91 								{ return fFirstChild; }
92 	inline	View*			LastChild() const
93 								{ return fLastChild; }
94 	inline	View*			PreviousSibling() const
95 								{ return fPreviousSibling; }
96 	inline	View*			NextSibling() const
97 								{ return fNextSibling; }
98 
99 			View*			TopView();
100 
101 			uint32			CountChildren(bool deep = false) const;
102 			void			CollectTokensForChildren(BList* tokenMap) const;
103 			void			FindViews(uint32 flags, BObjectList<View>& list,
104 								int32& left);
105 
106 			View*			ViewAt(const BPoint& where);
107 
108 			// coordinate conversion
109 			void			ConvertToParent(BPoint* point) const;
110 			void			ConvertToParent(IntPoint* point) const;
111 			void			ConvertToParent(BRect* rect) const;
112 			void			ConvertToParent(IntRect* rect) const;
113 			void			ConvertToParent(BRegion* region) const;
114 
115 			void			ConvertFromParent(BPoint* point) const;
116 			void			ConvertFromParent(IntPoint* point) const;
117 			void			ConvertFromParent(BRect* rect) const;
118 			void			ConvertFromParent(IntRect* rect) const;
119 			void			ConvertFromParent(BRegion* region) const;
120 
121 			void			ConvertToScreen(BPoint* point) const;
122 			void			ConvertToScreen(IntPoint* point) const;
123 			void			ConvertToScreen(BRect* rect) const;
124 			void			ConvertToScreen(IntRect* rect) const;
125 			void			ConvertToScreen(BRegion* region) const;
126 
127 			void			ConvertFromScreen(BPoint* point) const;
128 			void			ConvertFromScreen(IntPoint* point) const;
129 			void			ConvertFromScreen(BRect* rect) const;
130 			void			ConvertFromScreen(IntRect* rect) const;
131 			void			ConvertFromScreen(BRegion* region) const;
132 
133 			void			ConvertToScreenForDrawing(BPoint* point) const;
134 			void			ConvertToScreenForDrawing(BRect* rect) const;
135 			void			ConvertToScreenForDrawing(BRegion* region) const;
136 
137 			void			ConvertToScreenForDrawing(BPoint* dst, const BPoint* src, int32 num) const;
138 			void			ConvertToScreenForDrawing(BRect* dst, const BRect* src, int32 num) const;
139 			void			ConvertToScreenForDrawing(BRegion* dst, const BRegion* src, int32 num) const;
140 
141 			void			ConvertFromScreenForDrawing(BPoint* point) const;
142 				// used when updating the pen position
143 
144 			void			MoveBy(int32 dx, int32 dy,
145 								BRegion* dirtyRegion);
146 
147 			void			ResizeBy(int32 dx, int32 dy,
148 								BRegion* dirtyRegion);
149 
150 			void			ScrollBy(int32 dx, int32 dy,
151 								BRegion* dirtyRegion);
152 
153 			void			ParentResized(int32 dx, int32 dy,
154 								BRegion* dirtyRegion);
155 
156 			void			CopyBits(IntRect src, IntRect dst,
157 								BRegion& windowContentClipping);
158 
159 			const BRegion&	LocalClipping() const { return fLocalClipping; }
160 
161 			const rgb_color& ViewColor() const
162 								{ return fViewColor; }
163 			void			SetViewColor(const rgb_color& color)
164 								{ fViewColor = color; }
165 
166 			ServerBitmap*	ViewBitmap() const
167 								{ return fViewBitmap; }
168 			void			SetViewBitmap(ServerBitmap* bitmap,
169 								IntRect sourceRect, IntRect destRect,
170 								int32 resizingMode, int32 options);
171 
172 			void			PushState();
173 			void			PopState();
174 			DrawState*		CurrentState() const { return fDrawState; }
175 
176 			void			SetEventMask(uint32 eventMask, uint32 options);
177 			uint32			EventMask() const
178 								{ return fEventMask; }
179 			uint32			EventOptions() const
180 								{ return fEventOptions; }
181 
182 			void			SetCursor(ServerCursor* cursor);
183 			ServerCursor*	Cursor() const { return fCursor; }
184 
185 			void			SetPicture(ServerPicture* picture);
186 			ServerPicture*	Picture() const
187 								{ return fPicture; }
188 
189 			// for background clearing
190 			virtual void	Draw(DrawingEngine* drawingEngine,
191 								BRegion* effectiveClipping,
192 								BRegion* windowContentClipping,
193 								bool deep = false);
194 
195 			virtual void	MouseDown(BMessage* message, BPoint where);
196 			virtual void	MouseUp(BMessage* message, BPoint where);
197 			virtual void	MouseMoved(BMessage* message, BPoint where);
198 
199 			void			SetHidden(bool hidden);
200 			bool			IsHidden() const;
201 
202 			// takes into account parent views hidden status
203 			bool			IsVisible() const
204 								{ return fVisible; }
205 			// update visible status for this view and all children
206 			// according to the parents visibility
207 			void			UpdateVisibleDeep(bool parentVisible);
208 
209 			void			UpdateOverlay();
210 
211 			void			MarkBackgroundDirty();
212 			bool			IsBackgroundDirty() const
213 								{ return fBackgroundDirty; }
214 
215 			bool			IsDesktopBackground() const
216 								{ return fIsDesktopBackground; }
217 
218 			void			AddTokensForViewsInRegion(BPrivate::PortLink& link,
219 								BRegion& region,
220 								BRegion* windowContentClipping);
221 
222 			// clipping
223 			void			RebuildClipping(bool deep);
224 			BRegion&		ScreenAndUserClipping(
225 								BRegion* windowContentClipping,
226 								bool force = false) const;
227 			void			InvalidateScreenClipping();
228 	inline	bool			IsScreenClippingValid() const
229 								{
230 									return fScreenClippingValid
231 										&& (fUserClipping == NULL
232 										|| (fUserClipping != NULL
233 										&& fScreenAndUserClipping != NULL));
234 								}
235 
236 			// debugging
237 			void			PrintToStream() const;
238 #if 0
239 			bool			MarkAt(DrawingEngine* engine, const BPoint& where,
240 								int32 level = 0);
241 #endif
242 
243 	protected:
244 			BRegion&		_ScreenClipping(BRegion* windowContentClipping,
245 								bool force = false) const;
246 			void			_MoveScreenClipping(int32 x, int32 y,
247 								bool deep);
248 			Overlay*		_Overlay() const;
249 			void			_UpdateOverlayView() const;
250 
251 			BString			fName;
252 			int32			fToken;
253 			// area within parent coordinate space
254 			IntRect			fFrame;
255 			// offset of the local area (bounds)
256 			IntPoint		fScrollingOffset;
257 
258 			rgb_color		fViewColor;
259 			DrawState*		fDrawState;
260 			ServerBitmap*	fViewBitmap;
261 			IntRect			fBitmapSource;
262 			IntRect			fBitmapDestination;
263 			int32			fBitmapResizingMode;
264 			int32			fBitmapOptions;
265 
266 			uint32			fResizeMode;
267 			uint32			fFlags;
268 			bool			fHidden : 1;
269 			bool			fVisible : 1;
270 			bool			fBackgroundDirty : 1;
271 			bool			fIsDesktopBackground : 1;
272 
273 			uint32			fEventMask;
274 			uint32			fEventOptions;
275 
276 			::Window*		fWindow;
277 			View*			fParent;
278 
279 			View*			fFirstChild;
280 			View*			fPreviousSibling;
281 			View*			fNextSibling;
282 			View*			fLastChild;
283 
284 			ServerCursor*	fCursor;
285 			ServerPicture*	fPicture;
286 
287 			// clipping
288 			BRegion			fLocalClipping;
289 
290 	mutable	BRegion			fScreenClipping;
291 	mutable	bool			fScreenClippingValid;
292 
293 			BRegion*		fUserClipping;
294 	mutable	BRegion*		fScreenAndUserClipping;
295 };
296 
297 #endif	// VIEW_H
298