
/*
 *      You may freely copy, distribute and reuse the code
 *      in this example.  NeXT disclaims any warranty of
 *      any kind, expressed or implied, as to its fitness
 *      for any particular use.
 *
 *      Written by: Susan Rayl
 *
 *      Created 21-Mar-91
 */

#import "SSTFCell.h"
#import <appkit/Text.h>

@implementation SSTFCell

/* fill in the real text filter function for this type of TextFieldCell 
 * Note that this code is in the initialize method, not the initFrame:  method.
 * The initialize method initializes attributes of the class before it's ever used;
 * that is, before any instances are ever created.  Œn this initialize method, the
 * cell class of the SSTextField is being reset from the default TextFieldCell to
 * a custom TextFieldCell class, SSTFCell.  This must be done before any
 * instances are created so that all instances will have the correct cell class.
 * Remember, initialize is called before any instances of the class are created;
 * initFrame: is called as each instance is created.
 */
-init
{
	[super init];
	newTextFilter = (NXTextFilterFunc)ssFilter;
	return self;
}

/* Social Security nuumber is specified in the 123-45-6789 format */
char *ssFilter(id textObj, char *inputText, int *inputLength, int position)
{
	char temp[] = "";
	
	if ((position == 3) || (position == 6)) {
		if (*inputText != '-') {
			*inputLength = 0;
			return (temp);
		} else {
			return (inputText);
		}
	} else if (position >= 11) {
		*inputLength = 0;
		return (temp);
	} else if ((*inputText >= '0') && (*inputText <= '9')) {
		return (inputText);
	} else {
		*inputLength = 0;
		return (temp);
	}
}

@end
