Example 11-5. The menu_dir.c program (continued)
* recursive, a new menu is created for each subdirectory under the
* original path.
*/
Menu_item
add_path_to_menu(path)
char *path;
{
DIR *dirp;
struct direct *dp;
struct stat s_buf;
Menu_item mi;
Menu next_menu;
char buf[MAXPATHLEN];
/* dont add a folder to the list if user cant read it */
if (stat(path, &s_buf) == -1 || !(s_buf.st_mode & S_IREAD))
return NULL;
if (s_buf.st_mode & S_IFDIR) {
int cnt = 0;
if (!(dirp = opendir(path)))
/* dont bother adding to list if we cant scan it */
return NULL;
next_menu = (Menu)xv_create(XV_NULL, MENU, NULL);
while (dp = readdir(dirp))
if (strcmp(dp->d_name, ".") && strcmp(dp->d_name, "..")) {
(void) sprintf(buf, "%s/%s", path, dp>d_name);
if (!(mi = add_path_to_menu(buf)))
/* unreadable file or dir - deactivate item */
mi = xv_create(XV_NULL, MENUITEM,
MENU_STRING, getfilename(dp->d_name),
MENU_RELEASE,
MENU_RELEASE_IMAGE,
MENU_INACTIVE, TRUE,
NULL);
xv_set(next_menu, MENU_APPEND_ITEM, mi, NULL);
cnt++;
}
closedir(dirp);
mi = xv_create(XV_NULL, MENUITEM,
MENU_STRING, getfilename(path),
MENU_RELEASE,
MENU_RELEASE_IMAGE,
MENU_NOTIFY_PROC, my_action_proc,
NULL);
if (!cnt) {
xv_destroy(next_menu);
/* An empty or unsearchable directory - deactivate item */
xv_set(mi, MENU_INACTIVE, TRUE, NULL);
} else {
xv_set(next_menu, MENU_TITLE_ITEM, getfilename(path), NULL);
xv_set(mi, MENU_PULLRIGHT, next_menu, NULL);
}
return mi;
}
return (Menu_item)xv_create(NULL, MENUITEM,
MENU_STRING, getfilename(path),
Menus
Menus 303
Example 11-5. The menu_dir.c program (continued)
MENU_RELEASE,
MENU_RELEASE_IMAGE,
MENU_NOTIFY_PROC, my_action_proc,
NULL);
}
11.19 Menu Package Summary
Table 11-1 lists the procedures and macros in the MENU package. Table 11-2 lists the attri-
butes in the MENU package. This information is described fully in the XView Reference Man-
ual.
Table 11-1. Menu Procedures and Macros
MENUITEM_SPACE()
menu_return_item()
menu_return_value()
menu_show
Table 11-2. Menu Attributes
MENU_APPEND_ITEM MENU_NOTIFY_STATUS
MENU_CLASS MENU_NROWS
MENU_COLOR MENU_NTH_ITEM
MENU_CLIENT_DATA MENU_PARENT
MENU_COL_MAJOR MENU_PIN
MENU_DEFAULT MENU_PIN_PROC
MENU_DEFAULT_ITEM MENU_PIN_WINDOW
MENU_DESCEND_FIRST MENU_PULLRIGHT
MENU_DONE_PROC MENU_RELEASE
MENU_FIRST_EVENT MENU_RELEASE_IMAGE
MENU_GEN_PIN_WINDOW MENU_REMOVE
MENU_GEN_PROC MENU_REMOVE_ITEM
MENU_GEN_PULLRIGHT MENU_REPLACE
MENU_IMAGE MENU_REPLACE_ITEM
MENU_IMAGES MENU_SELECTED
MENU_INACTIVE MENU_SELECTED_ITEM
MENU_INSERT MENU_STRING
MENU_INSERT_ITEM MENU_STRINGS
MENU_ITEM MENU_TITLE
MENU_LAST_EVENT MENU_TITLE_ITEM
304 XView Programming Manual
Table 11-2. Menu Attributes (continued)
MENU_NCOLS MENU_TYPE
MENU_NITEMS MENU_VALID_RESULT
MENU_NOTIFY_PROC MENU_VALUE
XV_DEPTH XV_VISUAL
XV_VISUAL_CLASS
Menus
Menus 305
This page intentionally left blank
to preserve original page counts.

Get Volume 7A: XView Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.