Haiku API Bindings
Menu
Not logged in

Documentation | InterfaceKit | Menu

SYNOPSIS

Perl

Python

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);

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

Python

HaikuR1::Menu->new($name, $layout);
HaikuR1::Menu->new($name, $width, $height);
HaikuR1::Menu->new($archive);

DrawItems

Draws the Menu's MenuItems. Meant to be called from within a hook.

Perl

Python

$menu->DrawItems($updateRect);

Enabled state

IsEnabled

SetEnabled

Gets or sets the Menu's enabled state. SetEnabled can also be called as a hook.

Perl

Python

$menu->IsEnabled();
$menu->SetEnabled($enabled);

FindMarked

FindMarkedIndex

Finds the first marked MenuItem or its index.

Perl

Python

$menu->FindMarked();
$menu->FindMarkedIndex();

Items

AddItem

AddList

AddSeparatorItem

RemoveItem

RemoveItems

ItemAt

SubmenuAt

CountItems

IndexOf

FindItem

Manage the Menu's MenuItems.

Perl

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 margins

GetItemMargins

SetItemMargins

Gets or sets the margins for the Menu's MenuItem. Meant to be called from within a hook.

Perl

Python

$menu->GetItemMargins();
$menu->SetItemMargins($left, $top, $right, $bottom);

Layout

Returns the menu layout constant representing the menu layout.

Perl

Python

$menu->Layout();

MaxContentWidth

SetMaxContentWidth

Gets or sets the maximum content width of the Menu. SetMaxContentWidth can also be called as a hook.

Perl

Python

$menu->MaxContentWidth();
$menu->SetMaxContentWidth($width);

Radio mode

IsRadioMode

SetRadioMode

Gets or sets the radio mode state. SetRadioMode can also be called as a hook.

Perl

Python

$menu->IsRadioMode();
$menu->SetRadioMode($on);

SetTrackingHook

Sets a tracking hook.

Perl

Python

$menu->SetTrackingHook($hook, $state);

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.)

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

Python

$menu->IsRedrawAfterSticky();

Superitem

Returns the MenuItem that contains this Menu.

Perl

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

Python

$menu->IsLabelFromMarked();
$menu->SetLabelFromMarked($state);

Supermenu

Returns the Menu that contains this Menu.

Perl

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

Python

$menu->Track($startOpened, $specialRect);

Triggers

AreTriggersEnabled

SetTriggersEnabled

Gets or sets the triggers-enabled state. SetTriggersEnabled can also be called as a hook.

Perl

Python

$menu->AreTriggersEnabled();
$menu->SetTriggersEnabled($enable);

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

Python

$menu->AddDynamicItem($state);

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

Python

$menu->DrawBackground(BRect update);

ScreenLocation

Returns the location of the Menu on the screen as a Point. Meant to be called from within a hook.

Perl

Python

$menu->ScreenLocation();

SetTargetForItems

Sets the target for the Menu's MenuItems.

Perl

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

Python

$menu->Show($selectFirstItem);

FUNCTIONS

menu_info

get_menu_info

set_menu_info

Gets or sets system-wide menu settings.

Perl

Python

get_menu_info();
set_menu_info($info);

CONSTANTS

Add states

See AddDynamicItem for more information.

Perl

Python

use HaikuR1::Menu qw(:add_state)

Menu layouts

Perl

Python

use HaikuR1::Menu qw(:menu_layout)

SCRIPTING SUITE

The name of Menu's scripting suite is suite/vnd.Be-menu.

Menu also inherits the following suites: