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