DEFINITION Menus; (* Stephan Junker  *)

(* Menus simplifies using menus with key shortcuts
 *
 * Usage: Define your application as an extension to Menus.ApplDesc.
 * Use Menus.Set to assign procedures to menu items. Use Menus.Show to
 * display the manu.
 *)


TYPE
  MenuProc* = PROCEDURE ();
  Application* = POINTER TO ApplDesc;
  ApplDesc*    = RECORD(WinView.ApplDesc)
                   (* define your application of type Menus.Application
                      or an extension of that if you want your menus to
                      work *)

                   PROCEDURE(app : Application) HandleKeyEvent*;
                     (* calls a menu procedure if the key is defined in
                        the menu. Returns false if not *)

                   PROCEDURE(app : Application) HandleMsgEvent*;
                     (* if the message is MN_SELECTED, the according menu
                        procedure is called. The menu title is shown
                        normal afterwards *)
                 END;


VAR title*,entry* : INTEGER;

(* contain the values of the selected menu item if a procedure stored
   with Menus.Set is called. This is also correct if the procedure was
   called via a keyboard shortcut.
*)

PROCEDURE Set*(menuTree : S.PTR; title,entry : INTEGER; Proc : MenuProc);

(* stores a procedure which is called if the desired menu item is
   selected. If the corresponding menu entry contains a key definition,
   the procedure is also called if the key is pressed. The character for
   shift is the arrow up (01X), for control is "^", for alternate is the
   fuller character (07X). Function keys have the character "F" with a
   number. The "#" character is used to define the separate numerical keys.
   If a key is detected, the procedure is assigned to that key using module
   Key, so use this module for key procedures.
*)

PROCEDURE Show*(menuTree : S.PTR);

(* shows a menu bar. Different tasks may have there own menu bar. If a
   task is terminated, the menu bar of the previous task is shown
   automatically.
*)

PROCEDURE Hide*();

(* hide a menu (= disable) *)


END Menus.
