xref: /haiku/src/apps/webpositive/tabview/TabContainerView.h (revision 040a81419dda83d1014e9dc94936a4cb3f027303)
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			TabSelected(int32 tabIndex) = 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 			void				SelectTab(int32 tabIndex);
53 			void				SelectTab(TabView* tab);
54 
55 			void				SetTabLabel(int32 tabIndex, const char* label);
56 
57 			void				SetFirstVisibleTabIndex(int32 index);
58 			int32				FirstVisibleTabIndex() const;
59 			int32				MaxFirstVisibleTabIndex() const;
60 
61 			bool				CanScrollLeft() const;
62 			bool				CanScrollRight() const;
63 
64 private:
65 			TabView*			_TabAt(const BPoint& where) const;
66 			void				_MouseMoved(BPoint where, uint32 transit,
67 									const BMessage* dragMessage);
68 			void				_ValidateTabVisibility();
69 			void				_UpdateTabVisibility();
70 			float				_AvailableWidthForTabs() const;
71 			void				_SendFakeMouseMoved();
72 
73 private:
74 			TabView*			fLastMouseEventTab;
75 			bool				fMouseDown;
76 			uint32				fClickCount;
77 			TabView*			fSelectedTab;
78 			Controller*			fController;
79 			int32				fFirstVisibleTabIndex;
80 };
81 
82 #endif // TAB_CONTAINER_VIEW_H
83