BiMenu

This class represents a menu. Menus can be filled with menu items by adding BiMenuItem objects.

The content model for the menu is very similiar to the content model for BiComponent but there are slight differences.

This class extends BiEventTarget and therefore all methods and fields available for BiEventTarget are also available for BiMenu .

Constructor

new BiMenu ( )

Parameters

No parameters.

Properties

NameTypegetsetDescripton
childrenBiMenuItem[]checkedThe menu items added to the menu
componentBiComponentcheckedIf the menu was opened as a context menu for a component then this will point to the component that caused the menu to be shown.

This will return null if the menu is hidden or not opened by a component (by setting visible manually). This is available during the beforeshow event even though the menu is not yet visible. It is also available when the hide event fires.
enabledBooleancheckedcheckedWhether the menu is enabled.
firstChildBiMenuItemcheckedReturns the first menu item child
heightNumbercheckedcheckedThe height of the menu
hideTimeStampDatecheckedThe time when the menu was hidden. This can be useful to find out whether the popup was just hidden.
insetBottomNumbercheckedBorder bottom width.
insetLeftNumbercheckedBorder left width.
insetRightNumbercheckedBorder right width.
insetTopNumbercheckedBorder top width.
isEnabledBooleancheckedWhether the menu is enabled.
isVisibleBooleancheckedWhether the menu is shown on the screen
lastChildBiMenuItemcheckedReturns the last menu item child
leftNumbercheckedcheckedThe left position of the menu relative to the browser window (used to be screen!)
parentBiMenuItemcheckedThe parent menu item in case the menu acts as a sub menu
parentMenuBiMenucheckedThe parent menu in case the menu acts as a sub menu. This is the same as the parent of the parent menu item
preferredHeightNumbercheckedThe preferred height of the menu
preferredWidthNumbercheckedThe preferred width of the menu
rightToLeftBooleancheckedcheckedDescribes whether the component should be be layed out to support locales using right-to-left fonts. If this is set to null then the rightToLeft property for the parent component is used.
screenLeftNumbercheckedThe left position of the menu relative to screen
screenTopNumbercheckedThe top position of the menu relative to screen
showTimeStampDatecheckedThe time when the menu was shown.
topNumbercheckedcheckedThe top position of the menu relative to the browser window (used to be screen!)
topLevelComponentBiComponentcheckedReturns the top level ancestor component. This is usually the application window hosting the application.
widthNumbercheckedcheckedThe width of the menu

Methods

NameDescription
addAdds a menu item to the current menu. The added menu item becomes a child of the current menu. If the menu item is a child of another menu it is first removed from that menu. The second, optional, argument can be used to insert the new menu item before an existing child. If you know the index where you want to insert the item at you might want to consider using addAt instead.
addAtAdds a menu item at the given index to the current menu. The added menu item becomes a child of the current menu. If the menu item is a child of another menu it is first removed from that menu.
containsReturns true if the menu contains another menu item or menu. This means that the current component is an ancestor of the descendant. Note that the current component contains itself so calling component.contains(component) will return true.
hasChildrenReturns true if the menu has any child menu items
popupAtComponentDisplays the menu near a component.
popupAtMouseDisplays the menu at the mouse coordinates of an event.
removeRemoves an existing menu item from the component.
removeAllRemoves all menu items.
removeAtRemoves the menu item at the given index from the menu.
selectFirstItemSelects (and focuses) the first (top) visible and enabled item on the menu. If there are no visible and enabled items, the menu itself receives the focus.
selectLastItemSelects (and focuses) the last (bottom) visible and enabled item on the menu. If there are no visible and enabled items, the menu itself receives the focus.
setLocationSets the top, left position relative to the browser window (used to be screen!) for the menu.
setSizeSets the width and height of the menu.

Events

NameTypeBubblesDescripton
beforeshowBiEventFires before the menu is shown. This is a good place to change the content of the menu to reflect the component causing the menu to be shown
hideBiEventFires when the menu is hidden
showBiEventFires when the menu is shown

Static Methods

None.

Static Fields

NameTypeDescripton
SCROLL_DISTANCENumberThe distance (in pixels) to scroll the menu at each interval. A small value here (default 5) will make the scrolling smooth, but slow.
SCROLL_INTERVALNumberThe interval (in millliseconds) between each scroll step. A smaller interval makes for faster scrolling (defaults to 30).

Remarks

The location of the menu is relative to the screen. A menu can only be used as a sub menu for one menu item.

Method Details

add

Adds a menu item to the current menu. The added menu item becomes a child of the current menu. If the menu item is a child of another menu it is first removed from that menu. The second, optional, argument can be used to insert the new menu item before an existing child. If you know the index where you want to insert the item at you might want to consider using addAt instead.

Syntax

object.add ( oItem [ ,oBefore ] )

Parameters

NameTypeOptionalDefaultDescripton
oItemBiMenuItemThe menu item to add
oBeforeBiMenuItemcheckedThe existing child do add the new menu item before

Return Type

void

addAt

Adds a menu item at the given index to the current menu. The added menu item becomes a child of the current menu. If the menu item is a child of another menu it is first removed from that menu.

Syntax

object.addAt ( oChild,nIndex )

Parameters

NameTypeOptionalDefaultDescripton
oChildBiMenuItemThe menu item to add
nIndexNumberThe index to add the item at

Return Type

void

contains

Returns true if the menu contains another menu item or menu. This means that the current component is an ancestor of the descendant. Note that the current component contains itself so calling component.contains(component) will return true.

Syntax

object.contains ( oDescendant )

Parameters

NameTypeOptionalDefaultDescripton
oDescendantObjectThe BiMenu or BiMenuItem to test whether the current component contains it.

Return Type

Boolean

hasChildren

Returns true if the menu has any child menu items

Syntax

object.hasChildren ( )

Parameters

No arguments.

Return Type

Boolean

popupAtComponent

Displays the menu near a component.

Syntax

object.popupAtComponent ( oComponent,bSelectFirst )

Parameters

NameTypeOptionalDefaultDescripton
oComponentBiComponentthe component
bSelectFirstBooleanWhether to make the first (top) available item selected (and focused). Setting this parameter to false (or skipping it) instead focuses the menu itself and the user may select the first available item by pressing the down arrow.

Return Type

void

popupAtMouse

Displays the menu at the mouse coordinates of an event.

Syntax

object.popupAtMouse ( oMouseEvent,bSelectFirst )

Parameters

NameTypeOptionalDefaultDescripton
oMouseEventBiMouseEventthe event
bSelectFirstBooleanWhether to make the first (top) available item selected (and focused). Setting this parameter to false (or skipping it) instead focuses the menu itself and the user may select the first available item by pressing the down arrow.

Return Type

void

remove

Removes an existing menu item from the component.

Syntax

object.remove ( oItem )

Parameters

NameTypeOptionalDefaultDescripton
oItemBiMenuItemThe menu item to remove

Return Type

BiMenuItem

removeAll

Removes all menu items.

Syntax

object.removeAll ( )

Parameters

No arguments.

Return Type

void

removeAt

Removes the menu item at the given index from the menu.

Syntax

object.removeAt ( nIndex )

Parameters

NameTypeOptionalDefaultDescripton
nIndexNumberThe index of the menu item to remove

Return Type

BiMenuItem

selectFirstItem

Selects (and focuses) the first (top) visible and enabled item on the menu. If there are no visible and enabled items, the menu itself receives the focus.

Syntax

object.selectFirstItem ( )

Parameters

No arguments.

Return Type

void

selectLastItem

Selects (and focuses) the last (bottom) visible and enabled item on the menu. If there are no visible and enabled items, the menu itself receives the focus.

Syntax

object.selectLastItem ( )

Parameters

No arguments.

Return Type

void

setLocation

Sets the top, left position relative to the browser window (used to be screen!) for the menu.

Syntax

object.setLocation ( nLeft,nTop )

Parameters

NameTypeOptionalDefaultDescripton
nLeftNumberThe new left location for the menu
nTopNumberThe new top location for the menu

Return Type

void

setSize

Sets the width and height of the menu.

Syntax

object.setSize ( nWidth,nHeight )

Parameters

NameTypeOptionalDefaultDescripton
nWidthNumberThe new width for the menu
nHeightNumberThe new height for the menu

Return Type

void