TabView.h revision 65dfd2c6
1/*
2 * Copyright 2001-2009 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _TAB_VIEW_H
6#define _TAB_VIEW_H
7
8
9#include <View.h>
10
11
12enum tab_position {
13	B_TAB_FIRST = 999,
14	B_TAB_FRONT,
15	B_TAB_ANY
16};
17
18
19class BTab : public BArchivable {
20public:
21								BTab(BView* tabView = NULL);
22	virtual						~BTab();
23
24								BTab(BMessage* archive);
25	static	BArchivable*		Instantiate(BMessage* archive);
26
27	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
28	virtual	status_t			Perform(uint32 d, void* arg);
29
30			const char*			Label() const;
31	virtual	void				SetLabel(const char* label);
32
33			bool				IsSelected() const;
34	virtual	void				Select(BView* owner);
35	virtual	void				Deselect();
36
37	virtual	void				SetEnabled(bool enable);
38			bool				IsEnabled() const;
39
40			void				MakeFocus(bool focus = true);
41			bool				IsFocus() const;
42
43	//	sets/gets the view to be displayed for this tab
44	virtual	void				SetView(BView* view);
45			BView*				View() const;
46
47	virtual	void				DrawFocusMark(BView* owner, BRect frame);
48	virtual	void				DrawLabel(BView* owner, BRect frame);
49	virtual	void				DrawTab(BView* owner, BRect frame,
50									tab_position position, bool full = true);
51
52private:
53	// FBC padding and forbidden methods
54	virtual	void				_ReservedTab1();
55	virtual	void				_ReservedTab2();
56	virtual	void				_ReservedTab3();
57	virtual	void				_ReservedTab4();
58	virtual	void				_ReservedTab5();
59	virtual	void				_ReservedTab6();
60	virtual	void				_ReservedTab7();
61	virtual	void				_ReservedTab8();
62	virtual	void				_ReservedTab9();
63	virtual	void				_ReservedTab10();
64	virtual	void				_ReservedTab11();
65	virtual	void				_ReservedTab12();
66
67			BTab&				operator=(const BTab&);
68
69private:
70			bool 				fEnabled;
71			bool				fSelected;
72			bool				fFocus;
73			BView*				fView;
74
75			uint32				_reserved[12];
76};
77
78
79class BTabView : public BView {
80public:
81								BTabView(const char* name,
82									button_width width = B_WIDTH_AS_USUAL,
83									uint32 flags = B_FULL_UPDATE_ON_RESIZE
84										| B_WILL_DRAW | B_NAVIGABLE_JUMP
85										| B_FRAME_EVENTS | B_NAVIGABLE);
86								BTabView(BRect frame, const char* name,
87									button_width width = B_WIDTH_AS_USUAL,
88									uint32 resizeMask = B_FOLLOW_ALL,
89									uint32 flags = B_FULL_UPDATE_ON_RESIZE
90										| B_WILL_DRAW | B_NAVIGABLE_JUMP
91										| B_FRAME_EVENTS | B_NAVIGABLE);
92	virtual						~BTabView();
93
94								BTabView(BMessage* archive);
95	static	BArchivable*		Instantiate(BMessage* archive);
96	virtual	status_t			Archive(BMessage* into,
97									bool deep = true) const;
98	virtual status_t			AllUnarchived(const BMessage* from);
99	virtual	status_t			Perform(perform_code d, void* arg);
100
101	virtual	void 				AttachedToWindow();
102	virtual	void				DetachedFromWindow();
103	virtual	void				AllAttached();
104	virtual	void				AllDetached();
105
106	virtual	void 				MessageReceived(BMessage* message);
107	virtual	void				KeyDown(const char* bytes, int32 numBytes);
108	virtual	void				MouseDown(BPoint where);
109	virtual	void				MouseUp(BPoint where);
110	virtual	void 				MouseMoved(BPoint where, uint32 transit,
111									const BMessage* dragMessage);
112	virtual	void				Pulse();
113
114	virtual	void				Select(int32 tab);
115			int32				Selection() const;
116
117	virtual	void				WindowActivated(bool active);
118	virtual	void				MakeFocus(bool focused = true);
119	virtual	void				SetFocusTab(int32 tab, bool focused);
120			int32				FocusTab() const;
121
122	virtual	void				Draw(BRect updateRect);
123	virtual	BRect				DrawTabs();
124	virtual	void				DrawBox(BRect selectedTabRect);
125	virtual	BRect				TabFrame(int32 index) const;
126
127	virtual	void				SetFlags(uint32 flags);
128	virtual	void				SetResizingMode(uint32 mode);
129
130	virtual	void				ResizeToPreferred();
131	virtual	void				GetPreferredSize(float* _width, float* _height);
132
133	virtual	BSize				MinSize();
134	virtual	BSize				MaxSize();
135	virtual	BSize				PreferredSize();
136
137	virtual	void 				FrameMoved(BPoint newPosition);
138	virtual	void				FrameResized(float newWidth, float newHeight);
139
140	virtual	BHandler*			ResolveSpecifier(BMessage* message,
141									int32 index, BMessage* specifier,
142									int32 what, const char* property);
143	virtual	status_t			GetSupportedSuites(BMessage* message);
144
145	// BTabView
146	virtual	void				AddTab(BView* target, BTab* tab = NULL);
147	virtual	BTab*				RemoveTab(int32 tabIndex);
148
149	virtual	BTab*				TabAt(int32 index) const;
150
151	virtual	void				SetTabWidth(button_width width);
152			button_width		TabWidth() const;
153
154	virtual	void				SetTabHeight(float height);
155			float				TabHeight() const;
156
157	virtual	void				SetBorder(border_style border);
158			border_style		Border() const;
159
160			BView*				ContainerView() const;
161
162			int32				CountTabs() const;
163			BView*				ViewForTab(int32 tabIndex) const;
164
165private:
166	// FBC padding and forbidden methods
167	virtual	void				_ReservedTabView2();
168	virtual	void				_ReservedTabView3();
169	virtual	void				_ReservedTabView4();
170	virtual	void				_ReservedTabView5();
171	virtual	void				_ReservedTabView6();
172	virtual	void				_ReservedTabView7();
173	virtual	void				_ReservedTabView8();
174	virtual	void				_ReservedTabView9();
175	virtual	void				_ReservedTabView10();
176	virtual	void				_ReservedTabView11();
177	virtual	void				_ReservedTabView12();
178
179								BTabView(const BTabView&);
180			BTabView&			operator=(const BTabView&);
181
182private:
183			void				_InitObject(bool layouted, button_width width);
184			void				_InitContainerView(bool layouted);
185			BSize				_TabsMinSize() const;
186			float				_BorderWidth() const;
187			void				_LayoutContainerView(bool layouted);
188
189private:
190			BList*				fTabList;
191			BView*				fContainerView;
192			button_width		fTabWidthSetting;
193			float 				fTabWidth;
194			float				fTabHeight;
195			int32				fSelection;
196			int32				fInitialSelection;
197			int32				fFocus;
198			float				fTabOffset;
199			border_style		fBorderStyle;
200
201			uint32				_reserved[10];
202};
203
204#endif // _TAB_VIEW_H
205