home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / txcl552 / demo / entrdemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-06-22  |  17.2 KB  |  389 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:   entrdemo.c     552.13   26 Jun 1991 12:57:24  $
  9.  |
  10.  | $Log:   entrdemo.c    $
  11.  *-D--------------------------------------------------------------------*
  12.  | EntrDemo.C : Demonstration of the TCXL entry system.
  13.  *-N-----------------------[ Notes and Caveats ]------------------------*
  14.  | 1) Use the MakeDemo.Bat file to compile this file.
  15.  | 2) This demo makes use of new TCXL 5.52 EntBuild() and MnuBuild()
  16.  |    facilities.  See <TCXLent.h> and <TCXLmnu.h> for further
  17.  |    information about them
  18.  *======================================================================*/
  19. #include "demo\TCXLdemo.h"
  20. #include <TCXLstr.h>
  21. #include <TCXLent.h>
  22. #include <TCXLprn.h>
  23. #include <TCXLcod.h>
  24. #include <string.h>
  25.  
  26. LCL   VOID  CTYP  EntMode(BytT im);
  27.  
  28. /*----------------------------[ Local data ]----------------------------*/
  29.  
  30. #define  DEMO_CNT 13
  31.  
  32. LCL   ChrT  CDC   date[7];             /* entry field buffers           */
  33. LCL   ChrT  CDC   firstname[16];       /* ALLOW SPACE FOR TRAILING NUL! */
  34. LCL   ChrT  CDC   initial[2];
  35. LCL   ChrT  CDC   lastname[26];
  36. LCL   ChrT  CDC   address[41];
  37. LCL   ChrT  CDC   city[21];
  38. LCL   ChrT  CDC   state[3];
  39. LCL   ChrT  CDC   zipcode[10];
  40. LCL   ChrT  CDC   phone[11];
  41. LCL   ChrT  CDC   compiler[16];
  42. LCL   ChrT  CDC   amtenc[8];
  43. LCL   ChrT  CDC   comments[71];
  44. LCL   ChrT  CDC   company[41];
  45.  
  46. /*---------------------[ Local function prototypes ]--------------------*/
  47.  
  48. LCL   IntT  CTYP  CheckDate(ChrP b);
  49. LCL   VOID  CTYP  DisplayDate(NOARG);
  50. LCL   VOID  CTYP  EntMode(BytT im);
  51. LCL   KeyT  CTYP  GetKey(NOARG);
  52. LCL   VOID  CTYP  PickCompiler(NOARG);
  53.  
  54. /*----------[ Demo entry form-build and field-build objects ]-----------*
  55.  | These must be defined here to reference local functions.
  56.  *----------------------------------------------------------------------*/
  57.  
  58. LCL   FbldT   CDC   DemFld[DEMO_CNT] =    /*- field-build object list --*/
  59. {  {  "Date",        1,  3, date,         /* prompt, buffer             */
  60.        1, 16, "<01>#'/'<0123>#'/'##",     /* position, format           */
  61.       NULL, CheckDate, DisplayDate,       /* "before", "valid", "after" */
  62.       Key_A_D,  1, H_DATE,                /* hotkey, item-tag, help-tag */
  63.       FLD_TRM, 0, FLD_INI                 /* features, user, input-mode */
  64.    },
  65.    {  "First Name",  3,  3, firstname,    /* prompt, buffer             */
  66.        3, 16, "MMMMMMMMMMMMMMM",          /* position, format           */
  67.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  68.       Key_A_F,  2, H_FIRSTNAME,           /* hotkey, item-tag, help-tag */
  69.       FLD_TRM, 0, FLD_INI                 /* features, user, input-mode */
  70.    },
  71.    {  "Initial",     3, 37, initial,      /* prompt, buffer             */
  72.       3, 47, "U'.'",                      /* position, format           */
  73.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  74.       Key_A_I,  3, H_INITIAL,             /* hotkey, item-tag, help-tag */
  75.       FLD_TRM, 0, FLD_INI                 /* features, user, input-mode */
  76.    },
  77.    {  "Last Name",   5,  3, lastname,     /* prompt, buffer             */
  78.        5, 16, "MMMMMMMMMMMMMMMMMMMMMMMMM",/* position, format           */
  79.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  80.       Key_A_L,  4, H_LASTNAME,            /* hotkey, item-tag, help-tag */
  81.       FLD_TRM, 0, FLD_INI                 /* features, user, input-mode */
  82.    },
  83.    {  "Company",     7,  3, company,      /* prompt, buffer             */
  84.        7, 16, "****************************************",
  85.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  86.       Key_A_O,  5, H_NONE,                /* hotkey, item-tag, help-tag */
  87.       FLD_MIX | FLD_TRM, 0, FLD_INI       /* features, user, input-mode */
  88.    },
  89.    {  "Address",     9,  3, address,      /* prompt, buffer             */
  90.        9, 16, "****************************************",
  91.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  92.       Key_A_A,  6, H_NONE,                /* hotkey, item-tag, help-tag */
  93.       FLD_MIX | FLD_TRM, 0, FLD_INI       /* features, user, input-mode */
  94.    },
  95.    {  "City",       11,  3, city,         /* prompt, buffer             */
  96.       11, 16, "MMMMMMMMMMMMMMMMMMMM",     /* position, format           */
  97.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  98.       Key_A_C,  7, H_CITY,                /* hotkey, item-tag, help-tag */
  99.       FLD_TRM, 0, FLD_INI                 /* features, user, input-mode */
  100.    },
  101.    {  "State",      11, 41, state,        /* prompt, buffer             */
  102.       11, 50, "UU",                       /* position, format           */
  103.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  104.       Key_A_S,  8, H_STATE,               /* hotkey, item-tag, help-tag */
  105.       FLD_TRM, 0, FLD_INI                 /* features, user, input-mode */
  106.    },
  107.    {  "Zip Code",   13,  3, zipcode,      /* prompt, buffer             */
  108.       13, 16, "#####'-'%%%%",             /* position, format           */
  109.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  110.       Key_A_Z,  9, H_ZIPCODE,             /* hotkey, item-tag, help-tag */
  111.       FLD_TRM, 0, FLD_INI                 /* features, user, input-mode */
  112.    },
  113.    {  "Phone",      13, 31, phone,        /* prompt, buffer             */
  114.       13, 40, "'('###') '###'-'####",     /* position, format           */
  115.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  116.       Key_A_P, 10, H_NONE,                /* hotkey, item-tag, help-tag */
  117.       FLD_NWR | FLD_TRM, 0, FLD_INI       /* features, user, input-mode */
  118.    },
  119.    {  "Compiler",   15,  3, compiler,     /* prompt, buffer             */
  120.       15, 16, "***************",          /* position, format           */
  121.       PickCompiler, NULL, NULL,           /* "before", "valid", "after" */
  122.       Key_A_O, 11, H_COMPILER,            /* hotkey, item-tag, help-tag */
  123.       FLD_MIX | FLD_TRM, 0, FLD_INI       /* features, user, input-mode */
  124.    },
  125.    {  "Amount",     15, 37, amtenc,       /* prompt, buffer             */
  126.       15, 46, "$$$$.$$",                  /* position, format           */
  127.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  128.       Key_A_M, 12, H_AMOUNT,              /* hotkey, item-tag, help-tag */
  129.       FLD_CUR | FLD_TRM, 0, FLD_INI       /* features, user, input-mode */
  130.    },
  131.    {  "Comments",   17,  3, comments,     /* prompt, buffer             */
  132.       17, 16, "***********************************\n"
  133.               "***********************************",
  134.       NULL, NULL, NULL,                   /* "before", "valid", "after" */
  135.       Key_A_N, 13, H_NONE,                /* hotkey, item-tag, help-tag */
  136.       FLD_TRM, 0, FLD_INI                 /* features, user, input-mode */
  137.    }
  138. };
  139. LCL   EbldT   CDC   DemFrm =              /*- form-build object --------*/
  140. {  &DemFld[0], DEMO_CNT,                  /* field-build list, count    */
  141.    GetKey, NULL,                          /* getkey(), key-buffer       */
  142.    0, ENT_SAV,                            /* user, options              */
  143.    WHITE|_BLUE, BLUE|_LGREY,              /* prompt, field attributes   */
  144.    WHITE|_LGREY, BLUE|_LGREY              /* highlight, disabled attrs  */
  145. };
  146.  
  147. /*------[ Pop-up compiler menu item-build and menu buid objects ]-------*/
  148.  
  149. LCL   IbldT   CDC   EntItm[6] =           /*- item-build objects -------*/
  150. {  {  "Borland C++", 'B', 0,              /* item, quick-sel, feature   */
  151.       0, 0, 1, 0, 0, 0,                   /* pos, tag, help, key,, user */
  152.       NULL, NULL, NULL,                   /* "before","select","after"  */
  153.       NULL, NULL                          /* child, description         */
  154.    },
  155.    {  "Microsoft C", 'M', 0,              /* item, quick-sel, feature   */
  156.       1, 0, 2, 0, 0, 0,                   /* pos, tag, help, key,, user */
  157.       NULL, NULL, NULL,                   /* "before","select","after"  */
  158.       NULL, NULL                          /* child, description         */
  159.    },
  160.    {  "Quick C", 'Q', 0,                  /* item, quick-sel, feature   */
  161.       2, 0, 3, 0, 0, 0,                   /* pos, tag, help, key,, user */
  162.       NULL, NULL, NULL,                   /* "before","select","after"  */
  163.       NULL, NULL                          /* child, description         */
  164.    },
  165.    {  "Turbo C/C++", 'T', 0,              /* item, quick-sel, feature   */
  166.       3, 0, 4, 0, 0, 0,                   /* pos, tag, help, key,, user */
  167.       NULL, NULL, NULL,                   /* "before","select","after"  */
  168.       NULL, NULL                          /* child, description         */
  169.    },
  170.    {  "Zortech C++", 'Z', 0,              /* item, quick-sel, feature   */
  171.       4, 0, 5, 0, 0, 0,                   /* pos, tag, help, key,, user */
  172.       NULL, NULL, NULL,                   /* "before","select","after"  */
  173.       NULL, NULL                          /* child, description         */
  174.    },
  175.    {  "TopSpeed C/C++", 'S', 0,           /* item, quick-sel, feature   */
  176.       5, 0, 6, 0, 0, 0,                   /* pos, tag, help, key,, user */
  177.       NULL, NULL, NULL,                   /* "before","select","after"  */
  178.       NULL, NULL                          /* child, description         */
  179.    }
  180. };
  181. LCL   MbldT   CDC   EntMnu =              /*- menu-build object --------*/
  182. {  &EntItm[0], 6,                         /* item-build list, count     */
  183.     7, 22, 14, 38, MNU_VER,               /* start, end, type           */
  184.    BOX_SNG, BLUE|_MAGENTA,                /* frame type, attr           */
  185.    BLUE|_MAGENTA, BLUE|_MAGENTA,          /* window, text attrs         */
  186.    LCYAN|_MAGENTA, 0,                     /* quick, no-select attrs     */
  187.    BLUE|_LGREY, 1, PreMenu1,              /* bar attr, init tag, "open" */
  188.     0, 15, 1,                             /* user, width, offset        */
  189.    0xFF, 0xFF, 0xFF                       /* text desc (unused)         */
  190. };
  191.  
  192. TYP struct _DoMsg                   /* user type for messages           */
  193. {  ChrP     Msg;
  194.    BytT     Brd;
  195.    BytT     Col;
  196.    AtrT     Atr;
  197.    BytT     Pad;
  198. }  DoMsg, *DoMsgP;
  199.  
  200. DoMsg Msgs[4] =
  201. {  { "[ $50 Plus $3 S&H ]", BRD_TOP, 42, LCYAN|_BLUE },
  202.    { " [F10]=Finished ",    BRD_BOT,  5, LCYAN|_BLUE },
  203.    { " [F9]=Today ",        BRD_BOT, 25, LCYAN|_BLUE },
  204.    { " [Esc]=Abort ",       BRD_BOT, 45, LCYAN|_BLUE },
  205. };
  206.  
  207. LCL ChrP CDC EntrMsg1 = "Is this information correct? \033A\076Y\b";
  208.  
  209. /*========================[ The TCXL Entry Demo ]=======================*
  210.  | Called from the [E]ntry item of the UserDemo.C main menu
  211.  *----------------------------------------------------------------------*/
  212.  
  213. VOID  CTYP  EntryDemo(NOARG)
  214. {
  215.    REG IntT    i;
  216.    DoMsgP      mp;
  217.    KeyT        k;
  218.    VcelFP      s;
  219.    ChrT        c;
  220.  
  221.    s = FarVsave(LGREY|_BLUE);          /* save screen                   */
  222.    CurSave();                          /* save cursor state             */
  223.    DemFrm.etrm = &k;                   /* key-buffer                    */
  224.  
  225.    if(!WpopUp(CNT_CNT, 2, 8, 23, 70, 1, LCYAN|_BLUE, LCYAN|_BLUE))
  226.       ErrorExit(1);                    /* windowing error!              */
  227.  
  228.    AddShadow();                        /* add shadow, title, notes      */
  229.    Wtitle("[ TCXL Order Form ]", TTL_LFT, LCYAN|_BLUE);
  230.    mp = &Msgs[0];
  231.    for(i = 0; i < 4; i++)
  232.    {  Wmessage(mp->Msg, mp->Brd, mp->Col, mp->Atr);
  233.       mp++;
  234.    }
  235.    HlpPush(H_EDITKEYS);                /* set help category             */
  236.    EntBuild(&DemFrm);                  /* build the form, with prompts  */
  237.    EntSav();                           /* ??? save it for later         */
  238.    LOOP
  239.    {  k =0u;                           /* clear the last-key buffer     */
  240.       if(0 >= EntGet(DemFld[0].ftag))  /* process the form. If [Esc]    */
  241.          break;                        /* was pressed, don't bother     */
  242.                                        /* with confirmation message.    */
  243.  
  244.       if(!WpopUp(CNT_CNT, 9, 20, 13, 64, 0, WHITE|_CYAN, WHITE|_CYAN))
  245.          ErrorExit(1);                 /* windowing error!              */
  246.  
  247.       EntrMsg1[32] = NlsYes;
  248.  
  249.       if(k != Key_F10)                 /* if [F10] was pressed, don't   */
  250.       {                                /* display confirmation message. */
  251.          AddShadow();
  252.          Wputc('\n');                  /* Display confirmation message  */
  253.          WputCen(EntrMsg1);
  254.          KeyClear();
  255.          c = KwGetYn(NlsYes);
  256.       }
  257.       else
  258.          c = 'Y';
  259.       Wclose();
  260.       if(c == 'Y')                     /* all done with form            */
  261.          break;
  262.       EntMode(FLD_CHG);                /* change to update mode         */
  263.    }  /* LOOP */
  264.  
  265.    EntFree();                          /* free the form                 */
  266.    HlpDrop();                          /* clear help                    */
  267.    Wclose();                           /* close window                  */
  268.    CurPop();                           /* restore original cursor state */
  269.    FarVrestore(s);                     /* restore screen                */
  270.    MoveBarDn();                        /* next selection on main menu   */
  271. }
  272.  
  273. /*---------[ Validate the Date field in the data entry window ]---------*/
  274.  
  275. LCL   IntT  CTYP  CheckDate(ChrP b)
  276. {
  277.    IntT  y, m, d;
  278.  
  279.    if(!strblank(b))                    /* non-blank only                */
  280.    {  ParseDate(b, &m, &d, &y);
  281.  
  282.       if(m < 1 || m > 12)              /* validate numeric values       */
  283.       {  Wperror("Invalid month");
  284.          return(1);
  285.       }
  286.       if(d < 1 || d > 31)
  287.       {  Wperror("Invalid day");
  288.          return(3);
  289.       }
  290.    }
  291.    return(0);
  292. }  /* CheckDate() */
  293.  
  294. /*------[ Display the literal equivalent of the MMDDYY date field ]-----*
  295.  | Called immediately after the user leaves the Date field.
  296.  *----------------------------------------------------------------------*/
  297.  
  298. LCL   VOID  CTYP  DisplayDate(NOARG)
  299. {
  300.    FdfP  f;
  301.    IntT  m, d, y;
  302.  
  303.    if(NULL == (f = FldLoc(1)))            /* find address of Date field */
  304.       ErrorExit(1);
  305.  
  306.    Wgotoxy(1, 37);                        /* clear to end of line       */
  307.    WclrEol();
  308.    if(!strblank(FdfBfr(f)))               /* parse string date into     */
  309.    {  ParseDate(FdfBfr(f), &m, &d, &y);   /* numeric values             */
  310.       Wputf("%s %d, %d", months[m - 1], d, y);
  311.    }
  312. }  /* DisplayDate() */
  313.  
  314. /*-------------[ Change input mode of all fields to <im> ]--------------*/
  315.  
  316. LCL   VOID  CTYP  EntMode(BytT im)
  317. {
  318.    REG EdfP    e = EctlCur;            /* current form                  */
  319.    REG FdfP    f;
  320.  
  321.    im &= FDF_MOD;                      /* valid bits only               */
  322.    for(f = EdfTop; f <= EdfBot; f++)
  323.    {  FdfFlg(f) &= ~FDF_MOD;           /* update all fields             */
  324.       FdfFlg(f) |= im;
  325.    }
  326. }  /* EntMode() */
  327.  
  328. /*--------------------[ Alternate get key function ]--------------------*
  329.  | Do a normal keyboard get, with the following user-defined cases:
  330.  | 1) If the key is [F10], exit the form and pass back [F10] in the
  331.  |    last-key buffer.
  332.  | 2) If the key is [F9], fill in today's date via keyboard queue.
  333.  | In order to pass back an [F10] as the last key, we call EntTrm() to
  334.  | put Key_F10 in the buffer and preventing EntGet() from putting the
  335.  | Key_C_Ent we return to exit the form in it.
  336.  *----------------------------------------------------------------------*/
  337.  
  338. LCL   KeyT  CTYP  GetKey(NOARG)
  339. {
  340.    KeyT  x;
  341.    ChrP  b;
  342.  
  343.    x = KeyGetc();
  344.    if(x == Key_F9)                     /* [F9] - fill in today's date   */
  345.    {  b = SysDate(5);                  /* get date as MM/DD/YY          */
  346.       KqueStr(&b[1]);                  /* stuff it                      */
  347.       x = b[0];                        /* return 1st char               */
  348.    }
  349.    else                                /* [F10] - exit the form.  Put   */
  350.    {  if(x == Key_F10)                 /* Key_F10 in the last-key buffer*/
  351.       {  EntTrm(Key_F10);              /* and return K_C_Ent to exit.   */
  352.          x = Key_C_Ent;
  353.       }
  354.    }
  355.    return(x);
  356. }  /* GetKey() */
  357.  
  358. /*----------[ Select a compiler - string picking using a menu ]---------*/
  359.  
  360. LCL   VOID  CTYP  PickCompiler(NOARG)
  361. {
  362.    REG IntT    s;
  363.    FdfP        f;
  364.    KeyT        k;
  365.  
  366.    HlpCur();                           /* save help category            */
  367.    MnuBuild(&EntMnu);                  /* define a pop-up menu          */
  368.    if((s = MnuGet()) == -1)            /* get user input                */
  369.       ErrorExit(1);                    /* windowing error!              */
  370.  
  371.    f = FldCur();
  372.  
  373.    if(s)
  374.    {  s--;
  375.       strset(FdfBfr(f), ' ');
  376.       strncpy(FdfBfr(f), EntItm[s].istr, strlen(EntItm[s].istr));
  377.       FldInp();
  378.    }
  379.  
  380.    k = Key_Tab;
  381.    if(FdfPrv(f) || FdfUp(f))
  382.       k = Key_S_Tab;
  383.    KquePut(k);
  384.    HlpPop();                           /* restore help category         */
  385. }  /* PickCompiler() */
  386.  
  387. /*- end of EntrDemo.C --------------------------------------------------*/
  388.  
  389.