1/*
2 * Copyright 2001-2020 Haiku, Inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan A��mus, superstippi@gmx.de
7 *		DarkWyrm, bpmagic@columbus.rr.com
8 *		Ryan Leavengood, leavengood@gmail.com
9 *		Philippe Saint-Pierre, stpere@gmail.com
10 *		John Scipione, jscipione@gmail.com
11 *		Ingo Weinhold, ingo_weinhold@gmx.de
12 *		Clemens Zeidler, haiku@clemens-zeidler.de
13 *		Joseph Groover, looncraz@looncraz.net
14 *		Jacob Secunda, secundja@gmail.com
15 */
16#ifndef TAB_DECORATOR_H
17#define TAB_DECORATOR_H
18
19
20#include <Region.h>
21
22#include "Decorator.h"
23
24
25class Desktop;
26
27
28class TabDecorator: public Decorator {
29public:
30								TabDecorator(DesktopSettings& settings,
31									BRect frame, Desktop* desktop);
32	virtual						~TabDecorator();
33
34protected:
35			enum {
36				COLOR_TAB_FRAME_LIGHT	= 0,
37				COLOR_TAB_FRAME_DARK	= 1,
38				COLOR_TAB				= 2,
39				COLOR_TAB_LIGHT			= 3,
40				COLOR_TAB_BEVEL			= 4,
41				COLOR_TAB_SHADOW		= 5,
42				COLOR_TAB_TEXT			= 6
43			};
44
45			enum {
46				COLOR_BUTTON			= 0,
47				COLOR_BUTTON_LIGHT		= 1
48			};
49
50			enum Component {
51				COMPONENT_TAB,
52
53				COMPONENT_CLOSE_BUTTON,
54				COMPONENT_ZOOM_BUTTON,
55
56				COMPONENT_LEFT_BORDER,
57				COMPONENT_RIGHT_BORDER,
58				COMPONENT_TOP_BORDER,
59				COMPONENT_BOTTOM_BORDER,
60
61				COMPONENT_RESIZE_CORNER
62			};
63
64			typedef rgb_color ComponentColors[7];
65
66public:
67	virtual	void				Draw(BRect updateRect);
68	virtual	void				Draw();
69
70	virtual	Region				RegionAt(BPoint where, int32& tab) const;
71
72	virtual	bool				SetRegionHighlight(Region region,
73									uint8 highlight, BRegion* dirty,
74									int32 tab = -1);
75
76	virtual void				UpdateColors(DesktopSettings& settings);
77
78protected:
79	virtual	void				_DoLayout();
80	virtual	void				_DoOutlineLayout();
81	virtual	void				_DoTabLayout();
82			void				_DistributeTabSize(float delta);
83
84	virtual	void				_DrawFrame(BRect rect) = 0;
85	virtual	void				_DrawOutlineFrame(BRect rect);
86	virtual	void				_DrawTab(Decorator::Tab* tab, BRect r) = 0;
87
88	virtual	void				_DrawButtons(Decorator::Tab* tab,
89									const BRect& invalid);
90	virtual	void				_DrawClose(Decorator::Tab* tab, bool direct,
91									BRect r) = 0;
92	virtual	void				_DrawTitle(Decorator::Tab* tab, BRect r) = 0;
93	virtual	void				_DrawZoom(Decorator::Tab* tab, bool direct,
94									BRect r) = 0;
95
96	virtual	void				_SetTitle(Decorator::Tab* tab,
97									const char* string,
98									BRegion* updateRegion = NULL);
99
100	virtual	void				_MoveBy(BPoint offset);
101	virtual	void				_ResizeBy(BPoint offset, BRegion* dirty);
102
103	virtual	void				_SetFocus(Decorator::Tab* tab);
104	virtual	bool				_SetTabLocation(Decorator::Tab* tab,
105									float location, bool isShifting,
106									BRegion* updateRegion = NULL);
107
108	virtual	bool				_SetSettings(const BMessage& settings,
109									BRegion* updateRegion = NULL);
110
111	virtual	bool				_AddTab(DesktopSettings& settings,
112									int32 index = -1,
113									BRegion* updateRegion = NULL);
114	virtual	bool				_RemoveTab(int32 index,
115									BRegion* updateRegion = NULL);
116	virtual	bool				_MoveTab(int32 from, int32 to, bool isMoving,
117									BRegion* updateRegion = NULL);
118
119	virtual	void				_GetFootprint(BRegion* region);
120
121	virtual	void				_GetButtonSizeAndOffset(const BRect& tabRect,
122									float* offset, float* size,
123									float* inset) const;
124
125	virtual	void				_UpdateFont(DesktopSettings& settings);
126
127private:
128			void				_LayoutTabItems(Decorator::Tab* tab,
129									const BRect& tabRect);
130
131protected:
132	inline	float				_DefaultTextOffset() const;
133	inline	float				_SingleTabOffsetAndSize(float& tabSize);
134
135			void				_CalculateTabsRegion();
136
137protected:
138			BRegion				fTabsRegion;
139			BRect				fOldMovingTab;
140			float				fBorderResizeLength, fResizeKnobSize;
141
142			rgb_color			fFocusFrameColor;
143
144			rgb_color			fFocusTabColor;
145			rgb_color			fFocusTabColorLight;
146			rgb_color			fFocusTabColorBevel;
147			rgb_color			fFocusTabColorShadow;
148			rgb_color			fFocusTextColor;
149
150			rgb_color			fNonFocusFrameColor;
151
152			rgb_color			fNonFocusTabColor;
153			rgb_color			fNonFocusTabColorLight;
154			rgb_color			fNonFocusTabColorBevel;
155			rgb_color			fNonFocusTabColorShadow;
156			rgb_color			fNonFocusTextColor;
157};
158
159
160#endif	// TAB_DECORATOR_H
161