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

  1. /*------------------------------------------------------------*/
  2. /* filename -           tlabel.cpp                            */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                      TLabel 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_TLabel
  19. #define Uses_TEvent
  20. #define Uses_TDrawBuffer
  21. #define Uses_TGroup
  22. #define Uses_TView
  23. #define Uses_opstream
  24. #define Uses_ipstream
  25. #include <tv.h>
  26.  
  27. #if !defined( __CTYPE_H )
  28. #include <ctype.h>
  29. #endif  // __CTYPE_H
  30.  
  31. #define cpLabel "\x07\x08\x09\x09"
  32.  
  33. TLabel::TLabel( const TRect& bounds, const char *aText, TView* aLink) :
  34.     TStaticText( bounds, aText ),
  35.     link( aLink ),
  36.     light( False )
  37. {
  38.     options |= ofPreProcess | ofPostProcess;
  39.     eventMask |= evBroadcast;
  40. }
  41.  
  42. void TLabel::shutDown()
  43. {
  44.     link = 0;
  45.     TStaticText::shutDown();
  46. }
  47.  
  48. void TLabel::draw()
  49. {
  50.     ushort color;
  51.     TDrawBuffer b;
  52.     uchar scOff;
  53.  
  54.     if( light )
  55.         {
  56.         color = getColor(0x0402);
  57.         scOff = 0;
  58.         }
  59.     else
  60.         {
  61.         color = getColor(0x0301);
  62.         scOff = 4;
  63.         }
  64.  
  65.     b.moveChar( 0, ' ', color, size.x );
  66.     if( text != 0 )
  67.         b.moveCStr( 1, text, color );
  68.     if( showMarkers )
  69.         b.putChar( 0, specialChars[scOff] );
  70.     writeLine( 0, 0, size.x, 1, b );
  71. }
  72.  
  73. TPalette& TLabel::getPalette() const
  74. {
  75.     static TPalette palette( cpLabel, sizeof( cpLabel )-1 );
  76.     return palette;
  77. }
  78.  
  79. void TLabel::handleEvent( TEvent& event )
  80. {
  81.     TStaticText::handleEvent(event);
  82.     if( event.what == evMouseDown )
  83.         {
  84.         if( link != 0 )
  85.             link->select();
  86.         clearEvent( event );
  87.         }
  88.     else if( event.what == evKeyDown )
  89.         {
  90.         char c = hotKey( text );
  91.         if( getAltCode(c) == event.keyDown.keyCode ||
  92.                 ( c != 0 && owner->phase == TGroup::phPostProcess &&
  93.                 toupper(event.keyDown.charScan.charCode) ==  c )
  94.           )
  95.             {
  96.             if (link != 0 )
  97.                 link->select();
  98.             clearEvent( event );
  99.             }
  100.         }
  101.     else if( event.what == evBroadcast &&
  102.             ( event.message.command == cmReceivedFocus ||
  103.               event.message.command == cmReleasedFocus )
  104.            )
  105.             {
  106.             light = Boolean( (link->state & sfFocused) != 0 );
  107.             drawView();
  108.             }
  109. }
  110.  
  111. void TLabel::write( opstream& os )
  112. {
  113.     TStaticText::write( os );
  114.     os << link;
  115. }
  116.  
  117. void *TLabel::read( ipstream& is )
  118. {
  119.     TStaticText::read( is );
  120.     is >> link;
  121.     light = False;
  122.     return this;
  123. }
  124.  
  125. TStreamable *TLabel::build()
  126. {
  127.     return new TLabel( streamableInit );
  128. }
  129.  
  130. TLabel::TLabel( StreamableInit ) : TStaticText( streamableInit )
  131. {
  132. }
  133.  
  134.  
  135.