1 /*
2 * Copyright 2001-2010 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 * Ulrich Wimboeck
7 * Marc Flerackers (mflerackers@androme.be)
8 * Rene Gollent
9 */
10
11
12 #include <ListItem.h>
13
14 #include <Message.h>
15 #include <View.h>
16
17
BListItem(uint32 level,bool expanded)18 BListItem::BListItem(uint32 level, bool expanded)
19 :
20 fTop(0.0),
21 fTemporaryList(0),
22 fWidth(0),
23 fHeight(0),
24 fLevel(level),
25 fSelected(false),
26 fEnabled(true),
27 fExpanded(expanded),
28 fHasSubitems(false),
29 fVisible(true)
30 {
31 }
32
33
BListItem(BMessage * data)34 BListItem::BListItem(BMessage* data)
35 :
36 BArchivable(data),
37 fTop(0.0),
38 fWidth(0),
39 fHeight(0),
40 fLevel(0),
41 fSelected(false),
42 fEnabled(true),
43 fExpanded(false),
44 fHasSubitems(false),
45 fVisible(true)
46 {
47 data->FindBool("_sel", &fSelected);
48
49 if (data->FindBool("_disable", &fEnabled) != B_OK)
50 fEnabled = true;
51 else
52 fEnabled = false;
53
54 data->FindBool("_li_expanded", &fExpanded);
55 data->FindInt32("_li_outline_level", (int32*)&fLevel);
56 }
57
58
~BListItem()59 BListItem::~BListItem()
60 {
61 }
62
63
64 status_t
Archive(BMessage * archive,bool deep) const65 BListItem::Archive(BMessage* archive, bool deep) const
66 {
67 status_t status = BArchivable::Archive(archive, deep);
68 if (status == B_OK && fSelected)
69 status = archive->AddBool("_sel", true);
70
71 if (status == B_OK && !fEnabled)
72 status = archive->AddBool("_disable", true);
73
74 if (status == B_OK && fExpanded)
75 status = archive->AddBool("_li_expanded", true);
76
77 if (status == B_OK && fLevel != 0)
78 status = archive->AddInt32("_li_outline_level", fLevel);
79
80 return status;
81 }
82
83
84 float
Height() const85 BListItem::Height() const
86 {
87 return fHeight;
88 }
89
90
91 float
Width() const92 BListItem::Width() const
93 {
94 return fWidth;
95 }
96
97
98 bool
IsSelected() const99 BListItem::IsSelected() const
100 {
101 return fSelected;
102 }
103
104
105 void
Select()106 BListItem::Select()
107 {
108 fSelected = true;
109 }
110
111
112 void
Deselect()113 BListItem::Deselect()
114 {
115 fSelected = false;
116 }
117
118
119 void
SetEnabled(bool on)120 BListItem::SetEnabled(bool on)
121 {
122 fEnabled = on;
123 }
124
125
126 bool
IsEnabled() const127 BListItem::IsEnabled() const
128 {
129 return fEnabled;
130 }
131
132
133 void
SetHeight(float height)134 BListItem::SetHeight(float height)
135 {
136 fHeight = height;
137 }
138
139
140 void
SetWidth(float width)141 BListItem::SetWidth(float width)
142 {
143 fWidth = width;
144 }
145
146
147 void
Update(BView * owner,const BFont * font)148 BListItem::Update(BView* owner, const BFont* font)
149 {
150 font_height fh;
151 font->GetHeight(&fh);
152
153 SetWidth(owner->Bounds().Width());
154 SetHeight(ceilf(fh.ascent + fh.descent + fh.leading));
155 }
156
157
158 status_t
Perform(perform_code d,void * arg)159 BListItem::Perform(perform_code d, void* arg)
160 {
161 return BArchivable::Perform(d, arg);
162 }
163
164
165 void
SetExpanded(bool expanded)166 BListItem::SetExpanded(bool expanded)
167 {
168 fExpanded = expanded;
169 }
170
171
172 bool
IsExpanded() const173 BListItem::IsExpanded() const
174 {
175 return fExpanded;
176 }
177
178
179 uint32
OutlineLevel() const180 BListItem::OutlineLevel() const
181 {
182 return fLevel;
183 }
184
185
186 void
SetOutlineLevel(uint32 level)187 BListItem::SetOutlineLevel(uint32 level)
188 {
189 fLevel = level;
190 }
191
192
193 bool
HasSubitems() const194 BListItem::HasSubitems() const
195 {
196 return fHasSubitems;
197 }
198
199
_ReservedListItem1()200 void BListItem::_ReservedListItem1() {}
_ReservedListItem2()201 void BListItem::_ReservedListItem2() {}
202
203
204 bool
IsItemVisible() const205 BListItem::IsItemVisible() const
206 {
207 return fVisible;
208 }
209
210
211 void
SetTop(float top)212 BListItem::SetTop(float top)
213 {
214 fTop = top;
215 }
216
217
218 void
SetItemVisible(bool visible)219 BListItem::SetItemVisible(bool visible)
220 {
221 fVisible = visible;
222 }
223