xref: /haiku/headers/os/interface/TabView.h (revision adb0d19d561947362090081e81d90dde59142026)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		TabView.h
23 //	Author:			Marc Flerackers (mflerackers@androme.be)
24 //	Description:	BTab creates individual "tabs" that can be assigned
25 //                  to specific views.
26 //                  BTabView provides the framework for containing and
27 //                  managing groups of BTab objects.
28 //------------------------------------------------------------------------------
29 
30 #ifndef _TAB_VIEW_H
31 #define _TAB_VIEW_H
32 
33 
34 #include <BeBuild.h>
35 #include <View.h>
36 
37 
38 enum tab_position {
39 	B_TAB_FIRST = 999,
40 	B_TAB_FRONT,
41 	B_TAB_ANY
42 };
43 
44 
45 // BTab class ------------------------------------------------------------------
46 class BTab : public BArchivable {
47 
48 public:
49 						BTab(BView * tabView = NULL);
50 						virtual ~BTab();
51 
52 						BTab(BMessage *archive);
53 static BArchivable		*Instantiate(BMessage *archive);
54 
55 virtual	status_t		Archive(BMessage *archive, bool deep = true) const;
56 virtual status_t		Perform(uint32 d, void *arg);
57 
58 		const char		*Label() const;
59 virtual	void			SetLabel(const char *label);
60 
61 		bool			IsSelected() const;
62 virtual	void			Select(BView *owner);
63 virtual	void			Deselect();
64 
65 virtual	void			SetEnabled(bool enabled);
66 		bool			IsEnabled() const;
67 
68 		void			MakeFocus(bool inFocus = true);
69 		bool			IsFocus() const;
70 
71 		//	sets/gets the view to be displayed for this tab
72 virtual	void			SetView(BView *view);
73 		BView			*View() const;
74 
75 virtual void			DrawFocusMark(BView *owner, BRect frame);
76 virtual void			DrawLabel(BView *owner, BRect frame);
77 virtual void			DrawTab(BView *owner, BRect frame, tab_position position,
78 							bool full = true);
79 
80 private:
81 virtual	void			_ReservedTab1();
82 virtual	void			_ReservedTab2();
83 virtual	void			_ReservedTab3();
84 virtual	void			_ReservedTab4();
85 virtual	void			_ReservedTab5();
86 virtual	void			_ReservedTab6();
87 virtual	void			_ReservedTab7();
88 virtual	void			_ReservedTab8();
89 virtual	void			_ReservedTab9();
90 virtual	void			_ReservedTab10();
91 virtual	void			_ReservedTab11();
92 virtual	void			_ReservedTab12();
93 
94 	BTab				&operator=(const BTab &);
95 
96 	bool 				fEnabled;
97 	bool				fSelected;
98 	bool				fFocus;
99 	BView				*fView;
100 	uint32				_reserved[12];
101 };
102 //------------------------------------------------------------------------------
103 
104 
105 // BTabView class --------------------------------------------------------------
106 class BTabView : public BView
107 {
108 public:
109 						BTabView(const char *name,
110 							button_width width = B_WIDTH_AS_USUAL,
111 							uint32 flags = B_FULL_UPDATE_ON_RESIZE |
112 								 B_WILL_DRAW | B_NAVIGABLE_JUMP |
113 								 B_FRAME_EVENTS | B_NAVIGABLE);
114 						BTabView(BRect frame, const char *name,
115 							button_width width = B_WIDTH_AS_USUAL,
116 							uint32 resizingMode = B_FOLLOW_ALL,
117 							uint32 flags = B_FULL_UPDATE_ON_RESIZE |
118 								B_WILL_DRAW | B_NAVIGABLE_JUMP |
119 								B_FRAME_EVENTS | B_NAVIGABLE);
120 						~BTabView();
121 
122 						BTabView(BMessage *archive);
123 static BArchivable		*Instantiate(BMessage *archive);
124 virtual	status_t		Archive(BMessage*, bool deep=true) const;
125 virtual status_t		Perform(perform_code d, void *arg);
126 
127 virtual	void			WindowActivated(bool active);
128 virtual void 			AttachedToWindow();
129 virtual	void			AllAttached();
130 virtual	void			AllDetached();
131 virtual	void			DetachedFromWindow();
132 
133 virtual void 			MessageReceived(BMessage *message);
134 virtual void 			FrameMoved(BPoint newLocation);
135 virtual void			FrameResized(float width,float height);
136 virtual void			KeyDown(const char *bytes, int32 numBytes);
137 virtual void			MouseDown(BPoint point);
138 virtual void			MouseUp(BPoint point);
139 virtual void 			MouseMoved(BPoint point, uint32 transit,
140 								   const BMessage *message);
141 virtual	void			Pulse();
142 
143 virtual	void			Select(int32 tab);
144 		int32			Selection() const;
145 
146 virtual	void			MakeFocus(bool focused = true);
147 virtual	void			SetFocusTab(int32 tab, bool focused);
148 		int32			FocusTab() const;
149 
150 virtual	void			Draw(BRect updateRect);
151 virtual	BRect			DrawTabs();
152 virtual	void			DrawBox(BRect selTabRect);
153 virtual	BRect			TabFrame(int32 tab_index) const;
154 
155 virtual	void			SetFlags(uint32 flags);
156 virtual	void			SetResizingMode(uint32 mode);
157 
158 virtual	void			ResizeToPreferred();
159 virtual	void			GetPreferredSize(float* _width, float* _height);
160 
161 virtual BSize			MinSize();
162 virtual BSize			MaxSize();
163 virtual BSize			PreferredSize();
164 
165 virtual BHandler		*ResolveSpecifier(BMessage *message, int32 index,
166 							BMessage *specifier, int32 what, const char *property);
167 virtual	status_t		GetSupportedSuites(BMessage *message);
168 
169 virtual	void			AddTab(BView *target, BTab *tab = NULL);
170 virtual	BTab			*RemoveTab(int32 tabIndex);
171 
172 virtual	BTab			*TabAt ( int32 tab_index ) const;
173 
174 virtual	void			SetTabWidth(button_width width);
175 		button_width	TabWidth() const;
176 
177 virtual	void			SetTabHeight(float height);
178 		float			TabHeight() const;
179 
180 		BView			*ContainerView() const;
181 
182 		int32			CountTabs() const;
183 		BView			*ViewForTab(int32 tabIndex) const;
184 
185 private:
186 		void			_InitObject(bool layouted, button_width width);
187 
188 virtual	void			_ReservedTabView1();
189 virtual	void			_ReservedTabView2();
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 		BList			*fTabList;
205 		BView			*fContainerView;
206 		button_width	fTabWidthSetting;
207 		float 			fTabWidth;
208 		float			fTabHeight;
209 		int32			fSelection;
210 		int32			fInitialSelection;
211 		int32			fFocus;
212 		float			fTabOffset;
213 		uint32			_reserved[11];
214 };
215 
216 #endif // _TAB_VIEW_H
217