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