The menu class

A menu consists of a number of button-like entries, each associated with an action. A menu entry may also consist of another menu, that pops up whenever the entry is selected.
  interface menu : widget { 
\c{\fbox{menu}}
menu(char* p, char* options = ""); menu(widget* w, char* p, char* options = ""); menu* add(char* s, char* options = ""); menu* entry(char* s,char* args ="", char* opts=""); menu* entry(char*,action&, char* ="", char* =""); menu* cascade(char* s, char* m, char* opts = ""); menu* cascade(char* s, menu* m, char* opts = ""); char* entryconfigure(int i, char* options); int index(char *s); int active();
\c{// returns active index}
void del(int i);
\c{// delete entry with index i}
void del(char* s);
\c{// delete entry}
char* invoke(int i);
\c{// invoke entry with index i}
char* invoke(char *s );
\c{// invoke}
void post(int x = 500, int y = 500); void unpost(); protected: install(action&, char* args); };

slide: The menu class

The add function is included to allow arbitrary entries (as defined by Tk) to be added. We restrict ourselves to simple command and cascade entries. The entry function (used for adding simple command entries) may explicitly be given an action to be associated with the entry. Alternatively, if no action is specified, the default handler action installed by invoking widget::handler will be used. The string used as a label for the entries (the first parameter of entry) will be given as a parameter to the action invoked when selecting the entry. The string given in the args parameter will be added to the actual parameters for the action invoked. The cascade function may either be given a menu or a string, containing the pathname of the menu. In any case, the cascaded menu must be a descendant of the original menu. The function index returns the integer index associated with the string describing the entry. The function active may be used to ask which entry has been selected. Entries may be deleted using the function del and invoked by using invoke. For both functions, the entry may be indicated by its numerical index or a string. Menus are top level widgets; they are mapped to the screen either by invoking the function post, or by pressing the menubutton to which the menu is attached.