InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ArrangeUtils.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Richard Rodseth
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 __ARRANGEUTILS__
25 #define __ARRANGEUTILS__
26 
27 #include "UIDList.h"
28 
29 class IHierarchy;
30 class UIDRef;
31 
32 //===============================================================
33 // Debugging utilities
34 //===============================================================
35 
36 #ifdef DEBUG
37 void DumpItemList(UIDList* itemList);
38 void DumpIndexList(K2Vector<int32>* indexList);
39 void DumpChildren(IHierarchy* parent);
40 #endif
41 
42 
43 //===============================================================
44 // class Arranger
45 //===============================================================
46 
47 /*
48  This class is used by BringToFrontCmd, BringForwardCmd, SendBackwardCmd
49  and SendToBackCommand. It contains a few static methods, but is
50  generally allocated on the stack. This allows some of its methods to
51  cache frequently-computed values in data members.
52 */
53 
54 
55 class Arranger
56 {
57 public:
58 
59  enum
60  {
61  kNotSorted = 0,
62  kSorted = 1
63  };
64 
65  Arranger(UIDList* selectedItems, bool16 sorted);
66  // Construct an arranger on the stack. If the list is already
67  // sorted, pass kSorted, otherwise pass kNotSorted.
68 
69  ~Arranger();
70 
71  // -- Static functions --
72 
73  static int32 NodeDepth(IHierarchy* item);
74  // returns the depth of a node, where the root is 0
75  // Used by IsLessThan
76 
77  //static bool16 IsLessThan(IHierarchy* firstNode, IHierarchy* secondNode);
78  static bool16 IsLessThan(const UIDRef& firstItem, const UIDRef& secondItem);
79  // returns kTrue, if firstItem appears before secondItem in the display order
80  // firstItem and secondItem must have a common root, but need not be at the
81  // same depth in the tree
82 
83  static bool16 IsGreaterThan(const UIDRef& firstItem, const UIDRef& secondItem);
84  // returns kTrue, if firstItem appears after secondItem in the display order
85  // firstItem and secondItem must have a common root, but need not be at the
86  // same depth in the tree
87 
88  static void SortItemsBackToFront(UIDList* itemList);
89  // Sorts a list of nodes into display order. The nodes can be at any level
90  // in the hierarchy
91 
92  static void SortItemsFrontToBack(UIDList* itemList);
93  // Sorts a list of nodes into reverse-display order. The nodes can be at any level
94  // in the hierarchy
95 
96  // -- Member functions --
97 
98  void SortItems();
99  // Sorts fSelectedItems if it needs sorting
100 
101  int32 GetMaxBack(IHierarchy* parent);
102  // Returns the index of the frontmost selected item which is "at the back"
103 
104  int32 GetMinFront(IHierarchy* parent);
105  // Returns the index of the backmost selected item which is "at the front"
106 
107  bool16 CanSendBack(UID refObj = kInvalidUID);
108  // Returns kTrue if any items are eligible to move back
109 
110  bool16 IsAtBack(IHierarchy* node);
111  bool16 IsAtBack(IHierarchy* parent, int32 nodePosition);
112 
113  bool16 CanBringForward(UID refObj = kInvalidUID);
114  // Returns kTrue if any items are eligible to move forward
115 
116  bool16 IsInFront(IHierarchy* node);
117  bool16 IsInFront(IHierarchy* parent, int32 nodePosition);
118 
119 private:
120  UIDList* fSelectedItems; // The list of items to which the command is applied
121  bool16 fSorted;
122  UID fLastParent_MinFront;
123  UID fLastParent_MaxBack;
124  int32 fMaxBack; // The largest index known to be part of the back range
125  int32 fMinFront; // The smallest index known to be part of the front range
126 };
127 
128 
129 #endif // __ARRANGEUTILS__