1
2#ifndef	VIEW_LAYER_H
3#define VIEW_LAYER_H
4
5#include <GraphicsDefs.h>
6#include <Region.h>
7#include <String.h>
8
9class BList;
10class DrawingEngine;
11class WindowLayer;
12
13class ViewLayer {
14 public:
15							ViewLayer(BRect frame,
16									  const char* name,
17									  uint32 reizeMode,
18									  uint32 flags,
19									  rgb_color viewColor);
20
21	virtual					~ViewLayer();
22
23	inline	BRect			Frame() const
24								{ return fFrame; }
25			BRect			Bounds() const;
26			// converts the given frame up the view hirarchy and
27			// clips to each views bounds
28			void			ConvertToVisibleInTopView(BRect* bounds) const;
29
30	inline	rgb_color		ViewColor() const
31								{ return fViewColor; }
32
33			void			AttachedToWindow(WindowLayer* window);
34			void			DetachedFromWindow();
35
36			// tree stuff
37			void			AddChild(ViewLayer* layer);
38			bool			RemoveChild(ViewLayer* layer);
39
40	inline	ViewLayer*		Parent() const
41								{ return fParent; }
42
43			ViewLayer*		FirstChild() const;
44			ViewLayer*		PreviousChild() const;
45			ViewLayer*		NextChild() const;
46			ViewLayer*		LastChild() const;
47
48			ViewLayer*		TopLayer();
49
50			uint32			CountChildren(bool deep = false) const;
51			void			CollectTokensForChildren(BList* tokenMap) const;
52
53			ViewLayer*		ViewAt(const BPoint& where,
54								   BRegion* windowContentClipping);
55
56			// coordinate conversion
57			void			ConvertToParent(BPoint* point) const;
58			void			ConvertToParent(BRect* rect) const;
59			void			ConvertToParent(BRegion* region) const;
60
61			void			ConvertFromParent(BPoint* point) const;
62			void			ConvertFromParent(BRect* rect) const;
63			void			ConvertFromParent(BRegion* region) const;
64
65			void			ConvertToTop(BPoint* point) const;
66			void			ConvertToTop(BRect* rect) const;
67			void			ConvertToTop(BRegion* region) const;
68
69			void			ConvertFromTop(BPoint* point) const;
70			void			ConvertFromTop(BRect* rect) const;
71			void			ConvertFromTop(BRegion* region) const;
72
73			// settings
74			void			SetName(const char* string);
75	inline	const char*		Name() const
76								{ return fName.String(); }
77
78			void			MoveBy(			int32 dx, int32 dy,
79											BRegion* dirtyRegion);
80
81			void			ResizeBy(		int32 dx, int32 dy,
82											BRegion* dirtyRegion);
83
84			void			ScrollBy(		int32 dx, int32 dy,
85											BRegion* dirtyRegion);
86
87			void			ParentResized(	int32 dx, int32 dy,
88											BRegion* dirtyRegion);
89
90			// for background clearing
91			void			Draw(			DrawingEngine* drawingEngine,
92											BRegion* effectiveClipping,
93											BRegion* windowContentClipping,
94											bool deep = false);
95
96			// to simulate drawing triggered from client side
97			void			ClientDraw(		DrawingEngine* drawingEngine,
98											BRegion* effectiveClipping);
99
100			void			SetHidden(bool hidden);
101			bool			IsHidden() const;
102
103			// takes into account parent views hidden status
104			bool			IsVisible() const
105								{ return fVisible; }
106			// update visible status for this view and all children
107			// according to the parents visibility
108			void			UpdateVisibleDeep(bool parentVisible);
109
110			// clipping
111			void			RebuildClipping(bool deep);
112			BRegion&		ScreenClipping(BRegion* windowContentClipping,
113										   bool force = false) const;
114			void			InvalidateScreenClipping(bool deep);
115
116			// debugging
117			void			PrintToStream() const;
118
119private:
120			void			_MoveScreenClipping(int32 x, int32 y,
121												bool deep);
122
123			BString			fName;
124			// area within parent coordinate space
125			BRect			fFrame;
126			// scrolling offset
127			BPoint			fScrollingOffset;
128
129			rgb_color		fViewColor;
130
131			uint32			fResizeMode;
132			uint32			fFlags;
133			bool			fHidden;
134			bool			fVisible;
135
136			WindowLayer*	fWindow;
137			ViewLayer*		fParent;
138
139			ViewLayer*		fFirstChild;
140			ViewLayer*		fPreviousSibling;
141			ViewLayer*		fNextSibling;
142			ViewLayer*		fLastChild;
143
144			// used for traversing the childs
145	mutable	ViewLayer*		fCurrentChild;
146
147			// clipping
148			BRegion			fLocalClipping;
149
150	mutable	BRegion			fScreenClipping;
151	mutable	bool			fScreenClippingValid;
152
153};
154
155#endif // LAYER_H
156