home *** CD-ROM | disk | FTP | other *** search
- /* vmenu.c -- tutorial showing vertical pop-up menu
-
- ************* Copyright 1985 by Vermont Creative Software **************
-
- INTRODUCTION
-
- This program shows the steps required to implement a pop-up menu, using the
- functions provided in the Window library.
-
- The menu chosen for display is a vertical menu with one item per row. The
- menu is longer than the menu window; so vertical scrolling occurs.
-
- To keep the program simple, no files other than the menu-information file
- are read in for display. For a more complex and realistic example of
- implementing a pop-up menu, see dem_menu.c.
-
- OUTLINE OF PROGRAM
-
- The menu for this example is contained in an ASCII file, vmenu.txt,
- (also on the system diskette). The menu has 10 lines. Each line
- contains one menu item, and the longest item is 10 spaces. The total
- number of items (qitems) is 10, the length of of a menu item
- (itemlength) is 10, and the items per row (rowitems) 1.
-
- The menu is displayed in in a window, declared as WINDOW vmenu_wn, with
- the following characteristics: origin at 0,0; single-line border, left
- and right margins of 1; overall width of 14 spaces (10 inside borders
- and margins); overall height of 8 rows (6 inside of borders).
-
- The menu file is read into a memory file, information messages printed,
- and control turned over to the user. Pressing function key <F9> calls
- v_mf() to display the menu file. k_vcom() interprets cursor-pad
- keystrokes for moving through the menu. Pressing <Enter> exits from
- the menu and the underlying screen is restored. Pressing <F10> exits
- from the program.
-
- */
-
- /* #define WN_DEBUG commented out when debugging completed*/
- #include <wfc.h>
- #include <wfc_glob.h>
-
- #define FILENAME "vmenu.txt"
- #define MAXLINES 10 /*maximum number of lines in mem. file*/
- #define QITEMS 10 /*number of items in menu */
- #define ITEMLENGTH 10 /*maximum no. of columns in menu item */
- #define ROWITEMS 1 /*items per row */
- #define ROWCOL 10 /*items/row times itemlength */
-
- WINDOW vmenu_wn; /*window for file display */
-
-
- main()
- {
- int nlines; /*number of lines read into memory */
- int itemnumber; /* number or selcted menu item */
- int kc; /* keycode value */
- MFILEPTR mfp; /* pointer to memory file structure */
-
- init_wfc(); /*initialize the WFC system */
- cls(); /*clear screen */
- v_qch('*', v_rwq * v_coq, &wn0); /*fill screen with *'s, just to fill */
-
- defs_wn(&vmenu_wn, 0, 0, 8, ROWCOL + 4, BDR_LNP);/*define vmenu_wn window */
-
- /*----------------------------------------------------------------------------*/
- /*Note: menu2() will treat vmenu_wn as a pop-up; no need to set popup switch */
- /*----------------------------------------------------------------------------*/
-
- mfp = mf_def(FILENAME, MAXLINES, ROWCOL); /*define menu file record */
- if(mf_rd(mfp) == 0) /*read menu file to memory file */
- errout("error in reading file ", FILENAME);
- sw_mf(mfp, &vmenu_wn); /*point to menu in vmenu_wn */
-
- /*----------------------------------------------------------------------------*/
- /* Ready for menu display. Inform user of the rules */
- /*----------------------------------------------------------------------------*/
-
- mv_cs(v_rwq - 4, 0, &wn0);
- v_st("To call pop-up menu, press function key F9.\n", &wn0);
- v_st("Use cursor pad keys to move through menu.\n", &wn0);
- v_st("Press Enter key to select item and exit from menu.\n" , &wn0);
- v_st("Press F10 to exit from program.", &wn0);
-
- mv_csr(v_rwq, 0, &wn0); /*hide cursor */
-
- /*----------------------------------------------------------------------------*/
- /* check for keystrokes and implement correct action. */
- /* menu2() will allow user to user cursor keys and will redraw window */
- /* display when scrolling occurs. */
- /*----------------------------------------------------------------------------*/
-
- while((kc = ki()) != -K_F10) /*exit on F10 */
- {
- if(kc == -K_F9)
- {
- /*----------------------------------------------------------------*/
- /* The following call implements the pop-up menu */
- /*----------------------------------------------------------------*/
- itemnumber = menu2(&vmenu_wn, QITEMS, ITEMLENGTH, ROWITEMS, 1);
-
- /*display item number in reverse video in full-screen window */
-
- wn0.att = LREVERSE;
- mv_cs(19, 0, &wn0);
- if (itemnumber > 0)
- v_printf(&wn0, "Item %d selected", itemnumber);
- else
- v_printf(&wn0, "No selection");
- wn0.att = LNORMAL; /*restore normal attribute */
- }
- }
- cls();
- mv_csr(v_rwq - 1, 0, &wn0); /*place cursor on last line */
- exit_wfc();
- return(0);
- }