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