Documentation | InterfaceKit | Menu
SYNOPSIS
Perl
use HaikuR1::Menu qw(B_ITEMS_IN_ROW B_ITEMS_IN_COLUMN B_ITEMS_IN_MATRIX B_INITIAL_ADD B_PROCESSING B_ABORT); my $menu = HaikuR1::Menu->new($name); $menu->AddItem($item);
Python
from HaikuR1.InterfaceKit import Menu, B_ITEMS_IN_ROW, B_ITEMS_IN_COLUMN, B_ITEMS_IN_MATRIX, B_INITIAL_ADD, B_PROCESSING B_ABORT menu = Menu(name) menu.AddItem(item)
DESCRIPTION
Exposes the BMenu
object.
For more information on Menu, see the Be Book class description, the Be Book overview, and the Haiku Book class description.
METHODS
Constructor
Creates a Menu.
Perl
HaikuR1::Menu->new($name, $layout); HaikuR1::Menu->new($name, $width, $height); HaikuR1::Menu->new($archive);
Python
Menu(name, layout) Menu(name, width, height) Menu(archive)
name
A string, the Menu name. (If this Menu is a submenu of another Menu, the name will be used as the initial label of the controlling MenuItem.)
layout
Either
B_ITEMS_IN_ROW
orB_ITEMS_IN_COLUMN
; defaults toB_ITEMS_IN_COLUMN
. (However, MenuBar overrides this and defaults toB_ITEMS_IN_ROW
.)width
,height
Floating point numbers, the width and height of a matrix menu. (Note that you don't pass in the
B_ITEMS_IN_MATRIX
constant here; this version of the constructor supplies it automatically.)archive
A Message, contains an archived version of the Menu.
DrawItems
Draws the Menu's MenuItems. Meant to be called from within a hook.
Perl
$menu->DrawItems($updateRect);
Python
menu.DrawItems(updateRect)
updateRect
A Rect, the portion of the Menu's frame that needs to be updated. Only the items that fall within this rectangle will be drawn.
Enabled state
IsEnabled
SetEnabled
Gets or sets the Menu's enabled state. SetEnabled
can also be called as a
hook.
Perl
$menu->IsEnabled(); $menu->SetEnabled($enabled);
Python
menu.IsEnabled() menu.SetEnabled(enabled)
enabled
A boolean, the new enabled state.
FindMarked
FindMarkedIndex
Finds the first marked MenuItem or its index.
Perl
$menu->FindMarked(); $menu->FindMarkedIndex();
Python
menu.FindMarked() menu.FindMarkedIndex()
Items
AddItem
AddList
AddSeparatorItem
RemoveItem
RemoveItems
ItemAt
SubmenuAt
CountItems
IndexOf
FindItem
Manage the Menu's MenuItems.
Perl
$menu->AddItem($item, $index); $menu->AddItem($item, $frame); $menu->AddList($list, $index); $menu->AddSeparatorItem(); $menu->RemoveItem($item); $menu->RemoveItem($index); $menu->RemoveItems($index, $count); $menu->ItemAt($index); $menu->SubmenuAt($index); $menu->CountItems(); $menu->IndexOf($item); $menu->FindItem($label); $menu->FindItem($command);
Python
menu.AddItem(item, index) menu.AddItem(item, frame) menu.AddList(list, index) menu.AddSeparatorItem() menu.RemoveItem(item) menu.RemoveItem(index) menu.RemoveItems(index, count) menu.ItemAt(index) menu.SubmenuAt(index) menu.CountItems() menu.IndexOf(item) menu.FindItem(label) menu.FindItem(command)
item
A MenuItem or a Menu to be added to or removed from this Menu.
item
A native list of MenuItems or Menus to be added to this Menu.
index
An integer, the index at which to add, remove, or fetch the item in a standard menu. (You can omit this parameter for
AddItem
, in which case it will add the item to the end of the menu.)index
An integer, the number of items to remove.
frame
A Rect, the frame in which to locate the item in a matrix menu.
label
A string, the label of the menu item to find.
command
An integer, the command (Message.what value) of the menu item to find.
Item margins
GetItemMargins
SetItemMargins
Gets or sets the margins for the Menu's MenuItem. Meant to be called from within a hook.
Perl
$menu->GetItemMargins(); $menu->SetItemMargins($left, $top, $right, $bottom);
Python
menu.GetItemMargins() menu.SetItemMargins(left, top, right, bottom)
left
,top
,right
,bottom
Floating point numbers, the new margins.
Layout
Returns the menu layout constant representing the menu layout.
Perl
$menu->Layout();
Python
menu.Layout()
MaxContentWidth
SetMaxContentWidth
Gets or sets the maximum content width of the Menu. SetMaxContentWidth
can
also be called as a hook.
Perl
$menu->MaxContentWidth(); $menu->SetMaxContentWidth($width);
Python
menu.MaxContentWidth() menu.SetMaxContentWidth(width)
width
A floating point number, the new maximum width.
Radio mode
IsRadioMode
SetRadioMode
Gets or sets the radio mode state. SetRadioMode
can also be called as a
hook.
Perl
$menu->IsRadioMode(); $menu->SetRadioMode($on);
Python
menu.IsRadioMode() menu.SetRadioMode(on)
on
A boolean, the new radio state.
SetTrackingHook
Sets a tracking hook.
Perl
$menu->SetTrackingHook($hook, $state);
Python
menu.SetTrackingHook(hook, state)
hook
A function that will be called during tracking. Two parameters wll be passed: the Menu object and the state variable (see below).
Return true from this function to stop tracking; false to continue tracking. (Tracking may also stop for other reasons, such as the user selecting an item.)
state
Any variable, although it should be something you can update.
Perl
Any reference will do here.
Python
A tuple, list, or dict will work.
Stickiness
IsRedrawAfterSticky
This doesn't seem to have any effect at the current time.
Perl
$menu->IsRedrawAfterSticky();
Python
menu.IsRedrawAfterSticky()
Superitem
Returns the MenuItem that contains this Menu.
Perl
$menu->Superitem();
Python
menu.Superitem()
Superitem label
IsLabelFromMarked
SetLabelFromMarked
Gets or sets the automatic superitem label switching. If set to true, the superitem label will be set from the selected MenuItem. If set to false, the superitem label will not be automatically changed.
Note that setting this to true will also turn radio mode on, but setting it to false will not affect radio mode.
Perl
$menu->IsLabelFromMarked(); $menu->SetLabelFromMarked($state);
Python
menu.IsLabelFromMarked() menu.SetLabelFromMarked(state)
state
A boolean, the new automatic label state.
Supermenu
Returns the Menu that contains this Menu.
Perl
$menu->Supermenu();
Python
menu.Supermenu()
Track
Initiates menu tracking and returns the selected MenuItem (or the empty value if no item was selected). Meant to be called from within a hook.
Perl
$menu->Track($startOpened, $specialRect);
Python
menu.Track(startOpened, specialRect)
startOpened
A boolean; if true, the menu will be open even though no mouse button has been held down.
specialRect
A Rect; if provided, the stem will leave the menu open if the user releases the mouse button within the given rectangle.
Triggers
AreTriggersEnabled
SetTriggersEnabled
Gets or sets the triggers-enabled state. SetTriggersEnabled
can also be
called as a hook.
Perl
$menu->AreTriggersEnabled(); $menu->SetTriggersEnabled($enable);
Python
menu.AreTriggersEnabled() menu.SetTriggersEnabled(enable)
enable
A boolean, the new triggers-enabled state.
HOOKS
AddDynamicItem
Called at certain points to allow a subclass to add dynamic items. Return false to skip, abort, or terminate the process.
The default version always returns false.
Perl
$menu->AddDynamicItem($state);
Python
menu.AddDynamicItem(state)
state
An integer, one of the add state constants.
Will be called with B_INITIAL_ADD
to start the process of adding dynamic
items.
Will be called with B_PROCESSING
to continue the process of adding dynamic
items.
Will be called with B_ABORT
when the user clicks the mouse button in sticky
mode or releases the mouse button in nonsticky mode or moves the pointer over
another item.
DrawBackground
Called when the background needs to be drawn.
Perl
$menu->DrawBackground(BRect update);
Python
menu.DrawBackground(BRect update)
updateRect
A Rect, the portion of the Menu's frame that needs to be updated.
ScreenLocation
Returns the location of the Menu on the screen as a Point. Meant to be called from within a hook.
Perl
$menu->ScreenLocation();
Python
menu.ScreenLocation()
SetTargetForItems
Sets the target for the Menu's MenuItems.
Perl
$menu->SetTargetForItems($handler); $menu->SetTargetForItems($messenger);
Python
menu.SetTargetForItems(handler) menu.SetTargetForItems(messenger)
ARCHIVABLE INTERFACE
Menu
inherits the methods and hooks of Archivable.
HANDLER INTERFACE
Menu
inherits the methods and hooks of Handler.
VIEW INTERFACE
Menu
inherits the methods and hooks of View.
Show
The Menu version of Show
takes an optional parameter
Perl
$menu->Show($selectFirstItem);
Python
menu.Show(selectFirstItem)
selectFirstItem
A boolean; if true, the first MenuItem will be selected when the Menu is shown; defaults to false.
FUNCTIONS
menu_info
get_menu_info
set_menu_info
Gets or sets system-wide menu settings.
Perl
get_menu_info(); set_menu_info($info);
Python
get_menu_info() set_menu_info(info)
info
A menu_info structure.
CONSTANTS
Add states
See AddDynamicItem for more information.
Perl
use HaikuR1::Menu qw(:add_state)
Python
Python does not support export tags.
- B_INITIAL_ADD
- B_PROCESSING
- B_ABORT
Menu layouts
Perl
use HaikuR1::Menu qw(:menu_layout)
Python
Python does not support export tags.
B_ITEMS_IN_ROW
Menu items are arranged horizontally.
B_ITEMS_IN_COLUMN
Menu items are arranged vertically.
B_ITEMS_IN_MATRIX
Menu items are arranged in a grid.
SCRIPTING SUITE
The name of Menu's scripting suite is suite/vnd.Be-menu
.
Properties
Enabled
B_GET_PROPERTY
,B_SET_PROPERTY
A boolean, the enabled state of the Menu or the specified MenuItem
Label
B_GET_PROPERTY
,B_SET_PROPERTY
A string, the label of the Menu or the specified MenuItem
Mark
B_GET_PROPERTY
,B_SET_PROPERTY
A boolean, the marked state of the Menu's superitem or the specified MenuItem
Menu
B_CREATE_PROPERTY
,B_DELETE_PROPERTY
Creates or deletes a Menu; should be combined with a
B_NAME_SPECIFIER
,B_INDEX_SPECIFIER
, orB_REVERSE_INDEX_SPECIFIER
to indicate where to add or delete. When creating, the Message should contain a string calleddata
which will be the new Menu's label and an integer calledwhat
that will be the what value of the new Menu's message.
MenuItem
B_COUNT_PROPERTIES
,B_CREATE_PROPERTY
,B_DELETE_PROPERTY
,B_EXECUTE_PROPERTY
Creates, deletes, or executes a MenuItem; should be combined with a
B_NAME_SPECIFIER
,B_INDEX_SPECIFIER
, orB_REVERSE_INDEX_SPECIFIER
to indicate where to add or delete, or which item to invoke. When creating, the Message should contain a string calleddata
which will be the new Menu's label and an integer calledwhat
that will be the what value of the new MenuItem's message.
Specifiers
Menu
B_NAME_SPECIFIER
,B_INDEX_SPECIFIER
,B_REVERSE_INDEX_SPECIFIER
Targets a submenu by name or index
MenuItem
B_NAME_SPECIFIER
,B_INDEX_SPECIFIER
,B_REVERSE_INDEX_SPECIFIER
Targets a MenuItem by name or index
Menu also inherits the following suites: