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

  1. /*------------------------------------------------------------*/
  2. /* filename -       tlistbox.cpp                              */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TListBox 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_TListBox
  19. #define Uses_TEvent
  20. #define Uses_TCollection
  21. #define Uses_opstream
  22. #define Uses_ipstream
  23. #include <tv.h>
  24.  
  25. #if !defined( __STRING_H )
  26. #include <String.h>
  27. #endif  // __STRING_H
  28.  
  29. struct TListBoxRec 
  30. {
  31.     TCollection *items;
  32.     ushort selection;
  33. };
  34.  
  35. TListBox::TListBox( const TRect& bounds,
  36.                     ushort aNumCols,
  37.                     TScrollBar *aScrollBar ) :
  38.     TListViewer(bounds, aNumCols, 0, aScrollBar),
  39.     items( 0 )
  40. {
  41.     setRange(0);
  42. }
  43.  
  44. TListBox::~TListBox()
  45. {
  46. }
  47.  
  48. ushort TListBox::dataSize()
  49. {
  50.     return sizeof(TListBoxRec);
  51. }
  52.  
  53. void TListBox::getData( void * rec )
  54. {
  55.     TListBoxRec *p = (TListBoxRec *)rec;
  56.     p->items = items;
  57.     p->selection = focused;
  58. }
  59.  
  60. void TListBox::getText( char *dest, short item, short maxChars )
  61. {
  62.     if (items != 0 )
  63.         {
  64.         strncpy( dest, (const char *)(items->at(item)), maxChars );
  65.         dest[maxChars] = '\0';
  66.         }
  67.     else
  68.         *dest = EOS;
  69. }
  70.  
  71. void TListBox::newList( TCollection *aList )
  72. {
  73.     destroy( items );
  74.     items = aList;
  75.     if( aList != 0 )
  76.         setRange( aList->getCount() );
  77.     else
  78.         setRange(0);
  79.     if( range > 0 )
  80.         focusItem(0);
  81.     drawView();
  82. }
  83.  
  84. void TListBox::setData( void *rec )
  85. {
  86.     TListBoxRec *p = (TListBoxRec *)rec;
  87.     newList(p->items);
  88.     focusItem(p->selection);
  89.     drawView();
  90. }
  91.  
  92. void TListBox::write( opstream& os )
  93. {
  94.     TListViewer::write( os );
  95.     os << items;
  96. }
  97.  
  98. void *TListBox::read( ipstream& is )
  99. {
  100.     TListViewer::read( is );
  101.     is >> items;
  102.     return this;
  103. }
  104.  
  105. TStreamable *TListBox::build()
  106. {
  107.     return new TListBox( streamableInit );
  108. }
  109.  
  110. TListBox::TListBox( StreamableInit ) : TListViewer( streamableInit )
  111. {
  112. }
  113.  
  114.  
  115.