
Example F-2. The scroll_cells2.c program (continued)
xv_set(vert_scrollbar,
SCROLLBAR_OBJECT_LENGTH, CELLS_PER_COL,
SCROLLBAR_PAGE_LENGTH, page_h,
SCROLLBAR_VIEW_LENGTH, page_h,
NULL);
}
F.3 menu_dir2.c
In Chapter 11, Menus, the program menu_dir.c demonstrates the use of an XView menu in a
canvas subwindow. A menu is brought up with the MENU mouse button and displays menu
choices representing the files in the directory. The problem with menu_dir.c is that the entire
menu cascade is created for all the subdirectories at the very beginning of the program. If the
directory stack is very deep, it could take a very long time to build. You could also run out of
memory in the process. Further, if the contents of the directory tree is dynamic, the menu
entries could become invalid over time.
These problems are solved in menu_dir2.c because it creates only the top-level menu. For
each directory entry under the top-level, rather than creating an associated pullright menu, a
MENU_GEN_PULLRIGHT procedure is specified. This routine creates that menu only at the
time it is needed. So, when the user invokes the menu and tries to descend into a submenu
representing a subdirectory in the directory tree, only then is the directory entry searched and
a new submenu created. When the user backs out of the menu, the menu is des-
troyed—attempting to re-enter the submenu causes the process to be repeated.
An exercise for