home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 1995 December / SOFM_Dec1995.bin / pc / dos / biz / pbase / grpacct.edt < prev    next >
Text File  |  1995-10-31  |  8KB  |  261 lines

  1. /*
  2. ******************************************
  3. *     Variable Declaration Section
  4. ******************************************
  5. */
  6.  
  7. typedef struct {
  8.   bool    abort,
  9.           noneedited,
  10.           bypass,
  11.           edited,
  12.           finished,
  13.           fld_in_range;
  14.   int     sno,
  15.           fno,
  16.           incy,
  17.           last_fld;
  18.   winptr  winp,
  19.           edtwin;
  20. } editGlobalVars;
  21.  
  22. typedef struct {
  23.   int     sno,
  24.           fno,
  25.           incy;
  26.   winptr  winp;
  27. } dispGlobalVars;
  28.  
  29. editGlobalVars      edt;
  30. dispGlobalVars      dsp;
  31.  
  32.  
  33. /*
  34. ******************************************
  35. *     Function Declaration Section
  36. ******************************************
  37. */
  38.  
  39.  
  40. void dspf(int x, int y, byte a, byte s, byte l, fldtyp *f)
  41. {
  42.   if (dsp.incy == (tabidx[dsp.fno] - 1) && (tabsize[dsp.fno] > 1))
  43.      dsp_fld((byte)x, (byte)(y + dsp.incy), f->faddr, f->typ, f->pic, s, l, 0, dsp.winp);
  44.   else
  45.      dsp_fld((byte)x, (byte)(y + dsp.incy), f->faddr, f->typ, f->pic, s, l, a, dsp.winp);
  46. }
  47.  
  48. /*************************************************************************/
  49.  
  50. void GRPACCT_dsp(int fno, int sno, byte incy)
  51. {
  52.   dsp.fno   = fno;
  53.   dsp.sno   = sno;
  54.   dsp.incy  = incy;
  55.   dsp.winp  = uw.wa[sno];
  56.   switch(sno) {
  57.     case 1 : 
  58.         if (dsp.fno ==  1) {
  59.             if ((dsp.fno <= filno) && (dsp.incy == tabidx[dsp.fno]-1)) attrib = _av; else attrib = _iv;
  60.                         dspf( 1, 1,0,0,16,&GRPACCT1._GROUPS);
  61.                         dspf(18, 1,0,0,0,&GRPACCT1._GROUP_DESC);
  62.         }
  63.     break;
  64.   }
  65. }
  66.  
  67. /*************************************************************************/
  68.  
  69. bool skipfield(int fnum)
  70. {
  71.   bool tb;
  72.  
  73.   tb = False;
  74.   if (edt.sno ==  1) switch (fnum) {
  75.       case 0 : break;
  76.   }
  77.   return(tb);
  78. }
  79.  
  80. /*************************************************************************/
  81.  
  82. bool chk_fld(int chknum)
  83. {
  84.   string estr;
  85.  
  86.   *estr = '\0';
  87.   if (edt.sno ==  1) switch (chknum) {
  88.       case 0 : break;
  89.   }
  90.   if (*estr != '\0') {
  91.     if (strcmp(estr,LSC_BaseError) != 0) {
  92.       audible(Error);
  93.       message(edt.winp, estr);
  94.     }
  95.   }
  96.   return (bool)(*estr == '\0');
  97. }
  98.  
  99. /*************************************************************************/
  100.  
  101. void edt_n_chk(byte x, byte y, byte l, byte a, winptr h, fldtyp *f, int fldno)
  102. {
  103.   if (!skipfield(fldno)) {
  104.     do {
  105.       if (!edt.bypass) {
  106.         edt_fld(x, y + edt.incy, f->faddr, f->typ, f->pic, l, a, edt.winp);
  107.         edt.noneedited = False;
  108.         edt.edited     = True;
  109.         edt.abort      = False;
  110.         if (exitcode == HlpKey) disphelp(h);
  111.         if (custom_key(scrno, edt.fno, &fldnum, &exitcode)) exitcode = QitKey;
  112.       }
  113.       if ((exitcode != QitKey) && (exitcode != UArr) && (exitcode != HlpKey)) {
  114.         edt.fld_in_range = chk_fld(fldno);
  115.         if (tabsize[dsp.fno] > 1 && (edt.incy == (tabidx[edt.fno] - 1) || command == Cmd_Add_Record)) {
  116.            dsp_fld(x, y+edt.incy, f->faddr, f->typ, f->pic, 0, l, 0, edt.winp);
  117.         }
  118.         else
  119.           dsp_fld(x, y+edt.incy, f->faddr, f->typ, f->pic, 0, l, a, edt.winp);
  120.  
  121.         if (!edt.fld_in_range) {
  122.           fldnum = fldno;
  123.           edt.bypass = False;
  124.         }
  125.       }
  126.     } while (!edt.fld_in_range && (exitcode != QitKey) && (exitcode != UArr));
  127.     message(NULL,"");
  128.   }
  129. }
  130.  
  131. /*************************************************************************/
  132.  
  133. void openedtmnu(void)
  134. {
  135.   string editHelpString;
  136.  
  137.   strcpy(editHelpString, _EdtHelp);
  138.   if (openwin(0, (byte)(scrwid - strlen(editHelpString) + 1), scrhgt, (byte)(strlen(editHelpString)), 1, 0x4F, 0x4F, 0, "\0┐│┘─└│┌", TopCnt,"")) {
  139.     edt.edtwin = curwin;
  140.     writewxy(editHelpString, 0, 1, 1, edt.edtwin);
  141.     hidewin(T_ON, edt.edtwin);
  142.   }
  143.   else edt.edtwin = NULL;
  144. }
  145.  
  146. /*************************************************************************/
  147.  
  148. void GRPACCT_edt(int fno, int fld, int incy)
  149. {
  150.   openedtmnu();
  151.   attrib         = _av;
  152.   exitcode       = Nul;
  153.   edt.fno        = fno;
  154.   edt.sno        = scrno;
  155.   edt.incy       = incy;
  156.   edt.winp       = uw.wa[edt.sno];
  157.   edt.abort      = True;
  158.   edt.noneedited = True;
  159.   edt.bypass     = False;
  160.   edt.finished   = False;
  161.   fldnum = (fld == 0) ? 1 : fld;
  162.  
  163.   do {
  164.     if (fldnum == 1) edt.noneedited = True;
  165.     if (edt_spos && (edt.last_fld != fldnum)) edt_spos = 1;
  166.     edt.last_fld = fldnum;
  167.     edt.edited   = False;
  168.  
  169.     if (edt.sno ==  1) switch (fldnum) {
  170.         case 1 : if (edt.fno ==  1)        edt_n_chk( 1, 1,16,0,hw.wa[1],&GRPACCT1._GROUPS,fldnum); break;
  171.         case 2 : if (edt.fno ==  1)        edt_n_chk(18, 1,0,0,hw.wa[1],&GRPACCT1._GROUP_DESC,fldnum); break;
  172.         default : if (edt.noneedited) {
  173.             edt.finished = True;
  174.             if (edt.abort) {
  175.                 exitcode = QitKey;
  176.                 dberrm(_NoneEdited);
  177.             }
  178.         }
  179.         else if (exitcode == XeptKey) edt.finished = True; else fldnum =         0;
  180.     }
  181.  
  182.     if (edt.bypass || !edt.edited) {
  183.       if (_upward && (fldnum > 1)) fldnum--;
  184.       else                         fldnum++;
  185.     }
  186.  
  187.     if (exitcode == XeptKey)    edt.bypass   = True;
  188.     if (exitcode == QitKey)     edt.finished = True;
  189.     if (fldnum > edt.last_fld) _upward       = False;
  190.  
  191.   } while (!edt.finished);
  192.   if (edt.edtwin != NULL) closewin(&edt.edtwin);
  193. }
  194.  
  195. /*************************************************************************/
  196.  
  197. void editdefaultdata(int fno, ptr fb)
  198. {
  199.   byte    lengthOfText,
  200.           lengthOfPrompt,
  201.           windowX,
  202.           windowY,
  203.           windowWidth,
  204.           windowHeight;
  205.   int     fieldNumber,
  206.           saveFieldNumber;
  207.   winptr  aWindowPtr;
  208.   fldblk *aFieldBlock;
  209.   fldtyp *aFieldType;
  210.   string  tempString;
  211.   fldtyp  editArray[23];
  212.   char   colon[10];
  213.  
  214.   strcpy(colon, " : ");
  215.   aFieldBlock     = fb;
  216.   saveFieldNumber = fldnum;
  217.   lengthOfPrompt  = lengthOfText = windowWidth = windowHeight = 0;
  218.  
  219.   for (fieldNumber=0; fieldNumber < aFieldBlock->numf; fieldNumber++) {
  220.     aFieldType = &(*aFieldBlock->farr)[fieldNumber];
  221.     if (aFieldType->typ != _Memo && gvar->sec >= aFieldType->dsec && windowHeight < 23) {
  222.       windowHeight++;
  223.       if (strlen(aFieldType->fname) > lengthOfPrompt) lengthOfPrompt = strlen(aFieldType->fname);
  224.       if (strlen(aFieldType->faddr) > lengthOfText)   lengthOfText   = strlen(aFieldType->faddr);
  225.       memmove(&editArray[windowHeight], aFieldType, sizeof(fldtyp));
  226.     }
  227.   }
  228.  
  229.   lengthOfPrompt = lengthOfPrompt + 3;
  230.   if ((lengthOfPrompt + lengthOfText) > (scrwid - 2)) lengthOfText = scrwid - 2 - lengthOfPrompt;
  231.   if (windowHeight > (scrhgt - 2))                    windowHeight = scrhgt - 2;
  232.  
  233.   windowWidth  = lengthOfPrompt + lengthOfText;
  234.   windowX      = (int)((scrwid - windowWidth) / 2);
  235.   windowY      = (int)((scrhgt - windowHeight) / 2);
  236.  
  237.   if (openwin(0, windowX, windowY, windowWidth, windowHeight, 15, 31, 8, "─┐│┘─└│┌", TopCnt, "")) {
  238.     aWindowPtr = curwin;
  239.     for (fieldNumber = 1; fieldNumber <= windowHeight; fieldNumber++) {
  240.       aFieldType = &editArray[fieldNumber];
  241.       strcpy(tempString, aFieldType->fname);
  242.       strcat(tempString, colon);
  243.       writewxy(tempString, 0, 1, (byte)(fieldNumber), aWindowPtr);
  244.       dsp_fld(lengthOfPrompt + 1, fieldNumber, aFieldType->faddr, aFieldType->typ, aFieldType->pic, 0, lengthOfText, 0, aWindowPtr);
  245.     }
  246.  
  247.     hidewin(T_ON, aWindowPtr);
  248.     fieldNumber = 1;
  249.     do {
  250.       aFieldType = &editArray[fieldNumber];
  251.       edt_fld(lengthOfPrompt + 1, fieldNumber, aFieldType->faddr, aFieldType->typ, aFieldType->pic, lengthOfText, 0, aWindowPtr);
  252.       if (_upward)                    fieldNumber--;
  253.       else                            fieldNumber++;
  254.       if (!fieldNumber)               fieldNumber = windowHeight;
  255.       if (fieldNumber > windowHeight) fieldNumber = 1;
  256.     } while(exitcode != QitKey && exitcode != XeptKey);
  257.     closewin(&aWindowPtr);
  258.   }
  259.   fldnum = saveFieldNumber;
  260. }
  261.