home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / tvision / mess1 / myview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-31  |  4.0 KB  |  185 lines

  1. //========================================================================
  2. //  The following example routines have been provided by the Technical
  3. //  Support staff at Borland International.  They are provided as a
  4. //  courtesy and not as part of a Borland product, and as such, are
  5. //  provided without the assurance of technical support or any specific
  6. //  guarantees.
  7. //========================================================================
  8. //  Turbo Vision - Example of message passing
  9. //
  10. //------------------------------------------------------------------------
  11. //
  12. // myview.cpp:  The member function definition for TMyView.
  13. //
  14. //========================================================================
  15.  
  16. #define Uses_MsgBox
  17. #include <tv.h>
  18. #include <strstrea.h>
  19. #include <iomanip.h>
  20. #include <string.h>
  21. #include "myview.h"
  22. #include "cmds.h"
  23.  
  24. char *BBSType[] = {
  25.     "Bix",
  26.     "CompuSlave",
  27.     "Genie",
  28.     "IBBS",
  29.     "Letters",
  30.     "Training"
  31. };
  32.  
  33. char interestType[] = { 'I', 'T', 'P', 'W', '2', 'L',
  34.                         'E', 'O', 'D', 'C', 'B', 'A' };
  35.  
  36.  
  37. //
  38. // TMyView - Constructor
  39. //
  40.  
  41. TMyView::TMyView(TRect bounds) :
  42.     TView (bounds)
  43. {
  44.     windowFlag++;
  45.  
  46.     isValid = True;
  47.  
  48.     records = new techInfoRec *[size.y];
  49.  
  50.     if (!records)
  51.     {
  52.         isValid = False;
  53.     }
  54.  
  55.     maxRecords = size.y;
  56.     numRecords = 0;
  57.  
  58.     eventMask |= evBroadcast;
  59.     growMode |= gfGrowHiX | gfGrowHiY;
  60. }
  61.  
  62.  
  63. //
  64. // ~TMyView - Destructor
  65. //
  66.  
  67. TMyView::~TMyView()
  68. {
  69.   windowFlag--;
  70.  
  71.   delete records;
  72. }
  73.  
  74. //
  75. // draw - The draw function.  Simply uses writeChar and writeStr to display
  76. //        string.
  77. //
  78.  
  79. void TMyView::draw()
  80. {
  81.     for(int i = 0;i < size.y;i++)
  82.     {
  83.         writeChar(0,i,' ',1,size.x);
  84.  
  85.         if (i < numRecords)
  86.         {
  87.             char temp[200];
  88.  
  89.             ostrstream tempStream(temp,200);
  90.  
  91.             tempStream << setw(20) << records[i]->name
  92.                        << "|"
  93.                        << setw(4) << records[i]->ext
  94.                        << "|"
  95.                        << setw(10) << BBSType[records[i]->bbs];
  96.  
  97.             unsigned int k = 0x0800;
  98.             for(int j = 0;j < 12;j++)
  99.             {
  100.                 tempStream << "|";
  101.  
  102.                 if (records[i]->interest & k)
  103.                 {
  104.                     tempStream << interestType[j];
  105.                 }
  106.                 else
  107.                 {
  108.                     tempStream << ' ';
  109.                 }
  110.                 k >>= 1;
  111.             }
  112.             tempStream << ends;
  113.  
  114.  
  115.             temp[size.x+1] = 0;
  116.             writeStr(0,i,temp,1);
  117.         }
  118.     }
  119. }
  120.  
  121.  
  122. //
  123. // valid - Returns the state of the current instance of TMyView.
  124. //
  125.  
  126. Boolean TMyView::valid(ushort)
  127. {
  128.     return (isValid);
  129. }
  130.  
  131.  
  132. //
  133. // handleEvent - Handle event that tell the view that there is a record.
  134. //
  135.  
  136. void TMyView::handleEvent(TEvent& event)
  137. {
  138.     TView::handleEvent(event);
  139.  
  140.     switch(event.what)
  141.     {
  142.         case evBroadcast:
  143.         {
  144.             switch(event.message.command)
  145.             {
  146.                 case cmNewRecord:
  147.                 {
  148.                     char *data = (char *)event.message.infoPtr;
  149.                     techInfoRec *newRec = new techInfoRec;
  150.  
  151.                     strcpy(newRec->name,data);
  152.                     strcpy(newRec->ext,&data[21]);
  153.                     newRec->bbs = *(int *)&data[26];
  154.                     newRec->interest = *(int *)&data[28];
  155.                     addRecord(newRec);
  156.                     draw();
  157.                     clearEvent(event);
  158.                     break;
  159.                 }
  160.                 default:
  161.                 {
  162.                     return;
  163.                 }
  164.             }
  165.         }
  166.     }
  167. }
  168.  
  169.  
  170. //
  171. // addRecord - Add a record to the data base.
  172. //
  173.  
  174. void TMyView::addRecord(techInfoRec *newRec)
  175. {
  176.     if (numRecords != maxRecords)
  177.     {
  178.         records[numRecords++] = newRec;
  179.     }
  180.     else
  181.     {
  182.         delete newRec;
  183.     }
  184. }
  185.