Ejemplo n.º 1
0
void
BStatusBar::_SetTextData(BString& text, const char* source,
                         const BString& combineWith, bool rightAligned)
{
    if (source == NULL)
        source = "";

    // If there were no changes, we don't have to do anything
    if (text == source)
        return;

    bool oldHasText = _HasText();
    text = source;

    BString newString;
    if (rightAligned)
        newString << text << combineWith;
    else
        newString << combineWith << text;

    if (oldHasText != _HasText())
        InvalidateLayout();

    font_height fontHeight;
    GetFontHeight(&fontHeight);

//	Invalidate(BRect(position, 0, position + invalidateWidth,
//		ceilf(fontHeight.ascent) + ceilf(fontHeight.descent)));
// TODO: redrawing the entire area takes care of the edge case
// where the left side string changes because of truncation and
// part of it needs to be redrawn as well.
    Invalidate(BRect(0, 0, Bounds().right,
                     ceilf(fontHeight.ascent) + ceilf(fontHeight.descent)));
}
Ejemplo n.º 2
0
void
BStatusBar::_SetTextData(BString& text, const char* source,
	const BString& combineWith, bool rightAligned)
{
	if (source == NULL)
		source = "";

	// If there were no changes, we don't have to do anything
	if (text == source)
		return;

	float oldWidth;
	if (rightAligned)
		oldWidth = Bounds().right - fTextDivider;
	else
		oldWidth = fTextDivider;

	bool oldHasText = _HasText();

	text = source;

	BString newString;
	if (rightAligned)
		newString << text << combineWith;
	else
		newString << combineWith << text;

	float newWidth = ceilf(StringWidth(newString.String()));
		// might still be smaller in Draw(), but we use it
		// only for the invalidation rect here

	// determine which part of the view needs an update
	float invalidateWidth = max_c(newWidth, oldWidth);

	float position = 0.0;
	if (rightAligned)
		position = Bounds().right - invalidateWidth;

	if (oldHasText != _HasText())
		InvalidateLayout();

	font_height fontHeight;
	GetFontHeight(&fontHeight);

//	Invalidate(BRect(position, 0, position + invalidateWidth,
//		ceilf(fontHeight.ascent) + ceilf(fontHeight.descent)));
// TODO: redrawing the entire area takes care of the edge case
// where the left side string changes because of truncation and
// part of it needs to be redrawn as well.
	Invalidate(BRect(0, 0, Bounds().right,
		ceilf(fontHeight.ascent) + ceilf(fontHeight.descent)));
}
Ejemplo n.º 3
0
/*!
	Returns the inner bar frame without the surrounding bevel.
*/
BRect
BStatusBar::_BarFrame(const font_height* fontHeight) const
{
    float top = 2;
    if (_HasText()) {
        if (fontHeight == NULL) {
            font_height height;
            GetFontHeight(&height);
            top = ceilf(height.ascent + height.descent) + 6;
        } else
            top = ceilf(fontHeight->ascent + fontHeight->descent) + 6;
    }

    return BRect(2, top, Bounds().right - 2, top + BarHeight() - 4);
}
Ejemplo n.º 4
0
void
BStatusBar::GetPreferredSize(float* _width, float* _height)
{
    if (_width) {
        // AttachedToWindow() might not have been called yet
        *_width = ceilf(StringWidth(fLabel.String()))
                  + ceilf(StringWidth(fTrailingLabel.String()))
                  + ceilf(StringWidth(fText.String()))
                  + ceilf(StringWidth(fTrailingText.String()))
                  + 5;
    }

    if (_height) {
        float labelHeight = 0;
        if (_HasText()) {
            font_height fontHeight;
            GetFontHeight(&fontHeight);
            labelHeight = ceilf(fontHeight.ascent + fontHeight.descent) + 6;
        }

        *_height = labelHeight + BarHeight();
    }
}