home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / entryf.zip / EFTYPES.CPP next >
C/C++ Source or Header  |  1994-05-20  |  4KB  |  186 lines

  1. #include "eftypes.hpp"
  2. #include <Istring.hpp>
  3. #include <IWindow.hpp>
  4. #include <imsgbox.hpp>
  5.  #define INCL_DOSPROCESS   /* Process and thread values */
  6.  #include <os2.h>
  7.  #include <stdio.h>
  8.  
  9.  #define BEEP_FREQUENCY 1380
  10.  #define BEEP_DURATION 100
  11.  
  12.  
  13. /*******************************************************************
  14. *
  15. *  support of special entry field types
  16. *
  17. *******************************************************************/
  18.  
  19.  
  20.  
  21. EDate::EDate(unsigned long id,IWindow* parent):IEntryField(id,parent)
  22. {
  23.   ((IFocusHandler*)this)->handleEventsFor(this);    
  24. }
  25.  
  26.  
  27. /*******************************************************************
  28. *
  29. *  Post validation of date field with reformat
  30. *
  31. *******************************************************************/
  32.  
  33. Boolean EDate::lostFocus(IControlEvent& event )
  34. {
  35.     IString dStr = text();
  36.     if (dStr.length() == 0) return True;
  37.     dStr.translate('/',' ');
  38.     dStr.translate('-',' ');
  39.     dStr.translate('\\',' ');
  40.     IString A = dStr.word(1);
  41.     IString B = dStr.word(2);
  42.     IString C = dStr.word(3);
  43.     int month = A.asInt();
  44.     int day =   B.asInt();
  45.     int year =  C.asInt();
  46.     if (year < 1900) year += 1900;
  47.     IDate Dt((IDate::Month) month,day,year);
  48.     if (Dt.isValid((IDate::Month) month,day,year))
  49.      {
  50.         dStr = Dt.asString(IDate::yyyy);
  51.         setText(dStr);
  52.         return true;
  53.     }
  54. //    IMessageBox Error(owner());
  55. //    Error.show("Invalid date, must be mm-dd-yy or mm-dd-yyyy ",IMessageBox::okButton);
  56.      APIRET  rc;      /* Return code */
  57.     rc = DosBeep(BEEP_FREQUENCY,
  58.                  BEEP_DURATION *2);
  59.     setFocus();                 
  60.     return true;
  61. }    
  62.  
  63.  
  64. /*******************************************************************
  65. *
  66. *  Post validation of phone field with re-format
  67. *
  68. *******************************************************************/
  69.  
  70. EPhone::EPhone(unsigned long id,IWindow* parent):IEntryField(id,parent)
  71. {
  72.   ((IFocusHandler*)this)->handleEventsFor(this);    
  73. }
  74.  
  75. Boolean EPhone::lostFocus(IControlEvent& event )
  76. {
  77. /*******************************************************************
  78. *
  79. *  Assume a phone is (xxx) xxx-xxxx
  80. *
  81. *******************************************************************/
  82.    Boolean warn;
  83.     IString pStr= text();
  84.     if (pStr.length() == 0) return True;
  85.     pStr.translate('/',' ');
  86.     pStr.translate('-',' ');
  87.     pStr.translate('\\',' ');
  88.     pStr.translate('(',' ');
  89.     pStr.translate(')',' ');
  90.     IString A;
  91.     IString B;
  92.     IString C;
  93.     if (pStr.numWords() ==3)
  94.     {
  95.         A = pStr.word(1);
  96.         B = pStr.word(2);
  97.         C = pStr.word(3);
  98.         warn = false;
  99.     }
  100.     else
  101.     {
  102.     
  103.         A = "   ";
  104.         B = pStr.word(1);
  105.         C = pStr.word(2);
  106.         warn = true;
  107.         
  108.     }    
  109.     IString phone = "(";
  110.     phone += A;
  111.     phone +=") ";
  112.     phone += B;
  113.     phone += '-';
  114.     phone += C;
  115.     setText(phone);
  116.     if (warn)
  117.     {
  118.         IMessageBox Error(owner());
  119.         Error.show("WARNING missing area code ",IMessageBox::okButton);
  120.     }    
  121.     return true;
  122. }    
  123.  
  124.  
  125. /*******************************************************************
  126. *
  127. *  Upper case conversion - post
  128. *
  129. *******************************************************************/
  130.  
  131. EUEntryField::EUEntryField(unsigned long id,IWindow* parent):IEntryField(id,parent)
  132. {
  133.   ((IFocusHandler*)this)->handleEventsFor(this);    
  134.  
  135. }
  136.  
  137.  
  138. Boolean EUEntryField::lostFocus(IControlEvent & event)
  139. {
  140.     IString t = text();            // read the field
  141.     t.upperCase();        // convert to upper case
  142.     setText(t);            // display in upper case
  143.     return true;
  144. }    
  145.  
  146.  
  147.  
  148.  
  149. ENumeric::ENumeric(unsigned long id,IWindow* parent):IEntryField(id,parent)
  150. {
  151.   ((IKeyboardHandler*)this)->handleEventsFor(this);    
  152. }
  153.  
  154.  
  155.  
  156. /*******************************************************************
  157. *
  158. *  Keyboard validation of numeric char input only
  159. *  (allow a decimal point)
  160. *******************************************************************/
  161.  
  162.  
  163. ENumeric::characterKeyPress(IKeyboardEvent& event )
  164. {
  165.  
  166.     char a = event.character();
  167.    if((a >= '0' & a <= '9')| (a =='.'))
  168.     return false;
  169.     else
  170.     {
  171.         
  172.      APIRET  rc;      /* Return code */
  173.     rc = DosBeep(BEEP_FREQUENCY,
  174.                  BEEP_DURATION);
  175.     return true;                 
  176.          
  177.     }    
  178.  
  179. }    
  180.  
  181.  
  182.  
  183.     
  184.  
  185.         
  186.