xref: /haiku/headers/os/interface/OutlineListView.h (revision b66c623116aaccc1ea813f86c792fc0d7c25991f)
17c74b12bSAxel Dörfler /*
27c74b12bSAxel Dörfler  * Copyright 2006, 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,
187c74b12bSAxel Dörfler 								uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
19d734a8ceSbeveloper 								uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
20d734a8ceSbeveloper 									| B_NAVIGABLE);
217c74b12bSAxel Dörfler 							BOutlineListView(BMessage* archive);
22d734a8ceSbeveloper 		virtual 			~BOutlineListView();
23d734a8ceSbeveloper 
247c74b12bSAxel Dörfler 		static BArchivable*	Instantiate(BMessage* archive);
257c74b12bSAxel Dörfler 		virtual	status_t	Archive(BMessage* archive, bool deep = true) const;
26d734a8ceSbeveloper 
27d734a8ceSbeveloper 		virtual	void		MouseDown(BPoint where);
28d734a8ceSbeveloper 		virtual	void		KeyDown(const char* bytes, int32 numBytes);
297c74b12bSAxel Dörfler 		virtual	void		FrameMoved(BPoint newPosition);
307c74b12bSAxel Dörfler 		virtual	void		FrameResized(float newWidth, float newHeight);
31d734a8ceSbeveloper 		virtual	void		MouseUp(BPoint where);
32d734a8ceSbeveloper 
33d734a8ceSbeveloper 		virtual bool		AddUnder(BListItem* item, BListItem* underItem);
34d734a8ceSbeveloper 
35d734a8ceSbeveloper 		virtual bool		AddItem(BListItem* item);
36d734a8ceSbeveloper 		virtual bool		AddItem(BListItem* item, int32 fullListIndex);
37d734a8ceSbeveloper 		virtual bool		AddList(BList* newItems);
38d734a8ceSbeveloper 		virtual bool		AddList(BList* newItems, int32 fullListIndex);
39d734a8ceSbeveloper 
40d734a8ceSbeveloper 		virtual bool		RemoveItem(BListItem* item);
41d734a8ceSbeveloper 		virtual BListItem*	RemoveItem(int32 fullListIndex);
42d734a8ceSbeveloper 		virtual bool		RemoveItems(int32 fullListIndex, int32 count);
43d734a8ceSbeveloper 
44d734a8ceSbeveloper 		BListItem*			FullListItemAt(int32 fullListIndex) const;
45d734a8ceSbeveloper 		int32				FullListIndexOf(BPoint point) const;
46d734a8ceSbeveloper 		int32				FullListIndexOf(BListItem* item) const;
47d734a8ceSbeveloper 		BListItem*			FullListFirstItem() const;
48d734a8ceSbeveloper 		BListItem*			FullListLastItem() const;
49d734a8ceSbeveloper 		bool				FullListHasItem(BListItem* item) const;
50d734a8ceSbeveloper 		int32				FullListCountItems() const;
51d734a8ceSbeveloper 		int32				FullListCurrentSelection(int32 index = 0) const;
527c74b12bSAxel Dörfler 
53d734a8ceSbeveloper 		virtual	void		MakeEmpty();
54d734a8ceSbeveloper 		bool				FullListIsEmpty() const;
557c74b12bSAxel Dörfler 		void				FullListDoForEach(bool (*func)(BListItem* item));
567c74b12bSAxel Dörfler 		void				FullListDoForEach(bool (*func)(BListItem* item, void *), void*);
57d734a8ceSbeveloper 
58d734a8ceSbeveloper 		BListItem*			Superitem(const BListItem* item);
59d734a8ceSbeveloper 
60d734a8ceSbeveloper 		void				Expand(BListItem* item);
61d734a8ceSbeveloper 		void				Collapse(BListItem* item);
62d734a8ceSbeveloper 
63d734a8ceSbeveloper 		bool				IsExpanded(int32 fullListIndex);
64d734a8ceSbeveloper 
657c74b12bSAxel Dörfler 		virtual BHandler*	ResolveSpecifier(BMessage* message, int32 index,
667c74b12bSAxel Dörfler 								BMessage* specifier, int32 what, const char* property);
67d734a8ceSbeveloper 		virtual status_t	GetSupportedSuites(BMessage* data);
68d734a8ceSbeveloper 		virtual status_t	Perform(perform_code d, void* arg);
69d734a8ceSbeveloper 
70d734a8ceSbeveloper 		virtual void		ResizeToPreferred();
717c74b12bSAxel Dörfler 		virtual void		GetPreferredSize(float* _width, float* _height);
727c74b12bSAxel Dörfler 		virtual void		MakeFocus(bool focus = true);
73d734a8ceSbeveloper 		virtual void		AllAttached();
74d734a8ceSbeveloper 		virtual void		AllDetached();
75d734a8ceSbeveloper 		virtual void		DetachedFromWindow();
76d734a8ceSbeveloper 
777c74b12bSAxel Dörfler 		void				FullListSortItems(int (*compareFunc)(const BListItem* first,
787c74b12bSAxel Dörfler 								const BListItem* second));
797c74b12bSAxel Dörfler 		void				SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
807c74b12bSAxel Dörfler 								int (*compareFunc)(const BListItem* first,
817c74b12bSAxel Dörfler 								const BListItem* second));
82d734a8ceSbeveloper 		int32				CountItemsUnder(BListItem* under, bool oneLevelOnly) const;
837c74b12bSAxel Dörfler 		BListItem*			EachItemUnder(BListItem* underItem, bool oneLevelOnly,
847c74b12bSAxel Dörfler 								BListItem* (*eachFunc)(BListItem* item, void* arg),
857c74b12bSAxel Dörfler 								void* arg);
867c74b12bSAxel Dörfler 		BListItem*			ItemUnderAt(BListItem* underItem, bool oneLevelOnly,
87d734a8ceSbeveloper 								int32 index) const;
88d734a8ceSbeveloper 
89d734a8ceSbeveloper 	protected:
90d734a8ceSbeveloper 		virtual	bool		DoMiscellaneous(MiscCode code, MiscData* data);
917c74b12bSAxel Dörfler 		virtual void		MessageReceived(BMessage *message);
92d734a8ceSbeveloper 
93d734a8ceSbeveloper 	private:
94d734a8ceSbeveloper 		virtual	void		_ReservedOutlineListView1();
95d734a8ceSbeveloper 		virtual	void		_ReservedOutlineListView2();
96d734a8ceSbeveloper 		virtual	void		_ReservedOutlineListView3();
97d734a8ceSbeveloper 		virtual	void		_ReservedOutlineListView4();
98d734a8ceSbeveloper 
99d734a8ceSbeveloper 		typedef BListView	_inherited;
100d734a8ceSbeveloper 
101d734a8ceSbeveloper 		int32				FullListIndex(int32 index) const;
102d734a8ceSbeveloper 		int32				ListViewIndex(int32 index) const;
103d734a8ceSbeveloper 
104d734a8ceSbeveloper 	protected:
105d734a8ceSbeveloper 		virtual	void		ExpandOrCollapse(BListItem* underItem, bool expand);
106d734a8ceSbeveloper 		virtual BRect		LatchRect(BRect itemRect, int32 level) const;
107d734a8ceSbeveloper 		virtual void		DrawLatch(BRect itemRect, int32 level, bool collapsed,
108d734a8ceSbeveloper 								bool highlighted, bool misTracked);
1097c74b12bSAxel Dörfler 		virtual	void		DrawItem(BListItem* item, BRect itemRect, bool complete = false);
1107c74b12bSAxel Dörfler 
1117c74b12bSAxel Dörfler 	private:
1127c74b12bSAxel Dörfler 		void				_PopulateTree(BList* tree, BList& target,
1137c74b12bSAxel Dörfler 								int32& firstIndex, bool onlyVisible);
1147c74b12bSAxel Dörfler 		void				_SortTree(BList* tree, bool oneLevelOnly,
1157c74b12bSAxel Dörfler 								int (*compareFunc)(const BListItem* a, const BListItem* b));
1167c74b12bSAxel Dörfler 		void				_DestructTree(BList* tree);
1177c74b12bSAxel Dörfler 		BList*				_BuildTree(BListItem* underItem, int32& index);
118d734a8ceSbeveloper 
119f8f104b2SAxel Dörfler 		BListItem*			_RemoveItem(BListItem* item, int32 fullListIndex);
120d734a8ceSbeveloper 		BListItem*			RemoveOne(int32 fullListIndex);
121d734a8ceSbeveloper 
122d734a8ceSbeveloper 		static void			TrackInLatchItem(void *);
123d734a8ceSbeveloper 		static void			TrackOutLatchItem(void *);
124d734a8ceSbeveloper 
125d734a8ceSbeveloper 		bool				OutlineSwapItems(int32 a, int32 b);
126d734a8ceSbeveloper 		bool				OutlineMoveItem(int32 from, int32 to);
127d734a8ceSbeveloper 		bool				OutlineReplaceItem(int32 index, BListItem* item);
128d734a8ceSbeveloper 		void				CommonMoveItems(int32 from, int32 count, int32 to);
129*b66c6231SAxel Dörfler 		BListItem*			_SuperitemForIndex(int32 fullListIndex, int32 level,
130*b66c6231SAxel Dörfler 								int32* _superIndex = NULL);
131*b66c6231SAxel Dörfler 		int32				_FindPreviousVisibleIndex(int32 fullListIndex);
132d734a8ceSbeveloper 
1337c74b12bSAxel Dörfler 	private:
1347c74b12bSAxel Dörfler 		BList				fFullList;
135d734a8ceSbeveloper 		uint32				_reserved[2];
136d734a8ceSbeveloper };
137d734a8ceSbeveloper 
1387c74b12bSAxel Dörfler #endif	// _OUTLINE_LIST_VIEW_H
139