1 /* 2 * Copyright 2011, Axel Dörfler, axeld@pinc-software.de. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef GROUP_LIST_VIEW_H 6 #define GROUP_LIST_VIEW_H 7 8 9 #include <GroupView.h> 10 #include <Roster.h> 11 12 13 class GroupListModel { 14 public: 15 virtual int32 CountItems() = 0; 16 virtual void* ItemAt(int32 index) = 0; 17 18 virtual int32 CountGroups() = 0; 19 virtual void* GroupAt(int32 index) = 0; 20 virtual void* GroupForItemAt(int32 index) = 0; 21 }; 22 23 24 class ListItemRenderer { 25 public: 26 virtual void SetTo(BView* owner, void* item) = 0; 27 28 virtual BSize MinSize() = 0; 29 virtual BSize MaxSize() = 0; 30 virtual BSize PreferredSize() = 0; 31 32 virtual void Draw(BView* owner, BRect frame, int32 index, 33 bool selected) = 0; 34 }; 35 36 37 class GroupListView : public BView { 38 public: 39 GroupListView(const char* name, 40 GroupListModel* model = NULL, 41 enum orientation orientation = B_VERTICAL, 42 float spacing = 0); 43 virtual ~GroupListView(); 44 45 GroupListModel* Model() const 46 { return fModel; } 47 virtual void SetModel(GroupListModel* model); 48 49 ListItemRenderer* ItemRenderer() const 50 { return fItemRenderer; } 51 virtual void SetItemRenderer(ListItemRenderer* renderer); 52 ListItemRenderer* GroupRenderer() const 53 { return fGroupRenderer; } 54 virtual void SetGroupRenderer(ListItemRenderer* renderer); 55 56 BMessage* SelectionMessage() const 57 { return fSelectionMessage; } 58 virtual void SetSelectionMessage(BMessage* message, 59 BMessenger target); 60 61 virtual void AttachedToWindow(); 62 virtual void MessageReceived(BMessage* message); 63 virtual void MouseDown(BPoint point); 64 virtual void Draw(BRect updateRect); 65 66 private: 67 void _Draw(BLayoutItem* item, BRect updateRect); 68 BLayoutItem* _ItemAt(BLayoutItem* item, BPoint point); 69 70 private: 71 GroupListModel* fModel; 72 ListItemRenderer* fItemRenderer; 73 ListItemRenderer* fGroupRenderer; 74 75 BMessage* fSelectionMessage; 76 BMessenger fSelectionTarget; 77 }; 78 79 80 #endif // GROUP_LIST_VIEW_H 81