Chat-O-Matic/application/preferences/AccountListItem.cpp

96 lines
1.8 KiB
C++
Raw Normal View History

/*
* Copyright 2009-2010, Pier Luigi Fiorini. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Pier Luigi Fiorini, pierluigi.fiorini@gmail.com
*/
#include <View.h>
#include "AccountListItem.h"
#include "ProtocolSettings.h"
2010-05-20 16:31:55 -05:00
AccountListItem::AccountListItem(ProtocolSettings* settings,
const char* account)
:
BStringItem(account),
fSettings(settings),
fAccount(account),
fBaselineOffset(0)
{
}
AccountListItem::~AccountListItem()
{
}
ProtocolSettings*
AccountListItem::Settings() const
{
return fSettings;
}
const char*
AccountListItem::Account() const
{
return fAccount.String();
}
void
AccountListItem::SetAccount(const char* name)
{
fAccount = name;
SetText(fAccount);
}
void
AccountListItem::DrawItem(BView* owner, BRect frame, bool complete)
{
rgb_color highColor = owner->HighColor();
rgb_color lowColor = owner->LowColor();
// Draw selection
2010-05-20 16:31:55 -05:00
if (IsSelected()) {
rgb_color highlightColor = ui_color(B_CONTROL_HIGHLIGHT_COLOR);
owner->SetLowColor(highlightColor);
owner->SetHighColor(highlightColor);
owner->FillRect(frame);
}
// Draw account name
rgb_color textColor = ui_color(B_CONTROL_TEXT_COLOR);
2010-05-20 16:31:55 -05:00
owner->MovePenTo(frame.left, frame.top + fBaselineOffset);
if (!IsEnabled())
owner->SetHighColor(tint_color(textColor, B_LIGHTEN_2_TINT));
else
2010-05-20 16:31:55 -05:00
owner->SetHighColor(textColor);
owner->DrawString(Text());
owner->SetHighColor(highColor);
owner->SetLowColor(lowColor);
}
void
AccountListItem::Update(BView* owner, const BFont* font)
{
if (Text())
SetWidth(font->StringWidth(Text()));
font_height height;
font->GetHeight(&height);
fBaselineOffset = 2 + ceilf(height.ascent + height.leading / 2);
SetHeight(ceilf(height.ascent) + ceilf(height.descent)
+ ceilf(height.leading) + 4);
}