17c74b12bSAxel Dörfler /* 2*89208c77SStephan Aßmus * Copyright 2006-2009, Haiku, Inc. All rights reserved. 3*89208c77SStephan Aßmus * 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, 174b15b909SStephan Aßmus list_view_type type 184b15b909SStephan Aßmus = B_SINGLE_SELECTION_LIST, 1908a35638SAxel Dörfler uint32 resizeMode 2008a35638SAxel Dörfler = B_FOLLOW_LEFT | B_FOLLOW_TOP, 214b15b909SStephan Aßmus uint32 flags = B_WILL_DRAW 224b15b909SStephan Aßmus | B_FRAME_EVENTS | B_NAVIGABLE); 2308a35638SAxel Dörfler BOutlineListView(const char* name, 244b15b909SStephan Aßmus list_view_type type 254b15b909SStephan Aßmus = B_SINGLE_SELECTION_LIST, 264b15b909SStephan Aßmus uint32 flags = B_WILL_DRAW 274b15b909SStephan Aßmus | B_FRAME_EVENTS | B_NAVIGABLE); 287c74b12bSAxel Dörfler BOutlineListView(BMessage* archive); 29d734a8ceSbeveloper virtual ~BOutlineListView(); 30d734a8ceSbeveloper 317c74b12bSAxel Dörfler static BArchivable* Instantiate(BMessage* archive); 324b15b909SStephan Aßmus virtual status_t Archive(BMessage* archive, 334b15b909SStephan Aßmus bool deep = true) const; 34d734a8ceSbeveloper 35d734a8ceSbeveloper virtual void MouseDown(BPoint where); 36d734a8ceSbeveloper virtual void KeyDown(const char* bytes, int32 numBytes); 377c74b12bSAxel Dörfler virtual void FrameMoved(BPoint newPosition); 387c74b12bSAxel Dörfler virtual void FrameResized(float newWidth, float newHeight); 39d734a8ceSbeveloper virtual void MouseUp(BPoint where); 40d734a8ceSbeveloper 414b15b909SStephan Aßmus virtual bool AddUnder(BListItem* item, 424b15b909SStephan Aßmus BListItem* underItem); 43d734a8ceSbeveloper 44d734a8ceSbeveloper virtual bool AddItem(BListItem* item); 45d734a8ceSbeveloper virtual bool AddItem(BListItem* item, int32 fullListIndex); 46d734a8ceSbeveloper virtual bool AddList(BList* newItems); 47d734a8ceSbeveloper virtual bool AddList(BList* newItems, int32 fullListIndex); 48d734a8ceSbeveloper 49d734a8ceSbeveloper virtual bool RemoveItem(BListItem* item); 50d734a8ceSbeveloper virtual BListItem* RemoveItem(int32 fullListIndex); 51d734a8ceSbeveloper virtual bool RemoveItems(int32 fullListIndex, int32 count); 52d734a8ceSbeveloper 53d734a8ceSbeveloper BListItem* FullListItemAt(int32 fullListIndex) const; 54d734a8ceSbeveloper int32 FullListIndexOf(BPoint point) const; 55d734a8ceSbeveloper int32 FullListIndexOf(BListItem* item) const; 56d734a8ceSbeveloper BListItem* FullListFirstItem() const; 57d734a8ceSbeveloper BListItem* FullListLastItem() const; 58d734a8ceSbeveloper bool FullListHasItem(BListItem* item) const; 59d734a8ceSbeveloper int32 FullListCountItems() const; 604b15b909SStephan Aßmus int32 FullListCurrentSelection( 614b15b909SStephan Aßmus int32 index = 0) const; 627c74b12bSAxel Dörfler 63d734a8ceSbeveloper virtual void MakeEmpty(); 64d734a8ceSbeveloper bool FullListIsEmpty() const; 6508a35638SAxel Dörfler void FullListDoForEach( 664b15b909SStephan Aßmus bool (*func)(BListItem* item)); 674b15b909SStephan Aßmus void FullListDoForEach( 684b15b909SStephan Aßmus bool (*func)(BListItem* item, void*), 694b15b909SStephan Aßmus void*); 70d734a8ceSbeveloper 71d734a8ceSbeveloper BListItem* Superitem(const BListItem* item); 72d734a8ceSbeveloper 73d734a8ceSbeveloper void Expand(BListItem* item); 74d734a8ceSbeveloper void Collapse(BListItem* item); 75d734a8ceSbeveloper 76d734a8ceSbeveloper bool IsExpanded(int32 fullListIndex); 77d734a8ceSbeveloper 784b15b909SStephan Aßmus virtual BHandler* ResolveSpecifier(BMessage* message, 794b15b909SStephan Aßmus int32 index, BMessage* specifier, 804b15b909SStephan Aßmus int32 what, const char* property); 81d734a8ceSbeveloper virtual status_t GetSupportedSuites(BMessage* data); 824b15b909SStephan Aßmus virtual status_t Perform(perform_code code, void* data); 83d734a8ceSbeveloper 84d734a8ceSbeveloper virtual void ResizeToPreferred(); 854b15b909SStephan Aßmus virtual void GetPreferredSize(float* _width, 864b15b909SStephan Aßmus float* _height); 877c74b12bSAxel Dörfler virtual void MakeFocus(bool focus = true); 88d734a8ceSbeveloper virtual void AllAttached(); 89d734a8ceSbeveloper virtual void AllDetached(); 90d734a8ceSbeveloper virtual void DetachedFromWindow(); 91d734a8ceSbeveloper 9208a35638SAxel Dörfler void FullListSortItems(int (*compareFunc)( 9308a35638SAxel Dörfler const BListItem* first, 947c74b12bSAxel Dörfler const BListItem* second)); 9508a35638SAxel Dörfler void SortItemsUnder(BListItem* underItem, 9608a35638SAxel Dörfler bool oneLevelOnly, int (*compareFunc)( 9708a35638SAxel Dörfler const BListItem* first, 987c74b12bSAxel Dörfler const BListItem* second)); 9908a35638SAxel Dörfler int32 CountItemsUnder(BListItem* under, 10008a35638SAxel Dörfler bool oneLevelOnly) const; 10108a35638SAxel Dörfler BListItem* EachItemUnder(BListItem* underItem, 10208a35638SAxel Dörfler bool oneLevelOnly, BListItem* (*eachFunc)( 1034b15b909SStephan Aßmus BListItem* item, void* arg), 1044b15b909SStephan Aßmus void* arg); 1054b15b909SStephan Aßmus BListItem* ItemUnderAt(BListItem* underItem, 1064b15b909SStephan Aßmus bool oneLevelOnly, int32 index) const; 107d734a8ceSbeveloper 108d734a8ceSbeveloper protected: 109d734a8ceSbeveloper virtual bool DoMiscellaneous(MiscCode code, MiscData* data); 1107c74b12bSAxel Dörfler virtual void MessageReceived(BMessage* message); 111d734a8ceSbeveloper 112d734a8ceSbeveloper private: 113d734a8ceSbeveloper virtual void _ReservedOutlineListView1(); 114d734a8ceSbeveloper virtual void _ReservedOutlineListView2(); 115d734a8ceSbeveloper virtual void _ReservedOutlineListView3(); 116d734a8ceSbeveloper virtual void _ReservedOutlineListView4(); 117d734a8ceSbeveloper 118d734a8ceSbeveloper protected: 1194b15b909SStephan Aßmus virtual void ExpandOrCollapse(BListItem* underItem, 1204b15b909SStephan Aßmus bool expand); 121d734a8ceSbeveloper virtual BRect LatchRect(BRect itemRect, int32 level) const; 12208a35638SAxel Dörfler virtual void DrawLatch(BRect itemRect, int32 level, 12308a35638SAxel Dörfler bool collapsed, bool highlighted, 12408a35638SAxel Dörfler bool misTracked); 12508a35638SAxel Dörfler virtual void DrawItem(BListItem* item, BRect itemRect, 12608a35638SAxel Dörfler bool complete = false); 1277c74b12bSAxel Dörfler 1287c74b12bSAxel Dörfler private: 12908a35638SAxel Dörfler int32 _FullListIndex(int32 index) const; 13008a35638SAxel Dörfler 1317c74b12bSAxel Dörfler void _PopulateTree(BList* tree, BList& target, 1327c74b12bSAxel Dörfler int32& firstIndex, bool onlyVisible); 1337c74b12bSAxel Dörfler void _SortTree(BList* tree, bool oneLevelOnly, 13408a35638SAxel Dörfler int (*compareFunc)(const BListItem* a, 13508a35638SAxel Dörfler const BListItem* b)); 1367c74b12bSAxel Dörfler void _DestructTree(BList* tree); 1377c74b12bSAxel Dörfler BList* _BuildTree(BListItem* underItem, int32& index); 138d734a8ceSbeveloper 13984d75fa4SRene Gollent void _CullInvisibleItems(BList &list); 14008a35638SAxel Dörfler bool _SwapItems(int32 first, int32 second); 1414b15b909SStephan Aßmus BListItem* _RemoveItem(BListItem* item, 1424b15b909SStephan Aßmus int32 fullListIndex); 143d734a8ceSbeveloper 1444b15b909SStephan Aßmus BListItem* _SuperitemForIndex(int32 fullListIndex, 1454b15b909SStephan Aßmus int32 level, int32* _superIndex = NULL); 146b66c6231SAxel Dörfler int32 _FindPreviousVisibleIndex(int32 fullListIndex); 147d734a8ceSbeveloper 1487c74b12bSAxel Dörfler private: 1497c74b12bSAxel Dörfler BList fFullList; 1504b15b909SStephan Aßmus 151d734a8ceSbeveloper uint32 _reserved[2]; 152d734a8ceSbeveloper }; 153d734a8ceSbeveloper 1547c74b12bSAxel Dörfler #endif // _OUTLINE_LIST_VIEW_H 155