1/*
2 * Copyright 2001-2011, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		DarkWyrm <bpmagic@columbus.rr.com>
7 *		Stephan Aßmus <superstippi@gmx.de>
8 *		Clemens Zeidler <haiku@clemens-zeidler.de>
9 *		Ingo Weinhold <ingo_weinhold@gmx.de>
10 */
11#ifndef DECORATOR_H
12#define DECORATOR_H
13
14
15#include <Rect.h>
16#include <Region.h>
17#include <String.h>
18#include <Window.h>
19
20#include "DrawState.h"
21
22class DesktopSettings;
23class DrawingEngine;
24class ServerFont;
25class BRegion;
26
27
28class Decorator {
29public:
30			class Tab {
31			public:
32								Tab();
33				virtual			~Tab() {}
34
35				BRect			zoomRect;
36				BRect			closeRect;
37				BRect			minimizeRect;
38				BRect			tabRect;
39
40				bool			closePressed : 1;
41				bool			zoomPressed : 1;
42				bool			minimizePressed : 1;
43
44				window_look		look;
45				uint32			flags;
46				bool			isFocused : 1;
47
48				BString			title;
49			};
50
51			enum Region {
52				REGION_NONE,
53
54				REGION_TAB,
55
56				REGION_CLOSE_BUTTON,
57				REGION_ZOOM_BUTTON,
58				REGION_MINIMIZE_BUTTON,
59
60				REGION_LEFT_BORDER,
61				REGION_RIGHT_BORDER,
62				REGION_TOP_BORDER,
63				REGION_BOTTOM_BORDER,
64
65				REGION_LEFT_TOP_CORNER,
66				REGION_LEFT_BOTTOM_CORNER,
67				REGION_RIGHT_TOP_CORNER,
68				REGION_RIGHT_BOTTOM_CORNER,
69
70				REGION_COUNT
71			};
72
73			enum {
74				HIGHLIGHT_NONE,
75				HIGHLIGHT_RESIZE_BORDER,
76
77				HIGHLIGHT_USER_DEFINED
78			};
79
80public:
81							Decorator(DesktopSettings& settings, BRect rect);
82	virtual					~Decorator();
83
84	virtual	Decorator::Tab*	AddTab(DesktopSettings& settings, const char* title,
85								window_look look, uint32 flags,
86								int32 index = -1, BRegion* updateRegion = NULL);
87	virtual	bool			RemoveTab(int32 index,
88								BRegion* updateRegion = NULL);
89	virtual	bool			MoveTab(int32 from, int32 to, bool isMoving,
90								BRegion* updateRegion = NULL);
91	virtual int32			TabAt(const BPoint& where) const;
92			Decorator::Tab*	TabAt(int32 index) const
93								{ return fTabList.ItemAt(index); }
94			int32			CountTabs() const
95								{ return fTabList.CountItems(); }
96			void			SetTopTab(int32 tab);
97
98			void			SetDrawingEngine(DrawingEngine *driver);
99	inline	DrawingEngine*	GetDrawingEngine() const
100								{ return fDrawingEngine; }
101
102			void			FontsChanged(DesktopSettings& settings,
103								BRegion* updateRegion = NULL);
104			void			SetLook(int32 tab, DesktopSettings& settings,
105								window_look look, BRegion* updateRegion = NULL);
106			void			SetFlags(int32 tab, uint32 flags,
107								BRegion* updateRegion = NULL);
108
109			window_look		Look(int32 tab) const;
110			uint32			Flags(int32 tab) const;
111
112			BRect			BorderRect() const;
113			BRect			TitleBarRect() const;
114			BRect			TabRect(int32 tab) const;
115			BRect			TabRect(Decorator::Tab* tab) const;
116
117			void			SetClose(int32 tab, bool pressed);
118			void			SetMinimize(int32 tab, bool pressed);
119			void			SetZoom(int32 tab, bool pressed);
120
121			const char*		Title(int32 tab) const;
122			const char*		Title(Decorator::Tab* tab) const;
123			void			SetTitle(int32 tab, const char* string,
124								BRegion* updateRegion = NULL);
125
126			void			SetFocus(int32 tab, bool focussed);
127			bool			IsFocus(int32 tab) const;
128			bool			IsFocus(Decorator::Tab* tab) const;
129
130			/*! \return true if tab location updated, false if out of bounds
131			or unsupported */
132			bool			SetTabLocation(int32 tab, float location,
133								bool isShifting, BRegion* updateRegion = NULL);
134	virtual	float			TabLocation(int32 tab) const
135								{ return 0.0; }
136
137	virtual	Region			RegionAt(BPoint where, int32& tab) const;
138
139	virtual	void			GetSizeLimits(int32* minWidth, int32* minHeight,
140								int32* maxWidth, int32* maxHeight) const;
141
142			const BRegion&	GetFootprint();
143
144			void			MoveBy(float x, float y);
145			void			MoveBy(BPoint offset);
146			void			ResizeBy(float x, float y, BRegion* dirty);
147			void			ResizeBy(BPoint offset, BRegion* dirty);
148
149	virtual	bool			SetRegionHighlight(Region region, uint8 highlight,
150								BRegion* dirty, int32 tab = -1);
151	inline	uint8			RegionHighlight(Region region,
152								int32 tab = -1) const;
153
154			bool			SetSettings(const BMessage& settings,
155								BRegion* updateRegion = NULL);
156	virtual	bool			GetSettings(BMessage* settings) const;
157
158	virtual	void			Draw(BRect rect);
159	virtual	void			Draw();
160	virtual	void			DrawClose(int32 tab);
161	virtual	void			DrawMinimize(int32 tab);
162	virtual	void			DrawTab(int32 tab);
163	virtual	void			DrawTitle(int32 tab);
164	virtual	void			DrawZoom(int32 tab);
165	virtual	void			DrawFrame();
166
167			rgb_color		UIColor(color_which which);
168
169	virtual	void			ExtendDirtyRegion(Region region, BRegion& dirty);
170
171protected:
172	virtual	void			_DoLayout();
173
174	virtual	void			_DrawFrame(BRect rect);
175
176	virtual	void			_DrawTabs(BRect rect);
177	virtual	void			_DrawTab(Decorator::Tab* tab, BRect rect);
178	virtual	void			_DrawTitle(Decorator::Tab* tab, BRect rect);
179	//! direct means drawing without double buffering
180	virtual	void			_DrawClose(Decorator::Tab* tab, bool direct,
181								BRect rect);
182	virtual	void			_DrawZoom(Decorator::Tab* tab, bool direct,
183								BRect rect);
184	virtual	void			_DrawMinimize(Decorator::Tab* tab, bool direct,
185								BRect rect);
186
187	virtual	Decorator::Tab*	_AllocateNewTab() = 0;
188
189	virtual	void			_SetTitle(Decorator::Tab* tab, const char* string,
190								BRegion* updateRegion = NULL) = 0;
191			int32			_TitleWidth(Decorator::Tab* tab) const
192								{ return tab->title.CountChars(); }
193
194	virtual	bool			_SetTabLocation(Decorator::Tab* tab, float location,
195								bool isShifting, BRegion* updateRegion = NULL);
196	virtual	void			_SetFocus(Decorator::Tab* tab);
197
198	virtual void			_FontsChanged(DesktopSettings& settings,
199								BRegion* updateRegion = NULL);
200	virtual void			_SetLook(Decorator::Tab* tab,
201								DesktopSettings& settings, window_look look,
202								BRegion* updateRegion = NULL);
203	virtual void			_SetFlags(Decorator::Tab* tab, uint32 flags,
204								BRegion* updateRegion = NULL);
205
206	virtual void			_MoveBy(BPoint offset);
207	virtual	void			_ResizeBy(BPoint offset, BRegion* dirty) = 0;
208
209	virtual bool			_SetSettings(const BMessage& settings,
210								BRegion* updateRegion = NULL);
211
212	virtual bool			_AddTab(DesktopSettings& settings,
213								int32 index = -1,
214								BRegion* updateRegion = NULL) = 0;
215	virtual	bool			_RemoveTab(int32 index,
216								BRegion* updateRegion = NULL) = 0;
217	virtual	bool			_MoveTab(int32 from, int32 to, bool isMoving,
218								BRegion* updateRegion = NULL) = 0;
219
220	virtual	void			_GetFootprint(BRegion *region);
221			void			_InvalidateFootprint();
222
223			DrawingEngine*	fDrawingEngine;
224			DrawState		fDrawState;
225
226			BRect			fTitleBarRect;
227			BRect			fFrame;
228			BRect			fResizeRect;
229			BRect			fBorderRect;
230
231			Decorator::Tab*	fTopTab;
232			BObjectList<Decorator::Tab>	fTabList;
233private:
234			BRegion			fFootprint;
235			bool			fFootprintValid : 1;
236
237			uint8			fRegionHighlights[REGION_COUNT - 1];
238};
239
240
241uint8
242Decorator::RegionHighlight(Region region, int32 tab) const
243{
244	int32 index = (int32)region - 1;
245	return index >= 0 && index < REGION_COUNT - 1
246		? fRegionHighlights[index] : 0;
247}
248
249
250#endif	// DECORATOR_H
251