InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
CTreeViewMgr.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Sanjay Kumar
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 __CTreeViewMgr_h__
25 #define __CTreeViewMgr_h__
26 
27 
28 #include "ITreeViewMgr.h"
29 #include "IControlView.h"
30 
31 #include "K2Vector.h"
32 #include "KeyValuePair.h"
33 #include "NodeID.h"
34 #include <map>
35 
38 class ITreeViewWidgetMgr;
39 
40 
41 //----------------------------------------------------------------------------------------
42 // Class Info
43 //----------------------------------------------------------------------------------------
44 class DV_ CTreeViewMgr : public ITreeViewMgr
45 {
46 public:
47  CTreeViewMgr(IPMUnknown *boss);
48  ~CTreeViewMgr();
49 
50  virtual void ChangeRoot( bool16 widgetHeightIsConstant );
51 
52  virtual void NodeAdded( const NodeID& nodeAdded );
53  virtual void NodesAdded( const NodeIDList& nodesAdded );
54  virtual void BeforeNodeDeleted( const NodeID& nodeDeleted );
55  virtual void BeforeNodesDeleted( NodeIDList& nodesDeleted );
56  virtual void NodeMoved( const NodeID& nodeMoved, const NodeID& oldParent );
57  virtual void NodeChanged( const NodeID& nodeChanged, bool16 childrenChangedAlso, int32 message = 0 );
58  virtual void ScrollToNode( const NodeID& nodeDeleted, ScrollWhere whereToScroll );
59 
60  virtual bool16 IsNodeExpanded( const NodeID& nodeInQuestion ) const;
61  virtual bool16 IsNodeExpanded(IControlView* widget) const;
62  virtual void ExpandNode( const NodeID& nodeToExpand, bool16 expandAllDescendants = kFalse );
63  virtual void CollapseNode( const NodeID& nodeToCollapse, bool16 collapseAllDescendants = kFalse );
64 
65  virtual void HandleScroll( int32 amount, bool16 scrollVertical );
66  virtual void HandleResize();
67 
68  virtual void ScrollUp();
69  virtual void ScrollDown();
70 
71  virtual NodeID_rv Search( const PMString& partialNodeName ) const;
72  virtual NodeID_rv Search( const NodeID& nodeToSearch ) const;
73 
74  virtual IControlView* QueryWidgetFromNode( const NodeID& node ) const;
75 
76  virtual void Purge(int32 level);
77 
78  virtual void ClearTree(bool16 clearExpandedNodeList);
79  virtual void ReadWrite(IPMStream *s, ImplementationID prop);
80 
81  enum { kAbove = 1, kBelow = -1 };
82  static int32 AboveOrBelow(ITreeViewHierarchyAdapter* adapter, const NodeID& referenceNode, const NodeID& nodeInQuestion);
83  static void PurgeMemory(int32 level, void *refPtr);
84  virtual void ArrangeWidgets();
85 
86  virtual void RefreshSubTree(const NodeID& subTreeRoot, bool16 includeEntireHier);
87  virtual PMRect GetViewableArea();
89  enum { kNodeChangedMsgNotSet = 0, kNodeChangedMsgChangeAll = -1 };
90 
91  void AllowPurge()
92  { ++fAllowPurge; }
93  void DisallowPurge()
94  { --fAllowPurge; }
95  bool IsPurgeAllowed() const
96  { return (fAllowPurge == 0); }
97 
98 protected:
99  bool16 ExpandNodeRecurse( const NodeID& nodeToExpand, bool16 expandAllDescendants = kFalse);
100  bool16 CollapseNodeRecurse( const NodeID& nodeToCollapse, bool16 collapseAllDescendants = kFalse );
101  void PlaceWidgets( );
102  // framePositionLookup sorted
103  void DeselectNode( const NodeID& nodeToDeselect, ITreeViewController* controller, const ITreeViewHierarchyAdapter* adapter, bool16 notifyOfChange = kTrue);
104  virtual void ScrollHorizontal( int32 amount, bool16 forceRedraw = kTrue );
105  virtual void ScrollVertical( int32 amount, bool16 forceRedraw = kTrue );
106  virtual void AdjustTreeScrollerSize( PMPoint scrollerSize );
107  virtual PMReal AdjustScrollIncrements( WidgetID whichScrollBar, const PMReal& scrollerTop, const PMReal& scrollerBottom, const PMReal& viewSize );
108  void AdjustScrollValue(bool16 vertical = kTrue);
109  PMReal AdjustScrollerPosition( );
110 // PMPoint RecursiveGetSize( const NodeID& node, bool16 includeThisNodeInSize = kTrue, const NodeIDList* ignoreTheseNodes = nil );
111  IControlView* QueryWidgetForNode(const NodeID& node);
112  IControlView* QueryCachedWidget( WidgetID typeOfWidget );
113  void AdjustHorizSize( IControlView* widget );
114  void DisposeWidget(IControlView*);
115  void DeleteWidget(IControlView* widget);
116  NodeID_rv GetNodeIDFromInterface(IControlView* widget) const;
117  bool16 AncestorsAreExpanded(const NodeID& node);
118  bool16 IsAncestor(const NodeID& possibleAncestor, const NodeID& possibleDescendant) const;
119  typedef enum { kNodeAdded, kNodeChanged, kNodeDeleted } ChangeType;
120  PMReal GetNewScrollerWidth( const PMReal& sizeOfChangingNode, const NodeIDList* changingNodes, ChangeType typeOfChange );
121  void ExpandToShowNode( const NodeID& scrollToNode );
122  virtual void MoveScroller( const PMPoint& moveTo );
123  class TreeNode;
124  TreeNode* GetTreePtrFromNodeID( const NodeID& node, bool16 buildTreeToIncludeNode = kFalse ) const;
125  void SetRepositionWidgetsFlag( bool16 reposition );
126 
127 #ifdef DEBUG
128  void TestTree( const NodeID& node);
129  void CheckNode(const NodeID& node, const char *calledFrom, int32 i = -1) const;
130 #else
131  inline void TestTree( const NodeID& ) {}
132  inline void CheckNode(const NodeID& , const char *, int32 = -1) const {}
133 #endif
134 
135 #ifdef TESTCODE
136  void CheckWidgetPtrs( ) const;
137 #else
138  inline void CheckWidgetPtrs( ) const {}
139 #endif
140 
141 
142  IControlView* fTreeScrollerView;
143  IControlView* fVScrollBarView;
144  IControlView* fHScrollBarView;
145  int32 fVThumbScrollIncrement;
146 
147 private:
148 
149 // K2Vector<KeyValuePair<NodeID, int32> > fNodeToWidgetPositionLookup; // sorted
150 // NodeIDList fExpansionLookup; // sorted
151  bool16 fDisplayRootNode;
152  bool16 fRootIsValid; //We use this so that flag that calls after ClearTree() will fail until ChangeRoot is called,
153  //specifically, we want to ignore resize calls. We can't set the root to invalid because that
154  // would cause ChangeRoot() calls with the same root to lose the expansion info
155  bool16 fRepositionWidgetsFlag;
156  bool16 fSomeNodesChangedFlag;
157  bool16 fDirtyScrollerSize;
158  bool16 fCheckForReentry;
159  int32 fAllowPurge;
160 
161 
162  //Widget Cache
164  K2Vector<KeyValuePair<WidgetID, WidgetList> > fWidgetCache; // sorted
165 
166  friend class TreeNodeTraverser;
167  friend class TreeNodeHelper;
168 
169  class TreeNode
170  {
171  public:
172  TreeNode(const NodeID& nodeID);
173  TreeNode(const NodeID& nodeID, const PMPoint& nodeSize);
174  TreeNode(IPMStream* stream, TreeNode* parent );
175  // use this as the Destuctor
176  void Delete( bool16 deselect = kTrue );
177 
178  TreeNode* AddChild( int32 childIndex, const NodeID& node, bool16 ignoreExpandedState = kFalse);
179  void AddChild( int32 childIndex, TreeNode* node );
180  TreeNode* Remove( );
181  TreeNode* RemoveChild( int32 childIndex );
182  TreeNode* GetParent( ) const { return fParent; }
183 
184  void Expand();
185  void Collapse();
186  bool16 IsExpanded() const { return fFlags & kExpanded; }
187 
188  enum { kInvalidSize = -1 };
189  virtual const PMPoint& GetSize() const; // Dimensions of this node alone, not including child widgets
190  const PMPoint& GetFamilySize() const; // Dimension of this parent widget, including child widgets
191  void DirtyFamilySize();
192  void DirtySize();
193  const PMReal& GetIndent() const; // overall indent
194  void SetIndent(const PMReal& newIndent) { fIndent = newIndent; }
195 
196  void PlaceWidgets( const PMRect& viewableArea );
197  bool16 PositionWidgets( PMReal& location, const PMRect& viewableArea, K2Vector<IControlView*>& reusedViewList, K2Vector<KeyValuePair<TreeNode*, PMReal> >& needWidgetList );
198  PMReal GetVerticalPosition( ) const;
199  IControlView* QueryWidget( ) const;
200  void ClearWidgets( bool16 recursive = kFalse);
201  void RemoveFromLookup( bool16 recursive = kFalse );
202 
203  bool16 HasSubTree() const { return fChildren.size() > 0; }
204  void BuildSubtree();
205  const NodeID& GetNodeID() const { return fNodeID; }
206  void ReconcileTreeChanges( bool16 includeEntireHier = kTrue );
207 
208  void DirtyWidgetData(int32 messageToWidgetMgr = kNodeChangedMsgNotSet);
209  void RecursiveDirtyWidgetData( int32 messageToWidgetMgr = kNodeChangedMsgNotSet );
210  bool16 IsWidgetDataDirty() const { return fFlags & kDirtyWidgetData; }
211  void ReapplyWidgetData( );
212 
213  void ReadWrite(IPMStream* stream);
214  void CheckWidgetPtrs( ) const;
215 
216  virtual CTreeViewMgr* GetTreeViewMgr() const;
217  virtual const ITreeViewWidgetMgr* GetTreeViewWidgetMgr() const;
218 
219  protected:
220  TreeNode();
221  ~TreeNode();
222 
223  NodeID fNodeID;
224  enum { kExpanded = 1, kDirtyFamilySize = 2, kDirtyWidgetData = 4, kDirtySize = 8 };
225  mutable int16 fFlags;
226  mutable PMPoint fMySize;
227  mutable PMPoint fFamilySize;
228  PMReal fIndent;
229  K2Vector<TreeNode*> fChildren;
230  TreeNode* fParent;
231  IControlView* fMyWidget;
232 
233  };
234 
235  class RootTreeNode : public TreeNode
236  {
237  public:
238  RootTreeNode(const NodeID& nodeID, CTreeViewMgr* widgetMgr, bool16 isHiddenRootNode);
239  RootTreeNode(IPMStream* stream, CTreeViewMgr* widgetMgr);
240 
241  const PMPoint& GetSize() const; // Dimensions of this node alone, not including child widgets
242  CTreeViewMgr* GetTreeViewMgr() const { return fTreeViewMgr; }
243  const ITreeViewWidgetMgr* GetTreeViewWidgetMgr() const { return fTreeViewWidgetMgr; }
244 
245  protected:
246  CTreeViewMgr* fTreeViewMgr;
247  const ITreeViewWidgetMgr* fTreeViewWidgetMgr;
248  };
249 
250  friend class TreeNode;
251  friend class CheckReentryUtility;
252  TreeNode* fRootNode;
253  mutable K2Vector< KeyValuePair<PMString, NodeID> > fTreeNodeNameList;
254  mutable std::map<NodeID, TreeNode*> fNodeToTreeLookup;
255 
256  public:
257  virtual void ScrollVerticalAbsoluteAmount(int32 amount, bool16 forceRedraw = kTrue);
258 };
259 
260 
261 #endif