Modula-2 || Compiler & Tools || Library || Search Engine


Ulm's Modula-2 Library:
Menus


NAME

Menus - display and execution of menu windows

SYNOPSIS

TYPE Menu;


VAR Done: BOOLEAN;

PROCEDURE CreateMenu(VAR menu: Menu; title: ARRAY OF CHAR);

PROCEDURE AddCommand(menu: Menu; cmd: ARRAY OF CHAR; cmdno: CARDINAL); PROCEDURE AddProcedure(menu: Menu; cmd: ARRAY OF CHAR; cmdproc: PROC); PROCEDURE AddSubMenu(menu: Menu; cmd: ARRAY OF CHAR; submenu: Menu);

PROCEDURE ExecMenu(menu: Menu; background: Window; VAR selected: CARDINAL);

PROCEDURE DisposeMenu(VAR menu: Menu);

DESCRIPTION

Menus is based on Windows and allows to create and execute menus. A menu with headline title is created calling CreateMenu. The headline may be empty. The resulting parameter menu is used as reference on subsequent calls. DisposeMenu releases the space allocated with it.

A menu is constructed line by line by calling either AddSubMenu, AddProcedure, or AddCommand. The text to be printed on the menu line is given in cmd. AddSubMenu allows the construction of hierarchical menus. The parameter submenu must be initialized previously by CreateMenu but is not necessarily complete. So, recursive menus are possible. AddProcedure causes cmdproc to be called if the associated menu line is selected. After having called cmdproc the user returns to the menu point selected previously. AddCommand causes on selection the complete menu hierarchy to disappear. The parameter cmdno is then returned in selected of ExecMenu.

ExecMenu creates a window using NewWindow (see Windows) which fits into background. The window is boxed and consists of the underlined header line and the lines defined by AddSubMenu, AddProcedure, and AddCommand. The location of the upper left corner depends on the current position in background. The size of the window depends on the number of menu lines and the maximum width of the cmd parameters and the headline. If the number of lines does not fit into background only a part of the menu is displayed, but scroll commands and a scroll bar enable quick access to the other parts. ExecMenu returns when the menu is left, or a menu line created by AddCommand is selected. The resulting parameter selected equals 0 if the menu is left. The menu must not be changed during running ExecMenu by the procedures given to AddProcedure. But it is possible to append further menu lines when ExecMenu returns. If calls of ExecMenu are nested (due to calls of procedures given to AddProcedure) redisplays (on return of such procedures) affect the innermost menu hierarchy only.

Menu selection is done by function keys: up and down for movement, right for selection, and left for leaving the menu. Alternatively the vi(1) movement commands ('h', 'j', 'k', and 'l') and the return key for menu selection can be used. The vi(1) commands for fast movement can be used on menus with scroll bar as follows:

^D half page forward
^F full page forward
^U half page backward
^B full page backward

DIAGNOSTICS

Done is set to FALSE if ExecMenu fails. This is possible if background has less then four lines or not enough columns.

SEE ALSO

Windows, vi(1)
Edited by: borchert, last change: 1997/02/25, revision: 1.2, converted to HTML: 1997/04/28

Modula-2 || Compiler & Tools || Library || Search Engine