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

  1. /*
  2.  * TMultiCheckBoxes.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_TMultiCheckBoxes
  13. #include <tvision/tv.h>
  14.  
  15. TMultiCheckBoxes::TMultiCheckBoxes( TRect& bounds, TSItem* aStrings,
  16.                                     uchar aSelRange, ushort aFlags,
  17.                                     const char* aStates) :
  18.     TCluster(bounds, aStrings)
  19. {
  20.     selRange = aSelRange;
  21.     flags = aFlags;
  22.     states = newStr(aStates);
  23. }
  24.  
  25. #if !defined(NO_STREAMABLE)
  26.  
  27. TMultiCheckBoxes::TMultiCheckBoxes( StreamableInit ) :
  28.     TCluster( streamableInit )
  29. {
  30. }
  31.  
  32. void* TMultiCheckBoxes::read( ipstream& is )
  33. {
  34.     TCluster::read(is);
  35.     is >> selRange >> flags;
  36.     states = is.readString();
  37.  
  38.     return this;
  39. }
  40.  
  41. void TMultiCheckBoxes::write( opstream& os )
  42. {
  43.     TCluster::write( os );
  44.     os << selRange << flags;
  45.     os.writeString(states);
  46. }
  47.  
  48. TStreamable* TMultiCheckBoxes::build()
  49. {
  50.     return new TMultiCheckBoxes( streamableInit );
  51. }
  52.  
  53. #endif
  54.  
  55. TMultiCheckBoxes::~TMultiCheckBoxes()
  56. {
  57.     delete states;
  58. }
  59.  
  60. void TMultiCheckBoxes::draw()
  61. {
  62.     drawMultiBox(" [ ] ", states);
  63. }
  64.  
  65. ushort TMultiCheckBoxes::dataSize()
  66. {
  67.     return  sizeof(long);
  68. }
  69.  
  70. uchar TMultiCheckBoxes::multiMark(int item)
  71. {
  72.     return (long)((value&((flags&0xff)<<(item*(flags>>8))))>>(item*(flags>>8)));
  73. }
  74.  
  75. void TMultiCheckBoxes::getData(void* p)
  76. {
  77.     *(unsigned long*)p = value;
  78.     drawView();
  79. }
  80.  
  81. void TMultiCheckBoxes::press(int item)
  82. {
  83.     short curState;
  84.  
  85.     int flo = flags & 0xff;
  86.     int fhi = flags >> 8;
  87.  
  88.     curState = (long) (value & (flo << (item*fhi))) >> (item*fhi);
  89.  
  90.     curState--;
  91.  
  92.     if ((curState >= selRange) || (curState < 0))
  93.         curState = selRange - 1;
  94.  
  95.     value = (long)((value & ~(flo << (item*fhi))) | (curState<<(item * fhi)));
  96. }
  97.  
  98. void TMultiCheckBoxes::setData(void* p)
  99. {
  100.     value = *(unsigned long*)p;
  101.     drawView();
  102. }
  103.