|
|
Sample Programs from NeXSTEP 3.3
/* Generated by Interface Builder */
#import "DateTFCell.h"
#import <appkit/appkit.h>
@implementation DateTFCell
- select:(const NXRect *)aRect inView:controlView editor:textObj delegate:anObject start:(int)selStart length:(int)selLength
{
/* do what the superclass would do */
[super select:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
/* get the current text filter function */
oldTextFilter = [textObj textFilter];
/* set the filter func to be the custom function for DateTextField */
[textObj setTextFilter:(NXTextFilterFunc)dateFilter];
return self;
}
- edit:(const NXRect *)aRect inView:controlView editor:textObj delegate:anObject event:(NXEvent *)theEvent
{
/* do what the superclass would do */
[super edit:aRect inView:controlView editor:textObj delegate:anObject event:theEvent];
/* get the current text filter function */
oldTextFilter = [textObj textFilter];
/* set the filter func to be the custom function for DateTextField */
[textObj setTextFilter:(NXTextFilterFunc)dateFilter];
return self;
}
- endEditing:anObject
{
/* restore the original text filter function */
[anObject setTextFilter:(NXTextFilterFunc)oldTextFilter];
/* do whatever the superclass would do */
[super endEditing:anObject];
return self;
}
char *dateFilter(id textObj, char *inputText, int *inputLength, int position)
{
char temp[] = "";
/* The form of the date is MM/DD/YYYY. So find a '/' in position 2 and
* position 5. All other characters must be numbers but only 10
* characters allowed
*/
if ((position == 2) || (position == 5)) {
if (*inputText != '/') {
*inputLength = 0;
return (temp);
} else {
return (inputText);
}
} else if (position >= 10) {
*inputLength = 0;
return (temp);
} else if ((*inputText >= '0') && (*inputText <= '9')) {
return (inputText);
} else {
*inputLength = 0;
return (temp);
}
}
@end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.