home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / DevTools / eText5 / Source / NewXTeXT / XText0.9beta2 / XText.subproj / XText0.m < prev   
Encoding:
Text File  |  1995-07-28  |  2.5 KB  |  128 lines

  1. #import "XText0.h"
  2. #import "XTAction.h"
  3. #import "ErrorStream.h"
  4. #import <objc/objc.h>
  5. #import <appkit/Window.h>
  6. #import <appkit/publicWraps.h>
  7.  
  8. @implementation XText0
  9.  
  10. struct WindowGuts { @defs(Window); }; 
  11.  
  12. /*    everything except the setInitialAction/setErrorStream is copied straight
  13.     out of Window's getFieldEditor:for: method
  14. */
  15.  
  16. + newFieldEditorFor:win initialAction:action estream:errs
  17. {
  18.     id editor = nil;
  19.     
  20.     if ([win isKindOf: [Window class]]) {
  21.         editor = ((struct WindowGuts *)win)->fieldEditor;
  22.         if (editor == nil) {
  23.             editor = [[self allocFromZone:[win zone]] init];
  24.             [editor setCharFilter: &NXFieldFilter];
  25.             [editor setSelectable: YES];
  26.             [editor setFontPanelEnabled: NO];
  27.             [editor setInitialAction:action];
  28.             if (errs)
  29.                 [editor setErrorStream:errs];
  30.             ((struct WindowGuts *)win)->fieldEditor = editor;
  31.         }
  32.     }
  33.     return editor;
  34. }
  35.  
  36. - initFrame:(const NXRect *)frameRect text:(const char *)theText
  37.     alignment:(int)mode
  38. {
  39.     [super initFrame:frameRect text:theText alignment:mode];
  40.     nextAction = nil;
  41.     initialAction = nil;
  42.     errorStream = [ErrorStream default];
  43.     return self;
  44. }
  45.  
  46. /*    We want to make sure that unrecognized messages are reported nicely,
  47.     since it's easy to generate them while your experimenting.
  48. */
  49.  
  50. - doesNotRecognize:(SEL)sel
  51. {
  52.     char msg[100];
  53.  
  54.     sprintf(msg, "No method for %.48s on this text object", sel_getName(sel));
  55.     [errorStream report: msg];
  56.     return self;
  57. }
  58.  
  59. /*    Egregious paranoia: don't set the error stream to something that can't
  60.     report errors...
  61. */
  62.  
  63. - setErrorStream:errs
  64. {
  65.     if ([errs respondsTo: @selector(report:)])
  66.         errorStream = errs;
  67.     else
  68.         [errorStream report:"Invalid argument to setErrorStream:"];
  69.     return self;
  70. }
  71.  
  72. - errorStream
  73. {
  74.     return errorStream;
  75. }
  76.  
  77. - setInitialAction:action
  78. {
  79.     initialAction = nextAction = action;
  80.     return self;
  81. }
  82.  
  83. - initialAction
  84. {
  85.     return initialAction;
  86. }
  87.  
  88. - setNextAction:action
  89. {
  90.     nextAction = action;
  91.     return self;
  92. }
  93.  
  94. - keyDown:(NXEvent *)event
  95. {
  96.     id temp;
  97.  
  98.     temp = nextAction;
  99.     nextAction = initialAction;
  100.     if (temp) {
  101.         temp = [temp applyTo:self event:event];
  102.         if (vFlags.disableAutodisplay) {
  103.             [self setAutodisplay:YES];
  104.             [self display];
  105.         }
  106.         if (sp0.cp == spN.cp)
  107.             [self setSel:sp0.cp :sp0.cp];    // hack to make caret reappear
  108.     }
  109.     return temp ? self : [super keyDown:event];
  110. }
  111.  
  112. - unboundKey
  113. {
  114.     NXBeep();
  115.     return self;
  116. }
  117.  
  118. - disableAutodisplay
  119. {
  120.     // There seems to be a bug with turning off autodisplay in text fields,
  121.     // so try to avoid doing it.
  122.     if (charFilterFunc != &NXFieldFilter)
  123.         [self setAutodisplay:NO];
  124.     return self;
  125. }
  126.  
  127. @end
  128.