Syntax
int MenuModal( TopBarMenu *topBar, int selection, int msgRow, int msgLeft, int msgRight, const char *msgColor, Get *getList[], int count );
Arguments
topBar the root menu. NULL returns 0.
selection the one-based starting position on the bar. Use 0 or NIL to wait for an initial input event.
msgRow, msgLeft, msgRight the screen row and inclusive column bounds for item messages. Pass NIL for all three to disable messages.
msgColor the foreground/background color for the message line, or NULL to use the first color from SetColor().
getList, count the Get array and its element count during a READ. Use NULL, 0 for a standalone menu.
Return value
The identifier of the menu item whose action ends the loop. Esc on the top bar or a return to a Get gives -1. A NULL or empty bar, a starting position outside the item list, or a disabled starting item gives 0. A shortcut handled during initial selection returns its identifier immediately, including 0.
Description
Include xdev-wtui-classes.h. Build the menu from a `TopBarMenu` and `MenuItem` objects. An item can open a `PopUpMenu` or call a C callback. With `selection` set to `0`, a click on the bar or an Alt accelerator picks the starting item, a shortcut can run its action immediately, and another key starts at position `1`.
Left and Right move along the top bar. In a nested submenu they close one level, and on returning to the bar they move to the neighboring top-bar item and open its submenu when available. Up and Down move within a pop-up, and Down on the bar opens the current item's submenu. Arrow navigation skips disabled items and separators and wraps at the ends. Enter opens a submenu or runs the current action. Esc closes the active submenu or exits from the bar. Use Alt with a bar accelerator, the accelerator character in an active pop-up, or an assigned shortcut to reach an item directly.
Press the left mouse button to pick an item or open its submenu. Drag with the button held to follow other items. Release it over the current item to run its action if it has no submenu. A click outside the menus closes the active submenu.
After the initial selection, actions that return identifier `0` let the menu continue. Assign a positive identifier to an action that should end the loop and be distinguishable from Esc. The menu centers the current item's message within the configured bounds and truncates it to fit. On exit it clears the item message, closes the open submenus and restores the caller's cursor.
The C function adds `getList` and `count` to the six xBase menu arguments so a READ can resume at a Get. An eligible click outside the menus sets `GE_MOUSEHIT`, and an eligible Get accelerator sets `GE_SHORTCUT` on the active Get. The arrow keys drive navigation. A control key combination can be assigned as an item shortcut.
Example
#include "xdev-wtui.h"
#include "xdev-wtui-classes.h"
#include "xdev-wtui-inkey.h"
#include <stdio.h>
static int actionCount;
static void OnRun( MenuItem *item )
{
( void )item;
++actionCount;
}
int main( void )
{
TopBarMenu *topBar = TopBarNew( 0, 0, MaxCol() );
PopUpMenu *file = PopUpNew( NIL, NIL, NIL, NIL );
int result;
char text[ 80 ];
PopUpAddItem( file, MenuItemNewB( "&Run", OnRun, K_F2, "Run the action (F2)", 1 ) );
TopBarAddItem( topBar, MenuItemNewO( "&File", file, NIL, "Open the File menu", NIL ) );
SetPos( 2, 0 );
DispOut( "Use Down and Enter, F2, or Esc.", NULL );
result = MenuModal( topBar, 1, MaxRow(), 0, MaxCol(), "N/W", NULL, 0 );
snprintf( text, sizeof( text ), "MenuModal() returned %d. Action calls: %d.", result, actionCount );
SetPos( 4, 0 );
DispOut( text, NULL );
Inkey( 0, NIL );
TopBarFree( topBar );
return 0;
}