home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.0 / NeXTSTEP3.0.iso / NextDeveloper / Examples / AppKit / Draw / graphicsUndo.subproj / PerformTextGraphicsChange.m < prev    next >
Text File  |  1992-07-17  |  2KB  |  126 lines

  1. #import "drawundo.h"
  2.  
  3. @implementation PerformTextGraphicsChange
  4.  
  5. static id editText = nil;
  6. static id editWindow = nil;
  7.  
  8. - initGraphic:aGraph3iew:aGraphicView
  9. {
  10.     [super init];
  11.  
  12.     if (editText == nil) {
  13.     editText = [[UndoText alloc] initFrame:(NXRect *)0];
  14.     [editText setMonoFont:NO];
  15.     }
  16.  
  17.     if (editWindow == nil) {
  18.     editWindow = [[Window alloc] init];
  19.     }
  20.  
  21.     graphic = aGraphic;
  22.     graphicView = aGraphicView;
  23.     textChange = nil;
  24.  
  25.     return self;
  26. }
  27.  
  28. - free
  29. {
  30.     [textChange free];
  31.     return [super free];
  32. }
  33.  
  34. - (const char *)changeName
  35. {
  36.     return [textChange changeName];
  37. }
  38.  
  39. - undoChange
  40. {
  41.     NXRect bounds;
  42.  
  43.     [self loadGraphic];
  44.     [textChange undoChange];
  45.     [self unloadGraphic];
  46.     [graphic getBounds:&bounds];
  47.     [graphicView cache:&bounds];
  48.     [[graphicView window] flushWindow];
  49.  
  50.     return [super undoChange];
  51. }
  52.  
  53. - redoChange
  54. {
  55.     NXRect bounds;
  56.  
  57.     [self loadGraphic];
  58.     [textChange redoChange];
  59.     [self unloadGraphic];
  60.     [graphic getBounds:&bounds];
  61.     [graphicView cache:&bounds];
  62.     [[graphicView window] flushWindow];
  63.  
  64.     return [super redoChange];
  65. }
  66.  
  67. - (BOOL)incorporateChange:aChange
  68. {
  69.     if (textChange == nil) {
  70.     textChange = aChange;
  71.     return YES;
  72.     } else {
  73.     return NO;
  74.     }
  75. }
  76.  
  77. - loadGraphic
  78. {
  79.     NXRect graphicBounds;
  80.  
  81.     stream = NXOpenMemory([graphic data], [graphic length], NX_READONLY);
  82.     [editText readRichText:stream];
  83.     NXCloseMemory(stream, NX_SAVEBUFFER);
  84.  
  85.     [graphic getBounds:&graphicBounds];
  86.     [editText setFrame:&graphicBounds];
  87.  
  88.     [editWindow setNextResponder:graphicView]; /* so changes can find our */
  89.                                                /* change manager          */
  90.     [[editWindow contentView] addSubview:editText];
  91.  
  92.     [editText selectAll:self];
  93.  
  94.     return self;
  95. }
  96.  
  97. - unloadGraphic
  98. {
  99.     int length, maxlen;
  100.     char *buffer, *data;
  101.  
  102.     [editWindow setNextResponder:nil];
  103.     [editText removeFromSuperview];
  104.     [editText setSel:0 :0];
  105.     [graphic setFont:[editText font]];
  106.  
  107.     stream = NXOpenMemory(NULL, 0, NX_WRITEONLY);
  108.     [editText writeRichText:stream];
  109.     NXGetMemoryBuffer(stream, &buffer, &length, &maxlen);
  110.     NX_ZONEMALLOC([graphic zone], data, char, length);
  111.     bcopy(buffer, data, length);
  112.     NXCloseMemory(stream, NX_FREEBUFFER);
  113.  
  114.     [graphic setData:data];
  115.     [graphic setLength:length];
  116.  
  117.     return self;
  118. }
  119.  
  120. - editText
  121. {
  122.     return editText;
  123. }
  124.  
  125. @end
  126.