Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uakari.primate.wisc.edu!ames!uhccux!hale.ifa.hawaii.edu From: denault@hale.ifa.hawaii.edu (Tony Denault) Newsgroups: comp.windows.x Subject: XView menu-generating procedures Keywords: XView, menu Message-ID: <7059@uhccux.uhcc.hawaii.edu> Date: 22 Mar 90 04:51:30 GMT Sender: news@uhccux.uhcc.hawaii.edu Organization: Institute For Astronomy, Hawaii Lines: 175 Has anyone used the menu-generating procedures in XView. I want to create a menu of filenames when the user selects a menu item. I've gotten it to work, but its very unstable. It work when using the ACTION_MENU to move down the hierarchy of menus, but crashes when the user's selects the pullright menu's parent with the ACTION_SELECT button. I get the following warning messages when trying to destroy the pullright menu object: XView warning: obj 0x3bdc8 invalid object (embedding seal incorrect) xv_destroy_status Since the menu_dir2.c example in O'Reilly's XView Programming Manual behave in a similar fashion, I suspect it a bug in the XView programming kit. I'm using OpenWindows 1.0 on the a Sparc-1. If your interested, here is a test program using pullright menus: /* Example program starts with this line */ #include #include #include #include #include #include #include Frame frame; Xv_opaque dummy_menu_nproc( ); Menu gen_execute_menu( ); void command_execute_file_menu_nproc( ); void command_execute_menu_item_nproc( ); main( argc, argv) int argc; char * argv[]; { Panel panel; Menu command_menu; void quit(); xv_init( XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL); frame = (Frame) xv_create( NULL, FRAME, FRAME_LABEL, argv[0], XV_WIDTH, 200, XV_HEIGHT, 100, NULL); command_menu = (Menu) xv_create( NULL, MENU, MENU_ITEM, MENU_STRING, "Execute", MENU_NOTIFY_PROC, command_execute_menu_item_nproc, MENU_GEN_PULLRIGHT, gen_execute_menu, NULL, MENU_ACTION_ITEM, "Edit", dummy_menu_nproc, MENU_ACTION_ITEM, "Command line", dummy_menu_nproc, NULL); panel = (Panel) xv_create (frame, PANEL, NULL); (void) xv_create( panel, PANEL_BUTTON, PANEL_LABEL_STRING, "Commands", PANEL_ITEM_MENU, command_menu, NULL); (void) xv_create( panel, PANEL_BUTTON, PANEL_LABEL_STRING, "Quit", PANEL_NOTIFY_PROC, quit, NULL); xv_main_loop( frame ); exit(0); } void quit() { xv_destroy_safe(frame); } /* ** dummy_menu_nproc() */ Xv_opaque dummy_menu_nproc( item, event ) Panel_item item; Event *event; { printf("dummy_memu_nproc()\n"); } /******************************************************************************/ Menu gen_execute_menu( menu_item, op ) Menu_item menu_item; Menu_generate op; { Menu menu; int cnt; DIR * dirp; struct dirent * dp; /* Destroy any previous menu owned by menu item */ if( menu = (Menu) xv_get( menu_item, MENU_PULLRIGHT) ) xv_destroy(menu); if( op == MENU_DISPLAY ) /* Create a new menu */ { /* Create Menu */ menu = (Menu) xv_create(NULL, MENU, NULL); /* Find the menu items and append them to the menu */ cnt = 0; if( NULL != (dirp = opendir(".")) ) for( dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { cnt++; menu_item = xv_create( NULL, MENUITEM, MENU_STRING, strcpy( malloc(strlen(dp->d_name)+1), dp->d_name), MENU_NOTIFY_PROC, command_execute_file_menu_nproc, MENU_RELEASE, NULL); xv_set( menu, MENU_APPEND_ITEM, menu_item, NULL); } /* Make dummy menu item if no files are found */ if( cnt == 0 ) { menu_item = (Menu_item) xv_create( NULL, MENUITEM, MENU_STRING, "No Command Files Available", NULL); xv_set( menu, MENU_APPEND_ITEM, menu_item, NULL); } } else if( !(menu == (Menu) xv_get( menu_item, MENU_PULLRIGHT))) /* Always insure the menu item has a menu assoicated with it */ { menu = (Menu) xv_create( NULL, MENU, MENU_STRINGS, "Couldn't build a menu.", NULL, NULL); } return menu; } void command_execute_file_menu_nproc( menu, menu_item ) Menu menu; Menu_item menu_item; { char filename[40]; strncpy( filename, (char *) xv_get( menu_item, MENU_STRING), sizeof(filename) ); printf("command_execute_file_menu_nproc() - filename is [%s]\n", filename); } void command_execute_menu_item_nproc( menu, menu_item ) Menu menu; Menu_item menu_item; { xv_set( (Menu) xv_get( menu_item, MENU_PULLRIGHT ), XV_SHOW, TRUE, NULL); } /* Last line of example program */ ---------------------------------------------------------------------------- | Tony Denault | denault@hale.ifa.hawaii.edu | Institute for Astronomy, UH | | 2680 Woodlawn Drive, Honolulu, HI 96789 | ---------------------------------------------------------------------------- -- ---------------------------------------------------------------------------- | Tony Denault | denault@hale.ifa.hawaii.edu | Institute for Astronomy, UH | | 2680 Woodlawn Drive, Honolulu, HI 96789 |