Display item for the BMenu class. More...
Inherits BArchivable, and BInvoker.
Inherited by BSeparatorItem.
Public Member Functions | |
BMenuItem (BMenu *menu, BMessage *message=NULL) | |
Creates a new BMenuItem object with the specified menu and message. | |
BMenuItem (BMessage *data) | |
Archive constructor. | |
BMenuItem (const char *label, BMessage *message, char shortcut=0, uint32 modifiers=0) | |
Creates a new BMenuItem object with the specified label and message. | |
virtual | ~BMenuItem () |
Destructor. | |
BRect | Frame () const |
Returns the bounds rectangle of the menu item. | |
bool | IsEnabled () const |
Returns whether or not the item is enabled. | |
bool | IsMarked () const |
Returns whether or not the item is marked. | |
const char * | Label () const |
Returns the item's label. | |
BMenu * | Menu () const |
Returns a pointer to the menu that the item is attached to. | |
virtual void | SetEnabled (bool enable) |
Enables or disables the menu item. | |
virtual void | SetLabel (const char *name) |
Sets the menu item label to string. | |
virtual void | SetMarked (bool mark) |
Marks or unmarks the menu item. | |
virtual void | SetShortcut (char shortcut, uint32 modifiers) |
Set the keyboard shortcut of the menu item. | |
virtual void | SetTrigger (char trigger) |
Set the character that activates this menu item. The triggered character is drawn underlined in the menu. | |
char | Shortcut (uint32 *_modifiers=NULL) const |
Returns the currently set shortcut and fills out modifiers with a bitmap of the modifier keys required to invoke the item. | |
BMenu * | Submenu () const |
Returns a pointer to the attached menu. | |
char | Trigger () const |
Returns the item's trigger character. | |
Public Member Functions inherited from BArchivable | |
BArchivable () | |
Constructor. Does nothing. | |
BArchivable (BMessage *from) | |
Constructor. Does important behind-the-scenes work in the unarchiving process. | |
virtual | ~BArchivable () |
Destructor. Does nothing. | |
virtual status_t | AllArchived (BMessage *archive) const |
Method relating to the use of BArchiver . | |
virtual status_t | AllUnarchived (const BMessage *archive) |
Method relating to the use of BUnarchiver . | |
virtual status_t | Archive (BMessage *into, bool deep=true) const |
Archive the object into a BMessage. | |
virtual status_t | Perform (perform_code d, void *arg) |
Perform some action (Internal method defined for binary compatibility purposes). | |
Public Member Functions inherited from BInvoker | |
BInvoker () | |
Initializes a BInvoker without a message or target. | |
BInvoker (BMessage *message, BMessenger target) | |
Initializes the BInvoker with message and sets the target messenger where the message is sent when Invoke() is called. | |
BInvoker (BMessage *message, const BHandler *handler, const BLooper *looper=NULL) | |
Initializes the BInvoker with message and sets the target to either a local handler or as the preferred handler of a local looper where the message is sent when Invoke() is called. | |
virtual | ~BInvoker () |
Destructor method, deletes the BMessage object if set. | |
uint32 | Command () const |
Returns the message's what data member. | |
BHandler * | HandlerForReply () const |
Returns the previously set reply handler or NULL if not set. | |
virtual status_t | Invoke (BMessage *message=NULL) |
Sends the message to the invoker's target. | |
status_t | InvokeNotify (BMessage *message, uint32 kind=B_CONTROL_INVOKED) |
Sends the message to its target, using the notification code specified by kind. | |
bool | IsTargetLocal () const |
Returns whether or not the invoker and its target belong to the same team. | |
BMessage * | Message () const |
Returns a pointer to the invoker's message object. | |
BMessenger | Messenger () const |
Returns the BMessenger object that the invoker uses to send its messages. | |
virtual status_t | SetHandlerForReply (BHandler *handler) |
Sets the BHandler object responsible for handling reply messages. | |
virtual status_t | SetMessage (BMessage *message) |
Assigns message to the invoker, deleting any previously assigned message. | |
virtual status_t | SetTarget (BMessenger messenger) |
Sets the invoker's target to messenger. | |
virtual status_t | SetTarget (const BHandler *handler, const BLooper *looper=NULL) |
Sets the target to either a local handler or as the preferred handler of a local looper. | |
status_t | SetTimeout (bigtime_t timeout) |
Sets the timeout to use when sending the message to the target. | |
BHandler * | Target (BLooper **_looper=NULL) const |
Invoke BMessenger::Target() on the internal messenger. | |
bigtime_t | Timeout () const |
Returns the current timeout value. | |
Protected Member Functions | |
BPoint | ContentLocation () const |
Returns the top-left point of the content rectangle. | |
virtual void | Draw () |
Hook method used to draw the menu items. | |
virtual void | DrawContent () |
Hook method used to draw the menu items contents. | |
virtual void | GetContentSize (float *_width, float *_height) |
Fills out _width and _height with the content rectangle dimensions. | |
virtual void | Highlight (bool highlight) |
Highlights or unhighlights the menu item. | |
virtual status_t | Invoke (BMessage *message=NULL) |
Sends a copy of the model message to the target. | |
bool | IsSelected () const |
Returns whether or not the item is selected. | |
virtual void | TruncateLabel (float maxWidth, char *newLabel) |
Truncates the label and stashes it into newLabel. | |
Protected Member Functions inherited from BInvoker | |
void | BeginInvokeNotify (uint32 kind=B_CONTROL_INVOKED) |
Implement this method to set up an InvokeNotify() context. | |
void | EndInvokeNotify () |
Implement this method to tear down an InvokeNotify() context. | |
uint32 | InvokeKind (bool *_notify=NULL) |
Returns the kind set by InvokeNotify(). | |
Archiving | |
virtual status_t | Archive (BMessage *archive, bool deep=true) const |
Archives the the BMenuItem object into the data message. | |
static BArchivable * | Instantiate (BMessage *archive) |
Creates a new BMenuItem object from an data message. | |
Additional Inherited Members | |
Static Public Member Functions inherited from BArchivable | |
static BArchivable * | Instantiate (BMessage *archive) |
Static member to restore objects from messages. | |
Display item for the BMenu class.
A BMenuItem either consists of a label or a submenu and message that is sent to the attached menu's target when the item is selected. BMenu and BMenuItem work in concert with each other in order to create a menu tree hierarchy. BMenuItem's serve as nodes in the tree while BMenu's serve as branches.
A menu item, unless it represents a submenu, can have a keyboard shortcut which is a printable character used in combination with the Command key and possibly other modifiers to invoke the item. The shortcut is displayed right of the item's label.
A menu item may also have a trigger character assigned to it that invokes the item without using the Command key. The trigger characters is drawn underlined in the menu item's label. Unlike shortcuts, triggers are automatically assigned to a menu item. You can set the trigger character explicitly by calling SetTrigger().
Both the shortcut character and trigger character are case-insensitive.
A menu item may be marked, which draws a checkmark on the left side of the item. only one menu items may be marked at a time if attached to a menu in radio mode.
Menu items can also be enabled or disabled. A disabled item's label is drawn in a lighter color to indicate that it may not be used. A disabled menu item may not be selected or invoked. If the menu item controls a submenu the submenu may still be opened but each of the items will be disabled.
BMenuItem::BMenuItem | ( | const char * | label, |
BMessage * | message, | ||
char | shortcut = 0 , |
||
uint32 | modifiers = 0 |
||
) |
Creates a new BMenuItem object with the specified label and message.
label | The text label that is displayed. |
message | The BMessage that is sent when the item is selected. |
shortcut | The shortcut characters to activate the menu item. |
modifiers | The modifier keys to active the menu item, B_COMMAND_KEY is assumed. |
BMenuItem::BMenuItem | ( | BMessage * | data | ) |
Archive constructor.
data | The message data to construct the menu item from. |
|
virtual |
Destructor.
If this item is attached to a menu, it will be removed from it.
Also destroys the label and submenu.
Archives the the BMenuItem object into the data message.
Adds the label and current state of the BMenuItem to the archive.
data | A pointer to the BMessage to archive the object into. |
deep | Whether or not to archive attached menus as well. |
B_OK
if everything went well or an error code otherwise. B_OK | The object was archived successfully. |
B_NO_MEMORY | Ran out of memory while archiving the object. |
Reimplemented from BArchivable.
Reimplemented in BSeparatorItem.
|
protected |
Returns the top-left point of the content rectangle.
You only need to call this method if you're implementing your own DrawContent() method to override how the contents of the menu item are drawn.
The content rectangle can be calculated using this method as well as GetContentSize() to get the width and height.
|
protectedvirtual |
Hook method used to draw the menu items.
This method is called by automatically by BMenu::Draw(). You should not need to call this method yourself but you may want to override it in a derived class to do something other than the default. The default draws the mark, shortcut and possibly a right arrow to indicate there is submenu and then calls DrawContent() to fill in the label. Lastly Highlight() is called if the item is selected.
Reimplemented in BSeparatorItem.
|
protectedvirtual |
Hook method used to draw the menu items contents.
This method is called automatically by BMenu::Draw(), you need not call it yourself. You may want to override this method in derived classes to do something different than drawing a text label.
BRect BMenuItem::Frame | ( | ) | const |
Returns the bounds rectangle of the menu item.
|
protectedvirtual |
Fills out _width and _height with the content rectangle dimensions.
You only need to call this method if you're implementing your own DrawContent() method to override how the contents of the menu item are drawn.
The content rectangle excludes the item margins and the area that contains the checkmark, shortcut, and submenu arrow.
The content rectangle can be calculated using this method as well as ContentLocation() to get location of the top left corner.
_width | Filled out with the width of the content rectangle. |
_height | Filled out with the height of the content rectangle. |
Reimplemented in BSeparatorItem.
|
protectedvirtual |
Highlights or unhighlights the menu item.
This method is called by Draw() when the item is selected or unselected.
You shouldn't need to call this method unless you override the Draw() method in a derived class and you want to highlight differently.
highlight | Highlights if highlight is true , unhighlights if false . |
|
static |
Sends a copy of the model message to the target.
This method extends BInvoker::Invoke() to guarantee that only enabled items attached to the menu can be invoked and automatically marks the item.
The following fields added to the message:
B_INT64_TYPE
system_time()B_POINTER_TYPE
A pointer to the menu item object.B_INT32_TYPE
The index of the menu item.message | The message to send or NULL to send the message set in the constructor. |
B_OK
on success or an error code on error. B_OK | The message was sent successfully. |
B_BAD_VALUE | The message was NULL . |
Reimplemented from BInvoker.
bool BMenuItem::IsEnabled | ( | ) | const |
Returns whether or not the item is enabled.
true
if the item is enabled, false
if disabled.bool BMenuItem::IsMarked | ( | ) | const |
Returns whether or not the item is marked.
true
if the item is marked, false
if unmarked.
|
protected |
Returns whether or not the item is selected.
true
if selected, false
if not selected.const char * BMenuItem::Label | ( | ) | const |
Returns the item's label.
BMenu * BMenuItem::Menu | ( | ) | const |
Returns a pointer to the menu that the item is attached to.
|
virtual |
Enables or disables the menu item.
Enabling or disabling the menu item invalidates the attached menu.
enable | true to enable the menu item, false to disable it. |
Reimplemented in BSeparatorItem.
|
virtual |
Sets the menu item label to string.
The memory used by the label is copied so you may free the original. Setting the label invalidates the attached menu.
string | The string to set the label to. |
|
virtual |
Marks or unmarks the menu item.
Marking or unmarking the menu item invalidates the attached menu.
Marking a menu item attached to a menu in radio mode causes the currently marked item to be unmarked.
mark | true to mark the menu item, false to unmark it. |
|
virtual |
Set the keyboard shortcut of the menu item.
Setting a shortcut invalidates the attached menu.
This method will override the existing shortcut set to the window.
shortcut | The ASCII shortcut character to set. |
modifiers | A bitmap mask of modifier keys used to activate the shortcut. |
|
virtual |
Set the character that activates this menu item. The triggered character is drawn underlined in the menu.
trigger | The trigger character to set on this menu item. |
Returns the currently set shortcut and fills out modifiers with a bitmap of the modifier keys required to invoke the item.
modifiers | A pointer to a uint32 to fill out. |
BMenu * BMenuItem::Submenu | ( | ) | const |
Returns a pointer to the attached menu.
char BMenuItem::Trigger | ( | ) | const |
Returns the item's trigger character.
|
protectedvirtual |
Truncates the label and stashes it into newLabel.
You are responsible for allocating newLabel with enough space to fit the label including the trailing NUL
. The method will NUL
terminate the string for you.
maxWidth | The maximum number of bytes to truncate the label to. |
newLabel | The buffer to store the truncated label in. |