home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / c / actlib11 / tvtools / indate.cpp < prev    next >
C/C++ Source or Header  |  1993-02-02  |  2KB  |  74 lines

  1. /*  Copyright (C) 1993   Marc Stern  (internet: stern@mble.philips.be)  */
  2.  
  3. #define Uses_TStreamable
  4. #define Uses_MsgBox
  5. #define Uses_TInputDate
  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. #include "date.h"
  17.  
  18.  
  19. // TInputDate
  20.  
  21. const char * const TInputDate::name = "TInputDate";
  22.  
  23. TInputDate::TInputDate( const TRect& bounds )
  24.            :TInputRegExp( bounds, 7, "0-9" )
  25. {
  26. }
  27.  
  28.  
  29. TInputDate::TInputDate( int x, int y )
  30.            :TInputRegExp( x, y, 7, "0-9" )
  31. {
  32. }
  33.  
  34.  
  35. Boolean TInputDate::valid( ushort command )
  36. {
  37.   switch( command )
  38.         {
  39.           case cmReleasedFocus: return True;
  40.  
  41.           case cmQuit :
  42.           case cmClose:
  43.           case cmOK   :
  44. /*
  45.        if ( ! *data ) { struct date today ;
  46.                         getdate( &today ) ; // Get current date
  47.                         char buffer[10];
  48.                         sprintf( buffer, "%02d%02d%02d",
  49.                                  today.da_year - 1900, today.da_mon + 1, today.da_day
  50.                                );
  51.                         setData( buffer );
  52.                       }
  53. */
  54.                         unsigned long yymmdd = 0;
  55.                         sscanf( data , "%lu" , &yymmdd );
  56. #pragma warn -sig
  57.                         int year = yymmdd / 10000;
  58.                         int month = (yymmdd % 10000) / 100;
  59.                         int day = yymmdd % 100;
  60. #pragma warn .sig
  61.  
  62.                         if ( ! isdatevalid(day, month, year) )
  63.                            {
  64.                              select();
  65.                              messageBox( " \n\03Invalid date !", mfError | mfOKButton );
  66.                              selectAll( True );
  67.                              return False;
  68.                            }
  69.                         break;
  70.         }
  71.  
  72.   return TInputRegExp::valid( command );
  73. }
  74.