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 : BArchivable(data), 36 fTop(0.0), 37 fWidth(0), 38 fHeight(0), 39 fLevel(0), 40 fSelected(false), 41 fEnabled(true), 42 fExpanded(false), 43 fHasSubitems(false), 44 fVisible(true) 45{ 46 data->FindBool("_sel", &fSelected); 47 48 if (data->FindBool("_disable", &fEnabled) != B_OK) 49 fEnabled = true; 50 else 51 fEnabled = false; 52 53 data->FindBool("_li_expanded", &fExpanded); 54 data->FindInt32("_li_outline_level", (int32*)&fLevel); 55} 56 57 58BListItem::~BListItem() 59{ 60} 61 62 63status_t 64BListItem::Archive(BMessage* archive, bool deep) const 65{ 66 status_t status = BArchivable::Archive(archive, deep); 67 if (status == B_OK && fSelected) 68 status = archive->AddBool("_sel", true); 69 70 if (status == B_OK && !fEnabled) 71 status = archive->AddBool("_disable", true); 72 73 if (status == B_OK && fExpanded) 74 status = archive->AddBool("_li_expanded", true); 75 76 if (status == B_OK && fLevel != 0) 77 status = archive->AddInt32("_li_outline_level", fLevel); 78 79 return status; 80} 81 82 83float 84BListItem::Height() const 85{ 86 return fHeight; 87} 88 89 90float 91BListItem::Width() const 92{ 93 return fWidth; 94} 95 96 97bool 98BListItem::IsSelected() const 99{ 100 return fSelected; 101} 102 103 104void 105BListItem::Select() 106{ 107 fSelected = true; 108} 109 110 111void 112BListItem::Deselect() 113{ 114 fSelected = false; 115} 116 117 118void 119BListItem::SetEnabled(bool on) 120{ 121 fEnabled = on; 122} 123 124 125bool 126BListItem::IsEnabled() const 127{ 128 return fEnabled; 129} 130 131 132void 133BListItem::SetHeight(float height) 134{ 135 fHeight = height; 136} 137 138 139void 140BListItem::SetWidth(float width) 141{ 142 fWidth = width; 143} 144 145 146void 147BListItem::Update(BView* owner, const BFont* font) 148{ 149 font_height fh; 150 font->GetHeight(&fh); 151 152 SetWidth(owner->Bounds().Width()); 153 SetHeight(ceilf(fh.ascent + fh.descent + fh.leading)); 154} 155 156 157status_t 158BListItem::Perform(perform_code d, void* arg) 159{ 160 return BArchivable::Perform(d, arg); 161} 162 163 164void 165BListItem::SetExpanded(bool expanded) 166{ 167 fExpanded = expanded; 168} 169 170 171bool 172BListItem::IsExpanded() const 173{ 174 return fExpanded; 175} 176 177 178uint32 179BListItem::OutlineLevel() const 180{ 181 return fLevel; 182} 183 184 185void 186BListItem::SetOutlineLevel(uint32 level) 187{ 188 fLevel = level; 189} 190 191 192bool 193BListItem::HasSubitems() const 194{ 195 return fHasSubitems; 196} 197 198 199void BListItem::_ReservedListItem1() {} 200void BListItem::_ReservedListItem2() {} 201 202 203bool 204BListItem::IsItemVisible() const 205{ 206 return fVisible; 207} 208 209 210void 211BListItem::SetTop(float top) 212{ 213 fTop = top; 214} 215 216 217void 218BListItem::SetItemVisible(bool visible) 219{ 220 fVisible = visible; 221} 222 223