home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 (1993) / nebula.bin / SourceCode / MiniExamples / FilterFunctions / DateTFCell.m < prev    next >
Encoding:
Text File  |  1991-09-29  |  2.1 KB  |  81 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 "DateTFCell.h"
  14. #import <appkit/Text.h>
  15.  
  16. @implementation DateTFCell
  17.  
  18. - select:(const NXRect *)aRect inView:controlView editor:textObj delegate:anObject start:(int)selStart length:(int)selLength
  19. {
  20.     /* do what the superclass would do */
  21.     [super select:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
  22.  
  23.     /* get the current text filter function */
  24.     oldTextFilter = [textObj textFilter];
  25.     
  26.     /* set the filter func to be the custom function for DateTextField */
  27.     [textObj setTextFilter:(NXTextFilterFunc)dateFilter];
  28.     return self;
  29. }
  30.  
  31. - edit:(const NXRect *)aRect inView:controlView editor:textObj delegate:anObject event:(NXEvent *)theEvent
  32. {
  33.     /* do what the superclass would do */
  34.     [super edit:aRect inView:controlView editor:textObj delegate:anObject event:theEvent];
  35.  
  36.     /* get the current text filter function */
  37.     oldTextFilter = [textObj textFilter];
  38.     
  39.     /* set the filter func to be the custom function for DateTextField */
  40.     [textObj setTextFilter:(NXTextFilterFunc)dateFilter];
  41.     return self;
  42. }
  43.  
  44. - endEditing:anObject
  45. {
  46.     /* restore the original text filter function */
  47.     [anObject setTextFilter:(NXTextFilterFunc)oldTextFilter];
  48.     
  49.     /* do whatever the superclass would do */
  50.     [super endEditing:anObject];
  51.     return self;
  52. }
  53.  
  54. char *dateFilter(id textObj, char *inputText, int *inputLength, int position)
  55. {
  56.     char temp[] = "";
  57.     
  58.     /* The form of the date is MM/DD/YY.  So find a '/' in position 2 and 
  59.      * position 5.  All other characters must be numbers but only 8 
  60.      * characters allowed 
  61.      */
  62.     if ((position == 2) || (position == 5)) {
  63.         if (*inputText != '/') {
  64.             *inputLength = 0;
  65.             return (temp);
  66.         } else {
  67.             return (inputText);
  68.         }
  69.     } else if (position >= 8) {
  70.         *inputLength = 0;
  71.         return (temp);
  72.     } else if ((*inputText >= '0') && (*inputText <= '9')) {
  73.         return (inputText);
  74.     } else {
  75.         *inputLength = 0;
  76.         return (temp);
  77.     }
  78. }
  79.  
  80. @end
  81.