home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / MiniExamples / FilterFunctions / SSTFCell.m < prev    next >
Text File  |  1991-09-29  |  2KB  |  59 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 "SSTFCell.h"
  14. #import <appkit/Text.h>
  15.  
  16. @implementation SSTFCell
  17.  
  18. /* fill in the real text filter function for this type of TextFieldCell 
  19.  * Note that this code is in the initialize method, not the initFrame:  method.
  20.  * The initialize method initializes attributes of the class before it's ever used;
  21.  * that is, before any instances are ever created.  Ìn this initialize method, the
  22.  * cell class of the SSTextField is being reset from the default TextFieldCell to
  23.  * a custom TextFieldCell class, SSTFCell.  This must be done before any
  24.  * instances are created so that all instances will have the correct cell class.
  25.  * Remember, initialize is called before any instances of the class are created;
  26.  * initFrame: is called as each instance is created.
  27.  */
  28. -init
  29. {
  30.     [super init];
  31.     newTextFilter = (NXTextFilterFunc)ssFilter;
  32.     return self;
  33. }
  34.  
  35. /* Social Security nuumber is specified in the 123-45-6789 format */
  36. char *ssFilter(id textObj, char *inputText, int *inputLength, int position)
  37. {
  38.     char temp[] = "";
  39.     
  40.     if ((position == 3) || (position == 6)) {
  41.         if (*inputText != '-') {
  42.             *inputLength = 0;
  43.             return (temp);
  44.         } else {
  45.             return (inputText);
  46.         }
  47.     } else if (position >= 11) {
  48.         *inputLength = 0;
  49.         return (temp);
  50.     } else if ((*inputText >= '0') && (*inputText <= '9')) {
  51.         return (inputText);
  52.     } else {
  53.         *inputLength = 0;
  54.         return (temp);
  55.     }
  56. }
  57.  
  58. @end
  59.