Menus

The program Menu.m3 illustrates how to create a menu bar with pull down menus. Several key Trestle interfaces are involved: MenuBtnVBT, AnchorBtnVBT, and ButtonVBT. In addition to providing a button VBT, the ButtonVBT interface provides a function MenuBar that takes several VBT's as arguments. These are likely to be anchor buttons from the AnchorBtnVBT interface. Each anchor button takes a single VBT as an argument---most likely a vertical split VBT containing all the individual menu items. The individual menu items are VBTs of type MenuBtnVBT.T. As usual these menu items can be created using the New procedure
PROCEDURE New(ch: VBT.T; action: ButtonVBT.Proc; ref: REFANY := NIL): T;
provided with the MenuBtnVBT module. The argument ref, a pointer to any type, can be used to add an object to the menu item's property set---a convenient way to share global information. The menu item's child VBT (ch) is very often a text VBT. For this reason the MenuBtnVBT provides another procedure for making a menu button with a TextVBT child.
PROCEDURE TextItem(name: TEXT; action: ButtonVBT.Proc; ref: REFANY := NIL): T;
The program Menu.m3 illustrates an application with a simple menu bar with two buttons that activate pull-down menus. Each menu has two menu times. A BorderedVBT is used to surround the pull-down menus. This provides visual separation between the menus and the rest of the application. The following images show three views of the application. In the first view the menu bar is shown as it appears normally in the application. In the second view, one pull-down menu has been activated by clicking in the ``file'' button. In the third view the other pull-down menu has been activated and the menu item ``cut'' has been selected by moving the cursor into the button. Pressing the ``cut'' button will close the pull-down menu and activate the procedure associated with the ``cut'' menu item. In the case of this sample program the action is just printing the name of the button to the standard output.