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