xref: /haiku/src/apps/switcher/GroupListView.h (revision 9a6a20d4689307142a7ed26a1437ba47e244e73f)
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						~GroupListModel() {};
16 	virtual	int32				CountItems() = 0;
17 	virtual void*				ItemAt(int32 index) = 0;
18 
19 	virtual int32				CountGroups() = 0;
20 	virtual addr_t				GroupAt(int32 index) = 0;
21 	virtual addr_t				GroupForItemAt(int32 index) = 0;
22 };
23 
24 
25 class ListItemRenderer {
26 public:
27 	virtual						~ListItemRenderer() {};
28 	virtual void				SetTo(BView* owner, void* item) = 0;
29 
30 	virtual BSize				MinSize() = 0;
31 	virtual BSize				MaxSize() = 0;
32 	virtual BSize				PreferredSize() = 0;
33 
34 	virtual void				Draw(BView* owner, BRect frame, int32 index,
35 									bool selected) = 0;
36 };
37 
38 
39 class GroupListView : public BView {
40 public:
41 								GroupListView(const char* name,
42 									GroupListModel* model = NULL,
43 									enum orientation orientation = B_VERTICAL,
44 									float spacing = 0);
45 	virtual						~GroupListView();
46 
47 			GroupListModel*		Model() const
48 									{ return fModel; }
49 	virtual void				SetModel(GroupListModel* model);
50 
51 			ListItemRenderer*	ItemRenderer() const
52 									{ return fItemRenderer; }
53 	virtual	void				SetItemRenderer(ListItemRenderer* renderer);
54 			ListItemRenderer*	GroupRenderer() const
55 									{ return fGroupRenderer; }
56 	virtual	void				SetGroupRenderer(ListItemRenderer* renderer);
57 
58 			BMessage*			SelectionMessage() const
59 									{ return fSelectionMessage; }
60 	virtual void				SetSelectionMessage(BMessage* message,
61 									BMessenger target);
62 
63 	virtual void				AttachedToWindow();
64 	virtual	void				MessageReceived(BMessage* message);
65 	virtual void				MouseDown(BPoint point);
66 	virtual	void				Draw(BRect updateRect);
67 
68 private:
69 			void				_Draw(BLayoutItem* item, BRect updateRect);
70 			BLayoutItem*		_ItemAt(BLayoutItem* item, BPoint point);
71 
72 private:
73 			GroupListModel*		fModel;
74 			ListItemRenderer*	fItemRenderer;
75 			ListItemRenderer*	fGroupRenderer;
76 
77 			BMessage*			fSelectionMessage;
78 			BMessenger			fSelectionTarget;
79 };
80 
81 
82 #endif	// GROUP_LIST_VIEW_H
83