xref: /haiku/headers/os/interface/TabView.h (revision 7c095f47094e418e0c071dd84d861699660d35b9)
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 
12 class BTabView;
13 
14 
15 enum tab_position {
16 	B_TAB_FIRST = 999,
17 	B_TAB_FRONT,
18 	B_TAB_ANY
19 };
20 
21 
22 class BTab : public BArchivable {
23 public:
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 
57 private:
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 
76 private:
77 			uint32				_Borders(BView* owner, BRect frame);
78 
79 private:
80 			bool 				fEnabled;
81 			bool				fSelected;
82 			bool				fFocus;
83 			BView*				fView;
84 			BTabView*			fTabView;
85 
86 			uint32				_reserved[11];
87 };
88 
89 
90 class BTabView : public BView {
91 public:
92 			enum tab_side {
93 				kLeftSide	= 1 << 0,
94 				kRightSide	= 1 << 1,
95 				kTopSide	= 1 << 2,
96 				kBottomSide	= 1 << 3
97 			};
98 
99 								BTabView(const char* name,
100 									button_width width = B_WIDTH_FROM_WIDEST,
101 									uint32 flags = B_FULL_UPDATE_ON_RESIZE
102 										| B_WILL_DRAW | B_NAVIGABLE_JUMP
103 										| B_FRAME_EVENTS | B_NAVIGABLE);
104 								BTabView(BRect frame, const char* name,
105 									button_width width = B_WIDTH_AS_USUAL,
106 									uint32 resizeMask = B_FOLLOW_ALL,
107 									uint32 flags = B_FULL_UPDATE_ON_RESIZE
108 										| B_WILL_DRAW | B_NAVIGABLE_JUMP
109 										| B_FRAME_EVENTS | B_NAVIGABLE);
110 	virtual						~BTabView();
111 
112 								BTabView(BMessage* archive);
113 	static	BArchivable*		Instantiate(BMessage* archive);
114 	virtual	status_t			Archive(BMessage* into,
115 									bool deep = true) const;
116 	virtual status_t			AllUnarchived(const BMessage* from);
117 	virtual	status_t			Perform(perform_code d, void* arg);
118 
119 	virtual	void 				AttachedToWindow();
120 	virtual	void				DetachedFromWindow();
121 	virtual	void				AllAttached();
122 	virtual	void				AllDetached();
123 
124 	virtual	void 				MessageReceived(BMessage* message);
125 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
126 	virtual	void				MouseDown(BPoint where);
127 	virtual	void				MouseUp(BPoint where);
128 	virtual	void 				MouseMoved(BPoint where, uint32 transit,
129 									const BMessage* dragMessage);
130 	virtual	void				Pulse();
131 
132 	virtual	void				Select(int32 index);
133 			int32				Selection() const;
134 
135 	virtual	void				WindowActivated(bool active);
136 	virtual	void				MakeFocus(bool focused = true);
137 	virtual	void				SetFocusTab(int32 tab, bool focused);
138 			int32				FocusTab() const;
139 
140 	virtual	void				Draw(BRect updateRect);
141 	virtual	BRect				DrawTabs();
142 	virtual	void				DrawBox(BRect selectedTabRect);
143 	virtual	BRect				TabFrame(int32 index) const;
144 
145 	virtual	void				SetFlags(uint32 flags);
146 	virtual	void				SetResizingMode(uint32 mode);
147 
148 	virtual	void				ResizeToPreferred();
149 	virtual	void				GetPreferredSize(float* _width, float* _height);
150 
151 	virtual	BSize				MinSize();
152 	virtual	BSize				MaxSize();
153 	virtual	BSize				PreferredSize();
154 
155 	virtual	void 				FrameMoved(BPoint newPosition);
156 	virtual	void				FrameResized(float newWidth, float newHeight);
157 
158 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
159 									int32 index, BMessage* specifier,
160 									int32 what, const char* property);
161 	virtual	status_t			GetSupportedSuites(BMessage* message);
162 
163 	// BTabView
164 	virtual	void				AddTab(BView* target, BTab* tab = NULL);
165 	virtual	BTab*				RemoveTab(int32 tabIndex);
166 
167 	virtual	BTab*				TabAt(int32 index) const;
168 
169 	virtual	void				SetTabWidth(button_width width);
170 			button_width		TabWidth() const;
171 
172 	virtual	void				SetTabHeight(float height);
173 			float				TabHeight() const;
174 
175 	virtual	void				SetBorder(border_style borderStyle);
176 			border_style		Border() const;
177 
178 	virtual	void				SetTabSide(tab_side tabSide);
179 			tab_side			TabSide() const;
180 
181 			BView*				ContainerView() const;
182 
183 			int32				CountTabs() const;
184 			BView*				ViewForTab(int32 tabIndex) const;
185 
186 			int32				IndexOf(BTab* tab) const;
187 
188 private:
189 	// FBC padding and forbidden methods
190 	virtual	void				_ReservedTabView3();
191 	virtual	void				_ReservedTabView4();
192 	virtual	void				_ReservedTabView5();
193 	virtual	void				_ReservedTabView6();
194 	virtual	void				_ReservedTabView7();
195 	virtual	void				_ReservedTabView8();
196 	virtual	void				_ReservedTabView9();
197 	virtual	void				_ReservedTabView10();
198 	virtual	void				_ReservedTabView11();
199 	virtual	void				_ReservedTabView12();
200 
201 								BTabView(const BTabView&);
202 			BTabView&			operator=(const BTabView&);
203 
204 private:
205 			void				_InitObject(bool layouted, button_width width);
206 			void				_InitContainerView(bool layouted);
207 			BSize				_TabsMinSize() const;
208 			float				_BorderWidth() const;
209 			void				_LayoutContainerView(bool layouted);
210 
211 private:
212 			BList*				fTabList;
213 			BView*				fContainerView;
214 			button_width		fTabWidthSetting;
215 			float 				fTabWidth;
216 			float				fTabHeight;
217 			int32				fSelection;
218 			int32				fInitialSelection;
219 			int32				fFocus;
220 			float				fTabOffset;
221 			border_style		fBorderStyle;
222 			tab_side			fTabSide;
223 
224 			uint32				_reserved[9];
225 };
226 
227 #endif // _TAB_VIEW_H
228