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