home *** CD-ROM | disk | FTP | other *** search
/ C Programming Starter Kit 2.0 / SamsPublishing-CProgrammingStarterKit-v2.0-Win31.iso / bc45 / owlsrc.pak / FILTVAL.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-24  |  1.8 KB  |  76 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // (C) Copyright 1993, 1994 by Borland International, All Rights Reserved
  4. //
  5. //----------------------------------------------------------------------------
  6. #pragma hdrignore SECTION
  7. #include <owl/owlpch.h>
  8. #include <owl/validate.h>
  9. #include <owl/applicat.h>
  10. #include <owl/appdict.h>
  11. #include <owl/framewin.h>
  12.  
  13. #if !defined(SECTION) || SECTION == 1
  14.  
  15.  
  16. TFilterValidator::TFilterValidator(const TCharSet& validChars)
  17. :
  18.   TValidator()
  19. {
  20.   ValidChars = validChars;
  21. }
  22.  
  23. bool
  24. TFilterValidator::IsValidInput(char far* str, bool /*suppressFill*/)
  25. {
  26.   for (const char far* p = str; *p; p++)
  27.     if (!ValidChars.Has(*p))
  28.       return false;
  29.   return true;
  30. }
  31.  
  32. bool
  33. TFilterValidator::IsValid(const char far* str)
  34. {
  35.   for (const char far* p = str; *p; p++)
  36.     if (!ValidChars.Has(*p))
  37.       return false;
  38.   return true;
  39. }
  40.  
  41. void
  42. TFilterValidator::Error()
  43. {
  44.   TApplication* app = GetApplicationObject();
  45.   string msg = app->LoadString(IDS_VALINVALIDCHAR);
  46.   TWindow* w = GetWindowPtr(app->GetMainWindow()->GetLastActivePopup());
  47.   if (w)
  48.     w->MessageBox(msg.c_str(), app->GetName(), MB_ICONEXCLAMATION|MB_OK);
  49.   else
  50.     ::MessageBox(0, msg.c_str(), app->GetName(), MB_ICONEXCLAMATION|MB_OK|MB_TASKMODAL);
  51. }
  52.  
  53. #endif
  54. #if !defined(SECTION) || SECTION == 2
  55.  
  56. IMPLEMENT_STREAMABLE1(TFilterValidator, TValidator);
  57.  
  58. void*
  59. TFilterValidator::Streamer::Read(ipstream& is, uint32 /*version*/) const
  60. {
  61.   ReadBaseObject((TValidator*)GetObject(), is);
  62.   is >> GetObject()->ValidChars;
  63.   return GetObject();
  64. }
  65.  
  66. void
  67. TFilterValidator::Streamer::Write(opstream& os) const
  68. {
  69.   WriteBaseObject((TValidator*)GetObject(), os);
  70.   os << GetObject()->ValidChars;
  71. }
  72.  
  73. #endif
  74.  
  75.  
  76.