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