home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 9.ddi / TVSRC.ZIP / TSTATICT.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.5 KB  |  138 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       tstatict.cpp                              */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TStaticText member functions              */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*------------------------------------------------------------*/
  9. /*                                                            */
  10. /*    Turbo Vision -  Version 1.0                             */
  11. /*                                                            */
  12. /*                                                            */
  13. /*    Copyright (c) 1991 by Borland International             */
  14. /*    All Rights Reserved.                                    */
  15. /*                                                            */
  16. /*------------------------------------------------------------*/
  17.  
  18. #define Uses_TStaticText
  19. #define Uses_TDrawBuffer
  20. #define Uses_opstream
  21. #define Uses_ipstream
  22. #include <tv.h>
  23.  
  24. #if !defined( __CTYPE_H )
  25. #include <ctype.h>
  26. #endif  // __CTYPE_H
  27.  
  28. #if !defined( __STRING_H )
  29. #include <String.h>
  30. #endif  // __STRING_H
  31.  
  32. #define cpStaticText "\x06"
  33.  
  34. TStaticText::TStaticText( const TRect& bounds, const char *aText ) :
  35.     TView( bounds ),
  36.     text( newStr( aText ) )
  37. {
  38. }
  39.  
  40. TStaticText::~TStaticText()
  41. {
  42.     delete (char *)text;
  43. }
  44.  
  45. void TStaticText::draw()
  46. {
  47.     uchar color;
  48.     Boolean center;
  49.     int i, j, l, p, y;
  50.     TDrawBuffer b;
  51.     char s[256];
  52.  
  53.     color = getColor(1);
  54.     getText(s);
  55.     l = strlen(s);
  56.     p = 0;
  57.     y = 0;
  58.     center = False;
  59.     while (y < size.y)
  60.         {
  61.         b.moveChar(0, ' ', color, size.x);
  62.         if (p < l)
  63.             {
  64.             if (s[p] == 3)
  65.                 {
  66.                 center = True;
  67.                 ++p;
  68.                 }
  69.             i = p;
  70.             do {
  71.                j = p;
  72.                while ((p < l) && (s[p] == ' ')) 
  73.                    ++p;
  74.                while ((p < l) && (s[p] != ' ') && (s[p] != '\n'))
  75.                    ++p;
  76.                } while ((p < l) && (p < i + size.x) && (s[p] != '\n'));
  77.             if (p > i + size.x)
  78.                 if (j > i)
  79.                     p = j; 
  80.                 else 
  81.                     p = i + size.x;
  82.             if (center == True)
  83.                j = (size.x - p + i) / 2 ;
  84.             else 
  85.                j = 0;
  86.             b.moveBuf(j, &s[i], color, (p - i));
  87.             while ((p < l) && (s[p] == ' '))
  88.                 p++;
  89.             if ((p < l) && (s[p] == '\n'))
  90.                 {
  91.                 center = False;
  92.                 p++;
  93.                 if ((p < l) && (s[p] == 10))
  94.                     p++;
  95.                 }
  96.             }
  97.         writeLine(0, y++, size.x, 1, b);
  98.         }
  99. }
  100.  
  101. TPalette& TStaticText::getPalette() const
  102. {
  103.     static TPalette palette( cpStaticText, sizeof( cpStaticText )-1 );
  104.     return palette;
  105. }
  106.  
  107. void TStaticText::getText( char *s )
  108. {
  109.     if( text == 0 )
  110.         *s = EOS;
  111.     else
  112.         strcpy( s, text );
  113. }
  114.  
  115. void TStaticText::write( opstream& os )
  116. {
  117.     TView::write( os );
  118.     os.writeString( text );
  119. }
  120.  
  121. void *TStaticText::read( ipstream& is )
  122. {
  123.     TView::read( is );
  124.     text = is.readString();
  125.     return this;
  126. }
  127.  
  128. TStreamable *TStaticText::build()
  129. {
  130.     return new TStaticText( streamableInit );
  131. }
  132.  
  133. TStaticText::TStaticText( StreamableInit ) : TView( streamableInit )
  134. {
  135. }
  136.  
  137.  
  138.