HaikuDepot: Apply logic from 2a36368 to PackageListView fields.
Rename BBitmapStringField to SharedBitmapStringField and make it reference the SharedBitmap.
This commit is contained in:
@@ -59,19 +59,21 @@ package_state_to_string(PackageInfoRef ref)
|
|||||||
|
|
||||||
// A field type displaying both a bitmap and a string so that the
|
// A field type displaying both a bitmap and a string so that the
|
||||||
// tree display looks nicer (both text and bitmap are indented)
|
// tree display looks nicer (both text and bitmap are indented)
|
||||||
// TODO: Code-duplication with DriveSetup PartitionList.h
|
class SharedBitmapStringField : public BStringField {
|
||||||
class BBitmapStringField : public BStringField {
|
|
||||||
typedef BStringField Inherited;
|
typedef BStringField Inherited;
|
||||||
public:
|
public:
|
||||||
BBitmapStringField(const BBitmap* bitmap,
|
SharedBitmapStringField(SharedBitmap* bitmap,
|
||||||
|
SharedBitmap::Size size,
|
||||||
const char* string);
|
const char* string);
|
||||||
virtual ~BBitmapStringField();
|
virtual ~SharedBitmapStringField();
|
||||||
|
|
||||||
void SetBitmap(const BBitmap* bitmap);
|
void SetBitmap(SharedBitmap* bitmap,
|
||||||
|
SharedBitmap::Size size);
|
||||||
const BBitmap* Bitmap() const
|
const BBitmap* Bitmap() const
|
||||||
{ return fBitmap; }
|
{ return fBitmap; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
BitmapRef fReference;
|
||||||
const BBitmap* fBitmap;
|
const BBitmap* fBitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,7 +92,7 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
// BColumn for PackageListView which knows how to render
|
// BColumn for PackageListView which knows how to render
|
||||||
// a BBitmapStringField
|
// a SharedBitmapStringField
|
||||||
// TODO: Code-duplication with DriveSetup PartitionList.h
|
// TODO: Code-duplication with DriveSetup PartitionList.h
|
||||||
class PackageColumn : public BTitledColumn {
|
class PackageColumn : public BTitledColumn {
|
||||||
typedef BTitledColumn Inherited;
|
typedef BTitledColumn Inherited;
|
||||||
@@ -176,28 +178,30 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - BBitmapStringField
|
// #pragma mark - SharedBitmapStringField
|
||||||
|
|
||||||
|
|
||||||
// TODO: Code-duplication with DriveSetup PartitionList.cpp
|
SharedBitmapStringField::SharedBitmapStringField(SharedBitmap* bitmap,
|
||||||
BBitmapStringField::BBitmapStringField(const BBitmap* bitmap,
|
SharedBitmap::Size size, const char* string)
|
||||||
const char* string)
|
|
||||||
:
|
:
|
||||||
Inherited(string),
|
Inherited(string),
|
||||||
fBitmap(bitmap)
|
fBitmap(NULL)
|
||||||
{
|
{
|
||||||
|
SetBitmap(bitmap, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BBitmapStringField::~BBitmapStringField()
|
SharedBitmapStringField::~SharedBitmapStringField()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BBitmapStringField::SetBitmap(const BBitmap* bitmap)
|
SharedBitmapStringField::SetBitmap(SharedBitmap* bitmap,
|
||||||
|
SharedBitmap::Size size)
|
||||||
{
|
{
|
||||||
fBitmap = bitmap;
|
fReference = bitmap;
|
||||||
|
fBitmap = bitmap != NULL ? bitmap->Bitmap(size) : NULL;
|
||||||
// TODO: cause a redraw?
|
// TODO: cause a redraw?
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -255,8 +259,8 @@ PackageColumn::PackageColumn(const char* title, float width, float minWidth,
|
|||||||
void
|
void
|
||||||
PackageColumn::DrawField(BField* field, BRect rect, BView* parent)
|
PackageColumn::DrawField(BField* field, BRect rect, BView* parent)
|
||||||
{
|
{
|
||||||
BBitmapStringField* bitmapField
|
SharedBitmapStringField* bitmapField
|
||||||
= dynamic_cast<BBitmapStringField*>(field);
|
= dynamic_cast<SharedBitmapStringField*>(field);
|
||||||
BStringField* stringField = dynamic_cast<BStringField*>(field);
|
BStringField* stringField = dynamic_cast<BStringField*>(field);
|
||||||
RatingField* ratingField = dynamic_cast<RatingField*>(field);
|
RatingField* ratingField = dynamic_cast<RatingField*>(field);
|
||||||
|
|
||||||
@@ -404,8 +408,8 @@ PackageColumn::CompareFields(BField* field1, BField* field2)
|
|||||||
float
|
float
|
||||||
PackageColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
PackageColumn::GetPreferredWidth(BField *_field, BView* parent) const
|
||||||
{
|
{
|
||||||
BBitmapStringField* bitmapField
|
SharedBitmapStringField* bitmapField
|
||||||
= dynamic_cast<BBitmapStringField*>(_field);
|
= dynamic_cast<SharedBitmapStringField*>(_field);
|
||||||
BStringField* stringField = dynamic_cast<BStringField*>(_field);
|
BStringField* stringField = dynamic_cast<BStringField*>(_field);
|
||||||
|
|
||||||
float parentWidth = Inherited::GetPreferredWidth(_field, parent);
|
float parentWidth = Inherited::GetPreferredWidth(_field, parent);
|
||||||
@@ -503,10 +507,8 @@ PackageRow::UpdateTitle()
|
|||||||
if (fPackage.Get() == NULL)
|
if (fPackage.Get() == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const BBitmap* icon = NULL;
|
SetField(new SharedBitmapStringField(fPackage->Icon(),
|
||||||
if (fPackage->Icon().Get() != NULL)
|
SharedBitmap::SIZE_16, fPackage->Title()), kTitleColumn);
|
||||||
icon = fPackage->Icon()->Bitmap(SharedBitmap::SIZE_16);
|
|
||||||
SetField(new BBitmapStringField(icon, fPackage->Title()), kTitleColumn);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user