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