InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VOSRedline.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Eric Menninga
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // Copyright 1997-2010 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
18 // with the terms of the Adobe license agreement accompanying it. If you have received
19 // this file from a source other than Adobe, then your use, modification, or
20 // distribution of it requires the prior written permission of Adobe.
21 //
22 //
23 // ADOBE CONFIDENTIAL
24 //
25 // The following classes are defined: VOSRedlineChange, RedlineUndo, and VOS_RedlineObject.
26 // Public because the RedlineIterator can return a VOSRedlineChange and VOS_RedlineObject;
27 // however, the RedlineIterator should be considered the primary access to tracked changes.
28 //
29 //========================================================================================
30 
31 #ifndef __VOS_Redline__
32 #define __VOS_Redline__
33 
34 #include "VOSObject.h"
35 #include "VOSCursor.h"
36 #include "K2Vector.h"
37 #include "WideString.h"
38 #include "K2Vector.h"
39 #include "XMLReference.h"
40 
41 #ifdef DEBUG
42 #include "Trace.h"
43 #endif
44 
45 class IRedlineDataStrand;
46 class ITextIndexIDList;
47 class ITextModel;
48 
49 
50  // I didn't make this a virtual class with specializations for insert, delete, apply, etc. because
51  // the stack of these changes wouldn't be able to hold pointers to virtual objects unless every
52  // editing operation did a physical copy of every element. It was easier and more straightforward
53  // to have the collect handle the copies with data.
55 {
56  public:
57  typedef object_type data_type;
58  typedef enum { kUnknown = 0, kDelete, kInsert, kApply } RedlineChangeType;
59  // valid change types, kApply not used
60 
62  RedlineChangeType type,
63  uint64 stamp,
64  bool16 movedText,
65  IDataBase *docDB = nil,
66  IRedlineDataStrand *strand = nil,
67  int32 len = 0);
68  // constructor
69 
71  : fType(kUnknown)
72  , fTimeStamp(0)
73  , fIsMovedText(kFalse)
74  , fUserName("")
75  {}
76  // default constructor
77 
79  // copy constructor
80 
81  RedlineChangeType GetChangeType() const
82  { return fType; }
83 
84  PMString GetUserName() const
85  { return fUserName; }
86  void SetUserName(const PMString& userName)
87  { fUserName = userName; }
88 #ifdef DEBUG
89  void PrintUser() const
90  { TRACE("(%s) ", fUserName.GetUTF8String().c_str()); }
91  int32 GetUserID() const // obsolete, do not use!
92  { return -1; }
93 #endif
94 
95  uint64 GetTimeStamp() const
96  { return fTimeStamp; }
97  void SetTimeStamp(uint64 i)
98  { fTimeStamp = i; }
99 
100  bool16 GetIsMovedText() const
101  { return fIsMovedText; }
102  void SetIsMovedText(bool16 isMovedText)
103  { fIsMovedText = isMovedText; }
104 
105  bool16 GetIsDeletedText() const
106  { return fType == VOSRedlineChange::kDelete; }
107  bool16 GetIsAddedText() const
108  { return fType == VOSRedlineChange::kInsert && !fIsMovedText; }
109 
110  bool16 operator==(const VOSRedlineChange& other) const
111  { return fTimeStamp == other.fTimeStamp && fType == other.fType && fUserName == other.fUserName && fIsMovedText == other.fIsMovedText; }
112  // allows comparisons between objects of this type
113 
114  protected:
115  uint64 fTimeStamp; // time the change was created
116  RedlineChangeType fType; // type of the change
117  PMString fUserName; // name of the author that created the change
118  bool16 fIsMovedText; // flag to indicate if a kInsert type change is considered moved text
119  // - text pasted from within the same document or duplicated
120 };
121 
122 
124 
125 
127 {
128  public:
129  RedlineUndo(int32 len, VOSRedlineChange::RedlineChangeType type);
130  virtual void Undo(TextIndex start);
131 
132  void Target(const UIDRef& strand);
133 
134  private:
135  UIDRef fStrand;
136  int32 fLength;
137 #ifdef DEBUG
138  VOSRedlineChange::RedlineChangeType fType;
139 #endif
140 };
141 
142 
143 class RedlineUndo;
144 class IStrandPastePiece;
145 
147 {
148  protected:
150  : VOS_Object(copy)
151  , fLength(copy.fLength)
152  , fChangeStack(copy.fChangeStack)
153  {}
154 
155  public:
156  VOS_RedlineObject(int32 length = 0)
157  : VOS_Object()
158  , fLength(length)
159  , fChangeStack()
160  {}
161  VOS_RedlineObject(int32 length, const VOSRedlineChange& change);
162  virtual ~VOS_RedlineObject();
163 
164  virtual int32 VirtualLength() const;
165  virtual VOS_Object* Duplicate() const;
166  virtual VOS_Object* Divide(int32 atOffset);
167  virtual bool16 JoinWith(VOS_Object* next);
168  virtual VOS_Object* Split() { return nil; }; // SNOWBIRD:TO:DO
169 
170  void SetLength(int32 len);
171  void AdjustLength(int32 delta)
172  { PreDirty(); fLength += delta; AdjustObjectLength(delta); ASSERT_MSG(fLength > 0, "VOS_RedlineObject too small"); }
173 
174  int32 NumberOfChanges() const
175  { return fChangeStack.size(); }
176  const VOSRedlineChange& GetChange(int32 n) const
177  { return fChangeStack[n]; }
178  RedlineChangeUndo* AcceptThrough(const VOSRedlineChange& change, IRedlineDataStrand *redline);
179  RedlineChangeUndo* RejectChange(const VOSRedlineChange& change, IRedlineDataStrand *redline, TextIndex start, bool16 *removeObj);
180  void UndoChanges(RedlineChangeUndo *undo, bool16 undoReject, VOS_Cursor& cursor, int32 len);
181 
182  void ReadWrite(IPMStream *s, ImplementationID prop);
183 
184  static const PMString CurrentUser(VOS_RedlineObject *qThis);
185 
186  static void Insert(VOS_Cursor& cursor, IRedlineDataStrand *redline, int32 len, bool16 trackInsert, const VOSRedlineChange *useThisChange, bool16 pasting, bool16 isNoteChar, bool16 isTableContinuation = kFalse, bool16 isSaveBack = kFalse);
187  static RedlineUndo* ChangeAttribute(VOS_Cursor& cursor, int32 len);
188  static RedlineUndo* DoReplace(VOS_Cursor& cursor, IRedlineDataStrand *redline, TextIndex pos, int32 len, const WideString *newData);
189  static IStrandPastePiece* Cut(VOS_Cursor& cursor, IRedlineDataStrand *redline, TextIndex pos, int32 len, bool16 trackThisEdit);
190  static void InsertSavedData(VOS_Cursor& cursor, VOS_SavedData *data, IRedlineDataStrand *redline);
191  static void UnreplaceSavedData(VOS_Cursor& cursor, VOS_SavedData *data);
192 
193  static bool16 CanApplyDeleteChange(VOS_Cursor& cursor, int32 len);
194  // returns true when deleting text that was *not* inserted by the current user,
195  // in that case do not want to create a delete change record; false otherwise
196 
197 #ifdef DEBUG
198  static void UndoSimpleChange(VOS_Cursor& cursor, int32 len, VOSRedlineChange::RedlineChangeType type);
199 #else
200  static void UndoSimpleChange(VOS_Cursor& cursor, int32 len);
201 #endif
202 
203  // the following methods are used to move the change records on the end of
204  // story character (if any) when entire story is moved;
205 
206  RedlineChangeUndo* MoveChangeRecord(VOS_Cursor& cursor);
207  // removes this vos object's change records and moves the specified cursor's
208  // vos object change records to this vos object
209  bool16 UndoMoveChangeRecord(RedlineChangeUndo* undo);
210  // removes this vos object's change records and moves the change records
211  // in the specified undo to this vos object
212 
213  static bool16 CanApplyDeleteChange(VOS_Cursor& cursor, int32 len, const PMString& user);
214  // returns true when deleting text that was *not* inserted by the specified user,
215  // in that case do not want to create a delete change record; false otherwise
216 
217  void AppendChangeRecord(const VOSRedlineChange& change);
218  // Append a record to the change stack
219  void RemoveChangeRecord(int32 changeIndex);
220  // Remove a record to the change stack
221  void ClearChangeStack() { fChangeStack.clear(); }
222 
223  private:
224  int32 fLength; // length of this object
225  K2Vector<VOSRedlineChange> fChangeStack; // list of change records on this object
226 };
227 
228 
229 
230 #endif
231  // __VOS_Redline__
232