InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VOSSavedData.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: EricM
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 
24 #ifndef __VOSSavedData__
25 #define __VOSSavedData__
26 
27 #include "K2Vector.h"
28 #include "UIDRef.h"
29 #include "UIDList.h"
30 #include "KeyValuePair.h"
31 #include "AttributeBossList.h"
32 #include "K2SmartPtr.h"
33 #include "ErrorUtils.h"
34 #include "IStrand.h"
35 #include "ITextModelMemento.h"
36 
37 class VOS_Object;
38 class IVOSDiskPage;
39 class VOS_Cursor;
40 class IStrandPastePiece;
41 class ICommand;
42 class PasteData;
44 class IStyleRefConvSession;
45 
46 typedef struct _ComboKey
47 {
48  _ComboKey() : uid (kInvalidUID), key(0) {}
49  _ComboKey(UID uidIn) : uid(uidIn), key(0) {}
50  _ComboKey(UID uidIn, int32 keyIn) : uid(uidIn), key(keyIn) {}
51  bool operator==(const _ComboKey& y) const
52  {
53  return (uid == y.uid && key == y.key);
54  }
55 
56  bool operator<(const _ComboKey& y) const
57  {
58  if (uid == y.uid)
59  return (key < y.key);
60  else
61  return (uid < y.uid);
62  }
63 
64  UID uid;
65  int32 key;
66 }ComboKey;
67 
69 {
70  public:
71  typedef enum { kTerminated, kNonterminated } VSD_ExtraInfo;
72 
73  VOS_SavedData(IStrand *whichStrand);
74  VOS_SavedData(IDataBase *db, ClassID objectClass, ClassID strandClass);
75 
76  virtual ~VOS_SavedData();
77 
78  VOS_SavedData(const VOS_SavedData &) = delete;
79  VOS_SavedData &operator =(const VOS_SavedData &) = delete;
80 
81  virtual int32 GetDataLength() const
82  { return fDataLength; }
83 
84  void ReadWrite(IPMStream *str);
85 
86  void RemovePage(UID pageUID);
87 
88  void AddPage(IVOSDiskPage *page);
89  void AddPage (ClassID clsid, IDataBase *db, UID pageUID, int32 pageLen);
90  void AddSuffix(VOS_Object *data, bool16 copy = kTrue);
91  void AddPrefix(VOS_Object *data, bool16 copy = kTrue);
92  void InsertPrefix(VOS_Object *data, bool16 copy = kTrue);
93 
94  void SetExtraInformation(VSD_ExtraInfo info, VOS_Object *settings = nil);
95  VSD_ExtraInfo GetExtraInformation() const
96  { return fExtraInfo; }
97  VOS_Object* TakeExtraSettings();
98  IDataBase* GetDataBase() const
99  { return fDB; }
100  ClassID GetStrandClass() const
101  { return fStrandClassID; }
102  ClassID GetObjectClass() const
103  { return fObjectClassID; }
104 
105  // Ensures that that there always one or more prefixes in addition
106  // to either (zero Suffixes) OR (one or more Suffixes AND zero or
107  // more Pages). Or in other words, if you have pages then you have
108  // prefixes and suffixes.
109  void Normalize();
110  void UsedUpData();
111  virtual void DeletePages();
112  virtual void UndeletePages();
113  virtual ErrorCode OnCopy();
114  virtual ErrorCode OnPaste();
115 
116  virtual ErrorCode PreTransferTo(PasteDataXRefContext* /*xRefContext*/);
117  virtual ErrorCode TransferTo(PasteDataXRefContext* xRefContext);
118 
119  int32 PrefixLength() const
120  { return (int32)fPrefixList.size(); }
121  int32 SuffixLength() const
122  { return (int32)fSuffixList.size(); }
123  int32 PagesLength() const
124  { return fPages.size(); }
125 
126  VOS_Object* PrefixObj(int32 n) const
127  { return fPrefixList[n]; }
128  VOS_Object* SuffixObj(int32 n) const
129  { return fSuffixList[n]; }
130  UID PageUID(int32 n) const
131  { return fPages[n]; }
132 
133  protected:
134  //
135  // These internal helper methods are used by the TrasferPagesTo()
136  // and TransferPagesByDuplicateTo() to handle the process of
137  // duplicating or moving a VOSDiskPage to a new Story.
138  //
139 
147 
155 
162 
169 
179  virtual void PageTransferred(IVOSDiskPage* /* page */)
180  { }
181 
182  //
183  // TransferTo() transfers Prefixes and Suffixes via this method. The
184  // implementation is responsible for determining when it is valid
185  // to return oldObj and when it must create a new object.
186  //
187  virtual VOS_Object* TransferObjectTo(PasteDataXRefContext* xRefC,
188  VOS_Object* oldObj);
189 
190  //
191  // TransferTo() transfers Cut data within the same story or to the
192  // same DataBase via this method.
193  //
194  virtual void TransferPagesTo(PasteDataXRefContext* xRefContext)
195  { TransferPagesHelperNoTransferObject(xRefContext); }
196 
197  //
198  // TransferTo() transfers CopyRange data via this method. Note that
199  // it is invalid to transfer Cut data between different DataBases,
200  // it must be implemented as CopyRange/Delete.
201  //
202  virtual void TransferPagesByDuplicateTo(PasteDataXRefContext* xRefContext)
203  {
205  }
206 
207  ClassID fObjectClassID;
208  ClassID fStrandClassID;
209  IDataBase *fDB;
210  int32 fDataLength;
211  int32 fSubRange;
212 
213  protected:
214 
215  K2Vector<VOS_Object *> fPrefixList;
216  K2Vector<VOS_Object *> fSuffixList;
217  K2Vector<UID> fPages;
218  VOS_Object *fExtraSettings;
219  ClassID fClassOfPages;
220  VSD_ExtraInfo fExtraInfo;
221  bool16 fPagesDeleted;
222  bool16 fPagesAreAliases;
223 };
224 
225 
227 {
228  public:
229  PasteData(const UIDRef& story);
230  PasteData(const UIDRef& fromStory, TextIndex start, int32 len);
231 
232  virtual ~PasteData();
233 
234  int32 AddSubrange();
235  void RemoveSubrange(int32 srIndex);
236 
237  void SetSubDataRange(int32 srIndex,
238  TextIndex start, int32 len)
239  { fSubrangeList[srIndex].SetDataRange(start, len); }
240 
241  void AddMapping(int32 srIndex, ClassID cls,
242  IStrandPastePiece *d);
243 
244  int32 MapCount(int32 srIndex) const
245  { return fSubrangeList[srIndex].fPasteList.size(); }
246 
247  ClassID GetMapKey(int32 srIndex, int32 i) const
248  { return fSubrangeList[srIndex].fPasteList[i].Key(); }
249 
250  int32 Location(int32 srIndex, ClassID klas) const
251  { return FindLocation(fSubrangeList[srIndex].fPasteList, klas); }
252 
253  IStrandPastePiece* PeekMapValue(int32 srIndex, int32 i) const
254  { return fSubrangeList[srIndex].fPasteList[i].Value(); }
255 
256  ErrorCode CopyDone(PasteDataXRefContext* xRefContext);
257  ErrorCode CopyDone();
258  ErrorCode TransferTo(PasteDataXRefContext* xRefContext);
259  ErrorCode TransferTo(const UIDRef& toStory);
260  ErrorCode PastedAllSavedData(TextIndex start);
261 
262  const UIDRef& GetStoryRef() const
263  { return fStoryRef; }
264  void SetStoryRef(const UIDRef& story)
265  { fStoryRef = story; }
266  TextIndex GetDataStart() const
267  { return fDataStart; }
268  void SetDataStart(TextIndex start)
269  { fDataStart = start; }
270  int32 GetDataLength() const
271  { return fDataLength; }
272  void SetDataLength(int32 len)
273  { fDataLength = len; }
274  int32 GetNetDataLength() const;
275  void AddMemento(const InterfacePtr<ITextModelMemento>& m);
276  void XRefBind(UID uidInSrcStory,
277  UID uidInDestStory);
278  void XRefBind(UID uidInSrcStory, int32 subKeyInSrcStory,
279  UID uidInDestStory, int32 subKeyInDestStory);
280  bool16 XRefLookup(UID uidInSrcStory,
281  UID* uidInDestStory) const;
282  bool16 XRefLookup(UID uidInSrcStory, int32 subKeyInSrcStory,
283  UID* uidInDestStory, int32* subKeyInDestStory) const;
284  int32 GetSubrangeCount() const
285  { return fSubrangeList.size(); }
286  TextIndex GetSubrangeDataStart(int32 srIndex) const
287  { return fSubrangeList[srIndex].GetDataStart(); }
288  int32 GetSubrangeDataLength(int32 srIndex) const
289  { return fSubrangeList[srIndex].GetDataLength(); }
290  void SetSubrangeDataRange(int32 srIndex,
291  TextIndex start,
292  int32 len)
293  { fSubrangeList[srIndex].SetDataRange(start, len); }
294 
295  AttributeBossList* GetRootStyleTransferAttributes(PMIID& whichIID);
296  UID& GetDestRootStyle(PMIID& whichIID);
297  AttributeBossList* GetDest_SrcRootStyleDiffs(PMIID& whichIID);
298 
299  TextIndex GetFirstRemainingTextIndex() const;
300  private:
301  void UpdateRootStyleConvAttrs(IDataBase* srcDB, IDataBase* destDB, InterfacePtr<IStyleRefConvSession> &styleConvSession);
302 
303  class SubRange
304  {
305  public:
306  typedef object_type data_type;
307  SubRange() : fStart(0), fLength(0), fPasteList() {}
308 
309  TextIndex GetDataStart() const
310  { return fStart; }
311  int32 GetDataLength() const
312  { return fLength; }
313  void SetDataRange(TextIndex start, int32 length)
314  { fStart = start; fLength = length; }
316  private:
317  TextIndex fStart;
318  int32 fLength;
319  };
320  UIDRef fStoryRef;
321  TextIndex fDataStart;
322  int32 fDataLength;
323  K2Vector<SubRange> fSubrangeList;
324  IStrand::MementoList fMementoList;
325  K2Vector<KeyValuePair<UID, int32> > fMementoLookupList;
327  bool16 fFromCopyRange;
328  bool16 fDidTransfer;
329 
330  AttributeBossList fCharRootStyleTransferAttributes;
331  AttributeBossList fParaRootStyleTransferAttributes;
332  AttributeBossList fCharDest_SrcRootStyleDiffs;
333  AttributeBossList fParaDest_SrcRootStyleDiffs;
334  IDataBase* fDB;
335  UID fCharRootStyle;
336  UID fParaRootStyle;
337 };
338 
339 //===================================================================================
340 // class TextPasteDataXRefContext
341 //
342 // Abstract base class for VASD XRef context.
343 //===================================================================================
345 {
346 public:
347  virtual bool16 GetIsMyContext(const PasteData* vasd) const = 0;
348  virtual const UIDRef& GetSrcStoryRef() const = 0;
349  virtual const UIDRef& GetDestStoryRef() const = 0;
350  virtual void XRefBind(UID uidInSrcStory, UID uidInDestStory) = 0;
351  virtual void XRefBind(UID uidInSrcStory, int32 subKeyInSrcStory, UID uidInDestStory, int32 subKeyInDestStory) = 0;
352  virtual bool16 XRefLookup(UID uidInSrcStory, UID* uidInDestStory) const = 0;
353  virtual bool16 XRefLookup(UID uidInSrcStory, int32 subKeyInSrcStory, UID* uidInDestStory, int32* subKeyInDestStory) const = 0;
354 };
355 
356 
357 
358 #endif // __VOSSavedData__