home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / MiniExamples / FilterFunctions / SSTextField.m < prev    next >
Text File  |  1991-09-29  |  2KB  |  64 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 "SSTextField.h"
  14. #import "SSTFCell.h"
  15. #import <strings.h>
  16.  
  17. @implementation SSTextField
  18.  
  19. /* set the custom Cell class as the Cell class for this TextField class */
  20. + initialize
  21. {
  22.     [super initialize];
  23.     [SSTextField setCellClass:[SSTFCell class]];
  24.     return self;
  25. }
  26.  
  27. /* override to call endEditing: on the Cell so that the text filter function of 
  28.  * the fieldEditor will be reset to the original. 
  29.  */
  30. - textDidEnd:anObject endChar:(unsigned short)whyEnd
  31. {
  32.     [[self cell] endEditing:anObject];
  33.     [super textDidEnd:anObject endChar:whyEnd];
  34.     return self;
  35. }
  36.  
  37. /* override to check that when the user presses return to stop editing the 
  38.  * field, the entry is complete and correct.  Don't accept the value until it 
  39.  * has the right length.  Remember, the format of the entry has been validated 
  40.  * by the text filter function so just check the length here. 
  41.  */
  42. - textWillEnd:textObject
  43. {
  44.     char *currVal;
  45.     
  46.     /* get the current value in the DateTextField */
  47.     currVal = (char *)[self stringValue];
  48.     
  49.     /* if the string is 11 chars long then, because it's been filtered, it 
  50.      * must completely and correctly specify a date string.  Else, the user 
  51.      * has terminated the editing of the field before completing the SS.  
  52.      * By returning nil, the SSTextField will remain the firstResponder 
  53.      * and the user must finish entering the date.
  54.      */
  55.     if (strlen(currVal) == 11) {
  56.         return nil;
  57.     } else {
  58.         [super textWillEnd:textObject];
  59.         return self;
  60.     }
  61. }
  62.  
  63. @end
  64.