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