home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / c / actlib11 / tvtools / inlong.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-19  |  2.4 KB  |  112 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #define Uses_TStreamable
  4. #define Uses_MsgBox
  5. #define Uses_TInputLong
  6. #include "tvtools.h"
  7. __link( RInputLine )
  8.  
  9.  
  10. #include <string.h>
  11. #include <stdio.h>
  12. #include <values.h>
  13. #include <stdlib.h>
  14. #include <strstream.h>
  15.  
  16.  
  17. // TInputLong
  18.  
  19. const char * const TInputLong::name = "TInputLong";
  20.  
  21. void TInputLong::write( opstream& os )
  22. {
  23.   TInputLine::write( os );
  24.   os << min;
  25.   os << max;
  26. }
  27.  
  28. void *TInputLong::read( ipstream& is )
  29. {
  30.   TInputLine::read( is );
  31.   is >> min;
  32.   is >> max;
  33.   return this;
  34. }
  35.  
  36. TStreamable *TInputLong::build()
  37. {
  38.   return new TInputLong( streamableInit );
  39. }
  40.  
  41.  
  42. TStreamableClass RInputLong( TInputLong::name,
  43.                              TInputLong::build,
  44.                              __DELTA(TInputLong)
  45.                            );
  46.  
  47. TInputLong::TInputLong( const TRect& bounds,
  48.             int aMaxLen,
  49.             long aMin,
  50.             long aMax
  51.                       )
  52.            :TInputRegExp( bounds, aMaxLen, "-0-9" )
  53. {
  54.   min = aMin;
  55.   max = aMax;
  56. }
  57.  
  58.  
  59. TInputLong::TInputLong( int x, int y,
  60.             int aMaxLen,
  61.             long aMin,
  62.             long aMax
  63.                       )
  64.            :TInputRegExp( x, y, aMaxLen, "-0-9" )
  65. {
  66.   min = aMin;
  67.   max = aMax;
  68. }
  69.  
  70.  
  71. ushort TInputLong::dataSize()
  72. {
  73.   return sizeof( long );
  74. }
  75.  
  76. void TInputLong::getData( void *rec )
  77. {
  78.   *(long *)rec = atol(data);
  79. }
  80.  
  81. void TInputLong::setData( void *rec )
  82. {
  83.   ltoa(*(long *)rec, data, 10);
  84.   selectAll(True);
  85. }
  86.  
  87. Boolean TInputLong::valid( ushort command )
  88. {
  89.   switch( command )
  90.         {
  91.           case cmReleasedFocus: return True;
  92.  
  93.           case cmQuit :
  94.           case cmClose:
  95.           case cmOK   : if ( ! *data ) strcpy( data, "0" );
  96.                         long value = atol( data );
  97.                         if ( (value < min) || (value > max) || (! value && *data) )
  98.                            {
  99.                              select();
  100.                              messageBox( mfError | mfOKButton,
  101.                                          "\03Number must be between %ld and %ld.",
  102.                                          min, max
  103.                                        );
  104.                              selectAll( True );
  105.                              return False;
  106.                            }
  107.                         break;
  108.         }
  109.  
  110.   return TInputRegExp::valid( command );
  111. }
  112.