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 18BListItem::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 34BListItem::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 59BListItem::~BListItem() 60{ 61} 62 63 64status_t 65BListItem::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 84float 85BListItem::Height() const 86{ 87 return fHeight; 88} 89 90 91float 92BListItem::Width() const 93{ 94 return fWidth; 95} 96 97 98bool 99BListItem::IsSelected() const 100{ 101 return fSelected; 102} 103 104 105void 106BListItem::Select() 107{ 108 fSelected = true; 109} 110 111 112void 113BListItem::Deselect() 114{ 115 fSelected = false; 116} 117 118 119void 120BListItem::SetEnabled(bool on) 121{ 122 fEnabled = on; 123} 124 125 126bool 127BListItem::IsEnabled() const 128{ 129 return fEnabled; 130} 131 132 133void 134BListItem::SetHeight(float height) 135{ 136 fHeight = height; 137} 138 139 140void 141BListItem::SetWidth(float width) 142{ 143 fWidth = width; 144} 145 146 147void 148BListItem::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 158status_t 159BListItem::Perform(perform_code d, void* arg) 160{ 161 return BArchivable::Perform(d, arg); 162} 163 164 165void 166BListItem::SetExpanded(bool expanded) 167{ 168 fExpanded = expanded; 169} 170 171 172bool 173BListItem::IsExpanded() const 174{ 175 return fExpanded; 176} 177 178 179uint32 180BListItem::OutlineLevel() const 181{ 182 return fLevel; 183} 184 185 186void 187BListItem::SetOutlineLevel(uint32 level) 188{ 189 fLevel = level; 190} 191 192 193bool 194BListItem::HasSubitems() const 195{ 196 return fHasSubitems; 197} 198 199 200void BListItem::_ReservedListItem1() {} 201void BListItem::_ReservedListItem2() {} 202 203 204bool 205BListItem::IsItemVisible() const 206{ 207 return fVisible; 208} 209 210 211void 212BListItem::SetTop(float top) 213{ 214 fTop = top; 215} 216 217 218void 219BListItem::SetItemVisible(bool visible) 220{ 221 fVisible = visible; 222} 223