|
|
1.1 root 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: List *subGraphics;
40: int count, i;
41: id changeDetail;
42:
43: graphic = aGraphic;
44: change = aChange;
45: if ([graphic isKindOf:[Group class]] && [self useNestedDetails]) {
46: detailsDetails = [[List 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 objectAt: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: - free
63: {
64: [detailsDetails freeObjects];
65: [detailsDetails free];
66: return [super free];
67: }
68:
69: - 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: - recordDetail
85: {
86: if(detailsDetails)
87: [detailsDetails makeObjectsPerform:@selector(recordDetail)];
88: else
89: [self recordIt];
90: return self;
91: }
92:
93: - undoDetail
94: {
95: if (detailsDetails)
96: [detailsDetails makeObjectsPerform:@selector(undoDetail)];
97: else
98: [self undoIt];
99: return self;
100: }
101:
102: - redoDetail
103: {
104: if (detailsDetails)
105: [detailsDetails makeObjectsPerform:@selector(redoDetail)];
106: else
107: [self redoIt];
108: return self;
109: }
110:
111: - recordIt
112: {
113: /* Implemented by subclasses */
114: return self;
115: }
116:
117: - undoIt
118: {
119: /* Implemented by subclasses */
120: return self;
121: }
122:
123: - redoIt
124: {
125: /* Implemented by subclasses */
126: return self;
127: }
128:
129: - (BOOL)personalChangeExpected
130: {
131: return YES;
132: }
133:
134: @end
135:
136: @implementation ArrowChangeDetail
137:
138: - recordIt
139: {
140: oldLineArrow = [graphic lineArrow];
141: return self;
142: }
143:
144: - undoIt
145: {
146: [graphic setLineArrow:oldLineArrow];
147: return self;
148: }
149:
150: - redoIt
151: {
152: [graphic setLineArrow:[change lineArrow]];
153: return self;
154: }
155:
156: - (BOOL)personalChangeExpected
157: {
158: return ([graphic lineArrow] != [change lineArrow]);
159: }
160:
161: @end
162:
163: @implementation DimensionsChangeDetail
164:
165: - (BOOL)useNestedDetails
166: {
167: return NO;
168: }
169:
170: - recordDetail
171: {
172: [graphic getBounds:&oldBounds];
173: return self;
174: }
175:
176: - undoDetail
177: {
178: [graphic getBounds:&newBounds];
179: [graphic setBounds:&oldBounds];
180: return self;
181: }
182:
183: - redoDetail
184: {
185: [graphic setBounds:&newBounds];
186: return self;
187: }
188:
189: @end
190:
191: @implementation FillChangeDetail
192:
193: - recordIt
194: {
195: oldFillColor = [graphic fillColor];
196: oldFillMode = [graphic fill];
197: return self;
198: }
199:
200: - undoIt
201: {
202: newFillColor = [graphic fillColor];
203: newFillMode = [graphic fill];
204: [graphic setFillColor:&oldFillColor];
205: [graphic setFill:oldFillMode];
206: return self;
207: }
208:
209: - redoIt
210: {
211: [graphic setFillColor:&newFillColor];
212: [graphic setFill:newFillMode];
213: return self;
214: }
215:
216: - (BOOL)personalChangeExpected
217: {
218: return ([graphic fill] != [change fill]);
219: }
220:
221: @end
222:
223: @implementation LineCapChangeDetail
224:
225: - recordIt
226: {
227: oldLineCap = [graphic lineCap];
228: return self;
229: }
230:
231: - undoIt
232: {
233: [graphic setLineCap:oldLineCap];
234: return self;
235: }
236:
237: - redoIt
238: {
239: [graphic setLineCap:[change lineCap]];
240: return self;
241: }
242:
243: - (BOOL)personalChangeExpected
244: {
245: return ([graphic lineCap] != [change lineCap]);
246: }
247:
248: @end
249:
250: @implementation LineColorChangeDetail
251:
252: - recordIt
253: {
254: oldColor = [graphic lineColor];
255: oldIsOutlined = [graphic isOutlined];
256: return self;
257: }
258:
259: - undoIt
260: {
261: [graphic setLineColor:&oldColor];
262: [graphic setOutlined:oldIsOutlined];
263: return self;
264: }
265:
266: - redoIt
267: {
268: NXColor color = [change lineColor];
269: [graphic setLineColor:&color];
270: [graphic setOutlined:YES];
271: return self;
272: }
273:
274: - (BOOL)personalChangeExpected
275: {
276: return (!NXEqualColor([graphic lineColor], [change lineColor]));
277: }
278:
279: @end
280:
281: @implementation LineJoinChangeDetail
282:
283: - recordIt
284: {
285: oldLineJoin = [graphic lineJoin];
286: return self;
287: }
288:
289: - undoIt
290: {
291: [graphic setLineJoin:oldLineJoin];
292: return self;
293: }
294:
295: - redoIt
296: {
297: [graphic setLineJoin:[change lineJoin]];
298: return self;
299: }
300:
301: - (BOOL)personalChangeExpected
302: {
303: return ([graphic lineJoin] != [change lineJoin]);
304: }
305:
306: @end
307:
308: @implementation LineWidthChangeDetail
309:
310: - recordIt
311: {
312: oldLineWidth = [graphic lineWidth];
313: return self;
314: }
315:
316: - undoIt
317: {
318: [graphic setLineWidth:&oldLineWidth];
319: return self;
320: }
321:
322: - redoIt
323: {
324: float lineWidth = [change lineWidth];
325: [graphic setLineWidth:&lineWidth];
326: return self;
327: }
328:
329: - (BOOL)personalChangeExpected
330: {
331: return ([graphic lineWidth] != [change lineWidth]);
332: }
333:
334: @end
335:
336: @implementation MoveChangeDetail
337:
338: - (BOOL)useNestedDetails
339: {
340: return NO;
341: }
342:
343: - undoDetail
344: {
345: [graphic moveBy:[change undoVector]];
346: return self;
347: }
348:
349: - redoDetail
350: {
351: [graphic moveBy:[change redoVector]];
352: return self;
353: }
354:
355: @end
356:
357: @implementation OrderChangeDetail
358:
359: - (BOOL)useNestedDetails
360: {
361: return NO;
362: }
363:
364: - recordGraphicPositionIn:graphicList
365: {
366: graphicPosition = [graphicList indexOf:graphic];
367: return self;
368: }
369:
370: - (unsigned)graphicPosition
371: {
372: return graphicPosition;
373: }
374:
375: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.