xref: /haiku/headers/os/interface/ListItem.h (revision ddac407426cd3b3d0b4589d7a161b300b3539a2a)
1 /*
2  * Copyright 2006-2009, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _LIST_ITEM_H
6 #define _LIST_ITEM_H
7 
8 
9 #include <Archivable.h>
10 #include <Rect.h>
11 
12 class BFont;
13 class BList;
14 class BMessage;
15 class BOutlineListView;
16 class BView;
17 
18 
19 class BListItem : public BArchivable {
20 public:
21 							BListItem(uint32 outlineLevel = 0,
22 								bool expanded = true);
23 							BListItem(BMessage* archive);
24 	virtual					~BListItem();
25 
26 	virtual	status_t		Archive(BMessage* archive, bool deep = true) const;
27 
28 			float			Height() const;
29 			float			Width() const;
30 			bool			IsSelected() const;
31 			void			Select();
32 			void			Deselect();
33 
34 	virtual	void			SetEnabled(bool enabled);
35 			bool			IsEnabled() const;
36 
37 			void			SetHeight(float height);
38 			void			SetWidth(float width);
39 	virtual	void			DrawItem(BView* owner, BRect frame,
40 								bool complete = false) = 0;
41 	virtual	void			Update(BView* owner, const BFont* font);
42 
43 	virtual	status_t		Perform(perform_code code, void* arg);
44 
45 			bool			IsExpanded() const;
46 			void			SetExpanded(bool expanded);
47 			uint32			OutlineLevel() const;
48 
49 private:
50 	friend class BOutlineListView;
51 	friend class BListView;
52 
53 			bool			HasSubitems() const;
54 
55 	virtual	void			_ReservedListItem1();
56 	virtual	void			_ReservedListItem2();
57 
58 							BListItem(const BListItem& item);
59 			BListItem&		operator=(const BListItem& item);
60 
61 			bool			IsItemVisible() const;
62 			void			SetItemVisible(bool visible);
63 	inline	float			Top() const;
64 	inline	float			Bottom() const;
65 			void			SetTop(float top);
66 
67 private:
68 			float			fTop;
69 			BList*			fTemporaryList;
70 			float			fWidth;
71 			float			fHeight;
72 			uint32			fLevel;
73 			bool			fSelected;
74 			bool			fEnabled;
75 			bool			fExpanded;
76 			bool			fHasSubitems : 1;
77 			bool			fVisible : 1;
78 };
79 
80 
81 inline float
82 BListItem::Top(void) const
83 {
84 	return fTop;
85 }
86 
87 
88 inline float
89 BListItem::Bottom(void) const
90 {
91 	return fTop + ceilf(fHeight) - 1.0;
92 }
93 
94 
95 #include <StringItem.h>
96 	// to maintain source compatibility
97 
98 #endif	// _LIST_ITEM_H
99