xref: /haiku/headers/os/interface/TabView.h (revision b671e9bbdbd10268a042b4f4cc4317ccd03d105e)
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 enum tab_position {
13 	B_TAB_FIRST = 999,
14 	B_TAB_FRONT,
15 	B_TAB_ANY
16 };
17 
18 
19 class BTab : public BArchivable {
20 public:
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* archive,
28 									bool deep = true) const;
29 	virtual	status_t			Perform(uint32 d, void* arg);
30 
31 			const char*			Label() const;
32 	virtual	void				SetLabel(const char* label);
33 
34 			bool				IsSelected() const;
35 	virtual	void				Select(BView* owner);
36 	virtual	void				Deselect();
37 
38 	virtual	void				SetEnabled(bool enabled);
39 			bool				IsEnabled() const;
40 
41 			void				MakeFocus(bool inFocus = true);
42 			bool				IsFocus() const;
43 
44 	//	sets/gets the view to be displayed for this tab
45 	virtual	void				SetView(BView* view);
46 			BView*				View() const;
47 
48 	virtual	void				DrawFocusMark(BView* owner, BRect frame);
49 	virtual	void				DrawLabel(BView* owner, BRect frame);
50 	virtual	void				DrawTab(BView* owner, BRect frame,
51 									tab_position position, bool full = true);
52 
53 private:
54 	// FBC padding and forbidden methods
55 	virtual	void				_ReservedTab1();
56 	virtual	void				_ReservedTab2();
57 	virtual	void				_ReservedTab3();
58 	virtual	void				_ReservedTab4();
59 	virtual	void				_ReservedTab5();
60 	virtual	void				_ReservedTab6();
61 	virtual	void				_ReservedTab7();
62 	virtual	void				_ReservedTab8();
63 	virtual	void				_ReservedTab9();
64 	virtual	void				_ReservedTab10();
65 	virtual	void				_ReservedTab11();
66 	virtual	void				_ReservedTab12();
67 
68 			BTab&				operator=(const BTab&);
69 
70 private:
71 			bool 				fEnabled;
72 			bool				fSelected;
73 			bool				fFocus;
74 			BView*				fView;
75 
76 			uint32				_reserved[12];
77 };
78 
79 
80 class BTabView : public BView {
81 public:
82 								BTabView(const char* name,
83 									button_width width = B_WIDTH_AS_USUAL,
84 									uint32 flags = B_FULL_UPDATE_ON_RESIZE
85 										| B_WILL_DRAW | B_NAVIGABLE_JUMP
86 										| B_FRAME_EVENTS | B_NAVIGABLE);
87 								BTabView(BRect frame, const char* name,
88 									button_width width = B_WIDTH_AS_USUAL,
89 									uint32 resizingMode = B_FOLLOW_ALL,
90 									uint32 flags = B_FULL_UPDATE_ON_RESIZE
91 										| B_WILL_DRAW | B_NAVIGABLE_JUMP
92 										| B_FRAME_EVENTS | B_NAVIGABLE);
93 	virtual						~BTabView();
94 
95 								BTabView(BMessage* archive);
96 	static	BArchivable*		Instantiate(BMessage* archive);
97 	virtual	status_t			Archive(BMessage* into,
98 									bool deep = true) const;
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 point);
109 	virtual	void				MouseUp(BPoint point);
110 	virtual	void 				MouseMoved(BPoint point, 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,
132 									float* _height);
133 
134 	virtual	BSize				MinSize();
135 	virtual	BSize				MaxSize();
136 	virtual	BSize				PreferredSize();
137 
138 	virtual	void 				FrameMoved(BPoint newLocation);
139 	virtual	void				FrameResized(float width,float height);
140 
141 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
142 									int32 index, BMessage* specifier,
143 									int32 what, const char* property);
144 	virtual	status_t			GetSupportedSuites(BMessage* message);
145 
146 	// BTabView
147 	virtual	void				AddTab(BView* target, BTab* tab = NULL);
148 	virtual	BTab*				RemoveTab(int32 tabIndex);
149 
150 	virtual	BTab*				TabAt(int32 index) const;
151 
152 	virtual	void				SetTabWidth(button_width width);
153 			button_width		TabWidth() const;
154 
155 	virtual	void				SetTabHeight(float height);
156 			float				TabHeight() const;
157 
158 			BView*				ContainerView() const;
159 
160 			int32				CountTabs() const;
161 			BView*				ViewForTab(int32 tabIndex) const;
162 
163 private:
164 	// FBC padding and forbidden methods
165 	virtual	void				_ReservedTabView1();
166 	virtual	void				_ReservedTabView2();
167 	virtual	void				_ReservedTabView3();
168 	virtual	void				_ReservedTabView4();
169 	virtual	void				_ReservedTabView5();
170 	virtual	void				_ReservedTabView6();
171 	virtual	void				_ReservedTabView7();
172 	virtual	void				_ReservedTabView8();
173 	virtual	void				_ReservedTabView9();
174 	virtual	void				_ReservedTabView10();
175 	virtual	void				_ReservedTabView11();
176 	virtual	void				_ReservedTabView12();
177 
178 								BTabView(const BTabView&);
179 			BTabView&			operator=(const BTabView&);
180 
181 private:
182 			void				_InitObject(bool layouted, button_width width);
183 			BSize				_TabsMinSize() const;
184 
185 private:
186 			BList*				fTabList;
187 			BView*				fContainerView;
188 			button_width		fTabWidthSetting;
189 			float 				fTabWidth;
190 			float				fTabHeight;
191 			int32				fSelection;
192 			int32				fInitialSelection;
193 			int32				fFocus;
194 			float				fTabOffset;
195 
196 			uint32				_reserved[11];
197 };
198 
199 #endif // _TAB_VIEW_H
200