IupMenu

Creates a menu element, which groups 3 types of interface elements: item, submenu and separator. Any other interface element defined inside a menu will be an error.

Creation

Ihandle* IupMenu(Ihandle *child, ...); [in C]
Ihandle* IupMenuV(Ihandle* child,va_list arglist); [in C]
Ihandle* IupMenuv(Ihandle **children); [in C]
iup.menu{child, ...: ihandle} -> (ih: ihandle) [in Lua]
menu(child, ...) [in LED]

child, ... : List of identifiers that will be grouped by the menu. NULL must be used to mark the end of the list in C.  It can be empty in C or Lua, not in LED.

Returns: the identifier of the created element, or NULL if an error occurs.

Attributes

BGCOLOR: the background color of the menu, affects all items in the menu. (since 3.0)

POPUPALIGN (non inheritable): alignment of the popup menu relative to the given point in the format "horiz_align:vert_align". Where horiz_align can be: ALEFT, ACENTER or ARIGHT; and vert_align can be ATOP, ACENTER or ABOTTOM. Default: ALEFT:ATOP. (since 3.28)

RADIO (non inheritable): enables the automatic toggle of one child item. When a child item is selected the other item is automatically deselected. The menu acts like a IupRadio for its children. Submenus and their children are not affected.

WID (non inheritable): In Windows, returns the HMENU of the menu.

Callbacks

OPEN_CB: Called just before the menu is opened.

MENUCLOSE_CB: Called just after the menu is closed.


MAP_CB, UNMAP_CB, DESTROY_CB : common callbacks are supported.

Notes

A menu can be a menu bar of a dialog, defined by the dialog's MENU attribute, or a popup menu.

A popup menu is displayed for the user using the IupPopup function (usually on the mouse position) and disappears when an item is selected.

IupDestroy should be called only for popup menus. Menu bars associated with dialogs are automatically destroyed when the dialog is destroyed. But if you change the menu of a dialog for another menu, the previous one should be destroyed using IupDestroy. If you replace a menu bar of a dialog, the previous menu is unmapped.

Any item inside a menu bar can retrieve attributes from the dialog using IupGetAttribute. It is not necessary to call IupGetDialog.

The menu can be created with no elements and be dynamic filled using IupAppend or IupInsert

In GTK uses GtkMenuBar/GtkMenu/GtkMenu, in Windows uses CreateMenu/CreatePopupMenu/CreatePopupMenu, and in Motif uses xmRowColumn/xmPulldownMenu/xmPopupMenu, for Menu Bar/Regular Menu/Popup Menu.

Lua Binding 

Offers a "cleaner" syntax than LED for defining menu, submenu and separator items. The list of elements in the menu is described as a string, with one element after the other, separated by commas.

Each element can be:

{"<item_name>"} - menu item
{"<submenu_name>", <menu>} - submenu
{} - separator

For example:

mnu = iup.menu
{
  iup.submenu
  {
    iup.menu
    {
      iup.item{title="IupItem 1 Checked",value="ON"},
      iup.separator{},
      iup.item{title="IupItem 2 Disabled",active="NO"}
    } 
    ;title="IupSubMenu 1"
  },
  iup.item{title="IupItem 3"},
  iup.item{title="IupItem 4"}
}:popup(iup.CENTER, iup.CENTER)

The same example using the cleaner syntax:

mnu = iup.menu
{
  {
    "IupSubMenu 1",
    iup.menu
    {
      {"IupItem 1 Checked";value="ON"},
      {},
      {"IupItem 2 Disabled";active="NO"}
    } 
  },
  {"IupItem 3"},
  {"IupItem 4"}
}:popup(iup.CENTER, iup.CENTER)

It is also possible to mix the cleaner syntax with the normal syntax or with already create elements.

Examples

Browse for Example Files

Windows
Classic
Windows
w/ Styles
Motif GTK

The IupItem check is affected by the RADIO attribute in IupMenu:

Windows
Classic
Windows
XP Style
Motif GTK

See Also

IupDialog, IupItem, IupSeparator, IupSubmenu, IupPopup, IupDestroy