home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / txcl552 / demo / demomisc.c next >
Encoding:
C/C++ Source or Header  |  1991-06-22  |  18.3 KB  |  462 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:   demomisc.c     552.13   22 Jun 1991 14:03:44  $
  9.  |
  10.  | $Log:   demomisc.c    $
  11.  *-D--------------------------------------------------------------------*
  12.  | DemoMisc.C : Miscellaneous common utility functions for the various
  13.  | TCXL demonstration programs.
  14.  *-N-----------------------[ Notes and Caveats ]------------------------*
  15.  | 1) FarVsave() and FarVrestore() will ONLY work correctly in small-data
  16.  |    models (small, medium).  In large-data models (compact, large),
  17.  |    they may fail due to heap collisions.  There's only a far heap in
  18.  |    large-data.
  19.  *======================================================================*/
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include "demo\TCXLdemo.h"             /* TCXL demo-specific            */
  24. #if(_TCXL_cc_ == 1)                    /* needed for Turbo C            */
  25. #  include <alloc.h>
  26. #endif
  27. #if(_TCXL_cc_ == 2)                    /* needed for Zortech            */
  28. #  include <dos.h>
  29. #endif
  30. #if(_TCXL_cc_ == 3)                    /* needed for MicroSoft C        */
  31. #  include  <malloc.h>
  32. #  define     farmalloc(s)   _fmalloc(s)
  33. #  define     farfree(p)     _ffree(p)
  34. #endif
  35. #if(_TCXL_cc_ == 4)                    /* needed for TopSpeed C         */
  36. #  include <alloc.h>
  37. #endif
  38. #include <TCXLmem.h>                   /* TCXL memory system            */
  39. #include <TCXLfar.h>                   /* TCXL far-memory               */
  40. #include <TCXLcod.h>                   /* TCXL key-codes                */
  41. #include <TCXLnls.h>                   /* TCXL NLS sub-system           */
  42.  
  43. /*----------------------------[ Global data ]---------------------------*/
  44.  
  45. #define  INFO_CNT 14
  46. INFO TcxlI[INFO_CNT] =  /* text displayed in Information screen         */
  47. {  {  1, WHITE|_RED,
  48.      "The TesSeRact(TM) CXL User Interface Development System" },
  49.    {  2, WHITE|_RED,
  50.       "Copyright (c) 1987-1991, Innovative Data Concepts" },
  51.    {  3, WHITE|_RED,
  52.       "All Rights Reserved" },
  53.    {  5, BLACK|_RED,
  54.       "TCXL is a Full-Featured C Development System that supports" },
  55.    {  6, BLACK|_RED,
  56.       "Microsoft, Borland, Zortech, JPI, C Compilers (for DOS)," },
  57.    {  7, BLACK|_RED,
  58.       "as well as portability to Unix, OS/2 and 386 Protected Mode" },
  59.    {  9, WHITE|_RED, "Innovative Data Concepts" },
  60.    { 10, WHITE|_RED, "122 North York Road, Suite 5" },
  61.    { 11, WHITE|_RED, "Hatboro, PA 19040 USA" },
  62.    { 12, WHITE|_RED, "1-215-443-9705 (Support)" },
  63.    { 13, WHITE|_RED, "1-800-926-4551 (Sales)" },
  64.    { 14, WHITE|_RED, "1-215-443-9753 (FAX)" },
  65.    { 15, WHITE|_RED, "CompuServe 76702,1361" },
  66.    { 16, WHITE|_RED, "MCIMAIL 315-5415" },
  67. };
  68.  
  69. /*----------------------------[ Local data ]----------------------------*/
  70.  
  71. LCL   VcelFP   CDC   savescrn;         /* ptr to saved DOS screen       */
  72.  
  73. LCL   ChrP  CDC   error_text[] =       /* global error message table    */
  74. {  NULL,                               /* errnum = 0, no error          */
  75.    NULL,                               /* errnum = 1, windowing error   */
  76.    "Usage : TCXLDEMO [-switches]\n\n"  /* errnum = 2, syntax error      */
  77.    "\t-c = CGA snow elimination\n"
  78.    "\t-b = BIOS screen writing\n"
  79.    "\t-m = force monochrome text attributes",
  80.    "Out of memory!",                   /* errnum = 3, out of memory     */
  81.    "Far Heap Exhausted!"               /* errnum = 4, out of far heap   */
  82. };
  83.  
  84. LCL   ChrP CDC QuitMsg = "\n Quit demo, are you sure? \033A\156Y\b";
  85.  
  86. /*================[ Add a shadow to the current window ]================*/
  87.  
  88. VOID  CTYP  AddShadow(NOARG)
  89. {
  90.    Wshadow(LGREY|_BLACK);              /* simple, ain't it?             */
  91. }  /* AddShadow() */
  92.  
  93. /*===============[ Confirm the user really wants to quit ]==============*/
  94.  
  95. VOID  CTYP  ConfirmQuit(NOARG)
  96. {
  97.    KbndP    kblist;
  98.  
  99.    MouHide();                          /* hide mouse, if visible        */
  100.    kblist = KbndChg(NULL);             /* hide any existing hot keys    */
  101.  
  102.    if(ERR_ARG == Wopen(9, 26, 13, 55, 0, /* pop up a confirmation window*/
  103.          WHITE|_BROWN, WHITE|_BROWN))
  104.       ErrorExit(1);                    /* windowing error!              */
  105.  
  106.    AddShadow();                        /* add shadow, ask user          */
  107.    QuitMsg[30] = NlsYes;
  108.    Wputs(QuitMsg);
  109.    KeyClear();                         /* flush any lurking keys        */
  110.    CurPush(CUR_SHO, -1, -1, -1);       /* show cursor, save state       */
  111.    if(KwGetYn(NlsYes) == 'Y')          /* user said quit                */
  112.       NormalExit();
  113.  
  114.    Wclose();                           /* close window                  */
  115.    CurPop();                           /* restore cursor                */
  116.    KbndChg(kblist);                    /* restore any hidden hot keys   */
  117.    MouShow();                          /* show the mouse, if we hid it  */
  118. }  /* ConfirmQuit() */
  119.  
  120. /*=======================[ Abnormal termination ]=======================*
  121.  | If <e> is 1, it's a windowing system error.  Otherwise look up the
  122.  | error in the error message table.
  123.  *----------------------------------------------------------------------*/
  124.  
  125. VOID  CTYP   ErrorExit(IntT e)
  126. {
  127.    if(e)
  128.    {  if(e == 1)                       /* window-system error           */
  129.       {  if(Wperror(WerrMsg()))        /* use window if possible    jpl */
  130.             Werror();
  131.       }
  132.       else                             /* look up error message         */
  133.       {  if (Wperror(error_text[e]))   /* use window if possible    jpl */
  134.             printf("\n%s\n", error_text[e]);
  135.       }
  136.       CurPop();                        /* restore cursor                */
  137.       exit(e);                         /* _TcxlTerm() will clean up     */
  138.    }
  139. }  /* ErrorExit() */
  140.  
  141. /*===============[ Save the screen image on the far heap ]==============*/
  142.  
  143. #if (_TCXL_dat_ == 0)      /* small data memory models -- use far heap  */
  144.  
  145. VcelFP   CTYP  FarVsave(AtrT Atr)
  146. {
  147.    VcelFP   FarPtr;
  148.    VcelP    NearPtr;
  149. #if   (_TCXL_cc_ == 2)                 /* Zortech uses a DwdT           */
  150.    DwdT     sz;
  151. #else                                  /* everybody else uses a WrdT    */
  152.    WrdT     sz;
  153. #endif
  154.  
  155.    if(NULL == (NearPtr = Vsave()))     /* normal Vsave()                */
  156.       ErrorExit(3);                    /* out of memory!                */
  157.  
  158.    sz = (VidDep * VidWid * SIZ(VcelT)) + 1;
  159.    if(NULL == (FarPtr = (VcelFP)farmalloc(sz)))
  160.       ErrorExit(4);                    /* out of far heap!              */
  161.  
  162.    _PutFar((BytFP)FarPtr, (BytP)NearPtr, sz);   /* copy to far heap     */
  163.    free(NearPtr);                      /* free normal buffer            */
  164.    Vclear(Atr);                        /* clear the screen              */
  165.    return(FarPtr);                     /* return far-heap pointer       */
  166. }  /* FarVsave() */
  167.  
  168. #else                      /* large data memory models -- use near heap */
  169.  
  170. VcelFP   CTYP  FarVsave(AtrT Atr)
  171. {
  172.    VcelP    NearPtr;
  173.  
  174.    if(NULL == (NearPtr = Vsave()))     /* normal Vsave()                */
  175.       ErrorExit(3);                    /* out of memory!                */
  176.  
  177.    Vclear(Atr);                        /* clear the screen              */
  178.    return(NearPtr);                    /* return heap pointer           */
  179. }
  180.  
  181. #endif
  182.  
  183. /*===========[ Restore saved screen image from the far heap ]===========*/
  184.  
  185. #if (_TCXL_dat_ == 0)      /* small data memory models -- use far heap  */
  186.  
  187. VOID  CTYP  FarVrestore(VcelFP FarPtr)
  188. {
  189.    VcelP    NearPtr;
  190.    WrdT     sz;
  191.  
  192.    sz = (VidDep * VidWid * SIZ(VcelT)) + 1;
  193.    if(NULL == (NearPtr = (VcelP) malloc(sz)))
  194.       ErrorExit(3);                    /* out of memory!                */
  195.  
  196.    _GetFar((BytP)NearPtr, (BytFP)FarPtr, sz);   /* copy from far heap   */
  197.    farfree(FarPtr);                    /* free far buffer               */
  198.    Vrestore(NearPtr);                  /* restore the screen            */
  199. }  /* FarVrestore() */
  200.  
  201. #else                      /* large data memory models -- use near heap */
  202.  
  203. VOID  CTYP  FarVrestore(VcelFP FarPtr)
  204. {
  205.    Vrestore(FarPtr);
  206. }
  207.  
  208. #endif
  209.  
  210. /*===============[ Initialize TCXL for the demo program ]===============*/
  211.  
  212. VOID  CTYP  Initialize(NOARG)
  213. {
  214.    TcxlInit();                         /* general initialization        */
  215.    KextOff();                          /* no extended key BIOS          */
  216.    CurPush(CUR_HID, CUR_NOR, 0, 0);    /* save the cursor state, hide   */
  217.                                        /*    and home the cursor        */
  218.    savescrn = FarVsave(LGREY|_BLACK);  /* save the screen               */
  219.  
  220.    KbndSet(Key_A_X, ConfirmQuit, 0);   /* bind [Alt-X] to ConfirmQuit() */
  221.  
  222.    HlpDef("TCXLDEMO.HLP", Key_F1,      /* initialize help system,       */
  223.       YELLOW|_RED, YELLOW|_RED,        /*  help key = [F1]              */
  224.       LRED|_RED, WHITE|_RED, RED|_LGREY, BOX_DBL, _VFVCP(PreHelp));
  225.  
  226.    LeftRow = ((VidDep - 1) / 2) - 5;   /* set up display coordinates    */
  227.    RightRow = LeftRow + 6;
  228.    LeftCol = ((VidWid - 1) / 2) - 9;
  229.    RightCol = LeftCol + 19;
  230.  
  231. }  /* Initialize() */
  232.  
  233. /*================[ Define and process a main demo menu ]===============*
  234.  | First, push global help category onto help stack, so that when [F1] is
  235.  | pressed while the selection bar is on an item without help, the global
  236.  | help category will be used. Build the main menu defined by the Mbld
  237.  | object at <mp> and process it
  238.  *----------------------------------------------------------------------*/
  239.  
  240. VOID  CTYP  MainMenu(MbldP mp)
  241. {
  242.    HlpPush(H_GLOBAL);                  /* push global help catagory     */
  243.  
  244.    MnuBuild(mp);                       /* define the main menu          */
  245.    if(MnuGet() == -1)                  /* process the menu              */
  246.       if(TcxlErr > W_ESCPRESS)
  247.          ErrorExit(1);                 /* window error                  */
  248.  
  249.    HlpDrop();                          /* pop help category off stack   */
  250. }  /* MainMenu() */
  251.  
  252. /*===========[ Move the selection bar down in the Main Menu ]===========*
  253.  | Select the next menu item by getting the address of the current menu,
  254.  | then setting the current tag-id to the tag-id of the next menu item.
  255.  | If we had had not numbered the menu item tag-ids sequentially, this
  256.  | would not work.
  257.  *----------------------------------------------------------------------*/
  258.  
  259. VOID  CTYP  MoveBarDn(NOARG)
  260. {
  261.    REG TagT t = IdfTag(ItmCur());
  262.    if(t < 10)                          /* from main menu only           */
  263.       ItmNxt(t + 1);                   /* select next item              */
  264. }  /* MoveBarDn() */
  265.  
  266. /*========================[ Normal termination ]========================*
  267.  | Restore the original screen and cursor before exiting to DOS with
  268.  | ERRORLEVEL 0.
  269.  *----------------------------------------------------------------------*/
  270.  
  271. VOID  CTYP  NormalExit(NOARG)
  272. {
  273.    FarVrestore(savescrn);              /* restore the screen            */
  274.    MouPop();                           /* restore the mouse             */
  275.    CurPop();                           /* restore the cursor            */
  276.    exit(0);                            /* _TcxlTerm() will clean up     */
  277. }  /* NormalExit() */
  278.  
  279.  
  280. /*==[ Main background, program title and system information windows ]===*/
  281.  
  282. ChrT Ins1[] = "INSTALLED";
  283. ChrT Ins2[] = "NOT INSTALLED";
  284.  
  285. VOID  CTYP  OpenBkgrnd(NOARG)
  286. {
  287.    ChrT  str[90];
  288.                                        /* demo background window        */
  289.    if(ERR_ARG == Wopen(0, 0, VidDep - 2, VidWid - 1, 5, 0, LGREEN|_GREEN))
  290.       ErrorExit(1);                    /* windowing error!              */
  291.  
  292.                                        /* system information pop-up     */
  293.    if(!WpopUp(CNT_HOR, VidDep - 8, 0, VidDep - 3, 60, 0, LGREY|_RED,
  294.          LGREY|_RED))
  295.       ErrorExit(1);                    /* windowing error!              */
  296.  
  297.    AddShadow();                        /* add a shadow, display status  */
  298.    sprintf(str, "DPMI Status: %s   VCPI Status: %s\n",
  299.       (MemDPMI ? Ins1 : Ins2),
  300.       (MemVCPI ? Ins1 : Ins2));
  301.    WputCen(str);
  302.  
  303.    sprintf(str, "Total EMS: %dK   Free EMS: %dK\n",
  304.       MemEtot * 16, MemEfre * 16);
  305.    WputCen(str);
  306.  
  307.    sprintf(str, "Free XMS: %dK   HMA is %s\n", MemXtot,
  308.       (MemHfre ? "AVAILABLE" : "IN USE"));
  309.    WputCen(str);
  310.  
  311.    sprintf(str, "Ultravision is %s   Screen Size is %dx%d",
  312.       (TcxlUv ? Ins1 : Ins2), VidWid, VidDep);
  313.    WputCen(str);
  314.  
  315.    WsetFil('\xB0');                    /* bottom status bar, fancy fill */
  316.    if(ERR_ARG == Wopen(VidDep - 1, 0, VidDep - 1, VidWid - 1, 5, 0, 
  317.          LGREY|_RED))
  318.       ErrorExit(1);                    /* windowing error!              */
  319.  
  320.    Wprts(0, 1, LGREY|_RED, "[F1]=Help");
  321.    WprtCen(0, LGREY|_RED, "Select demonstration to view.");
  322.    Wprtrj(0, MsByt(VidWid - 2), LGREY|_RED, "[Alt-X]=Quit");
  323.    WsetFil(' ');                       /* blank fill again              */
  324.                                        /* program title pop-up          */
  325.    if(!WpopUp(CNT_HOR, 0, 12, 4, 67, 0, LRED|_MAGENTA, LRED|_MAGENTA))
  326.       ErrorExit(1);                    /* windowing error!              */
  327.  
  328.    AddShadow();                        /* add a shadow, display text    */
  329.    WprtCen(0, WHITE|_MAGENTA,
  330.       "Welcome to the TesSeRact CXL Demonstration Program!");
  331.    WprtCen(2, LCYAN|_MAGENTA,
  332.       "Copyright (c) 1987-1991, Innovative Data Concepts");
  333. }  /* OpenBkgrnd() */
  334.  
  335. /*=======[ Parse the command line for valid invocation switches ]=======*
  336.  | If any valid switches are found, set the appropriate video variable.
  337.  | If any invalid switches are found, display a syntax message. <ac> and
  338.  | <av> are the <argc> and <argv> arguments to main().
  339.  *----------------------------------------------------------------------*/
  340.  
  341. VOID  CTYP  ParseCmdLine(IntT ac, ChrP av[])
  342. {
  343.    REG IntT    i, j;
  344.    ChrP        p;
  345.  
  346.    for(i = 1; i < ac; i++)
  347.    {  p = av[i];
  348.       if(*p == '-' || *p == '/')
  349.       {  for(j = 1; *(p + j); j++)
  350.          {  switch(NlsToLower(*(p + j)))
  351.             {  case 'c':               /* CGA video                     */
  352.                   VidParm(VP_CGA);
  353.                   break;
  354.  
  355.                case 'b':               /* BIOS video                    */
  356.                   VidParm(VP_BIO);
  357.                   break;
  358.  
  359.                case 'm':               /* monochrome video              */
  360.                   VidParm(VP_MON);
  361.                   break;
  362.  
  363.                default:                /* unknown switch                */
  364.                   ErrorExit(2);        /* syntax error!                 */
  365.             }
  366.          }
  367.       }
  368.       else                             /* unknown parameter             */
  369.          ErrorExit(2);                 /* syntax error!                 */
  370.    }
  371. }  /* ParseCmdLine() */
  372.  
  373. /*======[ Parse a MMDDYY date string into separate numeric values ]=====*
  374.  | <b> is the date string, <m>, <d>, and <y> point to integers to receive
  375.  | the month, day and year
  376.  *----------------------------------------------------------------------*/
  377.  
  378. VOID  CTYP  ParseDate(ChrP b, IntP m, IntP d, IntP y)
  379. {
  380.    ChrT  t[7];
  381.  
  382.    strcpy(t, b);
  383.    *y = 1900 + atoi(t + 4);            /* year                          */
  384.    *(t + 4) = EOS;
  385.    *d = atoi(t + 2);                   /* day                           */
  386.    *(t + 2) = EOS;
  387.    *m = atoi(t);                       /* month                         */
  388. }  /* ParseDate() */
  389.  
  390. /*=======================[ Help "open" function ]=======================*
  391.  | Called when the user presses the help key and the help window is
  392.  | opened.
  393.  *----------------------------------------------------------------------*/
  394.  
  395. VOID  CTYP  PreHelp(NOARG)
  396. {
  397.    AddShadow();                        /* add a shadow to window        */
  398.    KbndSet(Key_A_X, ConfirmQuit, 0);   /* bind Alt[X] as exit key       */
  399. }  /* PreHelp() */
  400.  
  401. /*=====================[ Main menu "open" function ]====================*
  402.  | Called when the main demo menu window is opened.
  403.  *----------------------------------------------------------------------*/
  404.  
  405. VOID  CTYP  PreMenu1(NOARG)
  406. {
  407.    AddShadow();                        /* add a shadow                  */
  408. }  /* PreMenu1() */
  409.  
  410. /*======[ Display a pause message, then pause for for a keypress ]======*
  411.  | <r> is the window-row to display on.
  412.  *----------------------------------------------------------------------*/
  413.  
  414. VOID  CTYP  PressAKey(BytT r)
  415. {
  416.    PressAKey1(r, 36);                  /* wait for 2 seconds            */
  417. }  /* PressAKey() */
  418.  
  419. /*======[ Display a pause message, then pause for for a keypress ]======*
  420.  | <r> is the window-row to display on, <w> is the number of clock-ticks
  421.  | to wait.
  422.  *----------------------------------------------------------------------*/
  423.  
  424. VOID  CTYP  PressAKey1(BytT r, IntT w)
  425. {
  426.    AtrT a;
  427.  
  428.    if(DemoFast)                        /* check for window-demo delay   */
  429.       return;
  430.  
  431.    a = MsAtr((_BLINK|YELLOW)|(WdfDat(WctlAct) & (~WHITE)));      /* jpl */
  432.    WprtCen(r, a, "Press a key");       /* display message               */
  433.    if(w == -1)
  434.       KeyWait();                       /* wait for a key                */
  435.    else
  436.    {  if((ChrT)KeyTime(w) == ESC)      /* quit on [Esc]                 */
  437.          ConfirmQuit();
  438.    }
  439.    WprtCen(r, a, "           ");       /* erase message                 */
  440. }
  441.  
  442. /*=========[ Display window of information about TCXL and IDC ]=========*
  443.  | Called from the [I]nformation item in the main demo menu
  444.  *----------------------------------------------------------------------*/
  445.  
  446. VOID  CTYP  TcxlInfo(NOARG)
  447. {
  448.    IntT  i;
  449.  
  450.    if(!WpopUp(CNT_CNT, 3, 6, 21, 72, 0, WHITE|_RED, LMAGENTA|_RED))
  451.       ErrorExit(1);                    /* windowing error!              */
  452.  
  453.    AddShadow();                        /* add a shadow                  */
  454.  
  455.    for(i = 0; i < INFO_CNT; i++)       /* display the information       */
  456.       WprtCen(TcxlI[i].row, TcxlI[i].Atr, TcxlI[i].Str);
  457.  
  458.    KeyTime(200);                       /* wait for user to hit a key    */
  459.    Wclose();                           /* close the window              */
  460.    MoveBarDn();                        /* select next main-menu item    */
  461. }  /* TcxlInfo() */
  462.