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