home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / vlstde / vlistbox.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-12  |  3.6 KB  |  160 lines

  1. // vlistbox.cpp        VIRTUAL LISTBOX CLASS WITH TWO SCROLL BARS
  2. //    written by Gregory K. Miskin
  3. //    COPYRIGHT (C) 1992.  All Rights Reserved.
  4. //    Gregory K. Miskin, Orem, Utah  USA
  5.  
  6. #define Uses_TListViewer
  7. #define Uses_TEvent
  8. #define Uses_TScrollBar
  9. #define Uses_TKeys
  10. #define Uses_TView
  11. #define Uses_MsgBox
  12.  
  13. #include <tv.h>
  14. #include <string.h>
  15. #include <stdlib.h>
  16. #include "commands.hpp"
  17. #include "vlistbox.hpp"
  18.  
  19. long numRecs;
  20. long oldItem;
  21.  
  22. /*------------------------------------------------------------------------*/
  23. VListBox::VListBox( const TRect& bounds,
  24.                           ushort aNumCols,
  25.                           TScrollBar *hScrollBar,
  26.                           TScrollBar *vScrollBar):
  27.      TListViewer(bounds, aNumCols, hScrollBar, vScrollBar)
  28. {
  29.     cBase = new CodeBase;
  30.     name  = new DataIndex(cBase);
  31.  
  32.     cBase->open_error = 0;
  33.     OpenFiles();
  34.     name->top();
  35.     numRecs = name->reccount();
  36.  
  37.     oldItem = 0;
  38.     setRange(numRecs);
  39.     vScrollBar->maxVal = numRecs;
  40. }
  41.  
  42. /*------------------------------------------------------------------------*/
  43. VListBox::~VListBox()
  44. {
  45.     int rcode;
  46.     rcode = messageBox("\003 Remove Deleted Records?", mfConfirmation | mfOKCancel);
  47.  
  48.     if(rcode == cmOK)
  49.     {
  50.         long num_recs;
  51.         name->pack();
  52.         num_recs = name->reccount();
  53.         name->file.read(4, StrLen(&num_recs,sizeof(num_recs)));
  54.         name->zap(num_recs + 1L, name->reccount());
  55.     }
  56.     cBase->close_all();
  57. }
  58.  
  59. /*------------------------------------------------------------------------*/
  60. void VListBox::OpenFiles()
  61. {
  62.     name->open("DEMO");
  63.  
  64.     if(GeneralFlag == 1)
  65.         status = name->select("DEMONDX");
  66. }
  67.  
  68. /*------------------------------------------------------------------------*/
  69. void VListBox::getText( char *dest, long item, long )
  70. {
  71.     GetRecord(item);
  72.     strcpy( dest, line );
  73. }
  74.  
  75. /*------------------------------------------------------------------------*/
  76. long VListBox::GetRecord(long item)
  77. {
  78.     int rcode = 9;
  79.     long skipVal;
  80.     long RECNO = 0;
  81.  
  82.     skipVal     = item - oldItem;
  83.  
  84.     rcode         = name->skip(skipVal);
  85.     RECNO        = name->recno();
  86.     oldItem     = item;
  87.  
  88.     GetFields();
  89.     BuildLine();
  90.     return(RECNO);
  91. }
  92.  
  93. /*------------------------------------------------------------------------*/
  94. void VListBox::GetFields(void)
  95. {
  96.     memset(&fields, 0, sizeof(fields));
  97.     GetStr(nmFIRST_NAME, fields.fname);
  98.     GetStr(nmLAST_NAME,     fields.lname);
  99.     GetStr(nmSTREET,         fields.street);
  100.     GetStr(nmCITY,         fields.city);
  101.     GetStr(nmSTATE,         fields.state);
  102.     GetStr(nmZIP,             fields.zip);
  103. }
  104.  
  105. /*------------------------------------------------------------------------*/
  106. void VListBox::GetStr(int field_num, char *fld)
  107. {
  108.     int len = 0;
  109.  
  110.     Fld = name->field(field_num);
  111.     len = Fld->len();
  112.     strncpy(fld,Fld->ptr(),len);
  113. }
  114.  
  115. /*------------------------------------------------------------------------*/
  116. void VListBox::BuildLine()
  117. {
  118.     long recno;
  119.     char recstr[7];
  120.     char temp[7];
  121.     char blank[] = " ";
  122.     char del[]     = "*";
  123.     memset(&line, 0, sizeof(line));
  124.  
  125.     recno = name->recno();
  126.     ltoa(recno, temp, 10);
  127.     for(int x = 0; x < 7; x++)
  128.         recstr[x] = 32;
  129.  
  130.     recstr[6] = NULL;
  131.     int s = strlen(temp) - 1;
  132.  
  133.     for(int ln = strlen(recstr) -1; s >= 0; ln--)
  134.     {
  135.         recstr[ln] = temp[s];
  136.         s--;
  137.     }
  138.  
  139.     if(name->deleted())
  140.         strcpy(line, del);
  141.     else
  142.         strcpy(line, blank);
  143.  
  144.     strcat(line, recstr);
  145.     strcat(line, blank);
  146.     strcat(line, blank);
  147.     strcat(line, fields.lname);
  148.     strcat(line, blank);
  149.     strcat(line, fields.fname);
  150.     strcat(line, blank);
  151.     strcat(line, blank);
  152.     strcat(line, fields.street);
  153.     strcat(line, blank);
  154.     strcat(line, fields.city);
  155.     strcat(line, blank);
  156.     strcat(line, fields.state);
  157.     strcat(line, blank);
  158.     strcat(line, fields.zip);
  159. }
  160.