Fix update issues in BStringColumn.
In some cases, BStringColumn wouldn't properly detect that an update was needed, and would consequently fail to truncate a string as needed with a column resize.
This commit is contained in:
@@ -60,6 +60,7 @@ class BStringField : public BField
|
|||||||
void SetString (const char* string);
|
void SetString (const char* string);
|
||||||
const char* String () const;
|
const char* String () const;
|
||||||
void SetClippedString (const char* string);
|
void SetClippedString (const char* string);
|
||||||
|
bool HasClippedString () const;
|
||||||
const char* ClippedString ();
|
const char* ClippedString ();
|
||||||
void SetWidth (float);
|
void SetWidth (float);
|
||||||
float Width ();
|
float Width ();
|
||||||
|
|||||||
@@ -159,6 +159,13 @@ BStringField::SetClippedString(const char* val)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
BStringField::HasClippedString() const
|
||||||
|
{
|
||||||
|
return !fClippedString.IsEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
BStringField::ClippedString()
|
BStringField::ClippedString()
|
||||||
{
|
{
|
||||||
@@ -182,17 +189,22 @@ BStringColumn::DrawField(BField* _field, BRect rect, BView* parent)
|
|||||||
{
|
{
|
||||||
float width = rect.Width() - (2 * kTEXT_MARGIN);
|
float width = rect.Width() - (2 * kTEXT_MARGIN);
|
||||||
BStringField* field = static_cast<BStringField*>(_field);
|
BStringField* field = static_cast<BStringField*>(_field);
|
||||||
bool clipNeeded = width < field->Width();
|
float fieldWidth = field->Width();
|
||||||
|
bool updateNeeded = width != fieldWidth;
|
||||||
|
|
||||||
if (clipNeeded) {
|
if (updateNeeded) {
|
||||||
BString out_string(field->String());
|
BString out_string(field->String());
|
||||||
|
float preferredWidth = parent->StringWidth(out_string.String());
|
||||||
parent->TruncateString(&out_string, fTruncate, width + 2);
|
if (width < preferredWidth) {
|
||||||
field->SetClippedString(out_string.String());
|
parent->TruncateString(&out_string, fTruncate, width + 2);
|
||||||
|
field->SetClippedString(out_string.String());
|
||||||
|
} else
|
||||||
|
field->SetClippedString("");
|
||||||
field->SetWidth(width);
|
field->SetWidth(width);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawString(clipNeeded ? field->ClippedString() : field->String(), parent, rect);
|
DrawString(field->HasClippedString() ? field->ClippedString()
|
||||||
|
: field->String(), parent, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user