home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 (1993) / nebula.bin / SourceCode / MiniExamples / FilterFunctions / TimeTFCell.m < prev   
Encoding:
Text File  |  1991-09-29  |  1.6 KB  |  60 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 "TimeTFCell.h"
  14. #import <appkit/Text.h>
  15.  
  16. @implementation TimeTFCell
  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.  
  29. -init
  30. {
  31.     [super init];
  32.     newTextFilter = (NXTextFilterFunc)timeFilter;
  33.     return self;
  34. }
  35.  
  36. /* Time is specified in the HH:MM format */
  37. char *timeFilter(id textObj, char *inputText, int *inputLength, int position)
  38. {
  39.     char temp[] = "";
  40.     
  41.     if (position == 2) {
  42.         if (*inputText != ':') {
  43.             *inputLength = 0;
  44.             return (temp);
  45.         } else {
  46.             return (inputText);
  47.         }
  48.     } else if (position >= 5) {
  49.         *inputLength = 0;
  50.         return (temp);
  51.     } else if ((*inputText >= '0') && (*inputText <= '9')) {
  52.         return (inputText);
  53.     } else {
  54.         *inputLength = 0;
  55.         return (temp);
  56.     }
  57. }
  58.  
  59. @end
  60.