home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / TCXOS2.ZIP / DEMO / MENUDEMO.C < prev    next >
C/C++ Source or Header  |  1991-11-05  |  31KB  |  799 lines

  1. /*=====[ The TesSeRact(TM) CXL User Interface Development System ]======*
  2.  | Copyright (c) 1987-1991, Innovative Data Concepts, Inc.
  3.  | All Rights Reserved.
  4.  |
  5.  | This Library is part of IDC's TesSeRact Development Tools product
  6.  | line. For information about other IDC products, call  1-215-443-9705.
  7.  *-V--------------------------------------------------------------------*
  8.  | $Header:   D:/beta/version/menudemo.c_v   552.15   30 Sep 1991  6:33:32  $
  9.  |
  10.  | $Log:   D:/beta/version/menudemo.c_v  $
  11.  | 
  12.  |    Rev 552.15   30 Sep 1991  6:33:32
  13.  | a bit more room for debugger
  14.  | 
  15.  |    Rev 552.14   30 Sep 1991  6:16:52
  16.  | fix missing _TcxlI
  17.  | 
  18.  |    Rev 552.13   28 Sep 1991 12:19:32
  19.  | more zortect code reduction
  20.  | 
  21.  |    Rev 552.12   07 Sep 1991 18:19:18
  22.  | back out change
  23.  | 
  24.  |    Rev 552.10   22 Jun 1991 14:03:48
  25.  | check correct return value from Wopen
  26.  | 
  27.  |    Rev 552.9   22 Jun 1991 13:58:32
  28.  | put back DispSureMsg()
  29.  | 
  30.  |    Rev 552.8   21 Jun 1991 16:24:24
  31.  | code consolidation/reduction
  32.  | 
  33.  |    Rev 552.7   21 Jun 1991  6:02:06
  34.  | shut up MS6 warnings
  35.  | 
  36.  |    Rev 552.6   13 Jun 1991 11:30:38
  37.  | Fix bad col setting for KbndMou
  38.  | 
  39.  |    Rev 552.5   01 Jun 1991  7:14:20
  40.  | Fix Typos
  41.  | 
  42.  |    Rev 552.4   01 Jun 1991  7:02:20
  43.  | add hotkeys to top menus, and KbndMou stuff
  44.  | 
  45.  |    Rev 552.3   21 Apr 1991 12:02:00
  46.  | add unix compatibility updates
  47.  | 
  48.  |    Rev 552.2   05 Apr 1991  8:35:56
  49.  | set correct initial item in Default menu
  50.  | 
  51.  |    Rev 552.1   17 Mar 1991 20:03:00
  52.  | Version 5.52 (after unlog/build)
  53.  *-D--------------------------------------------------------------------*
  54.  | MenuDemo.C : TCXL Menu-system demonstration
  55.  *-N-----------------------[ Notes and Caveats ]------------------------*
  56.  | 1) Use the MakeDemo.Bat file to compile this file.
  57.  *======================================================================*/
  58. #include <stdio.h>
  59. #include <TCXL_os.h>                   /* TCXL DOS functions            */
  60. #if (_TCXL_cc_ < 128) && !defined(_TCXLos2_)
  61. #include <dos.h>
  62. #endif
  63. #include <string.h>
  64. #include <stdlib.h>
  65. #include "demo\TCXLdemo.h"             /* TCXL demo-specific            */
  66. #include <TCXLstr.h>                   /* TCXL string functions         */
  67. #include <TCXLsel.h>                   /* TCXL selection system         */
  68. #include <TCXLent.h>                   /* TCXL entry system             */
  69. #include <TCXLvUV.h>                   /* TCXL UltraVision/video        */
  70. #include <TCXLfmt.h>                   /* TCXL conversion functions     */
  71. #include <TCXLcod.h>                   /* TCXL key-codes                */
  72.  
  73. /*----------------------------[ Local data ]----------------------------*/
  74.  
  75. LCL   ChrP  CDC   LinArr[] =           /* screen lines table            */
  76. {  "25 Lines", "43 Lines", "50 Lines", NULL
  77. };
  78.  
  79. #if !defined(_TCXLos2_)
  80. LCL   ChrP  CDC   UvArr[] =            /* Ultravision screen modes      */
  81. {  "80x25",                   "80x43 EGA, 80x50 VGA",
  82.    "80x34 EGA, 80x36 VGA",    "80x60 EGA, 80x63 VGA",
  83.    "94x25",                   "94x43 EGA, 94x50 VGA",
  84.    "94x36",                   "94x63",
  85.    "108x25",                  "108x43 EGA, 108x50 VGA",
  86.    "108x34 EGA, 108x36 VGA",  "108x60 EGA, 108x63 VGA",
  87.    "120x25",                  "120x43 EGA, 120x50 VGA",
  88.    "120x36",                  "120x63",
  89.    "132x25",                  "132x44, 132x50 SuperVGA",
  90.    "132x36",                  "132x60",
  91.    NULL
  92. };
  93. #endif
  94.  
  95. #if !defined(_TCXLos2_)
  96. LCL   IntT  CDC   UvMode[] =           /* Ultravision mode numbers      */
  97. {  0x11, 0x12, 0x13, 0x14, 0x19, 0x1A, 0x1B, 0x1C,
  98.    0x21, 0x22, 0x23, 0x24, 0x31, 0x32, 0x39, 0x3A,
  99.    0x33, 0x34, 0x3B, 0x3C, 0
  100. };
  101. #endif
  102. LCL   ChrT  CDC   Rmargin[] = "Right margin     72";
  103. LCL   ChrT  CDC   Lmargin[] = "Left margin       0";
  104. #if !defined(_TCXLos2_)
  105. LCL   ChrP  CDC   UvVal[21];
  106. LCL   IntT  CDC   UvMd[21];
  107. #endif
  108. LCL   ChrP  CDC   Edemo[] =            /* Editor demo text              */
  109. {
  110.    "This is a sample editor interface to demonstrate how TCXL's menuing ",
  111.    "functions can be used to create a pull-down menu system.  Use the ",
  112.    "arrow keys to move the selection bar around and use the [Esc] key to ",
  113.    "back up to the previous menu.  Pressing [F1] will bring up ",
  114.    "context-sensitive help.  Select [Q]uit from any menu to exit the ",
  115.    "Menu Demonstration.  Be sure to try some of the menu options in ",
  116.    "the pull-down menus.  In particular, you might try to change ",
  117.    "the left and right margins under the <D>efault option, or to ",
  118. #if !defined(_TCXLos2_)
  119.    "adjust the screen size if you have an EGA/VGA, or use Ultravision.",
  120. #else
  121.    "adjust the screen size if you have an EGA/VGA.",
  122. #endif
  123.    NULL,
  124.    "  Since you have a mouse, you can use it to move around and ",
  125.    "select options!  You can also click the left mouse button on the ",
  126.    "highlighted words below to jump to a different part of this program:\n",
  127.    NULL
  128. };
  129.  
  130. INFO TcxlI[] =          /* text displayed in Information screen         */
  131. {  {  1, WHITE|_RED,
  132.      "The TesSeRact(TM) CXL User Interface Development System" },
  133.    {  2, WHITE|_RED,
  134.       "Copyright (c) 1987-1991, Innovative Data Concepts" },
  135.    {  3, WHITE|_RED,
  136.       "All Rights Reserved" },
  137.    {  5, BLACK|_RED,
  138.       "TCXL is a Full-Featured C Development System that supports" },
  139.    {  6, BLACK|_RED,
  140.       "Microsoft, Borland, Zortech, JPI, & Watcom Compilers (DOS)," },
  141.    {  7, BLACK|_RED,
  142.       "as well as portability to Unix, OS/2 and 386 Protected Mode" },
  143. };
  144.  
  145. /*---------------------[ Local function prototypes ]--------------------*/
  146.  
  147. LCL   VOID  CTYP  ChangeSize(NOARG);
  148. LCL   VOID  CTYP  Directory(NOARG);
  149. LCL   VOID  CTYP  DispSureMsg(NOARG);
  150. LCL   VOID  CTYP  DoNothing(NOARG);
  151. LCL   VOID  CTYP  DrawEditor(IntT Lmar, IntT Rmar);
  152. LCL   VOID  CTYP  Execute(NOARG);
  153. LCL   VOID  CTYP  OsShell(NOARG);
  154. LCL   VOID  CTYP  OsShell1(ChrP Cmd);
  155. LCL   VOID  CTYP  PopupDemo(NOARG);
  156. LCL   VOID  CTYP  QuitWindow(NOARG);
  157. LCL   VOID  CTYP  RMargin(NOARG);
  158. LCL   VOID  CTYP  SetupMenu(NOARG);
  159. LCL   VOID  CTYP  ToggleBlock(NOARG);
  160. LCL   VOID  CTYP  ToggleYN(NOARG);
  161. LCL   VOID  CTYP  UpdateClock(NOARG);
  162. LCL   IntT  CTYP  ValidMarg(ChrP Input);
  163. #if !defined(_TCXLos2_)
  164. LCL   IntT  CTYP  ValidModes(NOARG);
  165. #endif
  166.  
  167. /*-------------[ Demo item-build and menu-build objects ]---------------*
  168.  | Note that the *entire* demo menu-tree is defined here, from the top
  169.  | bar down through the pop-up.  This is done here to include local
  170.  | function pointers after the prototypes are defined. The structures are
  171.  | defined in <TCXLmnu.h>. Elements for each item IbldT are:
  172.  |    istr, ichr, imsk, irow, icol, itag, ihlp, ikey, iusr,
  173.  |    ibef, isel, iaft, itxt, isub
  174.  | Elements for each menu MbldT are:
  175.  |    mitm, mcnt, mbgr, mbgc, menr, menc, mtyp, mfrt, mfra,
  176.  |    mwat, mtat, msat, mnat, mbat,
  177.  |    mtag, mopn, musr, mwid, mofs, mdtr, mdtc, mdat
  178.  *----------------------------------------------------------------------*/
  179.  
  180. LCL   IbldT  CDC   FilItm[8] =         /*- "File" pulldown items -------*/
  181. {  {  "Load",          'L', 0,       0, 0, 20, H_LOAD,      0,      0,
  182.        NULL,      DoNothing, NULL,       NULL, NULL   },
  183.    {  "Save",          'S', 0,       1, 0, 21, H_SAVE,      0,      0,
  184.        NULL,      DoNothing, NULL,       NULL, NULL   },
  185.    {  "Rename",        'R', 0,       2, 0, 22, H_RENAME,    0,      0,
  186.        NULL,      DoNothing, NULL,       NULL, NULL   },
  187.    {  "New",           'N', 0,       3, 0, 23, H_NEW,       0,      0,
  188.        NULL,      DoNothing, NULL,       NULL, NULL   },
  189.    {  "Directory  F5", 'D', 0,       4, 0, 24, H_DIRECTORY, Key_F5, 0,
  190.        NULL,      Directory, NULL,       NULL, NULL   },
  191.    {  "Execute    F6", 'E', 0,       5, 0, 25, H_EXECUTE,   Key_F6, 0,
  192.        NULL,      Execute,   NULL,       NULL, NULL   },
  193.    {  "OS Shell   F7", 'O', ITM_BEF, 6, 0, 26, H_OSSHELL,   Key_F7, 0,
  194.        NULL,      OsShell,   NULL,       NULL, NULL   },
  195.    {  "Quit",          'Q', ITM_ALL, 7, 0, 27, H_QUIT,      0,      0,
  196.       QuitWindow, NULL,      QuitWindow, NULL, NULL   }
  197. };
  198. LCL   MbldT CDC   FilMnu =             /*- "File" pulldown menu --------*/
  199. {  &FilItm[0], 8,  2,  1, 11, 17, MNU_PUL|MNU_SAV, BOX_SNG, LGREY|_BLUE,
  200.    _BLUE, YELLOW|_BLUE, LCYAN|_BLUE, 0, YELLOW|_MAGENTA,
  201.    20, NULL,  0, 15,  1, 0xFF, 0xFF, 0xFF
  202. };
  203. LCL   IbldT CDC   EdtItm[7] =          /*- "Edit" pulldown items -------*/
  204. {  {  "Cut",         'C', 0,       0, 0, 29, H_NONE, 0, 0,
  205.        NULL, DoNothing,   NULL, NULL, NULL  },
  206.    {  "Paste",       'P', ITM_NSL, 1, 0, 30, H_NONE, 0, 0,
  207.        NULL, DoNothing,   NULL, NULL, NULL  },
  208.    {  "cOpy",        'O', ITM_NSL, 2, 0, 31, H_NONE, 0, 0,
  209.        NULL, DoNothing,   NULL, NULL, NULL  },
  210.    {  "block Begin", 'B', 0,       3, 0, 32, H_NONE, 0, 0,
  211.        NULL, ToggleBlock, NULL, NULL, NULL  },
  212.    {  "block End",   'E', ITM_NSL, 4, 0, 33, H_NONE, 0, 0,
  213.        NULL, ToggleBlock, NULL, NULL, NULL  },
  214.    {  "Insert line", 'I', 0,       5, 0, 34, H_NONE, 0, 0,
  215.        NULL, DoNothing,   NULL, NULL, NULL  },
  216.    {  "Delete line", 'D', 0,       6, 0, 35, H_NONE, 0, 0,
  217.        NULL, DoNothing,   NULL, NULL, NULL  },
  218. };
  219. LCL   MbldT CDC   EdtMnu =             /*- "Edit" pulldown menu --------*/
  220. {  &EdtItm[0], 7,  2, 14, 10, 28, MNU_PUL|MNU_SAV, BOX_SNG, LGREY|_BLUE,
  221.    _BLUE, YELLOW|_BLUE, LCYAN|_BLUE, CYAN|_BLUE, YELLOW|_MAGENTA,
  222.    29, NULL,  0, 13,  1, 0xFF, 0xFF, 0xFF
  223. };
  224. LCL   IbldT CDC   DefItm[8] =          /*- "Defaults" pulldown items----*/
  225. {  {  Lmargin,               'L', ITM_ALL, 0, 0, 37, H_NONE, 0, 0,
  226.        NULL, RMargin,   NULL, NULL, NULL  },
  227.    {  Rmargin,               'R', ITM_ALL, 1, 0, 38, H_NONE, 0, 0,
  228.        NULL, RMargin,   NULL, NULL, NULL  },
  229.    {  "Tab width         4", 'T', 0,       2, 0, 39, H_NONE, 0, 0,
  230.        NULL, DoNothing, NULL, NULL, NULL  },
  231.    {  "tab eXpansion   yes", 'X', 0,       4, 0, 40, H_NONE, 0, 0,
  232.        NULL, ToggleYN,  NULL, NULL, NULL  },
  233.  
  234.    {  "Insert mode     yes", 'I', 0,       5, 0, 41, H_NONE, 0, 0,
  235.        NULL, ToggleYN,  NULL, NULL, NULL  },
  236.    {  "iNdent mode     yes", 'N', 0,       6, 0, 42, H_NONE, 0, 0,
  237.        NULL, ToggleYN,  NULL, NULL, NULL  },
  238.    {  "Word wrap mode   no", 'W', 0,       7, 0, 43, H_NONE, 0, 0,
  239.        NULL, ToggleYN,  NULL, NULL, NULL  },
  240.    {  "Save defaults",       'S', 0,       9, 0, 44, H_NONE, 0, 0,
  241.        NULL, DoNothing, NULL, NULL, NULL  }
  242. };
  243. LCL   MbldT CDC   DefMnu =             /*- "Defaults" pulldown menu ----*/
  244. {  &DefItm[0], 8,  2, 30, 13, 52, MNU_PUL|MNU_SAV, BOX_SNG, LGREY|_BLUE,
  245.    _BLUE, YELLOW|_BLUE, LCYAN|_BLUE, 0, YELLOW|_MAGENTA,
  246.    38, SetupMenu,  0, 21,  1, 0xFF, 0xFF, 0xFF
  247. };
  248. LCL   IbldT CDC   OptItm[5] =          /*- "Options" pulldown items ----*/
  249. {  {  "screen siZe",        'Z', ITM_ALL, 0, 0, 47, H_NONE, 0, 0,
  250.        NULL, ChangeSize, NULL, NULL, NULL  },
  251.    {  "Backup files   yes", 'B', 0,       1, 0, 48, H_NONE, 0, 0,
  252.        NULL, ToggleYN,   NULL, NULL, NULL  },
  253.    {  "bOxed display   no", 'O', 0,       2, 0, 49, H_NONE, 0, 0,
  254.        NULL, ToggleYN,   NULL, NULL, NULL  },
  255.    {  "Load options",       'L', 0,       3, 0, 50, H_NONE, 0, 0,
  256.        NULL, DoNothing,  NULL, NULL, NULL  },
  257.    {  "Save options",       'S', 0,       4, 0, 51, H_NONE, 0, 0,
  258.        NULL, DoNothing,  NULL, NULL, NULL  }
  259. };
  260. LCL   MbldT CDC   OptMnu =             /*- "Options" pulldown menu -----*/
  261. {  &OptItm[0], 5,  2, 56,  8, 77, MNU_PUL|MNU_SAV, BOX_SNG, LGREY|_BLUE,
  262.    _BLUE, YELLOW|_BLUE, LCYAN|_BLUE, 0, YELLOW|_MAGENTA,
  263.    47, NULL,  0, 20,  1, 0xFF, 0xFF, 0xFF
  264. };
  265. LCL   IbldT CDC   QitItm[2] =          /*- "Quit" pulldown items -------*/
  266. {  {  "No",  'N', ITM_AFT, 2, 0, 53, H_NONE, 0, 0,
  267.       NULL, NULL, NULL, NULL, NULL  },
  268.    {  "Yes", 'Y', ITM_ALL, 3, 0, 54, H_NONE, 0, 0,
  269.       NULL, NULL, NULL, NULL, NULL  }
  270. };
  271. LCL   MbldT CDC   QitMnu =             /*- "Quit" pulldown menu --------*/
  272. {  &QitItm[0], 2,  2, 60,  7, 78, MNU_PUL, BOX_SNG, LGREY|_BLUE,
  273.    _BLUE, YELLOW|_BLUE, LCYAN|_BLUE, WHITE|_BLUE, YELLOW|_MAGENTA,
  274.    53, DispSureMsg,  0, 17, 7, 0xFF, 0xFF, 0xFF
  275. };
  276.  
  277. LCL   IbldT CDC   TopItm[6] =          /*- Main bar items --------------*/
  278. {  {  "File",     'F', ITM_PUL, 0,  2, 19, H_FILE,     Key_A_F, 0,
  279.       NULL,       NULL,      NULL,       NULL, &FilMnu  },
  280.    {  "Editing",  'E', ITM_PUL, 0, 15, 28, H_EDITING,  Key_A_E, 0,
  281.       NULL,       NULL,      NULL,       NULL, &EdtMnu  },
  282.    {  "Defaults", 'D', ITM_PUL, 0, 31, 36, H_DEFAULTS, Key_A_D, 0,
  283.       NULL,       NULL,      NULL,       NULL, &DefMnu  },
  284.    {  "Run",      'R', 0,       0, 47, 45, H_RUN,      Key_A_R, 0,
  285.       NULL,       PopupDemo, NULL,       NULL, NULL    },
  286.    {  "Options",  'O', ITM_PUL, 0, 59, 46, H_OPTIONS,  Key_A_O, 0,
  287.       NULL,       NULL,      NULL,       NULL, &OptMnu  },
  288.    {  "Quit",     'Q', ITM_PUL, 0, 73, 52, H_NONE,     Key_A_Q, 0,
  289.       QuitWindow, NULL,      QuitWindow, NULL, &QitMnu  }
  290. };
  291. LCL   MbldT CDC   TopMnu =             /*- Main bar menu ---------------*/
  292. {  &TopItm[0], 6,  1,  1,  1, 0, MNU_HOR, BOX_SPA, CYAN,
  293.    CYAN|_BLUE, YELLOW|_BLUE, LCYAN|_BLUE, 0, YELLOW|_MAGENTA,
  294.    19, NULL,  0,  0,  0, 0xFF, 0xFF, 0xFF
  295. };
  296.  
  297. LCL   IbldT CDC   PopItm[6] =          /*- Pop-up menu items -----------*/
  298. {  {  "Add",    'A', 0, 0,  0, 55, H_NONE, 0, 0,
  299.       NULL, NULL, NULL, "Create a new record",                  NULL  },
  300.    {  "Delete", 'D', 0, 0,  8, 56, H_NONE, 0, 0,
  301.       NULL, NULL, NULL, "Delete an existing record",            NULL  },
  302.    {  "Print",  'P', 0, 0, 19, 57, H_NONE, 0, 0,
  303.       NULL, NULL, NULL, "Print hardcopy of existing record",    NULL  },
  304.    {  "Show",   'S', 0, 0, 28, 58, H_NONE, 0, 0,
  305.       NULL, NULL, NULL, "Display an existing record on screen", NULL  },
  306.    {  "Update", 'U', 0, 0, 36, 59, H_NONE, 0, 0,
  307.       NULL, NULL, NULL, "Modify an existing record",            NULL  },
  308.    {  "Quit",   'Q', 0, 0, 45, 60, H_NONE, 0, 0,
  309.       NULL, NULL, NULL, "Quit and return to pull-down menu",    NULL  }
  310. };
  311. LCL   MbldT CDC   PopMnu =             /*- Pop-up menu -----------------*/
  312. {  &PopItm[0], 6,  7, 15, 10, 65, MNU_HOR, BOX_SNG, LRED,
  313.    LCYAN|_BLUE, LMAGENTA|_BLUE, WHITE|_BLUE, 0, YELLOW|_LGREY,
  314.    55, NULL,  0, 0, 0, 1, 0, LGREEN|_BLUE
  315. };
  316.  
  317. /*=========[ The TCXL Menu Demo, a simulated editor interface ]=========*
  318.  | Called from the [M]enuing item of the UserDemo.C main menu
  319.  *----------------------------------------------------------------------*/
  320.  
  321. VOID  CTYP  MenuDemo(NOARG)
  322. {
  323.    IntT     s = 0;
  324.    IntT     Lines;
  325.    IntT     Line1 = 0, Line2 = 0;
  326.    VcelFP   VidArea;
  327.  
  328.    KbndIdle(UpdateClock);              /* start clock display           */
  329.    HlpPush(H_PULLDOWN);                /* push help category            */
  330.  
  331. #ifndef TCXLDBG
  332. #if(_TCXL_cc_ != 2) && !defined(_TCXLos2_)  /* not for Zortech or OS/2  */
  333.    _CerrPush(_IFFPCP(_AltCrit));       /* install alternate CritErr     */
  334. #endif
  335. #endif
  336.  
  337. #if !defined(_TCXLos2_)
  338.    if(_VuvAct)                         /* draw editor display           */
  339.       Lines = _VuvGet();
  340.    else
  341. #endif
  342.       Lines = VidDep;
  343.    cvtic(&Rmargin[16], VidWid - 8, 3);
  344.    VidArea = FarVsave(LGREY|_BLACK);
  345.    CurSave();                          /* save cursor state             */
  346. redraw:                                /* come here to redraw the menu  */
  347.    if((s == 37) || (s == 38))
  348.       KquePut('D');
  349.    else
  350.       if(Line1 != Line2)
  351.       {  if((s == 47) || (s >= 100))
  352.          {  KquePut('O');
  353.             KquePut('Z');
  354.          }
  355.       }
  356. #if !defined(_TCXLos2_)
  357.    if(_VuvAct)
  358.       Line1 = _VuvGet();
  359.    else
  360. #endif
  361.       Line1 = VidDep;
  362.    if(atoi(&Rmargin[16]) > VidWid - 3)
  363.       cvtic(&Rmargin[16], VidWid - 8, 3);
  364.    DrawEditor(atoi(&Lmargin[16]), atoi(&Rmargin[16]));
  365.  
  366.    TopMnu.menc = MsByt(VidWid - 2);    /* adjust end-column             */
  367.    MnuBuild(&TopMnu);                  /* build the menu tree           */
  368.  
  369.    s = MnuGet();                       /* process the menu              */
  370.  
  371.    while(KbndClr(Key_M_ClkL) == 0)     /* clear left mouse macros       */
  372.       ;
  373.  
  374.    if(s == -1 && TcxlErr > W_ESCPRESS)
  375.       ErrorExit(1);                    /* windowing error!              */
  376.  
  377.    Wclose();                           /* close up windows              */
  378.    Wclose();
  379. #if !defined(_TCXLos2_)
  380.    if(_VuvAct)
  381.       Line2 = _VuvGet();
  382.    else
  383. #endif
  384.       Line2 = VidDep;
  385.    if((s == 37) || (s == 38) || (s == 47) || (s >= 100))
  386.       goto redraw;
  387. #if !defined(_TCXLos2_)
  388.    if(_VuvAct)                         /* Ultravision                   */
  389.    {  if(Lines != _VuvGet())
  390.          _VuvSet(Lines);
  391.    }
  392.    else                                /* ordinary BIOS                 */
  393. #endif
  394.    {  if(Lines != VidDep)
  395.          VsetLin(Lines);
  396.    }
  397.    CurPop();                           /* restore cursor                */
  398.    FarVrestore(VidArea);               /* restore screen                */
  399.    KbndIdle(NULL);                     /* kill the clock                */
  400.    HlpDrop();                          /* pop the help stack            */
  401.  
  402. #ifndef TCXLDBG
  403. #if(_TCXL_cc_ != 2) && !defined(_TCXLos2_) /* not for Zortech or OS/2   */
  404.    _CerrPop();                         /* restore CritErr-handler       */
  405. #endif
  406. #endif
  407.  
  408.    MoveBarDn();                        /* select next main-menu item    */
  409. }  /* MenuDemo() */
  410.  
  411. /*------------------------[ Change screen size ]------------------------*/
  412.  
  413. LCL   VOID  CTYP  ChangeSize(NOARG)
  414. {
  415.    IntT   s, t, w;
  416.  
  417.    CurSave();                          /* save cursor state             */
  418.    w = VidWid;                         /* current video width           */
  419. #if !defined(_TCXLos2_)
  420.    if(_VuvAct)                         /* UltraVision active            */
  421.    {  t = ValidModes();                /* display selection list        */
  422.       s = SelStr(4, 45, 12, 74, 0, LGREY|_BLUE, YELLOW|_BLUE,
  423.             YELLOW|_MAGENTA, UvVal, t, NULL);
  424.  
  425.       if(s >= 0)                       /* set selected mode             */
  426.          _VuvSet(UvMd[s]);
  427.    }
  428.    else                                /* no UltraVision                */
  429. #endif
  430.    {  if(VidWid != 80)                 /* has to be 80 columns          */
  431.          Wperror("Invalid Screen Width to Demonstrate");
  432.  
  433.       else                             /* EGA or higher BIOS            */
  434.       {  if(_VidTyp() != -1)           /* select number of lines        */
  435.             s = SelStr(4, 57, 8, 71, 0, LGREY|_BLUE, YELLOW|_BLUE,
  436.                    YELLOW|_MAGENTA, LinArr,
  437.                    ((VidDep == 43) ? 1 : ((VidDep == 50) ? 2 : 0)), NULL);
  438.             switch(s)
  439.             {  case 0:
  440.                   s = 25;
  441.                   break;
  442.  
  443.                case 1:
  444.                   s = 43;
  445.                   break;
  446.  
  447.                case 2:
  448.                   s = 50;
  449.                   break;
  450.             }
  451.             if(s > 2)
  452.                VsetLin(s);
  453.       }
  454.    }
  455.    if(w != VidWid)                     /* update right margin           */
  456.       cvtic(&Rmargin[16], VidWid - 8, 3);
  457.    CurPop();                           /* restore cursor-state          */
  458. }
  459.  
  460. /*--------[ Display a quick 'n' dirty directory of current path ]-------*
  461.  | Uses new TCXL  functions that are compiler independent                                    ]
  462.  *----------------------------------------------------------------------*/
  463.  
  464. LCL   VOID  CTYP  Directory(NOARG)
  465. {
  466.    ChrT        fs[49], f1[49];
  467.    IntT        i, f, l, n;
  468.    _FfbT       fb;
  469.  
  470.    strcpy(fs, "*.*");
  471.    CurPush(CUR_SHO, -1, -1, -1);       /* show cursor, save state       */
  472.    if(ERR_ARG == Wopen(4, 14, 20, 59, 0, /* open the window             */
  473.       YELLOW|_BLUE, YELLOW|_BLUE))
  474.       ErrorExit(1);                    /* windowing error!              */
  475.  
  476.    Wtitle("[ Directory ]", TTL_CNT, YELLOW|_BLUE);
  477.                                        /* open form window, define form */
  478.    if(ERR_ARG == Wopen(6, 6, 8, 49, 0, LCYAN|_RED, LCYAN|_RED))
  479.       ErrorExit(1);                    /* windowing error!              */
  480.  
  481.    Wtitle("[ Filespec ]", TTL_CNT, LCYAN|_RED);
  482.    EntDef(BLUE|_LGREY, BLUE|_LGREY, 1);
  483.    EntFld(0, 1, fs, "WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW",
  484.       FLD_TRM, 13, 2, NULL, H_EDITKEYS);
  485.    i = EntGet(13);                     /* get user input, close window  */
  486.    Wclose();
  487.    if(13 == i)
  488.    {  Wclear();                        /* clear directory window        */
  489.       WsetTxt(LCYAN|_BLUE);            /* set text attribute            */
  490.       l = n = 0;
  491.       f = _FndFst(fs, &fb, 0);         /* build the directory display   */
  492.       LOOP                             /*- endless loop ----------------*/
  493.       {  if(f)                         /* nothing found                 */
  494.             break;
  495.  
  496.          f1[0] = '\0';
  497.          for(i = 0; (i < 3) && !f; i++)
  498.          {  n++;                       /* next line                     */
  499.             sprintf(fs, "%s%-15s", f1, _FfbNam(fb));
  500.             strcpy(f1, fs);
  501.             f = _FndNxt(&fb);          /* find next file                */
  502.          }
  503.          strtrim(f1);
  504.          Wputf(" %s\n", f1);
  505.          l++;
  506.          if(l >= 14)                   /* more files to display ...     */
  507.          {  Wputf("\033" "A\x1A Press a key to continue....\033" "A\x1B");
  508.             i = (ChrT) KeyTime(36);
  509.             Wputf("\r");
  510.             if(i == ESC)
  511.                break;
  512.             l = 0;
  513.          }
  514.       }
  515.                                        /* display summary               */
  516.       Wputf("\033" "A\x1A Files found:  %d  Press a key....", n);
  517.       KeyTime(36);
  518.    }
  519.    CurPop();                           /* restore cursor state          */
  520.    Wclose();                           /* close the window              */
  521. }  /*Directory() */
  522.  
  523. /*-------------------[ Display "Are you sure" prompt ]------------------*/
  524.  
  525. LCL   VOID  CTYP  DispSureMsg(NOARG)
  526. {
  527.    Wprts(0, 2, WHITE|_BLUE, "Are you sure?");
  528. }  /* DispSureMsg() */
  529.  
  530. /*---------------[ Dummy function for several menu items ]--------------*/
  531.  
  532. LCL   VOID  CTYP  DoNothing(NOARG)
  533. {
  534. }  /* DoNothing() */
  535.  
  536. /*---------------------[ Draw a fake editor screen ]--------------------*/
  537.  
  538. LCL   VOID  CTYP  DrawEditor(IntT Lmar, IntT Rmar)
  539. {
  540.    IntT i = 0, j;
  541.  
  542.    if(ERR_ARG == Wopen(0, 0, VidDep - 1, VidWid - 1, 0, CYAN, CYAN))
  543.       ErrorExit(1);                    /* can't open the window!        */
  544.  
  545.    WdrwHor(1, 0, MsByt(VidWid - 2),    /* draw the editor screen        */
  546.       0, CYAN);
  547.    if(ERR_ARG == Wopen(3, Lmar + 1, VidDep - 2, Rmar + 1, BOX_SPA, CYAN, 
  548.          CYAN))
  549.       ErrorExit(1);                    /* can't open the window!        */
  550.  
  551.    Wgotoxy(0, 0);                      /* home the cursor               */
  552.    WsetTxt(YELLOW);                    /* set text attribute            */
  553.  
  554.    while(Edemo[i]  != NULL)            /* display the sample text       */
  555.       Wputsw(Edemo[i++]);
  556.  
  557.    if(MouEnab)                         /* gee, we've got rats!          */
  558.    {  i++;
  559.       while(Edemo[i]  != NULL)         /* display the sample text       */
  560.          Wputsw(Edemo[i++]);
  561.  
  562.       WposGet(&j, &i);                 /* current text-row              */
  563.       Wgotoxy(MsAtr(j+1),MsAtr(19));
  564.       j = WdfPosR(WctlAct);
  565.       i = WdfPosC(WctlAct);
  566.                                        /* set hot spot to position      */
  567.       KbndMou(Key_M_ClkL, TcxlInfo, j, i, 11);
  568.       KbndMou(Key_M_ClkL, EntryDemo, j, i + 16, 10);
  569.       KbndMou(Key_M_ClkL, SelectDemo, j, i + 31, 11);
  570.       Wputs("\033XInformation\033X     \033XEntry Demo\033X"
  571.          "    \033XSelect Demo\033X");
  572.    }
  573.  
  574.    WposGet(&j, &i);                    /* current text-row              */
  575.    j++;
  576.  
  577.    i = 0;
  578.    do
  579.    {  WprtCen(MsByt(TcxlI[i].row + j), TcxlI[i].Atr, TcxlI[i].Str);
  580.    }  while(++i < 6);
  581.  
  582. }  /* DrawEditor() */
  583.  
  584. /*-----------------------[ Execute a DOS command ]----------------------*/
  585.  
  586. LCL   VOID  CTYP  Execute(NOARG)
  587. {
  588.    ChrT        cd[61];
  589.  
  590.    if(ERR_ARG == Wopen(8, 7, 10, 70, 0, LGREY|_RED, LGREY|_RED))
  591.       ErrorExit(1);
  592.  
  593.    Wtitle("[ Execute DOS Command ]", TTL_CNT, LGREY|_RED);
  594.    EntDef(BLUE|_LGREY, BLUE|_LGREY, 1);
  595.    EntFld(0, 1, cd,
  596.       "************************************************************",
  597.       FLD_TRM, 14, 0, NULL, H_EDITKEYS);
  598.    if(14 == EntGet(14))                /* display the form              */
  599.       OsShell1(cd);                    /* shell out with command        */
  600.    Wclose();                           /* close window                  */
  601. }  /* Execute() */
  602.  
  603. /*-----------[ The [O]S Shell function under the [F]ile menu ]----------*/
  604.  
  605. LCL   VOID  CTYP  OsShell(NOARG)
  606. {
  607.    OsShell1("");                       /* shell out with no command     */
  608. }  /* OsShell() */
  609.  
  610. /*------------------[ Do the real work for OsShell() ]------------------*/
  611.  
  612. LCL   VOID  CTYP  OsShell1(ChrP Cmd)
  613. {
  614.    VcelFP   s;
  615.    ChrT     c;
  616.  
  617.    c = *Cmd;
  618.    CurPush(CUR_SHO, -1, -1, -1);       /* show cursor, save state       */
  619.    MouHide();                          /* hide mouse if shown           */
  620.    s = FarVsave(LGREY|_BLACK);         /* save the screen               */
  621.    if(c == EOS)                        /* no command -- need an 'Exit'  */
  622.       printf("Type EXIT to return....\n");
  623.  
  624. #if defined(__IBMAIX__) || defined(__SCOXENIX__)
  625.    _TTYshell(Cmd);                     /*  so TTY is cleaned up     jpl */
  626. #else
  627.    system(Cmd);                        /* send the command to DOS       */
  628. #endif
  629.  
  630.    if(c != EOS)                        /* got a command -- wait for key */
  631.    {  printf("Press a key to return....\n");
  632.       KeyWait();
  633.    }
  634.    FarVrestore(s);                     /* restore screen                */
  635.    CurPop();                           /* restore cursor                */
  636.    MouShow();                          /* show the mouse if we hid it   */
  637. }  /* OsShell1() */
  638.  
  639. /*--------[ Display a sample popup menu with text descriptions ]--------*/
  640.  
  641. LCL   VOID  CTYP  PopupDemo(NOARG)
  642. {
  643.    HlpPush(H_PULLDOWN);                /* set help category             */
  644.    MnuBuild(&PopMnu);                  /* build the pop-up menu         */
  645.    MnuGet();                           /* display the menu              */
  646.    HlpDrop();                          /* drop help category            */
  647. }  /* PopupDemo() */
  648.  
  649. /*---------------[ Display the [Q]uit item pop-up window ]--------------*
  650.  | Called anytime the selection bar moves on or off a [Q]uit menu item.
  651.  *----------------------------------------------------------------------*/
  652.  
  653. LCL   VOID  CTYP  QuitWindow(NOARG)
  654. {
  655.    LCL WndT    h = 0;
  656.  
  657.    if(h)
  658.    {  Wactiv(h);                       /* activate window               */
  659.       Wclose();                        /* then close it                 */
  660.       h = 0;
  661.    }
  662.    else                                /* open window                   */
  663.    {  h = Wopen(14, 41, 17, 70, 0, YELLOW|_RED, WHITE|_RED);
  664.       Wputs(" Quit takes you back to the\n demo program's main menu.");
  665.    }
  666. }  /* QuitWindow() */
  667.  
  668. /*------[ Get new [R]ight margin setting for the [D]efault menu ]-------*/
  669.  
  670. LCL   VOID  CTYP  RMargin(NOARG)
  671. {
  672.    EntDef(WHITE|_CYAN, WHITE|_CYAN, 1);
  673.    EntFld(IdfPosR(ItmCur()), 17, (IdfStr(ItmCur())) + 16,
  674.          "999", FLD_DEC, 15, 1, ValidMarg, 0);
  675.    EntGet(15);
  676.    ItmDsp((IdfTag(ItmCur())));
  677. }  /* RMargin() */
  678.  
  679. /*--------------------[ Set up the [D]efaults menu ]--------------------*/
  680.  
  681. LCL   VOID  CTYP  SetupMenu(NOARG)
  682. {
  683.    WdrwHor(3, 0, 21, 0, LGREY|_BLUE);
  684.    WdrwHor(8, 0, 21, 0, LGREY|_BLUE);
  685. }  /* SetupMenu() */
  686.  
  687. /*-------[ Toggle "block marking" on and off in the fake editor ]-------*/
  688.  
  689. LCL   VOID  CTYP  ToggleBlock(NOARG)
  690. {
  691.    LCL IntT    b = OFF;
  692.    IntT c;
  693.  
  694.    if(b)
  695.    {  b = OFF;
  696.       c = 32;
  697.    }
  698.    else
  699.    {  b = ON;
  700.       c = 33;
  701.    }
  702.    ItmEna(c);
  703.    ItmDis(c ^ 0x01);
  704.    ItmNxt(c);
  705.    if(ERR_ARG != Wopen(11, 30, 15, 49, 0, LGREY|_MAGENTA, WHITE|_MAGENTA))
  706.    {  Wputf("\n Block is now o%s", b ? "n" : "ff");
  707.       _Delay(10);
  708.       Wclose();
  709.    }
  710. }
  711.  
  712. /*------[ Toggles the yes/no status of some pull-down menu items ]------*
  713.  | This is to show modifying and redisplaying a menu item's string. We do
  714.  | this by getting the address of the current item's struct, then
  715.  | modifying the string pointed to by the istr element.  The redisp flag
  716.  | is set so that when you return to the menu, the screen will be
  717.  | automatically updated.
  718.  *----------------------------------------------------------------------*/
  719.  
  720. LCL   VOID  CTYP  ToggleYN(NOARG)
  721. {
  722.    IdfP i;
  723.    ChrP s, y;
  724.    LCL ChrT yes[] = "yes", no[] = " no";
  725.  
  726.    i = ItmCur();
  727.    s = ItmGet(IdfTag(i));
  728.    y = s + strlen(s) - 3;
  729.    strcpy(y, strcmp(y, yes) ? yes : no);
  730.    ItmDsp(IdfTag(i));
  731. }
  732.  
  733. /*------------[ Update the on-screen clock once per second ]------------*/
  734.  
  735. LCL   VOID  CTYP  UpdateClock(NOARG)
  736. {
  737.    LCL DwdT    t;
  738.    DwdT x;                             /* make a little faster      jpl */
  739.  
  740.    if(t < (x = _Timer()))
  741.    {  Vprints(0, 70, LGREEN, SysTime(1));
  742.       t = x + 18;
  743.    }
  744. }
  745.  
  746. /*--------[ Validates the [R]ight margin setting from RMargin()   ]-----*/
  747.  
  748. ChrT Lft[] = "Left Margin Too Large!";
  749. ChrT Rgt[] = "Right Margin Too Small!";
  750. LCL   IntT  CTYP  ValidMarg(ChrP Input)
  751. {
  752.    IntT Val, Err = 0;
  753.    ChrP Msg;
  754.  
  755.    Val = cvtci(Input);
  756.  
  757.    if((Val > (VidWid - 3)) || (Val < 0))
  758.    {  Wperror("Invalid Margin!");
  759.       Err = 1;
  760.    }
  761.    if(IdfTag(ItmCur()) == 37)
  762.    {  if(Val >= cvtci(&Rmargin[16]))
  763.       {  Msg = Lft;
  764.          goto e2;
  765.       }
  766.    }
  767.    else
  768.    {  if(cvtci(&Lmargin[16]) >= Val)
  769.       {  Msg = Rgt;
  770. e2:      Wperror(Msg);
  771.          Err = 1;
  772.       }
  773.    }
  774.    return(Err);
  775. }
  776.  
  777. #if !defined(_TCXLos2_)
  778. /*--------------[ Build arrays of valid Ultravision modes ]-------------*/
  779.  
  780. LCL   IntT  CTYP  ValidModes(NOARG)
  781. {
  782.    int   i, n, q, r;
  783.  
  784.    q = _VuvGet();
  785.    n = 0;
  786.  
  787.    for(i = 0; UvMode[i] != 0; i++)
  788.    {  if(_VuvVal(UvMode[i]) == 0)
  789.       {  UvVal[n] = UvArr[i];
  790.          UvMd[n++] = UvMode[i];
  791.          if(q == UvMode[i])
  792.             r = n - 1;
  793.       }
  794.    }
  795.    UvVal[n] = NULL;
  796.    return(r);
  797. }
  798. #endif
  799.