xref: /haiku/headers/os/interface/OutlineListView.h (revision 73ad2473e7874b3702cf5b0fdf4c81b747812ed9)
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 
12 class BOutlineListView : public BListView {
13 public:
14 								BOutlineListView(BRect frame, const char* name,
15 									list_view_type type
16 										= B_SINGLE_SELECTION_LIST,
17 									uint32 resizeMode
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,
40 									BListItem* underItem);
41 
42 	virtual bool				AddItem(BListItem* item);
43 	virtual bool				AddItem(BListItem* item, int32 fullListIndex);
44 	virtual bool				AddList(BList* newItems);
45 	virtual bool				AddList(BList* newItems, int32 fullListIndex);
46 
47 	virtual bool				RemoveItem(BListItem* item);
48 	virtual BListItem*			RemoveItem(int32 fullListIndex);
49 	virtual bool				RemoveItems(int32 fullListIndex, int32 count);
50 
51 			BListItem*			FullListItemAt(int32 fullListIndex) const;
52 			int32				FullListIndexOf(BPoint point) const;
53 			int32				FullListIndexOf(BListItem* item) const;
54 			BListItem*			FullListFirstItem() const;
55 			BListItem*			FullListLastItem() const;
56 			bool				FullListHasItem(BListItem* item) const;
57 			int32				FullListCountItems() const;
58 			int32				FullListCurrentSelection(
59 									int32 index = 0) const;
60 
61 	virtual	void				MakeEmpty();
62 			bool				FullListIsEmpty() const;
63 			void				FullListDoForEach(
64 									bool (*func)(BListItem* item));
65 			void				FullListDoForEach(
66 									bool (*func)(BListItem* item, void*),
67 									void*);
68 
69 			BListItem*			Superitem(const BListItem* item);
70 
71 			void				Expand(BListItem* item);
72 			void				Collapse(BListItem* item);
73 
74 			bool				IsExpanded(int32 fullListIndex);
75 
76 	virtual BHandler*			ResolveSpecifier(BMessage* message,
77 									int32 index, BMessage* specifier,
78 									int32 what, const char* property);
79 	virtual status_t			GetSupportedSuites(BMessage* data);
80 	virtual status_t			Perform(perform_code code, void* data);
81 
82 	virtual void				ResizeToPreferred();
83 	virtual void				GetPreferredSize(float* _width,
84 									float* _height);
85 	virtual void				MakeFocus(bool focus = true);
86 	virtual void				AllAttached();
87 	virtual void				AllDetached();
88 	virtual void				DetachedFromWindow();
89 
90 			void				FullListSortItems(int (*compareFunc)(
91 										const BListItem* first,
92 										const BListItem* second));
93 			void				SortItemsUnder(BListItem* underItem,
94 									bool oneLevelOnly, int (*compareFunc)(
95 										const BListItem* first,
96 										const BListItem* second));
97 			int32				CountItemsUnder(BListItem* under,
98 									bool oneLevelOnly) const;
99 			BListItem*			EachItemUnder(BListItem* underItem,
100 									bool oneLevelOnly, BListItem* (*eachFunc)(
101 										BListItem* item, void* arg),
102 									void* arg);
103 			BListItem*			ItemUnderAt(BListItem* underItem,
104 									bool oneLevelOnly, int32 index) const;
105 
106 protected:
107 	virtual	bool				DoMiscellaneous(MiscCode code, MiscData* data);
108 	virtual void				MessageReceived(BMessage* message);
109 
110 private:
111 	virtual	void				_ReservedOutlineListView1();
112 	virtual	void				_ReservedOutlineListView2();
113 	virtual	void				_ReservedOutlineListView3();
114 	virtual	void				_ReservedOutlineListView4();
115 
116 protected:
117 	virtual	void				ExpandOrCollapse(BListItem* underItem,
118 									bool expand);
119 	virtual BRect				LatchRect(BRect itemRect, int32 level) const;
120 	virtual void				DrawLatch(BRect itemRect, int32 level,
121 									bool collapsed, bool highlighted,
122 									bool misTracked);
123 	virtual	void				DrawItem(BListItem* item, BRect itemRect,
124 									bool complete = false);
125 
126 private:
127 			int32				_FullListIndex(int32 index) const;
128 
129 			void				_PopulateTree(BList* tree, BList& target,
130 									int32& firstIndex, bool onlyVisible);
131 			void				_SortTree(BList* tree, bool oneLevelOnly,
132 									int (*compareFunc)(const BListItem* a,
133 										const BListItem* b));
134 			void				_DestructTree(BList* tree);
135 			BList*				_BuildTree(BListItem* underItem, int32& index);
136 
137 			void				_CullInvisibleItems(BList &list);
138 			bool				_SwapItems(int32 first, int32 second);
139 			BListItem*			_RemoveItem(BListItem* item,
140 									int32 fullListIndex);
141 
142 			BListItem*			_SuperitemForIndex(int32 fullListIndex,
143 									int32 level, int32* _superIndex = NULL);
144 			int32				_FindPreviousVisibleIndex(int32 fullListIndex);
145 
146 private:
147 			BList				fFullList;
148 
149 			uint32				_reserved[2];
150 };
151 
152 #endif // _OUTLINE_LIST_VIEW_H
153