xref: /haiku/headers/os/interface/OutlineListView.h (revision 7c74b12b2a1df58a1337dc90ce758444f2e46f80)
1*7c74b12bSAxel Dörfler /*
2*7c74b12bSAxel Dörfler  * Copyright 2006, Haiku, Inc. All Rights Reserved.
3*7c74b12bSAxel Dörfler  * Distributed under the terms of the MIT License.
4*7c74b12bSAxel Dörfler  */
5d734a8ceSbeveloper #ifndef _OUTLINE_LIST_VIEW_H
6d734a8ceSbeveloper #define _OUTLINE_LIST_VIEW_H
7d734a8ceSbeveloper 
8*7c74b12bSAxel Dörfler 
9d734a8ceSbeveloper #include <ListView.h>
10d734a8ceSbeveloper 
11d734a8ceSbeveloper class BListItem;
12d734a8ceSbeveloper 
13d734a8ceSbeveloper 
14d734a8ceSbeveloper class BOutlineListView : public BListView {
15d734a8ceSbeveloper 	public:
16*7c74b12bSAxel Dörfler 							BOutlineListView(BRect frame, const char* name,
17d734a8ceSbeveloper 								list_view_type type = B_SINGLE_SELECTION_LIST,
18*7c74b12bSAxel Dörfler 								uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
19d734a8ceSbeveloper 								uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
20d734a8ceSbeveloper 									| B_NAVIGABLE);
21*7c74b12bSAxel Dörfler 							BOutlineListView(BMessage* archive);
22d734a8ceSbeveloper 		virtual 			~BOutlineListView();
23d734a8ceSbeveloper 
24*7c74b12bSAxel Dörfler 		static BArchivable*	Instantiate(BMessage* archive);
25*7c74b12bSAxel 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);
29*7c74b12bSAxel Dörfler 		virtual	void		FrameMoved(BPoint newPosition);
30*7c74b12bSAxel 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;
52*7c74b12bSAxel Dörfler 
53d734a8ceSbeveloper 		virtual	void		MakeEmpty();
54d734a8ceSbeveloper 		bool				FullListIsEmpty() const;
55*7c74b12bSAxel Dörfler 		void				FullListDoForEach(bool (*func)(BListItem* item));
56*7c74b12bSAxel 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 
65*7c74b12bSAxel Dörfler 		virtual BHandler*	ResolveSpecifier(BMessage* message, int32 index,
66*7c74b12bSAxel 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();
71*7c74b12bSAxel Dörfler 		virtual void		GetPreferredSize(float* _width, float* _height);
72*7c74b12bSAxel Dörfler 		virtual void		MakeFocus(bool focus = true);
73d734a8ceSbeveloper 		virtual void		AllAttached();
74d734a8ceSbeveloper 		virtual void		AllDetached();
75d734a8ceSbeveloper 		virtual void		DetachedFromWindow();
76d734a8ceSbeveloper 
77*7c74b12bSAxel Dörfler 		void				FullListSortItems(int (*compareFunc)(const BListItem* first,
78*7c74b12bSAxel Dörfler 								const BListItem* second));
79*7c74b12bSAxel Dörfler 		void				SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
80*7c74b12bSAxel Dörfler 								int (*compareFunc)(const BListItem* first,
81*7c74b12bSAxel Dörfler 								const BListItem* second));
82d734a8ceSbeveloper 		int32				CountItemsUnder(BListItem* under, bool oneLevelOnly) const;
83*7c74b12bSAxel Dörfler 		BListItem*			EachItemUnder(BListItem* underItem, bool oneLevelOnly,
84*7c74b12bSAxel Dörfler 								BListItem* (*eachFunc)(BListItem* item, void* arg),
85*7c74b12bSAxel Dörfler 								void* arg);
86*7c74b12bSAxel Dörfler 		BListItem*			ItemUnderAt(BListItem* underItem, bool oneLevelOnly,
87d734a8ceSbeveloper 								int32 index) const;
88d734a8ceSbeveloper 
89d734a8ceSbeveloper 	protected:
90d734a8ceSbeveloper 		virtual	bool		DoMiscellaneous(MiscCode code, MiscData* data);
91*7c74b12bSAxel 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);
109*7c74b12bSAxel Dörfler 		virtual	void		DrawItem(BListItem* item, BRect itemRect, bool complete = false);
110*7c74b12bSAxel Dörfler 
111*7c74b12bSAxel Dörfler 	private:
112*7c74b12bSAxel Dörfler 		void				_PopulateTree(BList* tree, BList& target,
113*7c74b12bSAxel Dörfler 								int32& firstIndex, bool onlyVisible);
114*7c74b12bSAxel Dörfler 		void				_SortTree(BList* tree, bool oneLevelOnly,
115*7c74b12bSAxel Dörfler 								int (*compareFunc)(const BListItem* a, const BListItem* b));
116*7c74b12bSAxel Dörfler 		void				_DestructTree(BList* tree);
117*7c74b12bSAxel Dörfler 		BList*				_BuildTree(BListItem* underItem, int32& index);
118d734a8ceSbeveloper 
119d734a8ceSbeveloper 		BListItem*			RemoveCommon(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);
129d734a8ceSbeveloper 		BListItem*			SuperitemForIndex(int32 fullListIndex, int32 level);
130d734a8ceSbeveloper 		int32				FindPreviousVisibleIndex(int32 fullListIndex);
131d734a8ceSbeveloper 
132*7c74b12bSAxel Dörfler 	private:
133*7c74b12bSAxel Dörfler 		BList				fFullList;
134d734a8ceSbeveloper 		uint32				_reserved[2];
135d734a8ceSbeveloper };
136d734a8ceSbeveloper 
137*7c74b12bSAxel Dörfler #endif	// _OUTLINE_LIST_VIEW_H
138