1 /* 2 * Copyright 2006-2009, 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 class BListItem; 12 13 14 class BOutlineListView : public BListView { 15 public: 16 BOutlineListView(BRect frame, const char* name, 17 list_view_type type = B_SINGLE_SELECTION_LIST, 18 uint32 resizeMode 19 = B_FOLLOW_LEFT | B_FOLLOW_TOP, 20 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS 21 | B_NAVIGABLE); 22 BOutlineListView(const char* name, 23 list_view_type type = B_SINGLE_SELECTION_LIST, 24 uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS 25 | B_NAVIGABLE); 26 BOutlineListView(BMessage* archive); 27 virtual ~BOutlineListView(); 28 29 static BArchivable* Instantiate(BMessage* archive); 30 virtual status_t Archive(BMessage* archive, 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* underItem); 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 point) 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(int32 index = 0) const; 57 58 virtual void MakeEmpty(); 59 bool FullListIsEmpty() const; 60 void FullListDoForEach(bool (*func)(BListItem* item)); 61 void FullListDoForEach( 62 bool (*func)(BListItem* item, void*), void*); 63 64 BListItem* Superitem(const BListItem* item); 65 66 void Expand(BListItem* item); 67 void Collapse(BListItem* item); 68 69 bool IsExpanded(int32 fullListIndex); 70 71 virtual BHandler* ResolveSpecifier(BMessage* message, int32 index, 72 BMessage* specifier, int32 what, 73 const char* property); 74 virtual status_t GetSupportedSuites(BMessage* data); 75 virtual status_t Perform(perform_code d, void* arg); 76 77 virtual void ResizeToPreferred(); 78 virtual void GetPreferredSize(float* _width, float* _height); 79 virtual void MakeFocus(bool focus = true); 80 virtual void AllAttached(); 81 virtual void AllDetached(); 82 virtual void DetachedFromWindow(); 83 84 void FullListSortItems(int (*compareFunc)( 85 const BListItem* first, 86 const BListItem* second)); 87 void SortItemsUnder(BListItem* underItem, 88 bool oneLevelOnly, int (*compareFunc)( 89 const BListItem* first, 90 const BListItem* second)); 91 int32 CountItemsUnder(BListItem* under, 92 bool oneLevelOnly) const; 93 BListItem* EachItemUnder(BListItem* underItem, 94 bool oneLevelOnly, BListItem* (*eachFunc)( 95 BListItem* item, void* arg), void* arg); 96 BListItem* ItemUnderAt(BListItem* underItem, bool oneLevelOnly, 97 int32 index) const; 98 99 protected: 100 virtual bool DoMiscellaneous(MiscCode code, MiscData* data); 101 virtual void MessageReceived(BMessage* message); 102 103 private: 104 virtual void _ReservedOutlineListView1(); 105 virtual void _ReservedOutlineListView2(); 106 virtual void _ReservedOutlineListView3(); 107 virtual void _ReservedOutlineListView4(); 108 109 protected: 110 virtual void ExpandOrCollapse(BListItem* underItem, bool expand); 111 virtual BRect LatchRect(BRect itemRect, int32 level) const; 112 virtual void DrawLatch(BRect itemRect, int32 level, 113 bool collapsed, bool highlighted, 114 bool misTracked); 115 virtual void DrawItem(BListItem* item, BRect itemRect, 116 bool complete = false); 117 118 private: 119 int32 _FullListIndex(int32 index) const; 120 121 void _PopulateTree(BList* tree, BList& target, 122 int32& firstIndex, bool onlyVisible); 123 void _SortTree(BList* tree, bool oneLevelOnly, 124 int (*compareFunc)(const BListItem* a, 125 const BListItem* b)); 126 void _DestructTree(BList* tree); 127 BList* _BuildTree(BListItem* underItem, int32& index); 128 129 void _CullInvisibleItems(BList &list); 130 bool _SwapItems(int32 first, int32 second); 131 BListItem* _RemoveItem(BListItem* item, int32 fullListIndex); 132 133 BListItem* _SuperitemForIndex(int32 fullListIndex, int32 level, 134 int32* _superIndex = NULL); 135 int32 _FindPreviousVisibleIndex(int32 fullListIndex); 136 137 private: 138 BList fFullList; 139 uint32 _reserved[2]; 140 }; 141 142 #endif // _OUTLINE_LIST_VIEW_H 143