OutlineListView.h revision 1f424632
1/*
2 * Copyright 2006-2013, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _OUTLINE_LIST_VIEW_H
6#define _OUTLINE_LIST_VIEW_H
7
8
9#include <ListView.h>
10
11
12class BOutlineListView : public BListView {
13public:
14								BOutlineListView(BRect frame, const char* name,
15									list_view_type type
16										= B_SINGLE_SELECTION_LIST,
17									uint32 resizingMode
18										= B_FOLLOW_LEFT | B_FOLLOW_TOP,
19									uint32 flags = B_WILL_DRAW
20										| B_FRAME_EVENTS | B_NAVIGABLE);
21								BOutlineListView(const char* name,
22									list_view_type type
23										= B_SINGLE_SELECTION_LIST,
24									uint32 flags = B_WILL_DRAW
25										| B_FRAME_EVENTS | B_NAVIGABLE);
26								BOutlineListView(BMessage* archive);
27	virtual						~BOutlineListView();
28
29	static	BArchivable*		Instantiate(BMessage* archive);
30	virtual	status_t			Archive(BMessage* archive,
31									bool deep = true) const;
32
33	virtual	void				MouseDown(BPoint where);
34	virtual	void				KeyDown(const char* bytes, int32 numBytes);
35	virtual	void				FrameMoved(BPoint newPosition);
36	virtual	void				FrameResized(float newWidth, float newHeight);
37	virtual	void				MouseUp(BPoint where);
38
39	virtual	bool				AddUnder(BListItem* item, BListItem* superItem);
40
41	virtual	bool				AddItem(BListItem* item);
42	virtual	bool				AddItem(BListItem* item, int32 fullListIndex);
43	virtual	bool				AddList(BList* newItems);
44	virtual	bool				AddList(BList* newItems, int32 fullListIndex);
45
46	virtual	bool				RemoveItem(BListItem* item);
47	virtual	BListItem*			RemoveItem(int32 fullListIndex);
48	virtual	bool				RemoveItems(int32 fullListIndex, int32 count);
49
50			BListItem*			FullListItemAt(int32 fullListIndex) const;
51			int32				FullListIndexOf(BPoint where) const;
52			int32				FullListIndexOf(BListItem* item) const;
53			BListItem*			FullListFirstItem() const;
54			BListItem*			FullListLastItem() const;
55			bool				FullListHasItem(BListItem* item) const;
56			int32				FullListCountItems() const;
57			int32				FullListCurrentSelection(
58									int32 index = 0) const;
59
60	virtual	void				MakeEmpty();
61			bool				FullListIsEmpty() const;
62			void				FullListDoForEach(bool (*func)(BListItem* item));
63			void				FullListDoForEach(bool (*func)(BListItem* item, void* arg),
64									void* arg);
65
66			BListItem*			Superitem(const BListItem* item);
67
68			void				Expand(BListItem* item);
69			void				Collapse(BListItem* item);
70
71			bool				IsExpanded(int32 fullListIndex);
72
73	virtual	BHandler*			ResolveSpecifier(BMessage* message,
74									int32 index, BMessage* specifier,
75									int32 what, const char* property);
76	virtual	status_t			GetSupportedSuites(BMessage* data);
77	virtual	status_t			Perform(perform_code code, void* data);
78
79	virtual	void				ResizeToPreferred();
80	virtual	void				GetPreferredSize(float* _width,
81									float* _height);
82	virtual	void				MakeFocus(bool focus = true);
83	virtual	void				AllAttached();
84	virtual	void				AllDetached();
85	virtual	void				DetachedFromWindow();
86
87			void				FullListSortItems(int (*compareFunc)(
88										const BListItem* first,
89										const BListItem* second));
90			void				SortItemsUnder(BListItem* superItem,
91									bool oneLevelOnly, int (*compareFunc)(
92										const BListItem* first,
93										const BListItem* second));
94			int32				CountItemsUnder(BListItem* superItem,
95									bool oneLevelOnly) const;
96			BListItem*			EachItemUnder(BListItem* superItem,
97									bool oneLevelOnly, BListItem* (*eachFunc)(
98										BListItem* item, void* arg),
99									void* arg);
100			BListItem*			ItemUnderAt(BListItem* superItem,
101									bool oneLevelOnly, int32 index) const;
102
103protected:
104	virtual	bool				DoMiscellaneous(MiscCode code, MiscData* data);
105	virtual void				MessageReceived(BMessage* message);
106
107private:
108	virtual	void				_ReservedOutlineListView1();
109	virtual	void				_ReservedOutlineListView2();
110	virtual	void				_ReservedOutlineListView3();
111	virtual	void				_ReservedOutlineListView4();
112
113protected:
114	virtual	void				ExpandOrCollapse(BListItem* superItem,
115									bool expand);
116	virtual BRect				LatchRect(BRect itemRect, int32 level) const;
117	virtual void				DrawLatch(BRect itemRect, int32 level,
118									bool collapsed, bool highlighted,
119									bool misTracked);
120	virtual	void				DrawItem(BListItem* item, BRect itemRect,
121									bool complete = false);
122
123private:
124			int32				_FullListIndex(int32 index) const;
125
126			void				_PopulateTree(BList* tree, BList& target,
127									int32& firstIndex, bool onlyVisible);
128			void				_SortTree(BList* tree, bool oneLevelOnly,
129									int (*compareFunc)(const BListItem* a,
130										const BListItem* b));
131			void				_DestructTree(BList* tree);
132			BList*				_BuildTree(BListItem* superItem, int32& index);
133
134			void				_CullInvisibleItems(BList &list);
135			bool				_SwapItems(int32 first, int32 second);
136			BListItem*			_RemoveItem(BListItem* item,
137									int32 fullListIndex);
138
139			BListItem*			_SuperitemForIndex(int32 fullListIndex,
140									int32 level, int32* _superIndex = NULL);
141			int32				_FindPreviousVisibleIndex(int32 fullListIndex);
142
143private:
144			BList				fFullList;
145
146			uint32				_reserved[2];
147};
148
149#endif // _OUTLINE_LIST_VIEW_H
150