Haiku API Bindings
Menu
Not logged in

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)

DrawItems

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

Perl

$menu->DrawItems($updateRect);

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

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

Python

menu.IsEnabled()
menu.SetEnabled(enabled)

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

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)

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)

SetTrackingHook

Sets a tracking hook.

Perl

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

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

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

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)

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)

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)

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)

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)

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)

CONSTANTS

Add states

See AddDynamicItem for more information.

Perl

use HaikuR1::Menu qw(:add_state)

Python

Python does not support export tags.

Menu layouts

Perl

use HaikuR1::Menu qw(:menu_layout)

Python

Python does not support export tags.

SCRIPTING SUITE

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

Menu also inherits the following suites: