
NULL);
XtRealizeWidget (toplevel);
XtAppMainLoop (app);
}
The majority of this program is composed of the new version of BuildPulldownMenu() and the menu and
submenu declarations. All the menus and menu items are declared in reverse order because the cascading menu
declaration must exist before the menu is actually referenced. The output of the program is shown in the figure.
Output of build_menu.c
All we have to do to get BuildPulldownMenu() to create a cascading menu is add code that checks whether or
not the current menu has a submenu. If it does, the routine calls itself to create the submenu. Because the function
creates and returns a CascadeButton, the return value can be used as the menu item in the menu that is currently being
built. We have to create the cascading menu first because it has to exist before it can be attached to a CascadeButton.
Recursion handles this problem for us by creating the deepest submenus first, which ensures that all the necessary
submenus are built before their CascadeButtons require them.
We also added support for ToggleButtons to this version of BuildPulldownMenu(), even though our menus do
not contain any ToggleButtons. The only change that we have to make here involves the callback function. Since
ToggleButtons have an XmNvalueChangedCallback, while PushButtons have an XmNactivateCallback,
we check the class of the item being added and specify the appropriate ...