xref: /haiku/src/apps/webpositive/tabview/TabContainerView.h (revision e53f0019b57484c9fe0b24371d9c8520b52af57d)
1 /*
2  * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
3  *
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
16  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
19  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef TAB_CONTAINER_VIEW_H
28 #define TAB_CONTAINER_VIEW_H
29 
30 #include <GroupView.h>
31 
32 
33 class TabView;
34 
35 
36 class TabContainerView : public BGroupView {
37 public:
38 	class Controller {
39 	public:
40 		virtual	void			TabSelected(int32 tabIndex) = 0;
41 		virtual	bool			HasFrames() = 0;
42 		virtual	TabView*		CreateTabView() = 0;
43 		virtual	void			DoubleClickOutsideTabs() = 0;
44 		virtual	void			UpdateTabScrollability(bool canScrollLeft,
45 									bool canScrollRight) = 0;
46 		virtual	void			SetToolTip(const BString& text) = 0;
47 	};
48 
49 public:
50 								TabContainerView(Controller* controller);
51 	virtual						~TabContainerView();
52 
53 	virtual	BSize				MinSize();
54 
55 	virtual	void				MessageReceived(BMessage*);
56 
57 	virtual	void				Draw(BRect updateRect);
58 
59 	virtual	void				MouseDown(BPoint where);
60 	virtual	void				MouseUp(BPoint where);
61 	virtual	void				MouseMoved(BPoint where, uint32 transit,
62 									const BMessage* dragMessage);
63 
64 	virtual	void				DoLayout();
65 
66 			void				AddTab(const char* label, int32 index = -1);
67 			void				AddTab(TabView* tab, int32 index = -1);
68 			TabView*			RemoveTab(int32 index);
69 			TabView*			TabAt(int32 index) const;
70 
71 			int32				IndexOf(TabView* tab) const;
72 
73 			void				SelectTab(int32 tabIndex);
74 			void				SelectTab(TabView* tab);
75 
76 			void				SetTabLabel(int32 tabIndex, const char* label);
77 
78 			void				SetFirstVisibleTabIndex(int32 index);
79 			int32				FirstVisibleTabIndex() const;
80 			int32				MaxFirstVisibleTabIndex() const;
81 
82 			bool				CanScrollLeft() const;
83 			bool				CanScrollRight() const;
84 
85 private:
86 			TabView*			_TabAt(const BPoint& where) const;
87 			void				_MouseMoved(BPoint where, uint32 transit,
88 									const BMessage* dragMessage);
89 			void				_ValidateTabVisibility();
90 			void				_UpdateTabVisibility();
91 			float				_AvailableWidthForTabs() const;
92 			void				_SendFakeMouseMoved();
93 
94 private:
95 			TabView*			fLastMouseEventTab;
96 			bool				fMouseDown;
97 			uint32				fClickCount;
98 			TabView*			fSelectedTab;
99 			Controller*			fController;
100 			int32				fFirstVisibleTabIndex;
101 };
102 
103 #endif // TAB_CONTAINER_VIEW_H
104