BStringView

Derived from: public BView

Declared in: be/interface/StringView.h

Library: libbe.so


Overview

[method summary]

A BStringView object draws a static character string. The user can't select the string or edit it; a BStringView doesn't respond to user actions. An instance of this class can be used to draw a label or other text that simply delivers a message of some kind to the user. Use a BTextView object for selectable and editable text.

You can also draw strings by calling BView's DrawString() function. However, assigning a string to a BStringView object locates it in the view hierarchy. The string will be updated automatically, just like other views. And, by setting the resizing mode of the object, you can make sure that it will be positioned properly when the window or the view it's in (the parent of the BStringView) is resized.


Constructor and Destructor


BStringView()

      BStringView(BRect frame, const char *name, const char *text, 
         uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, 
         uint32 flags = B_WILL_DRAW) 
      BStringView(BMessage *archive) 

Initializes the BStringView by assigning it a text string and the system plain font (be_plain_font). The frame, name, resizingMode, and flags arguments are the same as those declared for the BView class. They're passed unchanged to the BView constructor.

The frame rectangle needs to be large enough to display the entire string in the current font. The string is drawn at the bottom of the frame rectangle and, by default, is aligned to the left side. A different horizontal alignment can be set by calling SetAlignment().

See also: SetAlignment()


~BStringView()

      virtual ~BStringView()

Frees the text string.


Static Functions


Instantiate()

      static BArchivable *Instantiate(BMessage *archive) 

Returns a new BStringView object, allocated by new and created with the version of the constructor that takes a BMessage archive. However, if the archive message doesn't contain data for a BStringView, Instantiate() returns NULL.

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


Member Functions


Alignment() see SetAlignment()


Archive()

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

Calls the inherited version of Archive(), then adds the string and its alignment to the BMessage archive.

See also: BArchivable::Archive(), Instantiate() static function


AttachedToWindow()

      virtual void AttachedToWindow(void)

Sets the BStringView's low color and its background view color to match the background color of its new parent view.

See also: BView::AttachedToWindow()


Draw()

      virtual void Draw(BRect updateRect)

Draws the string along the bottom of the BStringView's frame rectangle in the current high color.


SetAlignment(), Alignment()

      void SetAlignment(alignment flag)
      alignment Alignment(void) const

These functions align the string within the BStringView's frame rectangle and return the current alignment. The alignment flag can be:

B_ALIGN_LEFT The string is aligned at the left side of the frame rectangle.
B_ALIGN_RIGHT The string is aligned at the right side of the frame rectangle.
B_ALIGN_CENTER The string is aligned so that the center of the string falls midway between the left and right sides of the frame rectangle.

The default is B_ALIGN_LEFT.


SetText(), Text()

      void SetText(const char *string)
      const char *Text(void) const

These functions set and return the text string that the BStringView draws. SetText() frees the previous string and copies string to replace it. Text() returns the null-terminated string.


Archived Fields

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

Field Type code Meaning
"_text" B_STRING_TYPE Text displayed in the view (present only if it is not NULL).
"_align" B_INT32_TYPE Alignment of text in frame.






The Be Book, in lovely HTML, for BeOS Release 4.

Copyright © 1998 Be, Inc. All rights reserved.

Last modified January 29, 1998.