|
|
1.1 ! root 1: ! 2: /* Generated by Interface Builder */ ! 3: ! 4: #import "DateTFCell.h" ! 5: #import <appkit/appkit.h> ! 6: ! 7: @implementation DateTFCell ! 8: ! 9: - select:(const NXRect *)aRect inView:controlView editor:textObj delegate:anObject start:(int)selStart length:(int)selLength ! 10: { ! 11: /* do what the superclass would do */ ! 12: [super select:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength]; ! 13: ! 14: /* get the current text filter function */ ! 15: oldTextFilter = [textObj textFilter]; ! 16: ! 17: /* set the filter func to be the custom function for DateTextField */ ! 18: [textObj setTextFilter:(NXTextFilterFunc)dateFilter]; ! 19: return self; ! 20: } ! 21: ! 22: - edit:(const NXRect *)aRect inView:controlView editor:textObj delegate:anObject event:(NXEvent *)theEvent ! 23: { ! 24: /* do what the superclass would do */ ! 25: [super edit:aRect inView:controlView editor:textObj delegate:anObject event:theEvent]; ! 26: ! 27: /* get the current text filter function */ ! 28: oldTextFilter = [textObj textFilter]; ! 29: ! 30: /* set the filter func to be the custom function for DateTextField */ ! 31: [textObj setTextFilter:(NXTextFilterFunc)dateFilter]; ! 32: return self; ! 33: } ! 34: ! 35: - endEditing:anObject ! 36: { ! 37: /* restore the original text filter function */ ! 38: [anObject setTextFilter:(NXTextFilterFunc)oldTextFilter]; ! 39: ! 40: /* do whatever the superclass would do */ ! 41: [super endEditing:anObject]; ! 42: return self; ! 43: } ! 44: ! 45: char *dateFilter(id textObj, char *inputText, int *inputLength, int position) ! 46: { ! 47: char temp[] = ""; ! 48: ! 49: /* The form of the date is MM/DD/YYYY. So find a '/' in position 2 and ! 50: * position 5. All other characters must be numbers but only 10 ! 51: * characters allowed ! 52: */ ! 53: if ((position == 2) || (position == 5)) { ! 54: if (*inputText != '/') { ! 55: *inputLength = 0; ! 56: return (temp); ! 57: } else { ! 58: return (inputText); ! 59: } ! 60: } else if (position >= 10) { ! 61: *inputLength = 0; ! 62: return (temp); ! 63: } else if ((*inputText >= '0') && (*inputText <= '9')) { ! 64: return (inputText); ! 65: } else { ! 66: *inputLength = 0; ! 67: return (temp); ! 68: } ! 69: } ! 70: ! 71: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.