2 * Copyright 2001-2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
7 * Marc Flerackers (mflerackers@androme.be)
12 #include <StringItem.h>
17 #include <ControlLook.h>
22 BStringItem::BStringItem(const char* text
, uint32 level
, bool expanded
)
24 BListItem(level
, expanded
),
32 BStringItem::BStringItem(BMessage
* archive
)
39 if (archive
->FindString("_label", &string
) == B_OK
)
44 BStringItem::~BStringItem()
51 BStringItem::Instantiate(BMessage
* archive
)
53 if (validate_instantiation(archive
, "BStringItem"))
54 return new BStringItem(archive
);
61 BStringItem::Archive(BMessage
* archive
, bool deep
) const
63 status_t status
= BListItem::Archive(archive
);
65 if (status
== B_OK
&& fText
!= NULL
)
66 status
= archive
->AddString("_label", fText
);
73 BStringItem::DrawItem(BView
* owner
, BRect frame
, bool complete
)
78 rgb_color lowColor
= owner
->LowColor();
80 if (IsSelected() || complete
) {
83 color
= ui_color(B_LIST_SELECTED_BACKGROUND_COLOR
);
85 color
= owner
->ViewColor();
87 owner
->SetLowColor(color
);
88 owner
->FillRect(frame
, B_SOLID_LOW
);
90 owner
->SetLowColor(owner
->ViewColor());
92 owner
->MovePenTo(frame
.left
+ be_control_look
->DefaultLabelSpacing(),
93 frame
.top
+ fBaselineOffset
);
95 owner
->DrawString(fText
);
97 owner
->SetLowColor(lowColor
);
102 BStringItem::SetText(const char* text
)
108 fText
= strdup(text
);
113 BStringItem::Text() const
120 BStringItem::Update(BView
* owner
, const BFont
* font
)
123 SetWidth(font
->StringWidth(fText
)
124 + be_control_look
->DefaultLabelSpacing());
128 font
->GetHeight(&fheight
);
130 fBaselineOffset
= 2 + ceilf(fheight
.ascent
+ fheight
.leading
/ 2);
132 SetHeight(ceilf(fheight
.ascent
) + ceilf(fheight
.descent
)
133 + ceilf(fheight
.leading
) + 4);
138 BStringItem::Perform(perform_code d
, void* arg
)
140 return BListItem::Perform(d
, arg
);
145 BStringItem::BaselineOffset() const
147 return fBaselineOffset
;
151 void BStringItem::_ReservedStringItem1() {}
152 void BStringItem::_ReservedStringItem2() {}
155 BStringItem::BStringItem(const BStringItem
&)
161 BStringItem::operator=(const BStringItem
&)