fix crashes when the text pointer is NULL, this lets you for example pick a background image with the Backrounds preflet, though it doesn't work further down
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15076 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -49,7 +49,7 @@ BStringView::BStringView(BRect frame, const char* name, const char* text,
|
|||||||
uint32 resizeMask, uint32 flags)
|
uint32 resizeMask, uint32 flags)
|
||||||
: BView(frame, name, resizeMask, flags)
|
: BView(frame, name, resizeMask, flags)
|
||||||
{
|
{
|
||||||
fText = strdup(text);
|
fText = text ? strdup(text) : NULL;
|
||||||
fAlign = B_ALIGN_LEFT;
|
fAlign = B_ALIGN_LEFT;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -99,7 +99,7 @@ BStringView::~BStringView()
|
|||||||
void BStringView::SetText(const char* text)
|
void BStringView::SetText(const char* text)
|
||||||
{
|
{
|
||||||
free(fText);
|
free(fText);
|
||||||
fText = strdup(text);
|
fText = text ? strdup(text) : NULL;
|
||||||
Invalidate();
|
Invalidate();
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -128,6 +128,9 @@ void BStringView::AttachedToWindow()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BStringView::Draw(BRect bounds)
|
void BStringView::Draw(BRect bounds)
|
||||||
{
|
{
|
||||||
|
if (!fText)
|
||||||
|
return;
|
||||||
|
|
||||||
SetLowColor(ViewColor());
|
SetLowColor(ViewColor());
|
||||||
BFont font;
|
BFont font;
|
||||||
GetFont(&font);
|
GetFont(&font);
|
||||||
@@ -136,14 +139,13 @@ void BStringView::Draw(BRect bounds)
|
|||||||
|
|
||||||
float y = Bounds().bottom - ceil(fh.descent);
|
float y = Bounds().bottom - ceil(fh.descent);
|
||||||
float x;
|
float x;
|
||||||
switch (fAlign)
|
switch (fAlign) {
|
||||||
{
|
|
||||||
case B_ALIGN_RIGHT:
|
case B_ALIGN_RIGHT:
|
||||||
x = Bounds().Width() - font.StringWidth(fText) - 2.0f;
|
x = Bounds().Width() - font.StringWidth(fText) - 2.0f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_ALIGN_CENTER:
|
case B_ALIGN_CENTER:
|
||||||
x = (Bounds().Width() - font.StringWidth(fText))/2.0f;
|
x = (Bounds().Width() - font.StringWidth(fText)) / 2.0f;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -151,7 +153,7 @@ void BStringView::Draw(BRect bounds)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawString( fText, BPoint(x,y) );
|
DrawString(fText, BPoint(x,y));
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BStringView::ResizeToPreferred()
|
void BStringView::ResizeToPreferred()
|
||||||
@@ -163,6 +165,9 @@ void BStringView::ResizeToPreferred()
|
|||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void BStringView::GetPreferredSize(float* width, float* height)
|
void BStringView::GetPreferredSize(float* width, float* height)
|
||||||
{
|
{
|
||||||
|
if (!fText)
|
||||||
|
return BView::GetPreferredSize(width, height);
|
||||||
|
|
||||||
BFont font;
|
BFont font;
|
||||||
GetFont(&font);
|
GetFont(&font);
|
||||||
font_height fh;
|
font_height fh;
|
||||||
|
|||||||
Reference in New Issue
Block a user