| Class Overview |
BMenuField(BRect frame,
const char* name,
const char* label,
BMenu* menu,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BMenuField(BRect frame,
const char* name,
const char* label,
BMenu* menu,
bool fixedSize,
uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
BMenuField(BMessage* archive);
Initializes the BMenuField object with the specified
frame rectangle, name,
resizingMode, and flags. These
arguments are the same as for any
BView object and are
passed unchanged to the BView
constructor. When the object is attached to a window, the height of its frame
rectangle will be adjusted to fit the height of the text it displays, which
depends on the user's preferred font for menus.
By default, the frame rectangle is divided horizontally in half, with the
label displayed on the left and the menu on the right. This division can
be changed with the
SetDivider()
function. The menu is assigned to a
BMenuBar object and
will pop up under the user's control. For most uses,
the menu should be a BPopUpMenu object.
The second form of the constructor accepts an added argument, fixedSize.
If this is true, the BMenuField won't adjust its size based on the width
of the items in the menu.
virtual ~BMenuField();
Frees the label, the BMenuBar
object, and other memory allocated by the BMenuField.
virtual void AttachedToWindow();virtual void AllAttached();
These functions override their BView
counterparts to make the
BMenuField's background color match the color of its parent view and to
adjust the height of the view to the height of the
BMenuBar child it
contains. The height of the child depends on the size of the user's
preferred font for menus.
See also:
BView::AttachedToWindow()
virtual void Draw(BRect updateRect);
Overrides the BView
version of this function to draw the view's border
and label. The way the menu field is drawn depends on whether it's
enabled or disabled and whether or not it's the current focus for
keyboard actions.
See also:
BView::Draw()
virtual void KeyDown(const char* bytes,
int32 numBytes);
Augments the BView
version of KeyDown()
to permit keyboard navigation to
and from the view and to allow users to open the menu by pressing the
space bar.
virtual void MouseDown(BPoint point);
Overrides the BView
version of MouseDown() to enable users to pop up the
menu using the mouse, even if the cursor isn't directly over the menu
portion of the bounds rectangle.
virtual void WindowActivated(bool active);
Makes sure that the BMenuField is redrawn when the window is activated
and deactivated, provided that it's the current focus view.
See also:
BView::WindowActivated()
virtual status_t Archive(BMessage* archive,
bool deep = true) const;
Calls the inherited version of Archive(), which will, in the normal
course of things, archive the child
BMenuBar and the
BMenu it displays,
provided the deep flag is true. This function then adds the label,
divider, and current state of the BMenuField to the
BMessage archive.
See also:
BArchivable::Archive(),
Instantiate() static function
virtual void MakeFocus(bool focused);
Augments the BView
version of MakeFocus()
to enable keyboard navigation.
This function calls Draw()
when the BMenuField becomes the focus view and
when it loses that status.
BMenu* Menu() const;BMenuBar* MenuBar() const;BMenuItem* MenuItem() const;
Menu() returns the
BMenu
object that pops up when the user operates the
BMenuField;
MenuBar() returns the
BMenuBar object that contains the menu.
The BMenuBar
is created by the BMenuField; the menu is assigned to it
during construction. MenuItem() returns the first
BMenuItem assigned to
the BMenuBar object containing the menu.
See also:
The BMenuField constructor
virtual void SetAlignment(alignment label);alignment Alignment() const;These functions set and return the alignment of the label in its portion of the frame rectangle.
| Constant | Description |
|---|---|
| The label is aligned at the left side of the bounds rectangle. |
| The label is aligned at the right boundary of its portion of the bounds rectangle. |
| The label is centered in its portion of the bounds rectangle. |
The default is B_ALIGN_LEFT.
virtual void SetDivider(float xCoordinate);float Divider() const;
These functions set and return the x coordinate value that divides the
bounds rectangle between the label's portion on the left and the portion
that holds the menu on the right. The coordinate is expressed in the
BMenuField's coordinate system.
The default divider splits the bounds rectangle in two equal sections. By resetting it, you can provide more or less room for the label or the menu.
virtual void SetEnabled(bool enabled);bool IsEnabled() const;
SetEnabled() enables the
BMenuField if the enabled flag is true, and
disables it if the flag is false. IsEnabled() returns whether or not the
object is currently enabled. When disabled, the BMenuField doesn't
respond to mouse and keyboard manipulations.
If the enabled flag changes the current state of the object,
SetEnabled()
causes the view to be redrawn, so that its new state can be displayed to
the user.
virtual void SetLabel(const char* string);const char* Label() const;
SetLabel() frees the current label and, if the argument it's passed is
not NULL, replaces it with a copy of string. Label() returns the current
label. The string it returns belongs to the BMenuField object.
See also:
The BMenuField constructor
static BArchivable* Instantiate(BMessage* archive);
Returns a new BMenuField 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 BMenuField object, this
function returns NULL.
See also:
BArchivable::Instantiate(),
instantiate_object(),
Archive()
The BMenu class implements the suite called "suite/vnd.Be-menu"
consisting of the following messages:
| Field | Type code | Description |
|---|---|---|
_label | B_STRING_TYPE | BMenuField label. |
_disable | B_BOOL_TYPE | Exists and true only if menu is disabled. |
_align | B_INT32_TYPE | Alignment of label in the frame rectangle. |
_divide | B_FLOAT_TYPE | The x-coordinate dividing the bounds rectangle between the label and the menu. |
The following views are added to the _views field (deep copy only):
| Name | Level | Description |
|---|---|---|
_mc_mb_ | 0 | Private menu bar. |