BStatusBar

Constructor and Destructor

BStatusBar()

BStatusBar::BStatusBar(BRect frame, const char *name, const char *label = NULL, const char *trailingLabel = NULL)
BStatusBar::BStatusBar(BMessage *archive)

Initializes the BStatusBar with a label and a trailingLabel, which can both be NULL. The frame rectangle is used for its origin and width only; when the BStatusBar is attached to a window, it will be resized to a height that precisely accommodates its parts. The name argument is passed on to the BView constructor.

The object is given a B_WILL_DRAW flag and a resizing mode that keeps it glued to the left and top sides of its parent.

The default font of the BStatusBar is the system plain font, and the default color of the bar is blue (50, 150, 255). It’s initial value is 0.0, the minimum, and its default maximum value is 100.0.

See also: SetMaxValue(), SetBarColor()

~BStatusBar()

virtual BStatusBar::~BStatusBar()

Frees the labels and the text.

Hook Functions

AttachedToWindow()

virtual void BStatusBar::AttachedToWindow()

Resizes the frame rectangle to accommodate the object’s graphical parts. The width isn’t altered.

This function also sets the view and low colors of the BStatusBar to match the background view color of its new parent.

Draw()

virtual void BStatusBar::Draw(BRect updateRect)

Draws the bar, labels, and text.

MessageReceived()

virtual void BStatusBar::MessageReceived(BMessage *message)

Responds to B_UPDATE_STATUS_BAR and B_RESET_STATUS_BAR messages by calling the Update() and Reset() functions. Each message contains data that can be passed as arguments to the functions.

See also: BView::MessageReceived(), “BStatusBar Messages” in the Message Protocols appendix

Member Functions

Archive()

virtual status_t BStatusBar::Archive(BMessage *archive, bool deep = true) const

Calls the inherited version of Archive(), then adds the bar color, bar height, current value, and maximum value to the BMessage archive, along with the current text, trailing text, label, and trailing label.

Label(), TrailingLabel()

const char *BStatusBar::Label() const
const char *BStatusBar::TrailingLabel() const

These functions return pointers to the object’s label and trailing label. The returned strings belong to the BStatusBar object and should not be altered. They can be set only on construction or when all values are reset.

See also: Reset()

Reset()

virtual void BStatusBar::Reset(const char *label = NULL, const char *trailingLabel = NULL)

Empties the status bar, sets its current value to 0.0 and its maximum value to 100.0, deletes and erases the text and trailing text, and replaces the label and trailing label with copies of the strings passed as arguments. If either argument is NULL, the label or trailing label will also be deleted and erased.

This gets the BStatusBar ready to be reused for another operation. For example, if several large files are being downloaded, the BStatusBar could be reset for each one.

See also: SetText(), Update(), the B_RESET_STATUS_BAR message constant.

SetBarColor(), BarColor()

virtual void BStatusBar::SetBarColor(rgb_color color)
rgb_color BStatusBar::BarColor() const

These functions set and return the color that fills the bar to show how much of an operation has been completed. The default bar color is blue (50, 150, 255).

SetBarHeight(), BarHeight()

virtual void BStatusBar::SetBarHeight(float height)
float BStatusBar::BarHeight() const

These functions set and return the height of the bar itself, minus the text and labels. The default height is 16.0 coordinate units. The frame rectangle is adjusted to accommodate the new height, and the object is redrawn.

SetMaxValue(), MaxValue(), CurrentValue()

virtual void BStatusBar::SetMaxValue(float max)
float BStatusBar::MaxValue() const
float BStatusBar::CurrentValue() const

SetMaxValue() sets the maximum value of the BStatusBar, which by default is 100.0. MaxValue() returns the current maximum. The minimum value is 0.0 and cannot be changed.

CurrentValue() returns the current value of the BStatusBar. The current value is set by Update() and reset to 0.0 by Reset().

The amount of “filling” in the status bar reflects the ratio CurrentValue()/MaxValue().

SetText(), SetTrailingText(), Text(), TrailingText()

virtual void BStatusBar::SetText(const char *string)
virtual void BStatusBar::SetTrailingText(const char *string)
const char *BStatusBar::Text() const
const char *BStatusBar::TrailingText() const

These SetText() and SetTrailingText() functions erase the previous text or trailing text and replace them with copies of the string argument. string can be NULL. The view is automatically redrawn.

Text() and TrailingText() return pointers to the current text strings.

Update()

virtual void BStatusBar::Update(float delta, const char *text = NULL, const char *trailingText = NULL)

Update() updates the BStatusBar by adding delta to its current value and resetting its text and trailing text. Passing NULL for the text or trailingText argument retains the existing string(s). The status bar is automatically redrawn.

See also: Reset(), the B_UPDATE_STATUS_BAR message constant.

Static Functions

Instantiate()

static BArchivable *BStatusBar::Instantiate(BMessage *archive)

Returns a new BStatusBar object, allocated by new and created with the version of the constructor that takes a BMessage archive. However, if the archive doesn’t contain data for an BStatusBar object, this function returns NULL.

See also BArchivable::Instantiate(), instantiate_object(), Archive()

Archived Fields

The Archive() function adds the following fields to its BMessage argument:

Field

Type code

Description

_high

B_FLOAT_TYPE

Status bar height.

_bcolor

B_INT32_TYPE

Status bar color.

_val

B_FLOAT_TYPE

Current value.

_max

B_FLOAT_TYPE

Maximum value.

_text

B_STRING_TYPE

Status bar text.

_ttext

B_STRING_TYPE

Trailing text.

_label

B_STRING_TYPE

Status bar label.

_tlabel

B_STRING_TYPE

Trailing text label.

Some of these fields may not be present if the setting they represent isn’t used, or is the default value. For example, if there is no trailing text, the _ttext field won’t be found in the archive.