home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 (1993) / nebula.bin / SourceCode / MiniExamples / FilterFunctions / TimeTextField.m < prev    next >
Encoding:
Text File  |  1991-09-29  |  1.7 KB  |  65 lines

  1.  
  2. /*
  3.  *      You may freely copy, distribute and reuse the code
  4.  *      in this example.  NeXT disclaims any warranty of
  5.  *      any kind, expressed or implied, as to its fitness
  6.  *      for any particular use.
  7.  *
  8.  *      Written by: Susan Rayl
  9.  *
  10.  *      Created 21-Mar-91
  11.  */
  12.  
  13. #import "TimeTextField.h"
  14. #import "TimeTFCell.h"
  15. #import <strings.h>
  16.  
  17. @implementation TimeTextField
  18.  
  19.  
  20. /* set the custom Cell class as the Cell class for this TextField class */
  21. + initialize
  22. {
  23.     [super initialize];
  24.     [TimeTextField setCellClass:[TimeTFCell class]];
  25.     return self;
  26. }
  27.  
  28. /* override to call endEditing: on the Cell so that the text filter function of 
  29.  * the fieldEditor will be reset to the original. 
  30.  */
  31. - textDidEnd:anObject endChar:(unsigned short)whyEnd
  32. {
  33.     [[self cell] endEditing:anObject];
  34.     [super textDidEnd:anObject endChar:whyEnd];
  35.     return self;
  36. }
  37.  
  38. /* override to check that when the user presses return to stop editing the 
  39.  * field, the entry is complete and correct.  Don't accept the value until it 
  40.  * has the right length.  Remember, the format of the entry has been validated 
  41.  * by the text filter function so just check the length here. 
  42.  */
  43. - textWillEnd:textObject
  44. {
  45.     char *currVal;
  46.     
  47.     /* get the current value in the DateTextField */
  48.     currVal = (char *)[self stringValue];
  49.     
  50.     /* if the string is 5 chars long then, because it has been filtered, it 
  51.      * must completely and correctly specify a date string.  Else, the user 
  52.      * has terminated the editing of the field before completing the time.  
  53.      * By returning nil, the TimeTextField will remain the firstResponder 
  54.      * and the user must finish entering the date.
  55.      */
  56.     if (strlen(currVal) == 5) {
  57.         return nil;
  58.     } else {
  59.         [super textWillEnd:textObject];
  60.         return self;
  61.     }
  62. }
  63.  
  64. @end
  65.