home *** CD-ROM | disk | FTP | other *** search
/ Nebula / nebula.bin / SourceCode / MiniExamples / FilterFunctions / FilterTextCell.m < prev    next >
Text File  |  1991-09-29  |  2KB  |  70 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 "FilterTextCell.h"
  14. #import <appkit/Text.h>
  15.  
  16. @implementation FilterTextCell
  17.  
  18. /* initialize the newTextFilter instance variable to nil until an instance of a 
  19.  * subclass of FilterTextCell fills in a value according to its requirements 
  20.  *
  21.  * Note that this code is in the initialize method, not the initFrame:  method.
  22.  * The initialize method initializes attributes of the class before it's ever used;
  23.  * that is, before any instances are ever created.  Ìn this initialize method, the
  24.  * cell class of the SSTextField is being reset from the default TextFieldCell to
  25.  * a custom TextFieldCell class, SSTFCell.  This must be done before any
  26.  * instances are created so that all instances will have the correct cell class.
  27.  * Remember, initialize is called before any instances of the class are created;
  28.  * initFrame: is called as each instance is created.
  29.  */
  30.  
  31.  
  32. - init
  33. {
  34.     [super init];
  35.     newTextFilter = (NXTextFilterFunc)nil;
  36.     return self;
  37. }
  38.  
  39. /* save original filter func and set the new one when the user selects the text 
  40.  * in this Cell by TABbing into this TextField. 
  41.  */
  42. - select:(const NXRect *)aRect inView:controlView editor:textObj delegate:anObject start:(int)selStart length:(int)selLength
  43. {
  44.     [super select:aRect inView:controlView editor:textObj delegate:anObject start:selStart length:selLength];
  45.     oldTextFilter = [textObj textFilter];
  46.     [textObj setTextFilter:(NXTextFilterFunc)newTextFilter];
  47.     return self;
  48. }
  49.  
  50. /* save original filter func and set the new one when the user selects the text 
  51.  * in this Cell by clicking in this TextField. 
  52.  */
  53. - edit:(const NXRect *)aRect inView:controlView editor:textObj delegate:anObject event:(NXEvent *)theEvent
  54. {
  55.     [super edit:aRect inView:controlView editor:textObj delegate:anObject event:theEvent];
  56.     oldTextFilter = [textObj textFilter];
  57.     [textObj setTextFilter:(NXTextFilterFunc)newTextFilter];
  58.     return self;
  59. }
  60.  
  61. /* reset the original filter func after the user is done */
  62. - endEditing:anObject
  63. {
  64.     [anObject setTextFilter:(NXTextFilterFunc)oldTextFilter];
  65.     [super endEditing:anObject];
  66.     return self;
  67. }
  68.  
  69. @end
  70.