xref: /haiku/headers/os/interface/OutlineListView.h (revision 621200ebbd67f15ca5d0d061675409960bfe0b52)
17c74b12bSAxel Dörfler /*
27f9368caSlooncraz  * Copyright 2006-2015, Haiku, Inc. All rights reserved.
389208c77SStephan Aßmus  * Distributed under the terms of the MIT License.
47c74b12bSAxel Dörfler  */
5d734a8ceSbeveloper #ifndef _OUTLINE_LIST_VIEW_H
6d734a8ceSbeveloper #define _OUTLINE_LIST_VIEW_H
7d734a8ceSbeveloper 
87c74b12bSAxel Dörfler 
9d734a8ceSbeveloper #include <ListView.h>
10d734a8ceSbeveloper 
11d734a8ceSbeveloper 
12d734a8ceSbeveloper class BOutlineListView : public BListView {
13d734a8ceSbeveloper public:
147c74b12bSAxel Dörfler 								BOutlineListView(BRect frame, const char* name,
154b15b909SStephan Aßmus 									list_view_type type
164b15b909SStephan Aßmus 										= B_SINGLE_SELECTION_LIST,
177f9368caSlooncraz 									uint32 resizingMode = B_FOLLOW_LEFT_TOP,
184b15b909SStephan Aßmus 									uint32 flags = B_WILL_DRAW
194b15b909SStephan Aßmus 										| B_FRAME_EVENTS | B_NAVIGABLE);
2008a35638SAxel Dörfler 								BOutlineListView(const char* name,
214b15b909SStephan Aßmus 									list_view_type type
224b15b909SStephan Aßmus 										= B_SINGLE_SELECTION_LIST,
234b15b909SStephan Aßmus 									uint32 flags = B_WILL_DRAW
244b15b909SStephan Aßmus 										| B_FRAME_EVENTS | B_NAVIGABLE);
257c74b12bSAxel Dörfler 								BOutlineListView(BMessage* archive);
26d734a8ceSbeveloper 	virtual						~BOutlineListView();
27d734a8ceSbeveloper 
287c74b12bSAxel Dörfler 	static	BArchivable*		Instantiate(BMessage* archive);
294b15b909SStephan Aßmus 	virtual	status_t			Archive(BMessage* archive,
304b15b909SStephan Aßmus 									bool deep = true) const;
31d734a8ceSbeveloper 
32d734a8ceSbeveloper 	virtual	void				MouseDown(BPoint where);
33d734a8ceSbeveloper 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
347c74b12bSAxel Dörfler 	virtual	void				FrameMoved(BPoint newPosition);
357c74b12bSAxel Dörfler 	virtual	void				FrameResized(float newWidth, float newHeight);
36d734a8ceSbeveloper 	virtual	void				MouseUp(BPoint where);
37d734a8ceSbeveloper 
381e1afb39SJohn Scipione 	virtual	bool				AddUnder(BListItem* item, BListItem* superItem);
39d734a8ceSbeveloper 
40d734a8ceSbeveloper 	virtual	bool				AddItem(BListItem* item);
41d734a8ceSbeveloper 	virtual	bool				AddItem(BListItem* item, int32 fullListIndex);
42d734a8ceSbeveloper 	virtual	bool				AddList(BList* newItems);
43d734a8ceSbeveloper 	virtual	bool				AddList(BList* newItems, int32 fullListIndex);
44d734a8ceSbeveloper 
45d734a8ceSbeveloper 	virtual	bool				RemoveItem(BListItem* item);
46d734a8ceSbeveloper 	virtual	BListItem*			RemoveItem(int32 fullListIndex);
47d734a8ceSbeveloper 	virtual	bool				RemoveItems(int32 fullListIndex, int32 count);
48d734a8ceSbeveloper 
49d734a8ceSbeveloper 			BListItem*			FullListItemAt(int32 fullListIndex) const;
501e1afb39SJohn Scipione 			int32				FullListIndexOf(BPoint where) const;
51d734a8ceSbeveloper 			int32				FullListIndexOf(BListItem* item) const;
52d734a8ceSbeveloper 			BListItem*			FullListFirstItem() const;
53d734a8ceSbeveloper 			BListItem*			FullListLastItem() const;
54d734a8ceSbeveloper 			bool				FullListHasItem(BListItem* item) const;
55d734a8ceSbeveloper 			int32				FullListCountItems() const;
564b15b909SStephan Aßmus 			int32				FullListCurrentSelection(
574b15b909SStephan Aßmus 									int32 index = 0) const;
587c74b12bSAxel Dörfler 
59d734a8ceSbeveloper 	virtual	void				MakeEmpty();
60d734a8ceSbeveloper 			bool				FullListIsEmpty() const;
611e1afb39SJohn Scipione 			void				FullListDoForEach(bool (*func)(BListItem* item));
621e1afb39SJohn Scipione 			void				FullListDoForEach(bool (*func)(BListItem* item, void* arg),
631e1afb39SJohn Scipione 									void* arg);
64d734a8ceSbeveloper 
65d734a8ceSbeveloper 			BListItem*			Superitem(const BListItem* item);
66d734a8ceSbeveloper 
67d734a8ceSbeveloper 			void				Expand(BListItem* item);
68d734a8ceSbeveloper 			void				Collapse(BListItem* item);
69d734a8ceSbeveloper 
70d734a8ceSbeveloper 			bool				IsExpanded(int32 fullListIndex);
71d734a8ceSbeveloper 
724b15b909SStephan Aßmus 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
734b15b909SStephan Aßmus 									int32 index, BMessage* specifier,
744b15b909SStephan Aßmus 									int32 what, const char* property);
75d734a8ceSbeveloper 	virtual	status_t			GetSupportedSuites(BMessage* data);
764b15b909SStephan Aßmus 	virtual	status_t			Perform(perform_code code, void* data);
77d734a8ceSbeveloper 
78d734a8ceSbeveloper 	virtual	void				ResizeToPreferred();
794b15b909SStephan Aßmus 	virtual	void				GetPreferredSize(float* _width,
804b15b909SStephan Aßmus 									float* _height);
817c74b12bSAxel Dörfler 	virtual	void				MakeFocus(bool focus = true);
82d734a8ceSbeveloper 	virtual	void				AllAttached();
83d734a8ceSbeveloper 	virtual	void				AllDetached();
84d734a8ceSbeveloper 	virtual	void				DetachedFromWindow();
85d734a8ceSbeveloper 
8608a35638SAxel Dörfler 			void				FullListSortItems(int (*compareFunc)(
8708a35638SAxel Dörfler 										const BListItem* first,
887c74b12bSAxel Dörfler 										const BListItem* second));
891e1afb39SJohn Scipione 			void				SortItemsUnder(BListItem* superItem,
9008a35638SAxel Dörfler 									bool oneLevelOnly, int (*compareFunc)(
9108a35638SAxel Dörfler 										const BListItem* first,
927c74b12bSAxel Dörfler 										const BListItem* second));
931e1afb39SJohn Scipione 			int32				CountItemsUnder(BListItem* superItem,
9408a35638SAxel Dörfler 									bool oneLevelOnly) const;
951e1afb39SJohn Scipione 			BListItem*			EachItemUnder(BListItem* superItem,
9608a35638SAxel Dörfler 									bool oneLevelOnly, BListItem* (*eachFunc)(
974b15b909SStephan Aßmus 										BListItem* item, void* arg),
984b15b909SStephan Aßmus 									void* arg);
991e1afb39SJohn Scipione 			BListItem*			ItemUnderAt(BListItem* superItem,
1004b15b909SStephan Aßmus 									bool oneLevelOnly, int32 index) const;
101d734a8ceSbeveloper 
102d734a8ceSbeveloper protected:
103d734a8ceSbeveloper 	virtual	bool				DoMiscellaneous(MiscCode code, MiscData* data);
1047c74b12bSAxel Dörfler 	virtual void				MessageReceived(BMessage* message);
105d734a8ceSbeveloper 
106d734a8ceSbeveloper private:
107d734a8ceSbeveloper 	virtual	void				_ReservedOutlineListView1();
108d734a8ceSbeveloper 	virtual	void				_ReservedOutlineListView2();
109d734a8ceSbeveloper 	virtual	void				_ReservedOutlineListView3();
110d734a8ceSbeveloper 	virtual	void				_ReservedOutlineListView4();
111d734a8ceSbeveloper 
112d734a8ceSbeveloper protected:
1131e1afb39SJohn Scipione 	virtual	void				ExpandOrCollapse(BListItem* superItem,
1144b15b909SStephan Aßmus 									bool expand);
115d734a8ceSbeveloper 	virtual BRect				LatchRect(BRect itemRect, int32 level) const;
11608a35638SAxel Dörfler 	virtual void				DrawLatch(BRect itemRect, int32 level,
11708a35638SAxel Dörfler 									bool collapsed, bool highlighted,
11808a35638SAxel Dörfler 									bool misTracked);
11908a35638SAxel Dörfler 	virtual	void				DrawItem(BListItem* item, BRect itemRect,
12008a35638SAxel Dörfler 									bool complete = false);
1217c74b12bSAxel Dörfler 
1227c74b12bSAxel Dörfler private:
12308a35638SAxel Dörfler 			int32				_FullListIndex(int32 index) const;
12408a35638SAxel Dörfler 
1257c74b12bSAxel Dörfler 			void				_PopulateTree(BList* tree, BList& target,
1267c74b12bSAxel Dörfler 									int32& firstIndex, bool onlyVisible);
1277c74b12bSAxel Dörfler 			void				_SortTree(BList* tree, bool oneLevelOnly,
12808a35638SAxel Dörfler 									int (*compareFunc)(const BListItem* a,
12908a35638SAxel Dörfler 										const BListItem* b));
1307c74b12bSAxel Dörfler 			void				_DestructTree(BList* tree);
1311e1afb39SJohn Scipione 			BList*				_BuildTree(BListItem* superItem, int32& index);
132d734a8ceSbeveloper 
13384d75fa4SRene Gollent 			void				_CullInvisibleItems(BList &list);
13408a35638SAxel Dörfler 			bool				_SwapItems(int32 first, int32 second);
1354b15b909SStephan Aßmus 			BListItem*			_RemoveItem(BListItem* item,
1364b15b909SStephan Aßmus 									int32 fullListIndex);
137d734a8ceSbeveloper 
1384b15b909SStephan Aßmus 			BListItem*			_SuperitemForIndex(int32 fullListIndex,
1394b15b909SStephan Aßmus 									int32 level, int32* _superIndex = NULL);
140b66c6231SAxel Dörfler 			int32				_FindPreviousVisibleIndex(int32 fullListIndex);
141d734a8ceSbeveloper 
142*621200ebSMáximo Castañeda 			status_t			_ItemsUnderSetup(BListItem* superItem, int32& startIndex,
143*621200ebSMáximo Castañeda 									uint32& baseLevel) const;
1447c74b12bSAxel Dörfler private:
1457c74b12bSAxel Dörfler 			BList				fFullList;
1464b15b909SStephan Aßmus 
147d734a8ceSbeveloper 			uint32				_reserved[2];
148d734a8ceSbeveloper };
149d734a8ceSbeveloper 
1507c74b12bSAxel Dörfler #endif // _OUTLINE_LIST_VIEW_H
151