xref: /haiku/src/apps/webpositive/tabview/TabContainerView.h (revision 072d3935c2497638e9c2502f574c133caeba9d3d)
1 /*
2  * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
3  *
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 #ifndef TAB_CONTAINER_VIEW_H
7 #define TAB_CONTAINER_VIEW_H
8 
9 #include <GroupView.h>
10 
11 
12 class TabView;
13 
14 
15 class TabContainerView : public BGroupView {
16 public:
17 	class Controller {
18 	public:
19 		virtual	void			UpdateSelection(int32 index) = 0;
20 		virtual	bool			HasFrames() = 0;
21 		virtual	TabView*		CreateTabView() = 0;
22 		virtual	void			DoubleClickOutsideTabs() = 0;
23 		virtual	void			UpdateTabScrollability(bool canScrollLeft,
24 									bool canScrollRight) = 0;
25 		virtual	void			SetToolTip(const BString& text) = 0;
26 	};
27 
28 public:
29 								TabContainerView(Controller* controller);
30 	virtual						~TabContainerView();
31 
32 	virtual	BSize				MinSize();
33 
34 	virtual	void				MessageReceived(BMessage*);
35 
36 	virtual	void				Draw(BRect updateRect);
37 
38 	virtual	void				MouseDown(BPoint where);
39 	virtual	void				MouseUp(BPoint where);
40 	virtual	void				MouseMoved(BPoint where, uint32 transit,
41 									const BMessage* dragMessage);
42 
43 	virtual	void				DoLayout();
44 
45 			void				AddTab(const char* label, int32 index = -1);
46 			void				AddTab(TabView* tab, int32 index = -1);
47 			TabView*			RemoveTab(int32 index);
48 			TabView*			TabAt(int32 index) const;
49 
50 			int32				IndexOf(TabView* tab) const;
51 
52 			int32				FirstTabIndex() { return 0; };
53 			int32				LastTabIndex()
54 									{ return GroupLayout() == NULL ? -1
55 										: GroupLayout()->CountItems() - 1; };
56 			int32				SelectedTabIndex()
57 									{ return fSelectedTab == NULL ? -1
58 										: IndexOf(fSelectedTab); };
59 
60 			TabView*			SelectedTab() { return fSelectedTab; };
61 
62 			void				SelectTab(int32 tabIndex);
63 			void				SelectTab(TabView* tab);
64 
65 			void				SetTabLabel(int32 tabIndex, const char* label);
66 
67 			void				SetFirstVisibleTabIndex(int32 index);
68 			int32				FirstVisibleTabIndex() const;
69 			int32				MaxFirstVisibleTabIndex() const;
70 
71 			bool				CanScrollLeft() const;
72 			bool				CanScrollRight() const;
73 
74 private:
75 			TabView*			_TabAt(const BPoint& where) const;
76 			void				_MouseMoved(BPoint where, uint32 transit,
77 									const BMessage* dragMessage);
78 			void				_ValidateTabVisibility();
79 			void				_UpdateTabVisibility();
80 			float				_AvailableWidthForTabs() const;
81 			void				_SendFakeMouseMoved();
82 
83 private:
84 			TabView*			fLastMouseEventTab;
85 			bool				fMouseDown;
86 			uint32				fClickCount;
87 			TabView*			fSelectedTab;
88 			Controller*			fController;
89 			int32				fFirstVisibleTabIndex;
90 };
91 
92 #endif // TAB_CONTAINER_VIEW_H
93