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:
Rene Gollent 2013-05-04 21:17:47 -04:00
parent 9187efd1a9
commit 69d85497fd
2 changed files with 22 additions and 9 deletions

View File

@ -60,10 +60,11 @@ class BStringField : public BField
void SetString (const char* string);
const char* String () const;
void SetClippedString (const char* string);
bool HasClippedString () const;
const char* ClippedString ();
void SetWidth (float);
float Width ();
private:
float fWidth;
BString fString;
@ -109,7 +110,7 @@ class BDateField : public BField
time_t Seconds ();
time_t UnixTime ();
private:
private:
struct tm fTime;
time_t fUnixTime;
time_t fSeconds;
@ -235,7 +236,7 @@ class BBitmapColumn : public BTitledColumn
virtual int CompareFields (BField* field1, BField* field2);
virtual bool AcceptsField (const BField* field) const;
};
//=====================================================================
// Column to display BIntegerField objects as a graph.

View File

@ -159,6 +159,13 @@ BStringField::SetClippedString(const char* val)
}
bool
BStringField::HasClippedString() const
{
return !fClippedString.IsEmpty();
}
const char*
BStringField::ClippedString()
{
@ -182,17 +189,22 @@ BStringColumn::DrawField(BField* _field, BRect rect, BView* parent)
{
float width = rect.Width() - (2 * kTEXT_MARGIN);
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());
parent->TruncateString(&out_string, fTruncate, width + 2);
field->SetClippedString(out_string.String());
float preferredWidth = parent->StringWidth(out_string.String());
if (width < preferredWidth) {
parent->TruncateString(&out_string, fTruncate, width + 2);
field->SetClippedString(out_string.String());
} else
field->SetClippedString("");
field->SetWidth(width);
}
DrawString(clipNeeded ? field->ClippedString() : field->String(), parent, rect);
DrawString(field->HasClippedString() ? field->ClippedString()
: field->String(), parent, rect);
}