home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / IBPalettes / WWTCLKit / WWTextField.m < prev    next >
Encoding:
Text File  |  1995-03-22  |  4.6 KB  |  216 lines

  1.  
  2. #import "WWTextField.h"
  3. #import "WWTextFieldCell.h"
  4.  
  5. #import "avoidStupidWarnings.h"
  6.  
  7. @implementation WWTextField
  8.  
  9. static id myStoredCellClass;
  10.  
  11.  
  12. + initialize 
  13.   [WWTextField setVersion:1]; 
  14.  
  15.   if (self == [WWTextField class])
  16.   {  myStoredCellClass = [WWTextFieldCell class];
  17.   }
  18.  
  19.   return self; 
  20. }
  21. //
  22. + setCellClass:classID
  23. {
  24.   myStoredCellClass = classID;
  25.   return self;
  26. }
  27. ////////////////////////////////////////////////////////
  28. - initFrame:(const NXRect *)frameRect
  29. {
  30.   id          oldCell;
  31.   const char  *WDRAG_PBTYPE[] = { NXFilenamePboardType, NULL};
  32.  
  33.  
  34.   [super initFrame:frameRect];
  35.   oldCell = [self setCell:[[WWTextFieldCell alloc] init]];
  36.   [oldCell free];
  37.   [self registerForDraggedTypes:WDRAG_PBTYPE count:1];
  38.   [[self cell] setScrollable:YES];
  39.   return self;
  40. }
  41. //
  42. - init
  43. {
  44.   id  oldCell;
  45.  
  46.  
  47.   [super init];
  48.   oldCell = [self setCell:[[myStoredCellClass alloc] init]];
  49.   [oldCell free];
  50.   return self;
  51. }
  52.  
  53. - awake
  54. {
  55.   const char  *WDRAG_PBTYPE[] = { NXFilenamePboardType, NULL};
  56.  
  57.  
  58.   [super awake];
  59.   [self registerForDraggedTypes:WDRAG_PBTYPE count:1];
  60.  
  61.   return self;
  62. }
  63.  
  64. - free
  65. {
  66.    const char *fileType[] = { "" };
  67.    Pasteboard *pboard = [Pasteboard newName:NXDragPboard];
  68.  
  69.    // why doesn't this work?
  70.    [pboard declareTypes:fileType num:0 owner:nil];
  71.    [self unregisterDraggedTypes];
  72.  
  73.    return [super free];
  74. }
  75.  
  76. - sendAction:(SEL)theAction to:theTarget
  77. {
  78.   if ([cell respondsTo:@selector(updateInterp)])
  79.   {  [cell updateInterp];
  80.   }
  81.  
  82.   return [super sendAction:theAction to:theTarget];
  83. }
  84.  
  85. // need to be able to see the cell's tclVar...
  86. - setTclVar:(const char *)str { return [[self cell] setTclVar:str]; }
  87. - (const char *)tclVar { return [[self cell] tclVar]; }
  88.  
  89. // need to be able to see the cell's controlString...
  90. - setControlString:(const char *)str { return [[self cell] setControlString:str]; }
  91. - (const char *)controlString { return [[self cell] controlString]; }
  92.  
  93. // need to be able to see the cell's tclExpression...
  94. - setTclExpression:(const char *)str { return [[self cell] setTclExpression:str]; }
  95. - (const char *)tclExpression { return [[self cell] tclExpression]; }
  96.  
  97. - setInterp:newInterp {  return [[self cell] setInterp:newInterp]; }
  98. - evaluateSelf { return [[self cell] evaluateSelf]; }
  99.  
  100. ////////////////////////////////////////////////////////////////////
  101. //            Font stuff
  102. ///////////////////////////////////////////////////////////////////
  103.  
  104. - changeFont:sender
  105. {
  106.   [cell setFont:[sender convertFont:[cell font]]];
  107.   if ([cell respondsTo:@selector(updateInterp)])
  108.   {  [cell updateInterp];
  109.   }
  110.   return self;
  111. }
  112.  
  113.  
  114. - changeIBFont:sender
  115. {
  116.   [cell setFont:[sender convertFont:[cell font]]];
  117.   if ([cell respondsTo:@selector(updateInterp)])
  118.   {  [cell updateInterp];
  119.   }
  120.   return self;
  121. }
  122.  
  123.  
  124. ////////////////////////////////////////////////////////////////////
  125. //            Dragging stuff
  126. ///////////////////////////////////////////////////////////////////
  127.  
  128.  
  129. - (NXDragOperation)draggingEntered:(id <NXDraggingInfo>)sender
  130. {
  131.     Pasteboard    *pboard;
  132.     const NXAtom  *theType;
  133.  
  134.  
  135.     pboard = [sender draggingPasteboard];
  136.     theType = [pboard types];
  137.  
  138.     if (*theType != NXFilenamePboardType)
  139.     {  fprintf(stderr, "Right type: acknowledging dragging starting...\n");
  140.        fflush(stderr);
  141.        return NX_DragOperationCopy;
  142.     }
  143.     fprintf(stderr, "Wrong type: unable to acknowledge dragging starting.\n");
  144.     fflush(stderr);
  145.  
  146.     return NX_DragOperationNone;
  147. }
  148.  
  149. - (NXDragOperation)draggingUpdated:(id <NXDraggingInfo>)sender
  150. {
  151.     return NX_DragOperationCopy;
  152. }
  153.  
  154.  
  155. - (BOOL)performDragOperation:(id <NXDraggingInfo>)sender
  156. {
  157.     Pasteboard    *pboard;
  158.     char          *argv;
  159.     int           len;
  160.     const NXAtom  *theType;
  161.  
  162.  
  163.     pboard = [sender draggingPasteboard];
  164.     theType = [pboard types];
  165.  
  166.     if (*theType != NXFilenamePboardType)
  167.     {  if ([pboard readType:NXFilenamePboardType data:&argv length:&len] == nil)
  168.        {  fprintf(stderr, "unable to read filename from pasteboard.\n"); fflush(stderr);
  169.       return NO;
  170.        }
  171.        else
  172.        {  [self setStringValue:(const char *)argv];
  173.       [self display];
  174.           return YES;
  175.        }
  176.     }
  177.     else
  178.     {  fprintf(stderr, "The type of the dragged object isn't a filename.\n"); fflush(stderr);
  179.        return NO;
  180.     }
  181. }
  182.  
  183. // IB stuff
  184. - (const char *)getInspectorClassName 
  185. {  
  186.    NXEvent  *event = [NXApp currentEvent];
  187.  
  188.    if (event->flags & NX_ALTERNATEMASK)
  189.    {  return [super getInspectorClassName];
  190.    }
  191.    
  192.    return "WWTextFieldIBInspector"; 
  193. }
  194.  
  195. - write:(NXTypedStream *)stream 
  196. {
  197.    [super write:stream];
  198.    return self;
  199. }
  200. //
  201. - read:(NXTypedStream *)stream 
  202. {
  203.    int version;
  204.  
  205.    [super read:stream];
  206.  
  207.    version = NXTypedStreamClassVersion(stream, "WWTextField");
  208.    if (version == 1)
  209.    {  
  210.    }
  211.    return self;
  212. }
  213.  
  214. @end
  215.