1e83820edSAxel Dörfler/*
2551438b9SJulian Harnath * Copyright (c) 2001-2015, Haiku, Inc.
3e83820edSAxel Dörfler * Distributed under the terms of the MIT license.
4e83820edSAxel Dörfler *
5e83820edSAxel Dörfler * Authors:
6e83820edSAxel Dörfler *		DarkWyrm <bpmagic@columbus.rr.com>
7e83820edSAxel Dörfler *		Adi Oanca <adioanca@gmail.com>
8ff3abf4dSAxel Dörfler *		Axel D��rfler, axeld@pinc-software.de
9e83820edSAxel Dörfler *		Stephan A��mus <superstippi@gmx.de>
100b0ecfabSMarcus Overhagen *		Marcus Overhagen <marcus@overhagen.de>
11e1a30115SAdrien Destugues *		Adrien Destugues <pulkomandy@pulkomandy.tk>
12551438b9SJulian Harnath *		Julian Harnath <julian.harnath@rwth-aachen.de>
137f9368caSlooncraz *		Joseph Groover <looncraz@looncraz.net>
14e83820edSAxel Dörfler */
15953d895eSAxel Dörfler#ifndef	VIEW_H
16953d895eSAxel Dörfler#define VIEW_H
17e83820edSAxel Dörfler
18e83820edSAxel Dörfler
19ab1bd2fdSJulian Harnath#include "Canvas.h"
20264fe59dSStephan Aßmus#include "IntRect.h"
21e83820edSAxel Dörfler
22e83820edSAxel Dörfler#include <GraphicsDefs.h>
237f9368caSlooncraz#include <InterfaceDefs.h>
242c184b20SAxel Dörfler#include <ObjectList.h>
25e83820edSAxel Dörfler#include <Region.h>
26e83820edSAxel Dörfler#include <String.h>
27e83820edSAxel Dörfler
28e83820edSAxel Dörflerclass BList;
29f6e4cbb9SAxel Dörflerclass BMessage;
30e83820edSAxel Dörfler
31bb160ab5SStephan Aßmusnamespace BPrivate {
32bb160ab5SStephan Aßmus	class PortLink;
33bb160ab5SStephan Aßmus};
34bb160ab5SStephan Aßmus
35e83820edSAxel Dörflerclass DrawingEngine;
360ac013e6SAxel Dörflerclass Overlay;
37953d895eSAxel Dörflerclass Window;
384c66abd6SAxel Dörflerclass ServerBitmap;
39ff3abf4dSAxel Dörflerclass ServerCursor;
4069706266SStefano Ceccheriniclass ServerPicture;
41991547efSStephan Aßmusclass BGradient;
42e83820edSAxel Dörfler
43ab1bd2fdSJulian Harnathclass View: public Canvas {
44a01eaea7SStephan Aßmuspublic:
45953d895eSAxel Dörfler							View(IntRect frame, IntPoint scrollingOffset,
46a4d578c4SStephan Aßmus								const char* name, int32 token,
47a4d578c4SStephan Aßmus								uint32 resizeMode, uint32 flags);
48953d895eSAxel Dörfler	virtual					~View();
49e83820edSAxel Dörfler
50e83820edSAxel Dörfler			int32			Token() const
51e83820edSAxel Dörfler								{ return fToken; }
52e83820edSAxel Dörfler
53264fe59dSStephan Aßmus			IntRect			Frame() const
54e83820edSAxel Dörfler								{ return fFrame; }
55e718dc91SJulian Harnath	virtual	IntRect			Bounds() const;
56e83820edSAxel Dörfler
57e83820edSAxel Dörfler			void			SetResizeMode(uint32 resizeMode)
58e83820edSAxel Dörfler								{ fResizeMode = resizeMode; }
59a7f936aaSStephan Aßmus
60a7f936aaSStephan Aßmus			void			SetName(const char* string);
61a7f936aaSStephan Aßmus			const char*		Name() const
62a7f936aaSStephan Aßmus								{ return fName.String(); }
63a7f936aaSStephan Aßmus
64a7f936aaSStephan Aßmus			void			SetFlags(uint32 flags);
65e83820edSAxel Dörfler			uint32			Flags() const
66e83820edSAxel Dörfler								{ return fFlags; }
67e83820edSAxel Dörfler
68264fe59dSStephan Aßmus	inline	IntPoint		ScrollingOffset() const
69264fe59dSStephan Aßmus								{ return fScrollingOffset; }
70e83820edSAxel Dörfler
71e83820edSAxel Dörfler			// converts the given frame up the view hierarchy and
72e83820edSAxel Dörfler			// clips to each views bounds
73264fe59dSStephan Aßmus			void			ConvertToVisibleInTopView(IntRect* bounds) const;
74e83820edSAxel Dörfler
75953d895eSAxel Dörfler	virtual	void			AttachedToWindow(::Window* window);
762c184b20SAxel Dörfler	virtual void			DetachedFromWindow();
77953d895eSAxel Dörfler			::Window*		Window() const { return fWindow; }
78e83820edSAxel Dörfler
79e1a30115SAdrien Destugues			// Shorthands for opaque Window access
80e1a30115SAdrien Destugues			DrawingEngine*	GetDrawingEngine() const;
81e1a30115SAdrien Destugues			ServerPicture*	GetPicture(int32 token) const;
82e1a30115SAdrien Destugues			void			ResyncDrawState();
83e1a30115SAdrien Destugues			void			UpdateCurrentDrawingRegion();
84e1a30115SAdrien Destugues
85e83820edSAxel Dörfler			// tree stuff
86437b1927SAxel Dörfler			void			AddChild(View* view);
87437b1927SAxel Dörfler			bool			RemoveChild(View* view);
88e83820edSAxel Dörfler
89442e7caaSMichael Lotz	inline	bool			HasParent(View* candidate) const
90442e7caaSMichael Lotz							{
91442e7caaSMichael Lotz								return fParent == candidate
92442e7caaSMichael Lotz									|| (fParent != NULL
93442e7caaSMichael Lotz										&& fParent->HasParent(candidate));
94442e7caaSMichael Lotz							}
95442e7caaSMichael Lotz
96953d895eSAxel Dörfler	inline	View*			Parent() const
97e83820edSAxel Dörfler								{ return fParent; }
98e83820edSAxel Dörfler
99953d895eSAxel Dörfler	inline	View*			FirstChild() const
100264fe59dSStephan Aßmus								{ return fFirstChild; }
101953d895eSAxel Dörfler	inline	View*			LastChild() const
102264fe59dSStephan Aßmus								{ return fLastChild; }
103953d895eSAxel Dörfler	inline	View*			PreviousSibling() const
104264fe59dSStephan Aßmus								{ return fPreviousSibling; }
105953d895eSAxel Dörfler	inline	View*			NextSibling() const
106264fe59dSStephan Aßmus								{ return fNextSibling; }
107e83820edSAxel Dörfler
108437b1927SAxel Dörfler			View*			TopView();
109e83820edSAxel Dörfler
110e83820edSAxel Dörfler			uint32			CountChildren(bool deep = false) const;
111e83820edSAxel Dörfler			void			CollectTokensForChildren(BList* tokenMap) const;
112953d895eSAxel Dörfler			void			FindViews(uint32 flags, BObjectList<View>& list,
113953d895eSAxel Dörfler								int32& left);
114e83820edSAxel Dörfler
1157f9368caSlooncraz			bool			HasView(View* view);
116953d895eSAxel Dörfler			View*			ViewAt(const BPoint& where);
117e83820edSAxel Dörfler
1186f2a446eSJulian Harnathpublic:
119e83820edSAxel Dörfler			void			MoveBy(int32 dx, int32 dy,
120e83820edSAxel Dörfler								BRegion* dirtyRegion);
121e83820edSAxel Dörfler
122e83820edSAxel Dörfler			void			ResizeBy(int32 dx, int32 dy,
123e83820edSAxel Dörfler								BRegion* dirtyRegion);
124e83820edSAxel Dörfler
125e83820edSAxel Dörfler			void			ScrollBy(int32 dx, int32 dy,
126e83820edSAxel Dörfler								BRegion* dirtyRegion);
127e83820edSAxel Dörfler
128e83820edSAxel Dörfler			void			ParentResized(int32 dx, int32 dy,
129e83820edSAxel Dörfler								BRegion* dirtyRegion);
130e83820edSAxel Dörfler
131264fe59dSStephan Aßmus			void			CopyBits(IntRect src, IntRect dst,
132953d895eSAxel Dörfler								BRegion& windowContentClipping);
133e83820edSAxel Dörfler
134e83820edSAxel Dörfler			const BRegion&	LocalClipping() const { return fLocalClipping; }
135e83820edSAxel Dörfler
136f7e1df75SStephan Aßmus			const rgb_color& ViewColor() const
137e83820edSAxel Dörfler								{ return fViewColor; }
138a7f936aaSStephan Aßmus			void			SetViewColor(const rgb_color& color)
139a7f936aaSStephan Aßmus								{ fViewColor = color; }
140fe19cff6SAxel Dörfler
1417f9368caSlooncraz			void			ColorUpdated(color_which which, rgb_color color);
1427f9368caSlooncraz			void			SetViewUIColor(color_which which, float tint);
1437f9368caSlooncraz			color_which		ViewUIColor(float* tint);
1447f9368caSlooncraz
145fe19cff6SAxel Dörfler			ServerBitmap*	ViewBitmap() const
146fe19cff6SAxel Dörfler								{ return fViewBitmap; }
147a4d578c4SStephan Aßmus			void			SetViewBitmap(ServerBitmap* bitmap,
148a4d578c4SStephan Aßmus								IntRect sourceRect, IntRect destRect,
149a4d578c4SStephan Aßmus								int32 resizingMode, int32 options);
150e83820edSAxel Dörfler
151e83820edSAxel Dörfler			void			PushState();
152e83820edSAxel Dörfler			void			PopState();
153e83820edSAxel Dörfler
154e83820edSAxel Dörfler			void			SetEventMask(uint32 eventMask, uint32 options);
155e83820edSAxel Dörfler			uint32			EventMask() const
156e83820edSAxel Dörfler								{ return fEventMask; }
157e83820edSAxel Dörfler			uint32			EventOptions() const
158e83820edSAxel Dörfler								{ return fEventOptions; }
159e83820edSAxel Dörfler
160ff3abf4dSAxel Dörfler			void			SetCursor(ServerCursor* cursor);
161a4d578c4SStephan Aßmus			ServerCursor*	Cursor() const { return fCursor; }
162ff3abf4dSAxel Dörfler
163ff3abf4dSAxel Dörfler			void			SetPicture(ServerPicture* picture);
164a4d578c4SStephan Aßmus			ServerPicture*	Picture() const
165a4d578c4SStephan Aßmus								{ return fPicture; }
16669706266SStefano Ceccherini
167551438b9SJulian Harnath			void			BlendAllLayers();
168551438b9SJulian Harnath
169e83820edSAxel Dörfler			// for background clearing
170e83820edSAxel Dörfler			virtual void	Draw(DrawingEngine* drawingEngine,
171e83820edSAxel Dörfler								BRegion* effectiveClipping,
172e83820edSAxel Dörfler								BRegion* windowContentClipping,
173e83820edSAxel Dörfler								bool deep = false);
174e83820edSAxel Dörfler
17514fe11cfSAxel Dörfler			virtual void	MouseDown(BMessage* message, BPoint where);
17614fe11cfSAxel Dörfler			virtual void	MouseUp(BMessage* message, BPoint where);
17714fe11cfSAxel Dörfler			virtual void	MouseMoved(BMessage* message, BPoint where);
17814fe11cfSAxel Dörfler
179e83820edSAxel Dörfler			void			SetHidden(bool hidden);
180e83820edSAxel Dörfler			bool			IsHidden() const;
181e83820edSAxel Dörfler
182e83820edSAxel Dörfler			// takes into account parent views hidden status
183e83820edSAxel Dörfler			bool			IsVisible() const
184e83820edSAxel Dörfler								{ return fVisible; }
185e83820edSAxel Dörfler			// update visible status for this view and all children
186e83820edSAxel Dörfler			// according to the parents visibility
187e83820edSAxel Dörfler			void			UpdateVisibleDeep(bool parentVisible);
188e83820edSAxel Dörfler
1898e2f6185SAxel Dörfler			void			UpdateOverlay();
1908e2f6185SAxel Dörfler
1913c0e5f8eSStephan Aßmus			void			MarkBackgroundDirty();
1923c0e5f8eSStephan Aßmus			bool			IsBackgroundDirty() const
1933c0e5f8eSStephan Aßmus								{ return fBackgroundDirty; }
1943c0e5f8eSStephan Aßmus
195966fbea6SAxel Dörfler			bool			IsDesktopBackground() const
196966fbea6SAxel Dörfler								{ return fIsDesktopBackground; }
197966fbea6SAxel Dörfler
198437b1927SAxel Dörfler			void			AddTokensForViewsInRegion(BPrivate::PortLink& link,
199bb160ab5SStephan Aßmus								BRegion& region,
200bb160ab5SStephan Aßmus								BRegion* windowContentClipping);
201bb160ab5SStephan Aßmus
202e83820edSAxel Dörfler			// clipping
203e83820edSAxel Dörfler			void			RebuildClipping(bool deep);
204f0c3c996SMichael Lotz			BRegion&		ScreenAndUserClipping(
205f0c3c996SMichael Lotz								BRegion* windowContentClipping,
206a4d578c4SStephan Aßmus								bool force = false) const;
207264fe59dSStephan Aßmus			void			InvalidateScreenClipping();
208264fe59dSStephan Aßmus	inline	bool			IsScreenClippingValid() const
209f0c3c996SMichael Lotz								{
210f0c3c996SMichael Lotz									return fScreenClippingValid
211f0c3c996SMichael Lotz										&& (fUserClipping == NULL
212f0c3c996SMichael Lotz										|| (fUserClipping != NULL
213f0c3c996SMichael Lotz										&& fScreenAndUserClipping != NULL));
214f0c3c996SMichael Lotz								}
215e83820edSAxel Dörfler
216e83820edSAxel Dörfler			// debugging
217e83820edSAxel Dörfler			void			PrintToStream() const;
21889ba97eaSAxel Dörfler#if 0
21989ba97eaSAxel Dörfler			bool			MarkAt(DrawingEngine* engine, const BPoint& where,
22089ba97eaSAxel Dörfler								int32 level = 0);
22189ba97eaSAxel Dörfler#endif
222e83820edSAxel Dörfler
223a01eaea7SStephan Aßmusprotected:
2246f2a446eSJulian Harnath	virtual	void			_LocalToScreenTransform(
2256f2a446eSJulian Harnath								SimpleTransform& transform) const;
2266f2a446eSJulian Harnath	virtual	void			_ScreenToLocalTransform(
2276f2a446eSJulian Harnath								SimpleTransform& transform) const;
2286f2a446eSJulian Harnath
229f0c3c996SMichael Lotz			BRegion&		_ScreenClipping(BRegion* windowContentClipping,
230f0c3c996SMichael Lotz								bool force = false) const;
231e83820edSAxel Dörfler			void			_MoveScreenClipping(int32 x, int32 y,
232a4d578c4SStephan Aßmus								bool deep);
2330ac013e6SAxel Dörfler			Overlay*		_Overlay() const;
234f7c7883bSAxel Dörfler			void			_UpdateOverlayView() const;
235e83820edSAxel Dörfler
236e83820edSAxel Dörfler			BString			fName;
237e83820edSAxel Dörfler			int32			fToken;
238e83820edSAxel Dörfler			// area within parent coordinate space
239264fe59dSStephan Aßmus			IntRect			fFrame;
240099fb2d3SStephan Aßmus			// offset of the local area (bounds)
241264fe59dSStephan Aßmus			IntPoint		fScrollingOffset;
242e83820edSAxel Dörfler
243f7e1df75SStephan Aßmus			rgb_color		fViewColor;
2447f9368caSlooncraz			color_which		fWhichViewColor;
2457f9368caSlooncraz			float			fWhichViewColorTint;
2464c66abd6SAxel Dörfler			ServerBitmap*	fViewBitmap;
247264fe59dSStephan Aßmus			IntRect			fBitmapSource;
248264fe59dSStephan Aßmus			IntRect			fBitmapDestination;
2494c66abd6SAxel Dörfler			int32			fBitmapResizingMode;
2504c66abd6SAxel Dörfler			int32			fBitmapOptions;
251e83820edSAxel Dörfler
252e83820edSAxel Dörfler			uint32			fResizeMode;
253e83820edSAxel Dörfler			uint32			fFlags;
254f7e1df75SStephan Aßmus			bool			fHidden : 1;
255f7e1df75SStephan Aßmus			bool			fVisible : 1;
256f7e1df75SStephan Aßmus			bool			fBackgroundDirty : 1;
257f7e1df75SStephan Aßmus			bool			fIsDesktopBackground : 1;
258e83820edSAxel Dörfler
259e83820edSAxel Dörfler			uint32			fEventMask;
260e83820edSAxel Dörfler			uint32			fEventOptions;
261e83820edSAxel Dörfler
262953d895eSAxel Dörfler			::Window*		fWindow;
263953d895eSAxel Dörfler			View*			fParent;
264e83820edSAxel Dörfler
265953d895eSAxel Dörfler			View*			fFirstChild;
266953d895eSAxel Dörfler			View*			fPreviousSibling;
267953d895eSAxel Dörfler			View*			fNextSibling;
268953d895eSAxel Dörfler			View*			fLastChild;
269e83820edSAxel Dörfler
270ff3abf4dSAxel Dörfler			ServerCursor*	fCursor;
271ff3abf4dSAxel Dörfler			ServerPicture*	fPicture;
272ff3abf4dSAxel Dörfler
273e83820edSAxel Dörfler			// clipping
274e83820edSAxel Dörfler			BRegion			fLocalClipping;
275e83820edSAxel Dörfler
276e83820edSAxel Dörfler	mutable	BRegion			fScreenClipping;
277e83820edSAxel Dörfler	mutable	bool			fScreenClippingValid;
278f0c3c996SMichael Lotz
279f0c3c996SMichael Lotz			BRegion*		fUserClipping;
280f0c3c996SMichael Lotz	mutable	BRegion*		fScreenAndUserClipping;
281e83820edSAxel Dörfler};
282e83820edSAxel Dörfler
283953d895eSAxel Dörfler#endif	// VIEW_H
284