home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / DEV.Z / ChangeDetail.m < prev    next >
Encoding:
Text File  |  1995-08-03  |  5.7 KB  |  354 lines

  1. #import "drawundo.h"
  2.  
  3. /*
  4.  * Please refer to external documentation about Draw
  5.  * with Undo for information about what ChangeDetails 
  6.  * are and where they fit in.
  7.  *
  8.  * The ChangeDetail.h and ChangeDetail.m files contain
  9.  * the @interfaces and @implementations for the 11 
  10.  * subclasses of ChangeDetail, as well as for ChangeDetail
  11.  * itself. We grouped all the classes into one pair of 
  12.  * files because the classes are so tiny and their behavior
  13.  * is so similar.
  14.  *
  15.  * ChangeDetail
  16.  *     ArrowChangeDetail
  17.  *     DimensionsChangeDetail
  18.  *     FillColorChangeDetail
  19.  *     FillModeChangeDetail
  20.  *     LineCapChangeDetail
  21.  *     LineColorChangeDetail
  22.  *     LineJoinChangeDetail
  23.  *     LineWidthChangeDetail
  24.  *     MoveChangeDetail
  25.  *     OrderChangeDetail
  26.  * 
  27.  */
  28.  
  29. @interface ChangeDetail(PrivateMethods)
  30.  
  31. - (BOOL)personalChangeExpected;
  32.  
  33. @end
  34.  
  35. @implementation ChangeDetail
  36.  
  37. - initGraphic:aGraphic change:aChange
  38. {
  39.     NSMutableArray *subGraphics;
  40.     int count, i;
  41.     id changeDetail;
  42.     
  43.     graphic = aGraphic;
  44.     change = aChange;
  45.     if ([graphic isKindOfClass:[Group class]] && [self useNestedDetails]) {
  46.         detailsDetails = [[NSArray alloc] init];
  47.     subGraphics = [(Group *)graphic subGraphics];
  48.     count = [subGraphics count];
  49.     changeExpected = NO;
  50.     for (i = 0; i < count; i++) {
  51.         changeDetail = [[[aChange changeDetailClass] alloc] initGraphic:[subGraphics objectAtIndex:i] change:aChange];
  52.         changeExpected = changeExpected || [changeDetail changeExpected];
  53.         [detailsDetails addObject:changeDetail];
  54.     }
  55.     } else {
  56.         detailsDetails = nil;
  57.     changeExpected = [self personalChangeExpected];
  58.     }
  59.     return self;
  60. }
  61.  
  62. - (void)dealloc
  63. {
  64.     [detailsDetails removeAllObjects];
  65.     [detailsDetails release];
  66.     [super dealloc];
  67. }
  68.  
  69. - (Graphic *)graphic
  70. {
  71.     return graphic;
  72. }
  73.  
  74. - (BOOL)useNestedDetails
  75. {
  76.     return YES;
  77. }
  78.  
  79. - (BOOL)changeExpected
  80. {
  81.     return changeExpected;
  82. }
  83.  
  84. - (void)recordDetail
  85. {
  86.     if(detailsDetails)
  87.         [detailsDetails makeObjectsPerform:@selector(recordDetail)];
  88.     else
  89.       [self recordIt]; 
  90. }
  91.  
  92. - (void)undoDetail
  93. {
  94.     if (detailsDetails)
  95.         [detailsDetails makeObjectsPerform:@selector(undoDetail)];
  96.     else
  97.       [self undoIt]; 
  98. }
  99.  
  100. - (void)redoDetail
  101. {
  102.     if (detailsDetails)
  103.         [detailsDetails makeObjectsPerform:@selector(redoDetail)];
  104.     else
  105.       [self redoIt]; 
  106. }
  107.  
  108. - (void)recordIt
  109. {
  110.     /* Implemented by subclasses */
  111.      
  112. }
  113.  
  114. - (void)undoIt
  115. {
  116.     /* Implemented by subclasses */
  117.      
  118. }
  119.  
  120. - (void)redoIt
  121. {
  122.     /* Implemented by subclasses */
  123.      
  124. }
  125.  
  126. - (BOOL)personalChangeExpected
  127. {
  128.     return YES;
  129. }
  130.  
  131. @end
  132.  
  133. @implementation ArrowChangeDetail
  134.  
  135. - (void)recordIt
  136. {
  137.     oldLineArrow = [graphic lineArrow]; 
  138. }
  139.  
  140. - (void)undoIt
  141. {
  142.     [graphic setLineArrow:oldLineArrow]; 
  143. }
  144.  
  145. - (void)redoIt
  146. {
  147.     [graphic setLineArrow:[change lineArrow]]; 
  148. }
  149.  
  150. - (BOOL)personalChangeExpected
  151. {
  152.     return ([graphic lineArrow] != [change lineArrow]);
  153. }
  154.  
  155. @end
  156.  
  157. @implementation DimensionsChangeDetail
  158.  
  159. - (BOOL)useNestedDetails
  160. {
  161.     return NO;
  162. }
  163.  
  164. - (void)recordDetail
  165. {
  166.     oldBounds = [graphic bounds]; 
  167. }
  168.  
  169. - (void)undoDetail
  170. {
  171.     newBounds = [graphic bounds];
  172.     [graphic setBounds:oldBounds]; 
  173. }
  174.  
  175. - (void)redoDetail
  176. {
  177.     [graphic setBounds:newBounds]; 
  178. }
  179.  
  180. @end
  181.  
  182. @implementation FillChangeDetail
  183.  
  184. - (void)recordIt
  185. {
  186.     [oldFillColor release];
  187.     oldFillColor = [[graphic fillColor] copy];
  188.     oldFillMode = [graphic fill]; 
  189. }
  190.  
  191. - (void)undoIt
  192. {
  193.     [newFillColor release];
  194.     newFillColor = [[graphic fillColor] copy];
  195.     newFillMode = [graphic fill];
  196.     [graphic setFillColor:oldFillColor];
  197.     [graphic setFill:oldFillMode]; 
  198. }
  199.  
  200. - (void)redoIt
  201. {
  202.     [graphic setFillColor:newFillColor];
  203.     [graphic setFill:newFillMode]; 
  204. }
  205.  
  206. - (BOOL)personalChangeExpected
  207. {
  208.     return ([graphic fill] != [change fill]);
  209. }
  210.  
  211. @end
  212.  
  213. @implementation LineCapChangeDetail
  214.  
  215. - (void)recordIt
  216. {
  217.     oldLineCap = [graphic lineCap]; 
  218. }
  219.  
  220. - (void)undoIt
  221. {
  222.     [graphic setLineCap:oldLineCap]; 
  223. }
  224.  
  225. - (void)redoIt
  226. {
  227.     [graphic setLineCap:[change lineCap]]; 
  228. }
  229.  
  230. - (BOOL)personalChangeExpected
  231. {
  232.     return ([graphic lineCap] != [change lineCap]);
  233. }
  234.  
  235. @end
  236.  
  237. @implementation LineColorChangeDetail
  238.  
  239. - (void)recordIt
  240. {
  241.     [oldColor release];
  242.     oldColor = [[graphic lineColor] copy];
  243.     oldIsOutlined = [graphic isOutlined]; 
  244. }
  245.  
  246. - (void)undoIt
  247. {
  248.     [graphic setLineColor:oldColor];
  249.     [graphic setOutlined:oldIsOutlined]; 
  250. }
  251.  
  252. - (void)redoIt
  253. {
  254.     NSColor * color = [change lineColor];
  255.     [graphic setLineColor:color];
  256.     [graphic setOutlined:YES]; 
  257. }
  258.  
  259. - (BOOL)personalChangeExpected
  260. {
  261.     return (![[graphic lineColor] isEqual:[change lineColor]]);
  262. }
  263.  
  264. @end
  265.  
  266. @implementation LineJoinChangeDetail
  267.  
  268. - (void)recordIt
  269. {
  270.     oldLineJoin = [graphic lineJoin]; 
  271. }
  272.  
  273. - (void)undoIt
  274. {
  275.     [graphic setLineJoin:oldLineJoin]; 
  276. }
  277.  
  278. - (void)redoIt
  279. {
  280.     [graphic setLineJoin:[change lineJoin]]; 
  281. }
  282.  
  283. - (BOOL)personalChangeExpected
  284. {
  285.     return ([graphic lineJoin] != [change lineJoin]);
  286. }
  287.  
  288. @end
  289.  
  290. @implementation LineWidthChangeDetail
  291.  
  292. - (void)recordIt
  293. {
  294.     oldLineWidth = [graphic lineWidth]; 
  295. }
  296.  
  297. - (void)undoIt
  298. {
  299.     [graphic setLineWidth:&oldLineWidth]; 
  300. }
  301.  
  302. - (void)redoIt
  303. {
  304.     float lineWidth = [change lineWidth];
  305.     [graphic setLineWidth:&lineWidth]; 
  306. }
  307.  
  308. - (BOOL)personalChangeExpected
  309. {
  310.     return ([graphic lineWidth] != [change lineWidth]);
  311. }
  312.  
  313. @end
  314.  
  315. @implementation MoveChangeDetail
  316.  
  317. - (BOOL)useNestedDetails
  318. {
  319.     return NO;
  320. }
  321.  
  322. - (void)undoDetail
  323. {
  324.     NSPoint offset = [change undoVector];
  325.     [graphic moveBy:&offset]; 
  326. }
  327.  
  328. - (void)redoDetail
  329. {
  330.     NSPoint offset = [change undoVector];
  331.     [graphic moveBy:&offset]; 
  332. }
  333.  
  334. @end
  335.  
  336. @implementation OrderChangeDetail
  337.  
  338. - (BOOL)useNestedDetails
  339. {
  340.     return NO;
  341. }
  342.  
  343. - (void)recordGraphicPositionIn:graphicList
  344. {
  345.     graphicPosition = [graphicList indexOfObject:graphic]; 
  346. }
  347.  
  348. - (unsigned)graphicPosition
  349. {
  350.     return graphicPosition;
  351. }
  352.  
  353. @end
  354.