xref: /haiku/headers/os/interface/TabView.h (revision d374a27286b8a52974a97dba0d5966ea026a665d)
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			AllUnarchived(const BMessage* from);
100 	virtual	status_t			Perform(perform_code d, void* arg);
101 
102 	virtual	void 				AttachedToWindow();
103 	virtual	void				DetachedFromWindow();
104 	virtual	void				AllAttached();
105 	virtual	void				AllDetached();
106 
107 	virtual	void 				MessageReceived(BMessage* message);
108 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
109 	virtual	void				MouseDown(BPoint point);
110 	virtual	void				MouseUp(BPoint point);
111 	virtual	void 				MouseMoved(BPoint point, uint32 transit,
112 									const BMessage* dragMessage);
113 	virtual	void				Pulse();
114 
115 	virtual	void				Select(int32 tab);
116 			int32				Selection() const;
117 
118 	virtual	void				WindowActivated(bool active);
119 	virtual	void				MakeFocus(bool focused = true);
120 	virtual	void				SetFocusTab(int32 tab, bool focused);
121 			int32				FocusTab() const;
122 
123 	virtual	void				Draw(BRect updateRect);
124 	virtual	BRect				DrawTabs();
125 	virtual	void				DrawBox(BRect selectedTabRect);
126 	virtual	BRect				TabFrame(int32 index) const;
127 
128 	virtual	void				SetFlags(uint32 flags);
129 	virtual	void				SetResizingMode(uint32 mode);
130 
131 	virtual	void				ResizeToPreferred();
132 	virtual	void				GetPreferredSize(float* _width,
133 									float* _height);
134 
135 	virtual	BSize				MinSize();
136 	virtual	BSize				MaxSize();
137 	virtual	BSize				PreferredSize();
138 
139 	virtual	void 				FrameMoved(BPoint newLocation);
140 	virtual	void				FrameResized(float width,float height);
141 
142 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
143 									int32 index, BMessage* specifier,
144 									int32 what, const char* property);
145 	virtual	status_t			GetSupportedSuites(BMessage* message);
146 
147 	// BTabView
148 	virtual	void				AddTab(BView* target, BTab* tab = NULL);
149 	virtual	BTab*				RemoveTab(int32 tabIndex);
150 
151 	virtual	BTab*				TabAt(int32 index) const;
152 
153 	virtual	void				SetTabWidth(button_width width);
154 			button_width		TabWidth() const;
155 
156 	virtual	void				SetTabHeight(float height);
157 			float				TabHeight() const;
158 
159 	virtual	void				SetBorder(border_style border);
160 			border_style		Border() const;
161 
162 			BView*				ContainerView() const;
163 
164 			int32				CountTabs() const;
165 			BView*				ViewForTab(int32 tabIndex) const;
166 
167 private:
168 	// FBC padding and forbidden methods
169 	virtual	void				_ReservedTabView2();
170 	virtual	void				_ReservedTabView3();
171 	virtual	void				_ReservedTabView4();
172 	virtual	void				_ReservedTabView5();
173 	virtual	void				_ReservedTabView6();
174 	virtual	void				_ReservedTabView7();
175 	virtual	void				_ReservedTabView8();
176 	virtual	void				_ReservedTabView9();
177 	virtual	void				_ReservedTabView10();
178 	virtual	void				_ReservedTabView11();
179 	virtual	void				_ReservedTabView12();
180 
181 								BTabView(const BTabView&);
182 			BTabView&			operator=(const BTabView&);
183 
184 private:
185 			void				_InitObject(bool layouted, button_width width);
186 			void				_InitContainerView(bool layouted);
187 			BSize				_TabsMinSize() const;
188 			float				_BorderWidth() const;
189 			void				_LayoutContainerView(bool layouted);
190 
191 private:
192 			BList*				fTabList;
193 			BView*				fContainerView;
194 			button_width		fTabWidthSetting;
195 			float 				fTabWidth;
196 			float				fTabHeight;
197 			int32				fSelection;
198 			int32				fInitialSelection;
199 			int32				fFocus;
200 			float				fTabOffset;
201 			border_style		fBorderStyle;
202 
203 			uint32				_reserved[10];
204 };
205 
206 #endif // _TAB_VIEW_H
207