InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
TreeLazyNotificationData.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Habib Khalfallah
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 __LazyTreeMsgCookie__
25 #define __LazyTreeMsgCookie__
26 
27 #include "LazyNotificationData.h"
28 #include "KeyValuePair.h"
29 #include "ChangeTree.h"
30 
31 class ITreeViewMgr;
32 
38 template<class ItemType>
40 {
42  typedef typename ChangeTree<ItemType>::Node TreeNode;
43 public:
45  TreeLazyNotificationData():LazyNotificationData(), fMustRebuildChangeRecords (false)
46  {
47  }
48 
51  {
52  }
53 
60  virtual void Add (const LazyNotificationData* other);
61 
69  virtual LazyNotificationData* Clone (bool16 undoData) const;
70 
80  virtual void Validate(IDataBase *)
81  {}
82 
83 
85  virtual void MarkShouldRebuildAll();
86 
89  virtual bool ShouldRebuildAll() const;
90 
94  void ItemAdded(const ItemType &item);
95 
99  void ItemDeleted(const ItemType &item);
100 
104  void ItemChanged(const ItemType &item);
105 
111  void ItemRebuilt(const ItemType &item);
112 
124  template<typename TAdded, typename TDeleted, typename TChanged, typename TBuild>
125  void ProcessChanges(TAdded Added,
126  TDeleted Deleted,
127  TChanged Changed,
128  TBuild Rebuilt);
129 
137  struct IgnoreItem : std::function<void (const ItemType &) >
138  {
139  void operator () (const ItemType &) const {}
140  };
141 
142 #ifdef DEBUG
143 
146  virtual void WriteTree(std::ofstream *file);
147 #endif
148 
149  /*
150  / ** Used to indicate to external clients what type of change
151  happened to a given item
152  * /
153  enum ChangeType
154  {
155  / ** Item was added * /
156  kAdd,
157  / ** Item was deleted * /
158  kDelete,
159  / ** Item was changed * /
160  kChange,
161  / ** Item and its children need to be rebuilt * /
162  kRebuild
163  };
164 
165  / ** Each item in the iterator will be a ChangeRecord * /
166  typedef std::pair<ChangeType,ItemType> ChangeRecord;
167  / ** Used as a typedef simply to make less typing and easier reading * /
168  typedef std::vector<ChangeRecord> ChangeRecordsContainer;
169  / ** Used as a typedef simply to make less typing and easier reading * /
170  typedef typename ChangeRecordsContainer::const_iterator change_records_iterator;
171 
172  / ** This method can be used to ask for an iterator
173  which starts at the beginning of the changes.
174  NOTE: When using this iterator it is highly
175  recommended that you handle each item change
176  in the order that you iterate them, rather than
177  skip some and try to handle them later.
178  @return - A const iterator for looking at the changes
179  * /
180  change_records_iterator begin_change_records ();
181 
182  / ** The end of the list of changes. Use this in
183  conjuction with begin_change_records
184  @return - The end of the changes.
185  * /
186  change_records_iterator end_change_records ();
187  */
188 
189 protected:
195  virtual TreeLazyNotificationData *CreateNewCookie() const = 0;
196 
205  virtual bool16 GetParent(const ItemType &item, ItemType &parent) const = 0;
206 
207 #ifdef DEBUG
208  virtual PMString GetNodeName(const ItemType &item) const
209  {
210  return "";
211  }
212 #endif
213 
214 private:
225  void AddChange(const ItemType &item, typename TreeNode::ChangeState nodeChange);
226 
236  void MergeChildren(typename ChangeTree<ItemType>::Node *whole, const TreeNode *part);
237 
242  void InsertSubBranch(TreeNode *myStart, const TreeNode *otherStart);
243 
254  void ChangeNode(TreeNode *node, typename ChangeTree<ItemType>::Node::ChangeState newState);
255 
261  void SwapAddAndDelete (const ItemType item);
262 
264  ChangeTree<ItemType> fTree;
265 
267  bool fMustRebuildChangeRecords;
268 
270  enum {kMaxSize = 200};
271 };
272 
273 
274 #endif