home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 328_01 / demomenu.c < prev    next >
C/C++ Source or Header  |  1991-02-28  |  6KB  |  218 lines

  1. /* demomenu.c
  2.  *
  3.  * Demonstration of pulldown menus
  4.  *
  5.  *
  6.  *
  7.  *
  8.  */
  9.  
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "wtwg.h"
  13.  
  14.  
  15. #define  mfunc(aa,nn)  void mf##aa##nn (void);  \
  16.      void mf##aa##nn (void) {  \
  17.         wsetlocation (WLOC_ATCUR, 2, 1); \
  18.         wpromptc(NULL, "menu func " #aa #nn, NULL);\
  19.         return;  }
  20.  
  21.  
  22. /* The following macros generate a series of 'empty' functions
  23.  * that are called by the menu,
  24.  * this is just to demonstrate creation of a menu tree
  25.  * Actual menu functions can do anything, with these restrictions:
  26.  *      1) must return nothing and 2) must take no arguments
  27.  *              ie: be of form: void function(void) { do stuff... return; }
  28.  *      3) must quit eventually after repetitive ESCAPE key presses
  29.  */
  30. mfunc(a,1)
  31. mfunc(a,2)
  32. mfunc(a,3)
  33.  
  34. mfunc(a1,1)
  35. mfunc(a1,2)
  36. mfunc(a1,3)
  37.  
  38. mfunc(a2,1)
  39. mfunc(a2,2)
  40. mfunc(a2,3)
  41.  
  42. mfunc(a3,1)
  43. mfunc(a3,2)
  44. mfunc(a3,3)
  45.  
  46.  
  47.  
  48.  
  49. mfunc(b,1)
  50. mfunc(b,2)
  51. mfunc(b,3)
  52. mfunc(b,4)
  53.  
  54.  
  55. mfunc(c,1)
  56. mfunc(c,2)
  57. mfunc(c,3)
  58. mfunc(c,4)
  59.  
  60.  
  61. /* define a 'switch' that could be used to disable a menu option
  62.  *     in this demo, all the menu options are always ON
  63.  *
  64.  * if you had separate switches for each menu function,
  65.  *     you could temporarily inactivate a particular menu function
  66.  *     by moving 0 to that function's switch.
  67.  *
  68.  * the function and the switch are associated with each other
  69.  *    via the menu table.
  70.  */
  71. unsigned char  Mon[1]= {1};
  72.  
  73.  
  74.  
  75. /* Define a 'menu tree'
  76.  * this tree is defined with the most deeply nested menu options on top
  77.  * higher choices then reference their sub-menus by address.
  78.  * The highest level menu (the top menu) is addressed in main()
  79.  *   via the call to wpulldown ( ...top menu table... );
  80.  */
  81.  
  82.  
  83. WMENU  A1menu[] =    {
  84. /* mu_entry  mu_func  mu_help mu_menu mu_enable mu_highlight mu_key  */
  85. "A1 1",       mfa11,   "A1", NULL,  Mon,      3,           '1',
  86. "A1 2",       mfa12,   "A1", NULL,  Mon,      3,           '2',
  87. "A1 3",       mfa13,   "A1", NULL,  Mon,      3,           '3',
  88. NULL,         NULL,    NULL,    NULL,  NULL,     0,           0
  89.             };
  90.  
  91.  
  92. WMENU  A2menu[] =    {
  93. /* mu_entry  mu_func  mu_help mu_menu mu_enable mu_highlight mu_key */
  94. "A2 1",       mfa21,   "A2", NULL,  Mon,      3,           '1',
  95. "A2 2",       mfa22,   "A2", NULL,  Mon,      3,           '2',
  96. "A2 3",       mfa23,   "A2", NULL,  Mon,      3,           '3',
  97. NULL,         NULL,    NULL,    NULL,  NULL,     0,           0
  98.             };
  99.  
  100.  
  101. WMENU  A3menu[] =    {
  102. /* mu_entry  mu_func  mu_help mu_menu mu_enable mu_highlight mu_key */
  103. "A3 1",       mfa31,   "A3", NULL,  Mon,      0,           '1',
  104. "A3 2",       mfa32,   "A3", NULL,  Mon,      1,           '2',
  105. "A3 3",       mfa33,   "A3", NULL,  Mon,      3,           '3',
  106. NULL,         NULL,    NULL,    NULL,  NULL,     0,           0
  107.             };
  108.  
  109.  
  110.  
  111.    /* one level up in the menu tree, references A1menu, A2menu, A3menu
  112.     */
  113. WMENU  Amenu[] =    {
  114. /* mu_entry  mu_func  mu_help mu_menu mu_enable mu_highlight mu_key */
  115. "A 1",       NULL,    "A1", A1menu, Mon,      2,           '1',
  116. "A 2",       NULL,    "A2", A2menu, Mon,      2,           '2',
  117. "A 3",       NULL,    "A3", A3menu, Mon,      2,           '3',
  118. NULL,         NULL,    NULL,    NULL,  NULL,     0,           0
  119.             };
  120.  
  121.  
  122.  
  123.  
  124. WMENU  Bmenu[] =    {
  125. /* mu_entry  mu_func  mu_help mu_menu mu_enable mu_highlight mu_key */
  126. "B 1",       mfb1,    "B1", NULL,  Mon,      2,           '1',
  127. "B 2",       mfb2,    "B2", NULL,  Mon,      2,           '2',
  128. "B 3",       mfb3,    "B3", NULL,  Mon,      2,           '3',
  129. "B 4",       mfb4,    "B4", NULL,  Mon,      2,           '4',
  130. NULL,         NULL,    NULL,    NULL,  NULL,     0,           0
  131.             };
  132.  
  133.  
  134.  
  135.  
  136. WMENU  Cmenu[] =    {
  137. /* mu_entry  mu_func  mu_help mu_menu mu_enable mu_highlight mu_key */
  138. "C 1",       mfc1,    "C1", NULL,  Mon,      2,           '1',
  139. "C 2",       mfc2,    "C2", NULL,  Mon,      2,           '2',
  140. "C 3",       mfc3,    "C3", NULL,  Mon,      2,           '3',
  141. "C 4",       mfc4,    "C4", NULL,  Mon,      2,           '4',
  142. NULL,         NULL,    NULL,    NULL,  NULL,     0,           0
  143.             };
  144.  
  145.  
  146.  
  147. WMENU  topmenu[] =    {
  148. /* mu_entry  mu_func  mu_help mu_menu mu_enable mu_highlight mu_key */
  149.  
  150. "A top",     NULL,    "A top", Amenu, Mon,      0,           ALT_A,
  151. "B top",     NULL,    "B top", Bmenu, Mon,      0,           ALT_B,
  152. "C top",     NULL,    "C top", Cmenu, Mon,      0,           ALT_C,
  153. NULL,         NULL,    NULL,    NULL,  NULL,     0,           0
  154.             };
  155.  
  156.  
  157.  
  158.  
  159.  
  160. main ()
  161.     {
  162.     int key;
  163.  
  164.     winit('T');
  165.  
  166.     key = wpromptc ( "MODE", "\tSelect a mode", "Text", "Graphics", NULL );
  167.     
  168.     if ( key == 'G' )
  169.         {
  170.         winit ( 'G' );
  171.         }
  172.     else 
  173.     if ( key == ESCAPE )
  174.         {
  175.         exit (0);
  176.         }
  177.  
  178.     #ifdef __TURBOC__
  179.         /* install a 'clock' onscreen in lower right corner
  180.          * NOTE 1) Microsoft C won't run this very well.
  181.          *         2) In graphics on EGA/VGA some drawing will occassionally get
  182.          *            lost or garbled due to clock operation. OK in hercules.
  183.          */
  184.         if ( (wmode == 'T') || ( wmonitor == 'H' ) )
  185.             {
  186.             wclockinstall ( wxabsmax-5, wyabsmax );
  187.             }
  188.     #endif     /* TURBOC clock */
  189.  
  190.  
  191.     /* install context-sensitive help
  192.      * NOTE demomenu.hlp and demomenu.hx are the names of the help files
  193.      *      MUST be in current directory
  194.      */
  195.     whelp_install ( "demomenu" );
  196.  
  197.     /* install pulldown menus -
  198.      * NOTE topmenu is address of the 'root' of the menu tree
  199.      */
  200.     wpulldown (topmenu);
  201.  
  202.     wsetattr ( LIGHTGRAY );
  203.     wsetc ( 176 );        /* speckles */
  204.  
  205.     whelp_ptr = "demohelp";        /* setup help ptr for main menu */
  206.  
  207.     wsetattr ( (RED<<4) + LIGHTGRAY );
  208.     do     {
  209.         key =wpromptc (NULL, "main program here\nF1 for help.",
  210.                 "continue", NULL );
  211.         }
  212.     while   ( key != ESCAPE );
  213.  
  214.     return (00);
  215.  
  216.  
  217.     }
  218.