home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tv20os2.zip / src / TListBox.cpp < prev    next >
C/C++ Source or Header  |  1998-01-19  |  2KB  |  103 lines

  1. /*
  2.  * TListBox.cc
  3.  *
  4.  * Turbo Vision - Version 2.0
  5.  *
  6.  * Copyright (c) 1994 by Borland International
  7.  * All Rights Reserved.
  8.  *
  9.  * Modified by Sergio Sigala <ssigala@globalnet.it>
  10.  */
  11.  
  12. #define Uses_TListBox
  13. #define Uses_TEvent
  14. #define Uses_TCollection
  15. #define Uses_opstream
  16. #define Uses_ipstream
  17. #include <tvision/tv.h>
  18.  
  19. #include <string.h>
  20.  
  21. TListBox::TListBox( const TRect& bounds,
  22.                     ushort aNumCols,
  23.                     TScrollBar *aScrollBar ) :
  24.     TListViewer(bounds, aNumCols, 0, aScrollBar),
  25.     items( 0 )
  26. {
  27.     setRange(0);
  28. }
  29.  
  30. TListBox::~TListBox()
  31. {
  32. }
  33.  
  34. ushort TListBox::dataSize()
  35. {
  36.     return sizeof(TListBoxRec);
  37. }
  38.  
  39. void TListBox::getData( void * rec )
  40. {
  41.     TListBoxRec *p = (TListBoxRec *)rec;
  42.     p->items = items;
  43.     p->selection = focused;
  44. }
  45.  
  46. void TListBox::getText( char *dest, short item, short maxChars )
  47. {
  48.     if (items != 0 )
  49.         {
  50.         strncpy( dest, (const char *)(items->at(item)), maxChars );
  51.         dest[maxChars] = '\0';
  52.         }
  53.     else
  54.         *dest = EOS;
  55. }
  56.  
  57. void TListBox::newList( TCollection *aList )
  58. {
  59.     destroy( items );
  60.     items = aList;
  61.     if( aList != 0 )
  62.         setRange( aList->getCount() );
  63.     else
  64.         setRange(0);
  65.     if( range > 0 )
  66.         focusItem(0);
  67.     drawView();
  68. }
  69.  
  70. void TListBox::setData( void *rec )
  71. {
  72.     TListBoxRec *p = (TListBoxRec *)rec;
  73.     newList(p->items);
  74.     focusItem(p->selection);
  75.     drawView();
  76. }
  77.  
  78. #if !defined(NO_STREAMABLE)
  79.  
  80. void TListBox::write( opstream& os )
  81. {
  82.     TListViewer::write( os );
  83.     os << items;
  84. }
  85.  
  86. void *TListBox::read( ipstream& is )
  87. {
  88.     TListViewer::read( is );
  89.     is >> items;
  90.     return this;
  91. }
  92.  
  93. TStreamable *TListBox::build()
  94. {
  95.     return new TListBox( streamableInit );
  96. }
  97.  
  98. TListBox::TListBox( StreamableInit ) : TListViewer( streamableInit )
  99. {
  100. }
  101.  
  102. #endif
  103.