xref: /haiku/headers/os/interface/OutlineListView.h (revision 08a3563801c70c9219f6ea3b5cd92000ec15b1b1)
17c74b12bSAxel Dörfler /*
2*08a35638SAxel Dörfler  * Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
37c74b12bSAxel Dörfler  * 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 class BListItem;
12d734a8ceSbeveloper 
13d734a8ceSbeveloper 
14d734a8ceSbeveloper class BOutlineListView : public BListView {
15d734a8ceSbeveloper public:
167c74b12bSAxel Dörfler 							BOutlineListView(BRect frame, const char* name,
17d734a8ceSbeveloper 								list_view_type type = B_SINGLE_SELECTION_LIST,
18*08a35638SAxel Dörfler 								uint32 resizeMode
19*08a35638SAxel Dörfler 									= B_FOLLOW_LEFT | B_FOLLOW_TOP,
20*08a35638SAxel Dörfler 								uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
21*08a35638SAxel Dörfler 									| B_NAVIGABLE);
22*08a35638SAxel Dörfler 							BOutlineListView(const char* name,
23*08a35638SAxel Dörfler 								list_view_type type = B_SINGLE_SELECTION_LIST,
24d734a8ceSbeveloper 								uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
25d734a8ceSbeveloper 									| B_NAVIGABLE);
267c74b12bSAxel Dörfler 							BOutlineListView(BMessage* archive);
27d734a8ceSbeveloper 	virtual 				~BOutlineListView();
28d734a8ceSbeveloper 
297c74b12bSAxel Dörfler 	static	BArchivable*	Instantiate(BMessage* archive);
307c74b12bSAxel Dörfler 	virtual	status_t		Archive(BMessage* archive, 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 
38d734a8ceSbeveloper 	virtual bool			AddUnder(BListItem* item, BListItem* underItem);
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;
50d734a8ceSbeveloper 			int32			FullListIndexOf(BPoint point) 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;
56d734a8ceSbeveloper 			int32			FullListCurrentSelection(int32 index = 0) const;
577c74b12bSAxel Dörfler 
58d734a8ceSbeveloper 	virtual	void			MakeEmpty();
59d734a8ceSbeveloper 			bool			FullListIsEmpty() const;
607c74b12bSAxel Dörfler 			void			FullListDoForEach(bool (*func)(BListItem* item));
61*08a35638SAxel Dörfler 			void			FullListDoForEach(
62*08a35638SAxel Dörfler 								bool (*func)(BListItem* item, void*), void*);
63d734a8ceSbeveloper 
64d734a8ceSbeveloper 			BListItem*		Superitem(const BListItem* item);
65d734a8ceSbeveloper 
66d734a8ceSbeveloper 			void			Expand(BListItem* item);
67d734a8ceSbeveloper 			void			Collapse(BListItem* item);
68d734a8ceSbeveloper 
69d734a8ceSbeveloper 			bool			IsExpanded(int32 fullListIndex);
70d734a8ceSbeveloper 
717c74b12bSAxel Dörfler 	virtual BHandler*		ResolveSpecifier(BMessage* message, int32 index,
72*08a35638SAxel Dörfler 								BMessage* specifier, int32 what,
73*08a35638SAxel Dörfler 								const char* property);
74d734a8ceSbeveloper 	virtual status_t		GetSupportedSuites(BMessage* data);
75d734a8ceSbeveloper 	virtual status_t		Perform(perform_code d, void* arg);
76d734a8ceSbeveloper 
77d734a8ceSbeveloper 	virtual void			ResizeToPreferred();
787c74b12bSAxel Dörfler 	virtual void			GetPreferredSize(float* _width, float* _height);
797c74b12bSAxel Dörfler 	virtual void			MakeFocus(bool focus = true);
80d734a8ceSbeveloper 	virtual void			AllAttached();
81d734a8ceSbeveloper 	virtual void			AllDetached();
82d734a8ceSbeveloper 	virtual void			DetachedFromWindow();
83d734a8ceSbeveloper 
84*08a35638SAxel Dörfler 			void			FullListSortItems(int (*compareFunc)(
85*08a35638SAxel Dörfler 									const BListItem* first,
867c74b12bSAxel Dörfler 									const BListItem* second));
87*08a35638SAxel Dörfler 			void			SortItemsUnder(BListItem* underItem,
88*08a35638SAxel Dörfler 								bool oneLevelOnly, int (*compareFunc)(
89*08a35638SAxel Dörfler 									const BListItem* first,
907c74b12bSAxel Dörfler 									const BListItem* second));
91*08a35638SAxel Dörfler 			int32			CountItemsUnder(BListItem* under,
92*08a35638SAxel Dörfler 								bool oneLevelOnly) const;
93*08a35638SAxel Dörfler 			BListItem*		EachItemUnder(BListItem* underItem,
94*08a35638SAxel Dörfler 								bool oneLevelOnly, BListItem* (*eachFunc)(
95*08a35638SAxel Dörfler 									BListItem* item, void* arg), void* arg);
967c74b12bSAxel Dörfler 			BListItem*		ItemUnderAt(BListItem* underItem, bool oneLevelOnly,
97d734a8ceSbeveloper 								int32 index) const;
98d734a8ceSbeveloper 
99d734a8ceSbeveloper protected:
100d734a8ceSbeveloper 	virtual	bool			DoMiscellaneous(MiscCode code, MiscData* data);
1017c74b12bSAxel Dörfler 	virtual void			MessageReceived(BMessage* message);
102d734a8ceSbeveloper 
103d734a8ceSbeveloper private:
104d734a8ceSbeveloper 	virtual	void			_ReservedOutlineListView1();
105d734a8ceSbeveloper 	virtual	void			_ReservedOutlineListView2();
106d734a8ceSbeveloper 	virtual	void			_ReservedOutlineListView3();
107d734a8ceSbeveloper 	virtual	void			_ReservedOutlineListView4();
108d734a8ceSbeveloper 
109d734a8ceSbeveloper protected:
110d734a8ceSbeveloper 	virtual	void			ExpandOrCollapse(BListItem* underItem, bool expand);
111d734a8ceSbeveloper 	virtual BRect			LatchRect(BRect itemRect, int32 level) const;
112*08a35638SAxel Dörfler 	virtual void			DrawLatch(BRect itemRect, int32 level,
113*08a35638SAxel Dörfler 								bool collapsed, bool highlighted,
114*08a35638SAxel Dörfler 								bool misTracked);
115*08a35638SAxel Dörfler 	virtual	void			DrawItem(BListItem* item, BRect itemRect,
116*08a35638SAxel Dörfler 								bool complete = false);
1177c74b12bSAxel Dörfler 
1187c74b12bSAxel Dörfler private:
119*08a35638SAxel Dörfler 			int32			_FullListIndex(int32 index) const;
120*08a35638SAxel Dörfler 
1217c74b12bSAxel Dörfler 			void			_PopulateTree(BList* tree, BList& target,
1227c74b12bSAxel Dörfler 								int32& firstIndex, bool onlyVisible);
1237c74b12bSAxel Dörfler 			void			_SortTree(BList* tree, bool oneLevelOnly,
124*08a35638SAxel Dörfler 								int (*compareFunc)(const BListItem* a,
125*08a35638SAxel Dörfler 									const BListItem* b));
1267c74b12bSAxel Dörfler 			void			_DestructTree(BList* tree);
1277c74b12bSAxel Dörfler 			BList*			_BuildTree(BListItem* underItem, int32& index);
128d734a8ceSbeveloper 
12984d75fa4SRene Gollent 			void			_CullInvisibleItems(BList &list);
130*08a35638SAxel Dörfler 			bool			_SwapItems(int32 first, int32 second);
131*08a35638SAxel Dörfler 			BListItem*		_RemoveItem(BListItem* item, int32 fullListIndex);
132d734a8ceSbeveloper 
133b66c6231SAxel Dörfler 			BListItem*		_SuperitemForIndex(int32 fullListIndex, int32 level,
134b66c6231SAxel Dörfler 								int32* _superIndex = NULL);
135b66c6231SAxel Dörfler 			int32			_FindPreviousVisibleIndex(int32 fullListIndex);
136d734a8ceSbeveloper 
1377c74b12bSAxel Dörfler private:
1387c74b12bSAxel Dörfler 			BList			fFullList;
139d734a8ceSbeveloper 			uint32			_reserved[2];
140d734a8ceSbeveloper };
141d734a8ceSbeveloper 
1427c74b12bSAxel Dörfler #endif	// _OUTLINE_LIST_VIEW_H
143