Using IlvAbstractMenu

The class IlvAbstractMenu, a subclass of IlvGadget, defines a common interface for menu bars, toolbars, and pop-up menus. IlvAbstractMenu also inherits from the class IlvListGadgetItemHolder, which handles lists of gadget items. IlvAbstractMenu handles a list of IlvMenuItem objects, a subclass of IlvGadgetItem.

Manipulating Menu Items

Member functions for manipulating menu items are defined in the class IlvListGadgetItemHolder.

Callbacks

When the user highlights a menu item, the Highlight callback is invoked. This callback allows actions to take place according to the user selection. For example, the Highlight callback can be used to display a small help message when the user highlights an item in a pop-up menu.

You can set a Highlight callback with the symbol returned by the member function HighlightCBSymbol.

Here is an example of Highlight callback that simply writes the index of the highlighted item:

static void

Highlight(IlvGraphic* g, IlvAny any)

{

// Highlighted item position.

IlvShort pos = *(IlvShort*)any;

IlvAbstractMenu* menu = (IlvAbstractMenu*)g;

if (pos != -1)

IlvPrint("Item %d highlighted", pos);

else

IlvPrint("No item highlighted");

}

Note

Once it has been cast to IlvShort, the value of the any parameter is the position of the highlighted menu item, or -1 if no item is highlighted.

Handling Events

The class IlvAbstractMenu includes the following virtual member functions that you can redefine in subclasses:

  • isSelectable specifies whether a menu item can be selected.

  • selectNext and selectPrevious return the next or previous selectable item when the user moves in the menu using the arrow keys.

  • IlvAbstractMenu::select and unSelect are called when the specified item is selected or deselected.