home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c003 / 1.ddi / DEMOS / VMENU.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-20  |  4.9 KB  |  118 lines

  1. /* vmenu.c -- tutorial showing vertical pop-up menu
  2.  
  3.     ************* Copyright 1985 by Vermont Creative Software **************
  4.  
  5.     INTRODUCTION
  6.  
  7.     This program shows the steps required to implement a pop-up menu, using the
  8.     functions provided in the Window library.
  9.  
  10.     The menu chosen for display is a vertical menu with one item per row.  The
  11.     menu is longer than the menu window; so vertical scrolling occurs.
  12.  
  13.     To keep the program simple, no files other than the menu-information file
  14.     are read in for display.  For a more complex and realistic example of
  15.     implementing a pop-up menu, see dem_menu.c.
  16.  
  17.     OUTLINE OF PROGRAM
  18.  
  19.     The menu for this example is contained in an ASCII file, vmenu.txt,
  20.     (also on the system diskette).  The menu has 10 lines.  Each line
  21.     contains one menu item, and the longest item is 10 spaces.    The total
  22.     number of items (qitems) is 10, the length of of a menu item
  23.     (itemlength) is 10, and the items per row (rowitems) 1.
  24.  
  25.     The menu is displayed in in a window, declared as WINDOW vmenu_wn, with
  26.     the following characteristics:  origin at 0,0; single-line border, left
  27.     and right margins of 1; overall width of 14 spaces (10 inside borders
  28.     and margins); overall height of 8 rows (6 inside of borders).
  29.  
  30.     The menu file is read into a memory file, information messages printed,
  31.     and control turned over to the user.  Pressing function key <F9> calls
  32.     v_mf() to display the menu file.  k_vcom() interprets cursor-pad
  33.     keystrokes for moving through the menu.  Pressing <Enter> exits from
  34.     the menu and the underlying screen is restored.  Pressing <F10> exits
  35.     from the program.
  36.  
  37. */
  38.  
  39. /* #define WN_DEBUG            commented out when debugging completed*/
  40. #include <wfc.h>
  41. #include <wfc_glob.h>
  42.  
  43. #define FILENAME "vmenu.txt"
  44. #define MAXLINES 10            /*maximum number of lines in mem. file*/
  45. #define QITEMS 10            /*number of items in menu          */
  46. #define ITEMLENGTH 10            /*maximum no. of columns in menu item */
  47. #define ROWITEMS 1            /*items per row               */
  48. #define ROWCOL 10            /*items/row times itemlength          */
  49.  
  50. WINDOW vmenu_wn;            /*window for file display          */
  51.  
  52.  
  53. main()
  54. {
  55.     int nlines;             /*number of lines read into memory    */
  56.     int itemnumber;            /* number or selcted menu item          */
  57.     int kc;                /* keycode value              */
  58.     MFILEPTR mfp;            /* pointer to memory file structure   */
  59.  
  60.     init_wfc();             /*initialize the WFC system          */
  61.     cls();                /*clear screen                  */
  62.     v_qch('*', v_rwq * v_coq, &wn0);    /*fill screen with *'s, just to fill  */
  63.  
  64.     defs_wn(&vmenu_wn, 0, 0, 8, ROWCOL + 4, BDR_LNP);/*define vmenu_wn window */
  65.  
  66. /*----------------------------------------------------------------------------*/
  67. /*Note: menu2() will treat vmenu_wn as a pop-up; no need to set popup switch  */
  68. /*----------------------------------------------------------------------------*/
  69.  
  70.     mfp = mf_def(FILENAME, MAXLINES, ROWCOL);      /*define menu file record   */
  71.     if(mf_rd(mfp) == 0)              /*read menu file to memory file  */
  72.     errout("error in reading file ", FILENAME);
  73.     sw_mf(mfp, &vmenu_wn);           /*point to menu in vmenu_wn          */
  74.  
  75. /*----------------------------------------------------------------------------*/
  76. /* Ready for menu display.  Inform user of the rules                  */
  77. /*----------------------------------------------------------------------------*/
  78.  
  79.     mv_cs(v_rwq - 4, 0, &wn0);
  80.     v_st("To call pop-up menu, press function key F9.\n", &wn0);
  81.     v_st("Use cursor pad keys to move through menu.\n", &wn0);
  82.     v_st("Press Enter key to select item and exit from menu.\n" , &wn0);
  83.     v_st("Press F10 to exit from program.", &wn0);
  84.  
  85.     mv_csr(v_rwq, 0, &wn0);           /*hide cursor                  */
  86.  
  87. /*----------------------------------------------------------------------------*/
  88. /*  check for keystrokes and implement correct action.                  */
  89. /*  menu2() will allow user to user cursor keys and will redraw window          */
  90. /*  display when scrolling occurs.                          */
  91. /*----------------------------------------------------------------------------*/
  92.  
  93.     while((kc = ki()) != -K_F10)       /*exit on  F10                  */
  94.     {
  95.     if(kc == -K_F9)
  96.     {
  97.         /*----------------------------------------------------------------*/
  98.         /*    The following call implements the pop-up menu              */
  99.         /*----------------------------------------------------------------*/
  100.         itemnumber =  menu2(&vmenu_wn, QITEMS, ITEMLENGTH, ROWITEMS, 1);
  101.  
  102.         /*display item number in reverse video in full-screen window      */
  103.  
  104.         wn0.att = LREVERSE;
  105.         mv_cs(19, 0, &wn0);
  106.         if (itemnumber > 0)
  107.         v_printf(&wn0, "Item %d selected", itemnumber);
  108.         else
  109.         v_printf(&wn0, "No selection");
  110.         wn0.att = LNORMAL;        /*restore normal attribute          */
  111.     }
  112.     }
  113.     cls();
  114.     mv_csr(v_rwq - 1, 0, &wn0);     /*place cursor on last line          */
  115.     exit_wfc();
  116.     return(0);
  117. }
  118.