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