[Haiku-commits] r31088 - in haiku/trunk: headers/os/interface src/kits/interface

axeld at mail.berlios.de axeld at mail.berlios.de
Wed Jun 17 16:56:59 CEST 2009


Author: axeld
Date: 2009-06-17 16:56:57 +0200 (Wed, 17 Jun 2009)
New Revision: 31088
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31088&view=rev

Modified:
   haiku/trunk/headers/os/interface/OutlineListView.h
   haiku/trunk/src/kits/interface/OutlineListView.cpp
Log:
* Added layout-friendly constructor.
* Reordered functions to match the order in the header (and vice versa).
* Removed unused private functions.
* Updated the header to follow our coding style.
* Cleanup.


Modified: haiku/trunk/headers/os/interface/OutlineListView.h
===================================================================
--- haiku/trunk/headers/os/interface/OutlineListView.h	2009-06-17 14:18:55 UTC (rev 31087)
+++ haiku/trunk/headers/os/interface/OutlineListView.h	2009-06-17 14:56:57 UTC (rev 31088)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2006, Haiku, Inc. All Rights Reserved.
+ * Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  */
 #ifndef _OUTLINE_LIST_VIEW_H
@@ -12,129 +12,131 @@
 
 
 class BOutlineListView : public BListView {
-	public:
+public:
 							BOutlineListView(BRect frame, const char* name,
 								list_view_type type = B_SINGLE_SELECTION_LIST,
-								uint32 resizeMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
+								uint32 resizeMode
+									= B_FOLLOW_LEFT | B_FOLLOW_TOP,
 								uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS 
 									| B_NAVIGABLE);
+							BOutlineListView(const char* name,
+								list_view_type type = B_SINGLE_SELECTION_LIST,
+								uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS
+									| B_NAVIGABLE);
 							BOutlineListView(BMessage* archive);
-		virtual 			~BOutlineListView();
+	virtual 				~BOutlineListView();
 
-		static BArchivable*	Instantiate(BMessage* archive);
-		virtual	status_t	Archive(BMessage* archive, bool deep = true) const;
+	static	BArchivable*	Instantiate(BMessage* archive);
+	virtual	status_t		Archive(BMessage* archive, bool deep = true) const;
 
-		virtual	void		MouseDown(BPoint where);
-		virtual	void		KeyDown(const char* bytes, int32 numBytes);
-		virtual	void		FrameMoved(BPoint newPosition);
-		virtual	void		FrameResized(float newWidth, float newHeight);
-		virtual	void		MouseUp(BPoint where);
+	virtual	void			MouseDown(BPoint where);
+	virtual	void			KeyDown(const char* bytes, int32 numBytes);
+	virtual	void			FrameMoved(BPoint newPosition);
+	virtual	void			FrameResized(float newWidth, float newHeight);
+	virtual	void			MouseUp(BPoint where);
 
-		virtual bool		AddUnder(BListItem* item, BListItem* underItem);
+	virtual bool			AddUnder(BListItem* item, BListItem* underItem);
 
-		virtual bool		AddItem(BListItem* item);
-		virtual bool		AddItem(BListItem* item, int32 fullListIndex);
-		virtual bool		AddList(BList* newItems);
-		virtual bool		AddList(BList* newItems, int32 fullListIndex);
+	virtual bool			AddItem(BListItem* item);
+	virtual bool			AddItem(BListItem* item, int32 fullListIndex);
+	virtual bool			AddList(BList* newItems);
+	virtual bool			AddList(BList* newItems, int32 fullListIndex);
 
-		virtual bool		RemoveItem(BListItem* item);
-		virtual BListItem*	RemoveItem(int32 fullListIndex);
-		virtual bool		RemoveItems(int32 fullListIndex, int32 count);
+	virtual bool			RemoveItem(BListItem* item);
+	virtual BListItem*		RemoveItem(int32 fullListIndex);
+	virtual bool			RemoveItems(int32 fullListIndex, int32 count);
 
-		BListItem*			FullListItemAt(int32 fullListIndex) const;
-		int32				FullListIndexOf(BPoint point) const;
-		int32				FullListIndexOf(BListItem* item) const;
-		BListItem*			FullListFirstItem() const;
-		BListItem*			FullListLastItem() const;
-		bool				FullListHasItem(BListItem* item) const;
-		int32				FullListCountItems() const;
-		int32				FullListCurrentSelection(int32 index = 0) const;
+			BListItem*		FullListItemAt(int32 fullListIndex) const;
+			int32			FullListIndexOf(BPoint point) const;
+			int32			FullListIndexOf(BListItem* item) const;
+			BListItem*		FullListFirstItem() const;
+			BListItem*		FullListLastItem() const;
+			bool			FullListHasItem(BListItem* item) const;
+			int32			FullListCountItems() const;
+			int32			FullListCurrentSelection(int32 index = 0) const;
 
-		virtual	void		MakeEmpty();
-		bool				FullListIsEmpty() const;
-		void				FullListDoForEach(bool (*func)(BListItem* item));
-		void				FullListDoForEach(bool (*func)(BListItem* item, void *), void*);
+	virtual	void			MakeEmpty();
+			bool			FullListIsEmpty() const;
+			void			FullListDoForEach(bool (*func)(BListItem* item));
+			void			FullListDoForEach(
+								bool (*func)(BListItem* item, void*), void*);
 
-		BListItem*			Superitem(const BListItem* item);
+			BListItem*		Superitem(const BListItem* item);
 
-		void				Expand(BListItem* item);
-		void				Collapse(BListItem* item);
+			void			Expand(BListItem* item);
+			void			Collapse(BListItem* item);
 
-		bool				IsExpanded(int32 fullListIndex);
+			bool			IsExpanded(int32 fullListIndex);
 
-		virtual BHandler*	ResolveSpecifier(BMessage* message, int32 index,
-								BMessage* specifier, int32 what, const char* property);
-		virtual status_t	GetSupportedSuites(BMessage* data);
-		virtual status_t	Perform(perform_code d, void* arg);
+	virtual BHandler*		ResolveSpecifier(BMessage* message, int32 index,
+								BMessage* specifier, int32 what,
+								const char* property);
+	virtual status_t		GetSupportedSuites(BMessage* data);
+	virtual status_t		Perform(perform_code d, void* arg);
 
-		virtual void		ResizeToPreferred();
-		virtual void		GetPreferredSize(float* _width, float* _height);
-		virtual void		MakeFocus(bool focus = true);
-		virtual void		AllAttached();
-		virtual void		AllDetached();
-		virtual void		DetachedFromWindow();
+	virtual void			ResizeToPreferred();
+	virtual void			GetPreferredSize(float* _width, float* _height);
+	virtual void			MakeFocus(bool focus = true);
+	virtual void			AllAttached();
+	virtual void			AllDetached();
+	virtual void			DetachedFromWindow();
 
-		void				FullListSortItems(int (*compareFunc)(const BListItem* first,
-								const BListItem* second));
-		void				SortItemsUnder(BListItem* underItem, bool oneLevelOnly,
-								int (*compareFunc)(const BListItem* first,
-								const BListItem* second));
-		int32				CountItemsUnder(BListItem* under, bool oneLevelOnly) const;
-		BListItem*			EachItemUnder(BListItem* underItem, bool oneLevelOnly,
-								BListItem* (*eachFunc)(BListItem* item, void* arg),
-								void* arg);
-		BListItem*			ItemUnderAt(BListItem* underItem, bool oneLevelOnly,
+			void			FullListSortItems(int (*compareFunc)(
+									const BListItem* first,
+									const BListItem* second));
+			void			SortItemsUnder(BListItem* underItem,
+								bool oneLevelOnly, int (*compareFunc)(
+									const BListItem* first,
+									const BListItem* second));
+			int32			CountItemsUnder(BListItem* under,
+								bool oneLevelOnly) const;
+			BListItem*		EachItemUnder(BListItem* underItem,
+								bool oneLevelOnly, BListItem* (*eachFunc)(
+									BListItem* item, void* arg), void* arg);
+			BListItem*		ItemUnderAt(BListItem* underItem, bool oneLevelOnly,
 								int32 index) const;
 
-	protected:
-		virtual	bool		DoMiscellaneous(MiscCode code, MiscData* data);
-		virtual void		MessageReceived(BMessage *message);
+protected:
+	virtual	bool			DoMiscellaneous(MiscCode code, MiscData* data);
+	virtual void			MessageReceived(BMessage* message);
 
-	private:
-		virtual	void		_ReservedOutlineListView1();
-		virtual	void		_ReservedOutlineListView2();
-		virtual	void		_ReservedOutlineListView3();
-		virtual	void		_ReservedOutlineListView4();
+private:
+	virtual	void			_ReservedOutlineListView1();
+	virtual	void			_ReservedOutlineListView2();
+	virtual	void			_ReservedOutlineListView3();
+	virtual	void			_ReservedOutlineListView4();
 
-		typedef BListView	_inherited;
+protected:
+	virtual	void			ExpandOrCollapse(BListItem* underItem, bool expand);
+	virtual BRect			LatchRect(BRect itemRect, int32 level) const;
+	virtual void			DrawLatch(BRect itemRect, int32 level,
+								bool collapsed, bool highlighted,
+								bool misTracked);
+	virtual	void			DrawItem(BListItem* item, BRect itemRect,
+								bool complete = false);
 
-		int32				FullListIndex(int32 index) const;
-		int32				ListViewIndex(int32 index) const;
+private:
+			int32			_FullListIndex(int32 index) const;
 
-	protected:
-		virtual	void		ExpandOrCollapse(BListItem* underItem, bool expand);
-		virtual BRect		LatchRect(BRect itemRect, int32 level) const;
-		virtual void		DrawLatch(BRect itemRect, int32 level, bool collapsed,
-								bool highlighted, bool misTracked);
-		virtual	void		DrawItem(BListItem* item, BRect itemRect, bool complete = false);
-
-	private:
-		void				_PopulateTree(BList* tree, BList& target,
+			void			_PopulateTree(BList* tree, BList& target,
 								int32& firstIndex, bool onlyVisible);
-		void				_SortTree(BList* tree, bool oneLevelOnly,
-								int (*compareFunc)(const BListItem* a, const BListItem* b));
-		void				_DestructTree(BList* tree);
-		BList*				_BuildTree(BListItem* underItem, int32& index);
+			void			_SortTree(BList* tree, bool oneLevelOnly,
+								int (*compareFunc)(const BListItem* a,
+									const BListItem* b));
+			void			_DestructTree(BList* tree);
+			BList*			_BuildTree(BListItem* underItem, int32& index);
 
-		BListItem*			_RemoveItem(BListItem* item, int32 fullListIndex);
-		bool				_SwapItems(int32 first, int32 second);
-		void				_CullInvisibleItems(BList &list);
-		BListItem*			RemoveOne(int32 fullListIndex);
+			void			_CullInvisibleItems(BList &list);
+			bool			_SwapItems(int32 first, int32 second);
+			BListItem*		_RemoveItem(BListItem* item, int32 fullListIndex);
 
-		static void			TrackInLatchItem(void *);
-		static void			TrackOutLatchItem(void *);
-
-		bool				OutlineSwapItems(int32 a, int32 b);
-		bool				OutlineMoveItem(int32 from, int32 to);
-		bool				OutlineReplaceItem(int32 index, BListItem* item);
-		void				CommonMoveItems(int32 from, int32 count, int32 to);
-		BListItem*			_SuperitemForIndex(int32 fullListIndex, int32 level,
+			BListItem*		_SuperitemForIndex(int32 fullListIndex, int32 level,
 								int32* _superIndex = NULL);
-		int32				_FindPreviousVisibleIndex(int32 fullListIndex);
+			int32			_FindPreviousVisibleIndex(int32 fullListIndex);
 
-	private:
-		BList				fFullList;
-		uint32				_reserved[2];
+private:
+			BList			fFullList;
+			uint32			_reserved[2];
 };
 
 #endif	// _OUTLINE_LIST_VIEW_H

Modified: haiku/trunk/src/kits/interface/OutlineListView.cpp
===================================================================
--- haiku/trunk/src/kits/interface/OutlineListView.cpp	2009-06-17 14:18:55 UTC (rev 31087)
+++ haiku/trunk/src/kits/interface/OutlineListView.cpp	2009-06-17 14:56:57 UTC (rev 31088)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2001-2008, Haiku Inc.
+ * Copyright 2001-2009, Haiku Inc.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -12,34 +12,69 @@
 //! BOutlineListView represents a "nestable" list view.
 
 #include <OutlineListView.h>
-#include <Window.h>
 
+#include <algorithm>
+
 #include <stdio.h>
 #include <stdlib.h>
 
-#include <algorithm>
+#include <Window.h>
 
 #include <binary_compatibility/Interface.h>
 
 
-const float kLatchHeight = 8.0f;
-const float kLatchWidth = 4.0f;
+typedef int (*compare_func)(const BListItem* a, const BListItem* b);
 
 struct ListItemComparator {
-	ListItemComparator(int (*compareFunc)(const BListItem *, const BListItem *))
-		: fCompareFunc(compareFunc)
+	ListItemComparator(compare_func compareFunc)
+		:
+		fCompareFunc(compareFunc)
 	{
 	}
 
-	bool operator()(const BListItem *a, const BListItem *b) const
+	bool operator()(const BListItem* a, const BListItem* b) const
 	{
 		return fCompareFunc(a, b) < 0;
 	}
 
 private:
-	int (*fCompareFunc)(const BListItem *, const BListItem *);
+	compare_func	fCompareFunc;
 };
 
+
+const float kLatchHeight = 8.0f;
+const float kLatchWidth = 4.0f;
+
+
+static void
+_GetSubItems(BList& sourceList, BList& destList, BListItem* parent, int32 start)
+{
+	for (int32 i = start; i < sourceList.CountItems(); i++) {
+		BListItem* item = (BListItem*)sourceList.ItemAt(i);
+		if (item->OutlineLevel() <= parent->OutlineLevel())
+			break;
+		destList.AddItem(item);
+	}
+}
+
+
+static void
+_DoSwap(BList& list, int32 firstIndex, int32 secondIndex, BList* firstItems,
+	BList* secondItems)
+{
+	BListItem* item = (BListItem*)list.ItemAt(firstIndex);
+	list.SwapItems(firstIndex, secondIndex);
+	list.RemoveItems(secondIndex + 1, secondItems->CountItems());
+	list.RemoveItems(firstIndex + 1, firstItems->CountItems());
+	list.AddList(secondItems, firstIndex + 1);
+	int32 newIndex = list.IndexOf(item);
+	if (newIndex + 1 < list.CountItems())
+		list.AddList(firstItems, newIndex + 1);
+	else
+		list.AddList(firstItems);
+}
+
+
 //	#pragma mark -
 
 
@@ -50,17 +85,24 @@
 }
 
 
+BOutlineListView::BOutlineListView(const char* name, list_view_type type,
+		uint32 flags)
+	: BListView(name, type, flags)
+{
+}
+
+
 BOutlineListView::BOutlineListView(BMessage* archive)
 	: BListView(archive)
 {
 	int32 i = 0;
 	BMessage subData;
 	while (archive->FindMessage("_l_full_items", i++, &subData) == B_OK) {
-		BArchivable *object = instantiate_object(&subData);
+		BArchivable* object = instantiate_object(&subData);
 		if (!object)
 			continue;
 
-		BListItem *item = dynamic_cast<BListItem*>(object);
+		BListItem* item = dynamic_cast<BListItem*>(object);
 		if (item)
 			AddItem(item);
 	}
@@ -73,7 +115,7 @@
 }
 
 
-BArchivable *
+BArchivable*
 BOutlineListView::Instantiate(BMessage* archive)
 {
 	if (validate_instantiation(archive, "BOutlineListView"))
@@ -97,7 +139,7 @@
 	status = archive->AddInt32("_lv_type", fListType);
 	if (status == B_OK && deep) {
 		int32 i = 0;
-		BListItem *item = NULL;
+		BListItem* item = NULL;
 		while ((item = static_cast<BListItem*>(fFullList.ItemAt(i++)))) {
 			BMessage subData;
 			status = item->Archive(&subData, true);
@@ -127,7 +169,7 @@
 	int32 index = IndexOf(point);
 
 	if (index != -1) {
-		BListItem *item = ItemAt(index);
+		BListItem* item = ItemAt(index);
 
 		if (item->fHasSubitems
 			&& LatchRect(ItemFrame(index), item->fLevel).Contains(point)) {
@@ -149,7 +191,7 @@
 		switch (bytes[0]) {
 			case B_RIGHT_ARROW:
 			{
-				BListItem *item = ItemAt(currentSel);
+				BListItem* item = ItemAt(currentSel);
 				if (item && item->fHasSubitems) {
 					if (!IsExpanded(currentSel)) 
 						Expand(item);
@@ -161,7 +203,7 @@
 
 			case B_LEFT_ARROW:
 			{
-				BListItem *item = ItemAt(currentSel);
+				BListItem* item = ItemAt(currentSel);
 				if (item) {
 					if (item->fHasSubitems)
 						Collapse(item);
@@ -248,7 +290,7 @@
 	// other list, too
 
 	if (item->fLevel > 0) {
-		BListItem *super = _SuperitemForIndex(fullListIndex, item->fLevel);
+		BListItem* super = _SuperitemForIndex(fullListIndex, item->fLevel);
 		if (super == NULL)
 			return true;
 
@@ -290,7 +332,7 @@
 		return false;
 
 	for (int32 i = 0; i < newItems->CountItems(); i++)
-		AddItem((BListItem *)newItems->ItemAt(i), fullListIndex + i);
+		AddItem((BListItem*)newItems->ItemAt(i), fullListIndex + i);
 
 	return true;
 }
@@ -327,7 +369,7 @@
 }
 
 
-BListItem *
+BListItem*
 BOutlineListView::FullListItemAt(int32 fullListIndex) const
 {
 	return (BListItem*)fFullList.ItemAt(fullListIndex);
@@ -340,7 +382,7 @@
 	int32 index = BListView::IndexOf(point);
 
 	if (index > 0)
-		index = FullListIndex(index);
+		index = _FullListIndex(index);
 
 	return index;
 }
@@ -353,14 +395,14 @@
 }
 
 
-BListItem *
+BListItem*
 BOutlineListView::FullListFirstItem() const
 {
 	return (BListItem*)fFullList.FirstItem();
 }
 
 
-BListItem *
+BListItem*
 BOutlineListView::FullListLastItem() const
 {
 	return (BListItem*)fFullList.LastItem();
@@ -368,7 +410,7 @@
 
 
 bool
-BOutlineListView::FullListHasItem(BListItem *item) const
+BOutlineListView::FullListHasItem(BListItem* item) const
 {
 	return fFullList.HasItem(item);
 }
@@ -386,7 +428,7 @@
 {
 	int32 i = BListView::CurrentSelection(index);
 
-	BListItem *item = BListView::ItemAt(i);
+	BListItem* item = BListView::ItemAt(i);
 	if (item)
 		return fFullList.IndexOf(item);
 
@@ -424,7 +466,7 @@
 }
 
 
-BListItem *
+BListItem*
 BOutlineListView::Superitem(const BListItem* item)
 {
 	int32 index = FullListIndexOf((BListItem*)item);
@@ -546,7 +588,7 @@
 bool
 BOutlineListView::IsExpanded(int32 fullListIndex)
 {
-	BListItem *item = FullListItemAt(fullListIndex);
+	BListItem* item = FullListItemAt(fullListIndex);
 	if (!item)
 		return false;
 
@@ -554,7 +596,7 @@
 }
 
 
-BHandler *
+BHandler*
 BOutlineListView::ResolveSpecifier(BMessage* msg, int32 index,
 	BMessage* specifier, int32 what, const char* property)
 {
@@ -597,8 +639,8 @@
 		{
 			perform_data_get_height_for_width* data
 				= (perform_data_get_height_for_width*)_data;
-			BOutlineListView::GetHeightForWidth(data->width, &data->min, &data->max,
-				&data->preferred);
+			BOutlineListView::GetHeightForWidth(data->width, &data->min,
+				&data->max, &data->preferred);
 			return B_OK;
 		}
 		case PERFORM_CODE_SET_LAYOUT:
@@ -692,7 +734,8 @@
 	// Populate to the full list
 	_PopulateTree(tree, fFullList, firstIndex, false);
 
-	if (underItem == NULL || (underItem->IsItemVisible() && underItem->IsExpanded())) {
+	if (underItem == NULL
+		|| (underItem->IsItemVisible() && underItem->IsExpanded())) {
 		// Populate to BListView's list
 		firstIndex = fList.IndexOf(underItem) + 1;
 		lastIndex = firstIndex;
@@ -715,91 +758,9 @@
 	_DestructTree(tree);
 }
 
-void
-BOutlineListView::_PopulateTree(BList* tree, BList& target,
-	int32& firstIndex, bool onlyVisible)
-{
-	BListItem** items = (BListItem**)target.Items();
-	int32 count = tree->CountItems();
 
-	for (int32 index = 0; index < count; index++) {
-		BListItem* item = (BListItem*)tree->ItemAtFast(index);
-
-		items[firstIndex++] = item;
-
-		if (item->HasSubitems() && (!onlyVisible || item->IsExpanded()))
-			_PopulateTree(item->fTemporaryList, target, firstIndex, onlyVisible);
-	}
-}
-
-
-void
-BOutlineListView::_SortTree(BList* tree, bool oneLevelOnly,
-	int (*compareFunc)(const BListItem* a, const BListItem* b))
-{
-	BListItem **items = (BListItem **)tree->Items();
-	std::sort(items, items + tree->CountItems(), ListItemComparator(compareFunc));
-
-	if (oneLevelOnly)
-		return;
-
-	for (int32 index = tree->CountItems(); index-- > 0;) {
-		BListItem* item = (BListItem*)tree->ItemAt(index);
-
-		if (item->HasSubitems())
-			_SortTree(item->fTemporaryList, false, compareFunc);
-	}
-}
-
-
-void
-BOutlineListView::_DestructTree(BList* tree)
-{
-	for (int32 index = tree->CountItems(); index-- > 0;) {
-		BListItem* item = (BListItem*)tree->ItemAt(index);
-
-		if (item->HasSubitems())
-			_DestructTree(item->fTemporaryList);
-	}
-
-	delete tree;
-}
-
-
-BList*
-BOutlineListView::_BuildTree(BListItem* underItem, int32& fullIndex)
-{
-	int32 fullCount = FullListCountItems();
-	uint32 level = underItem != NULL ? underItem->OutlineLevel() + 1 : 0;
-	BList* list = new BList;
-	if (underItem != NULL)
-		underItem->fTemporaryList = list;
-
-	while (fullIndex < fullCount) {
-		BListItem *item = FullListItemAt(fullIndex);
-
-		// If we jump out of the subtree, break out
-		if (item->fLevel < level)
-			break;
-
-		// If the level matches, put them into the list
-		// (we handle the case of a missing sublevel gracefully)
-		list->AddItem(item);
-		fullIndex++;
-
-		if (item->HasSubitems()) {
-			// we're going deeper
-			_BuildTree(item, fullIndex);
-		}
-	}
-
-	return list;
-}
-
-
 int32
-BOutlineListView::CountItemsUnder(BListItem* underItem,
-	bool oneLevelOnly) const
+BOutlineListView::CountItemsUnder(BListItem* underItem, bool oneLevelOnly) const
 {
 	int32 i = FullListIndexOf(underItem);
 	if (i == -1)
@@ -810,7 +771,7 @@
 	uint32 baseLevel = underItem->OutlineLevel();
 
 	for (; i < FullListCountItems(); i++) {
-		BListItem *item = FullListItemAt(i);
+		BListItem* item = FullListItemAt(i);
 
 		// If we jump out of the subtree, return count
 		if (item->fLevel <= baseLevel)
@@ -825,16 +786,16 @@
 }
 
 
-BListItem *
-BOutlineListView::EachItemUnder(BListItem *underItem, bool oneLevelOnly,
-	BListItem *(*eachFunc)(BListItem* item, void* arg), void* arg)
+BListItem*
+BOutlineListView::EachItemUnder(BListItem* underItem, bool oneLevelOnly,
+	BListItem* (*eachFunc)(BListItem* item, void* arg), void* arg)
 {
 	int32 i = IndexOf(underItem);
 	if (i == -1)
 		return NULL;
 
 	while (i < FullListCountItems()) {
-		BListItem *item = FullListItemAt(i);
+		BListItem* item = FullListItemAt(i);
 
 		// If we jump out of the subtree, return NULL
 		if (item->fLevel < underItem->OutlineLevel())
@@ -854,7 +815,7 @@
 }
 
 
-BListItem *
+BListItem*
 BOutlineListView::ItemUnderAt(BListItem* underItem,
 	bool oneLevelOnly, int32 index) const
 {
@@ -863,7 +824,7 @@
 		return NULL;
 
 	while (i < FullListCountItems()) {
-		BListItem *item = FullListItemAt(i);
+		BListItem* item = FullListItemAt(i);
 
 		// If we jump out of the subtree, return NULL
 		if (item->fLevel < underItem->OutlineLevel())
@@ -883,90 +844,8 @@
 	return NULL;
 }
 
-static void _GetSubItems(BList &sourceList, BList &destList,
-	BListItem *parent, int32 start)
-{
-	for (int32 i = start; i < sourceList.CountItems(); i++) {
-		BListItem *item = (BListItem *)sourceList.ItemAt(i);
-		if (item->OutlineLevel() <= parent->OutlineLevel())
-			break;
-		destList.AddItem(item);
-	}
-}
 
-static void
-_DoSwap(BList &list, int32 firstIndex, int32 secondIndex, BList *firstItems,
-	BList *secondItems)
-{
-	BListItem *item = (BListItem *)list.ItemAt(firstIndex);
-	list.SwapItems(firstIndex, secondIndex);
-	list.RemoveItems(secondIndex + 1, secondItems->CountItems());
-	list.RemoveItems(firstIndex + 1, firstItems->CountItems());
-	list.AddList(secondItems, firstIndex + 1);
-	int32 newIndex = list.IndexOf(item);
-	if (newIndex + 1 < list.CountItems())
-		list.AddList(firstItems, newIndex + 1);
-	else
-		list.AddList(firstItems);
-}
-
-void
-BOutlineListView::_CullInvisibleItems(BList &list)
-{
-	int32 index = 0;
-	while (index < list.CountItems()) {
-		if (reinterpret_cast<BListItem *>(list.ItemAt(index))->IsItemVisible())
-			++index;
-		else
-			list.RemoveItem(index);
-	}
-}
-
 bool
-BOutlineListView::_SwapItems(int32 first, int32 second)
-{
-	// same item, do nothing
-	if (first == second)
-		return true;
-
-	// fail, first item out of bounds
-	if ((first < 0) || (first >= CountItems()))
-		return false;
-
-	// fail, second item out of bounds
-	if ((second < 0) || (second >= CountItems()))
-		return false;
-
-	int32 firstIndex = min_c(first, second);
-	int32 secondIndex = max_c(first, second);
-	BListItem *firstItem = ItemAt(firstIndex);
-	BListItem *secondItem = ItemAt(secondIndex);
-	BList firstSubItems, secondSubItems;
-
-	if (Superitem(firstItem) != Superitem(secondItem))
-		return false;
-	if (!firstItem->IsItemVisible() || !secondItem->IsItemVisible())
-		return false;
-
-	int32 fullFirstIndex = FullListIndex(firstIndex);
-	int32 fullSecondIndex = FullListIndex(secondIndex);
-	_GetSubItems(fFullList, firstSubItems, firstItem, fullFirstIndex + 1);
-	_GetSubItems(fFullList, secondSubItems, secondItem, fullSecondIndex + 1);
-	_DoSwap(fFullList, fullFirstIndex, fullSecondIndex, &firstSubItems,
-		&secondSubItems);
-
-	_CullInvisibleItems(firstSubItems);
-	_CullInvisibleItems(secondSubItems);
-	_DoSwap(fList, firstIndex, secondIndex, &firstSubItems,
-		&secondSubItems);
-
-	_RecalcItemTops(firstIndex);
-	_RescanSelection(firstIndex, secondIndex + secondSubItems.CountItems());
-	Invalidate(Bounds());
-	return true;
-}
-
-bool
 BOutlineListView::DoMiscellaneous(MiscCode code, MiscData* data)
 {
 	if (code == B_SWAP_OP)
@@ -989,32 +868,8 @@
 void BOutlineListView::_ReservedOutlineListView4() {}
 
 
-int32
-BOutlineListView::FullListIndex(int32 index) const
-{
-	BListItem *item = ItemAt(index);
-
-	if (item == NULL)
-		return -1;
-
-	return FullListIndexOf(item);
-}
-
-
-int32
-BOutlineListView::ListViewIndex(int32 index) const
-{
-	BListItem *item = ItemAt(index);
-
-	if (item == NULL)
-		return -1;
-
-	return BListView::IndexOf(item);
-}
-
-
 void
-BOutlineListView::ExpandOrCollapse(BListItem *underItem, bool expand)
+BOutlineListView::ExpandOrCollapse(BListItem* underItem, bool expand)
 {
 }
 
@@ -1081,20 +936,171 @@
 	if (item->fHasSubitems)
 		DrawLatch(itemRect, item->fLevel, !item->IsExpanded(), false, false);
 
-	itemRect.left += (item->fLevel) * 10.0f + 15.0f;
+	itemRect.left += item->fLevel * 10.0f + 15.0f;
 	item->DrawItem(this, itemRect, complete);
 }
 
 
-/*!
-	\brief Removes a single item from the list and all of its children.
+int32
+BOutlineListView::_FullListIndex(int32 index) const
+{
+	BListItem* item = ItemAt(index);
 
+	if (item == NULL)
+		return -1;
+
+	return FullListIndexOf(item);
+}
+
+
+void
+BOutlineListView::_PopulateTree(BList* tree, BList& target,
+	int32& firstIndex, bool onlyVisible)
+{
+	BListItem** items = (BListItem**)target.Items();
+	int32 count = tree->CountItems();
+
+	for (int32 index = 0; index < count; index++) {
+		BListItem* item = (BListItem*)tree->ItemAtFast(index);
+
+		items[firstIndex++] = item;
+
+		if (item->HasSubitems() && (!onlyVisible || item->IsExpanded()))
+			_PopulateTree(item->fTemporaryList, target, firstIndex, onlyVisible);
+	}
+}
+
+
+void
+BOutlineListView::_SortTree(BList* tree, bool oneLevelOnly,
+	int (*compareFunc)(const BListItem* a, const BListItem* b))
+{
+	BListItem** items = (BListItem**)tree->Items();
+	std::sort(items, items + tree->CountItems(), ListItemComparator(compareFunc));
+
+	if (oneLevelOnly)
+		return;
+
+	for (int32 index = tree->CountItems(); index-- > 0;) {
+		BListItem* item = (BListItem*)tree->ItemAt(index);
+
+		if (item->HasSubitems())
+			_SortTree(item->fTemporaryList, false, compareFunc);
+	}
+}
+
+
+void
+BOutlineListView::_DestructTree(BList* tree)
+{
+	for (int32 index = tree->CountItems(); index-- > 0;) {
+		BListItem* item = (BListItem*)tree->ItemAt(index);
+
+		if (item->HasSubitems())
+			_DestructTree(item->fTemporaryList);
+	}
+
+	delete tree;
+}
+
+
+BList*
+BOutlineListView::_BuildTree(BListItem* underItem, int32& fullIndex)
+{
+	int32 fullCount = FullListCountItems();
+	uint32 level = underItem != NULL ? underItem->OutlineLevel() + 1 : 0;
+	BList* list = new BList;
+	if (underItem != NULL)
+		underItem->fTemporaryList = list;
+
+	while (fullIndex < fullCount) {
+		BListItem* item = FullListItemAt(fullIndex);
+
+		// If we jump out of the subtree, break out
+		if (item->fLevel < level)
+			break;
+
+		// If the level matches, put them into the list
+		// (we handle the case of a missing sublevel gracefully)
+		list->AddItem(item);
+		fullIndex++;
+
+		if (item->HasSubitems()) {
+			// we're going deeper
+			_BuildTree(item, fullIndex);
+		}
+	}
+
+	return list;
+}
+
+
+void
+BOutlineListView::_CullInvisibleItems(BList& list)
+{
+	int32 index = 0;
+	while (index < list.CountItems()) {
+		if (reinterpret_cast<BListItem*>(list.ItemAt(index))->IsItemVisible())
+			++index;
+		else
+			list.RemoveItem(index);
+	}
+}
+
+
+bool
+BOutlineListView::_SwapItems(int32 first, int32 second)
+{
+	// same item, do nothing
+	if (first == second)
+		return true;
+
+	// fail, first item out of bounds
+	if ((first < 0) || (first >= CountItems()))
+		return false;
+
+	// fail, second item out of bounds
+	if ((second < 0) || (second >= CountItems()))
+		return false;
+
+	int32 firstIndex = min_c(first, second);
+	int32 secondIndex = max_c(first, second);
+	BListItem* firstItem = ItemAt(firstIndex);
+	BListItem* secondItem = ItemAt(secondIndex);
+	BList firstSubItems, secondSubItems;
+
+	if (Superitem(firstItem) != Superitem(secondItem))
+		return false;
+	if (!firstItem->IsItemVisible() || !secondItem->IsItemVisible())
+		return false;
+
+	int32 fullFirstIndex = _FullListIndex(firstIndex);
+	int32 fullSecondIndex = _FullListIndex(secondIndex);
+	_GetSubItems(fFullList, firstSubItems, firstItem, fullFirstIndex + 1);
+	_GetSubItems(fFullList, secondSubItems, secondItem, fullSecondIndex + 1);
+	_DoSwap(fFullList, fullFirstIndex, fullSecondIndex, &firstSubItems,
+		&secondSubItems);
+
+	_CullInvisibleItems(firstSubItems);
+	_CullInvisibleItems(secondSubItems);
+	_DoSwap(fList, firstIndex, secondIndex, &firstSubItems,
+		&secondSubItems);
+
+	_RecalcItemTops(firstIndex);
+	_RescanSelection(firstIndex, secondIndex + secondSubItems.CountItems());
+	Invalidate(Bounds());
+	return true;
+}
+
+
+/*!	\brief Removes a single item from the list and all of its children.
+
 	Unlike the BeOS version, this one will actually delete the children, too,
 	as there should be no reference left to them. This may cause problems for
 	applications that actually take the misbehaviour of the Be classes into
 	account.
 */
-BListItem *
+BListItem*
 BOutlineListView::_RemoveItem(BListItem* item, int32 fullIndex)
 {
 	if (item == NULL || fullIndex < 0 || fullIndex >= FullListCountItems())
@@ -1107,7 +1113,7 @@
 	if (item->IsItemVisible()) {
 		// remove children, too
 		while (fullIndex + 1 < CountItems()) {
-			BListItem *subItem = ItemAt(fullIndex + 1);
+			BListItem* subItem = ItemAt(fullIndex + 1);
 
 			if (subItem->OutlineLevel() <= level)
 				break;
@@ -1133,61 +1139,14 @@
 }
 
 
-BListItem *
-BOutlineListView::RemoveOne(int32 fullListIndex)
-{
-	return NULL;
-}
-
-
-void
-BOutlineListView::TrackInLatchItem(void *)
-{
-}
-
-
-void
-BOutlineListView::TrackOutLatchItem(void *)
-{
-}
-
-
-bool
-BOutlineListView::OutlineSwapItems(int32 a, int32 b)
-{
-	return false;
-}
-
-
-bool

[... truncated: 35 lines follow ...]



More information about the Haiku-commits mailing list