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