xref: /AOO41X/main/sw/inc/SwNumberTree.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef _SW_NUMBER_TREE_HXX
29*cdf0e10cSrcweir #define _SW_NUMBER_TREE_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <set>
32*cdf0e10cSrcweir #include <vector>
33*cdf0e10cSrcweir #include <tools/string.hxx>
34*cdf0e10cSrcweir #include <swdllapi.h>
35*cdf0e10cSrcweir #include <SwNumberTreeTypes.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir class SwNumberTreeNode;
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir bool SwNumberTreeNodeLessThan (const SwNumberTreeNode * pA,
40*cdf0e10cSrcweir                                const SwNumberTreeNode * pB);
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir struct compSwNumberTreeNodeLessThan
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir     bool operator()(const SwNumberTreeNode * pA,
45*cdf0e10cSrcweir                     const SwNumberTreeNode * pB) const
46*cdf0e10cSrcweir     { return SwNumberTreeNodeLessThan(pA, pB); }
47*cdf0e10cSrcweir };
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir /**
50*cdf0e10cSrcweir    A tree of numbered nodes.
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir    Simple example:
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir    <pre>
55*cdf0e10cSrcweir    1. kshdkjfs
56*cdf0e10cSrcweir      1.1. lskjf
57*cdf0e10cSrcweir    2. sdfjlksaf
58*cdf0e10cSrcweir    3. fka�slk
59*cdf0e10cSrcweir      3.1. lfjlaskf
60*cdf0e10cSrcweir      3.2. jaslkjflsf
61*cdf0e10cSrcweir        3.2.1. hkljhkjhk
62*cdf0e10cSrcweir 
63*cdf0e10cSrcweir    + R
64*cdf0e10cSrcweir      + 1 kshdkjfs
65*cdf0e10cSrcweir      | + 1 lskjf
66*cdf0e10cSrcweir      + 2 sdfjlksaf
67*cdf0e10cSrcweir      + 3 fka�slk
68*cdf0e10cSrcweir        + 1 lfjlaskf
69*cdf0e10cSrcweir        + 2 jaslkjflsf
70*cdf0e10cSrcweir          + 1 hkljhkjhk
71*cdf0e10cSrcweir    </pre>
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir    The root contains the nodes of the first level. Each node A of the
74*cdf0e10cSrcweir    first level contains those nodes of the second level that have the
75*cdf0e10cSrcweir    same first level number as A and so on for the subsidiary levels.
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir    The numbering label of a node A is resolved by concatenating the
78*cdf0e10cSrcweir    numbers of the nodes on the path from the root to A.
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     ------------------------------------------
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir     Phantoms
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir     A phantom is an auxiliary node that is used to emulate numberings
85*cdf0e10cSrcweir     starting with nodes not at top level. The phantom contains the
86*cdf0e10cSrcweir     number for the level but is not considered part of the numbering.
87*cdf0e10cSrcweir 
88*cdf0e10cSrcweir      Constraint 1: A phantom is always the first child node.
89*cdf0e10cSrcweir      Constraint 2: At each node there is at most one child that is a phantom.
90*cdf0e10cSrcweir      Constraint 3: A phantom is the smallest of all numbering nodes.
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir     Uncounted Phantoms
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir       0.1. dljflskjlasf
95*cdf0e10cSrcweir     5. �ds�fka�s
96*cdf0e10cSrcweir       5.1.
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir     + R (nStart = 5)
99*cdf0e10cSrcweir       + 0 (phantom, not counted)
100*cdf0e10cSrcweir       | + 1 dljflskjlasf
101*cdf0e10cSrcweir       + 5 �ds�fka�s
102*cdf0e10cSrcweir         + 1
103*cdf0e10cSrcweir 
104*cdf0e10cSrcweir      The phantom gets numbered with 0. The first non-phantom node gets
105*cdf0e10cSrcweir      numbered with the start value.
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir      -----------------------------------------
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir      Counted Phantoms
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir        5.1. lgkjjgklg
112*cdf0e10cSrcweir      6. lkjfalskjflsaf
113*cdf0e10cSrcweir        6.1. ljdflaksjflkjasflkjsf
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir      + R (nStart = 5)
116*cdf0e10cSrcweir        + 5 (phantom, counted)
117*cdf0e10cSrcweir        | + 1 lgkjjgklg
118*cdf0e10cSrcweir        + 6 lkjfalskjflsaf
119*cdf0e10cSrcweir          + 1 ljdflaksjflkjasflkjsf
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir      The phantom gets numbered with the start value.
122*cdf0e10cSrcweir */
123*cdf0e10cSrcweir class SW_DLLPUBLIC SwNumberTreeNode
124*cdf0e10cSrcweir {
125*cdf0e10cSrcweir protected:
126*cdf0e10cSrcweir     typedef std::set<SwNumberTreeNode *, compSwNumberTreeNodeLessThan>
127*cdf0e10cSrcweir     tSwNumberTreeChildren;
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir public:
130*cdf0e10cSrcweir     SwNumberTreeNode();
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     virtual ~SwNumberTreeNode();
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir     /**
135*cdf0e10cSrcweir        Add a child.
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir        @param pChild   child to add
138*cdf0e10cSrcweir        @param nDepth   depth in which to add the child
139*cdf0e10cSrcweir      */
140*cdf0e10cSrcweir     void AddChild( SwNumberTreeNode* pChild,
141*cdf0e10cSrcweir                    const int nDepth = 0 );
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir     /**
144*cdf0e10cSrcweir        Remove a child.
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir        OD 2008-02-19 #refactorlists# - no longer virtual
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir        @param pChild     child to be removed
149*cdf0e10cSrcweir      */
150*cdf0e10cSrcweir     void RemoveChild( SwNumberTreeNode* pChild );
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     /**
153*cdf0e10cSrcweir        Remove this child from the tree.
154*cdf0e10cSrcweir      */
155*cdf0e10cSrcweir     void RemoveMe();
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir     /**
158*cdf0e10cSrcweir        Returns the parent of this node.
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir        @return the parent
161*cdf0e10cSrcweir     */
162*cdf0e10cSrcweir     inline SwNumberTreeNode* GetParent() const
163*cdf0e10cSrcweir     {
164*cdf0e10cSrcweir         return mpParent;
165*cdf0e10cSrcweir     }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir     /**
168*cdf0e10cSrcweir        Returns number of this node.
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir        @param bValidate     validate the number?
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir        @return number of this node
173*cdf0e10cSrcweir      */
174*cdf0e10cSrcweir     SwNumberTree::tSwNumTreeNumber GetNumber( bool bValidate = true ) const;
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir     // --> OD 2008-11-26 #158694#
177*cdf0e10cSrcweir     bool IsContinueingPreviousSubTree() const;
178*cdf0e10cSrcweir     // <--
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir     /**
181*cdf0e10cSrcweir        Returns level numbers of this node.
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir        @return level numbers of this node
184*cdf0e10cSrcweir      */
185*cdf0e10cSrcweir     SwNumberTree::tNumberVector GetNumberVector() const;
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir     /**
188*cdf0e10cSrcweir        Return if numbering is restartet at this node.
189*cdf0e10cSrcweir      */
190*cdf0e10cSrcweir     virtual bool IsRestart() const = 0;
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir     /**
193*cdf0e10cSrcweir        Return start value.
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir        @return start value
196*cdf0e10cSrcweir      */
197*cdf0e10cSrcweir     virtual SwNumberTree::tSwNumTreeNumber GetStartValue() const = 0;
198*cdf0e10cSrcweir 
199*cdf0e10cSrcweir     /**
200*cdf0e10cSrcweir        Return if this node is counted.
201*cdf0e10cSrcweir 
202*cdf0e10cSrcweir        @retval true this node is counted
203*cdf0e10cSrcweir        @retval false this node is NOT counted
204*cdf0e10cSrcweir      */
205*cdf0e10cSrcweir     virtual bool IsCounted() const;
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir     /**
208*cdf0e10cSrcweir        Return if this node is counted continuous.
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir        @retval true    This node is counted continuous.
211*cdf0e10cSrcweir        @retval false   else
212*cdf0e10cSrcweir      */
213*cdf0e10cSrcweir     virtual bool IsContinuous() const = 0;
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir     /**
216*cdf0e10cSrcweir        Return if a node is first non-phantom child of this node.
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir        @param pNode     the node to check
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir        @retval true     pNode is first child of this node
221*cdf0e10cSrcweir        @retval false    else
222*cdf0e10cSrcweir      */
223*cdf0e10cSrcweir     virtual bool IsFirst(const SwNumberTreeNode * pNode) const;
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir     /**
226*cdf0e10cSrcweir        Return if this node if the first non-phantom node in the tree.
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir        @retval true     this node is the first non-phantom node in the tree
229*cdf0e10cSrcweir        @retval false    else
230*cdf0e10cSrcweir      */
231*cdf0e10cSrcweir     virtual bool IsFirst() const;
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir     /**
234*cdf0e10cSrcweir        Return if this node is a phantom.
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir        @retval true this node is a phantom
237*cdf0e10cSrcweir        @retval false this node is NOT a phantom
238*cdf0e10cSrcweir      */
239*cdf0e10cSrcweir     bool IsPhantom() const;
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     /** set level of this node
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir         OD 2008-03-13 #refactorlists#
244*cdf0e10cSrcweir         precondition: node is already member of a list tree
245*cdf0e10cSrcweir 
246*cdf0e10cSrcweir         @author OD
247*cdf0e10cSrcweir     */
248*cdf0e10cSrcweir     void SetLevelInListTree( const int nLevel );
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir     /**
251*cdf0e10cSrcweir        Return level of this node.
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir        The level of this node is the length of the path from the root
254*cdf0e10cSrcweir        to this node.
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir        @return the level of this node
257*cdf0e10cSrcweir      */
258*cdf0e10cSrcweir     int GetLevelInListTree() const;
259*cdf0e10cSrcweir 
260*cdf0e10cSrcweir     /**
261*cdf0e10cSrcweir        Returns if this node is less than another node.
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir        @param rTreeNode   node to compare with
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir        @attention A phantom node is considered the least element with
266*cdf0e10cSrcweir        respect to lessThan.
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir        @retval true this node is less than rTreeNode
269*cdf0e10cSrcweir        @retval false else
270*cdf0e10cSrcweir     */
271*cdf0e10cSrcweir     virtual bool LessThan(const SwNumberTreeNode & rTreeNode) const;
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     /**
274*cdf0e10cSrcweir        Invalidate this node and all its descendants.
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir        All iterators holding the last valid node in the according list
277*cdf0e10cSrcweir        of childs are set to the end of this list, thereby stating all
278*cdf0e10cSrcweir        children in the list are invalid.
279*cdf0e10cSrcweir        OD 2007-10-26 #i83479# - made public
280*cdf0e10cSrcweir      */
281*cdf0e10cSrcweir     void InvalidateTree() const;
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir     /**
284*cdf0e10cSrcweir        Notifies all invalid children of this node.
285*cdf0e10cSrcweir        OD 2007-10-26 #i83479# - made public
286*cdf0e10cSrcweir      */
287*cdf0e10cSrcweir     void NotifyInvalidChildren();
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir     /**
290*cdf0e10cSrcweir        Notifies the node.
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir        Calls Invalidate(this) on parent.
293*cdf0e10cSrcweir      */
294*cdf0e10cSrcweir     void InvalidateMe();
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     /**
297*cdf0e10cSrcweir        Validate the tree.
298*cdf0e10cSrcweir 
299*cdf0e10cSrcweir        Validates all nodes in this subtree.
300*cdf0e10cSrcweir     */
301*cdf0e10cSrcweir     void ValidateTree();
302*cdf0e10cSrcweir 
303*cdf0e10cSrcweir     /**
304*cdf0e10cSrcweir        Validates this node.
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir        Calls Validate(this) on parent.
307*cdf0e10cSrcweir     */
308*cdf0e10cSrcweir     void ValidateMe();
309*cdf0e10cSrcweir 
310*cdf0e10cSrcweir     /**
311*cdf0e10cSrcweir        Notifies all invalid siblings of this node.
312*cdf0e10cSrcweir     */
313*cdf0e10cSrcweir     void NotifyInvalidSiblings();
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir     /** notification of all nodes in the list tree on certain list level
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir         OD 2008-04-17 #refactorlists#
318*cdf0e10cSrcweir     */
319*cdf0e10cSrcweir     void NotifyNodesOnListLevel( const int nListLevel );
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     /** Invalidation and notification of complete numbering tree
322*cdf0e10cSrcweir 
323*cdf0e10cSrcweir         OD 2006-04-26 #i64010#
324*cdf0e10cSrcweir         Usage: on <IsCounted()> state change its needed to invalidate the
325*cdf0e10cSrcweir                complete numbering tree due to wide influence of this change.
326*cdf0e10cSrcweir     */
327*cdf0e10cSrcweir     inline void InvalidateAndNotifyTree()
328*cdf0e10cSrcweir     {
329*cdf0e10cSrcweir         if ( GetRoot() )
330*cdf0e10cSrcweir         {
331*cdf0e10cSrcweir             GetRoot()->InvalidateTree();
332*cdf0e10cSrcweir             GetRoot()->Notify();
333*cdf0e10cSrcweir         }
334*cdf0e10cSrcweir     }
335*cdf0e10cSrcweir 
336*cdf0e10cSrcweir     /**
337*cdf0e10cSrcweir        Returns the greatest descendant of the root that is smaller than
338*cdf0e10cSrcweir        this node, aka the predecessor of this node.
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir        @return the predecessor
341*cdf0e10cSrcweir      */
342*cdf0e10cSrcweir     SwNumberTreeNode* GetPred( bool bSibling = false ) const;
343*cdf0e10cSrcweir 
344*cdf0e10cSrcweir     /** determines the node, which is preceding the node
345*cdf0e10cSrcweir 
346*cdf0e10cSrcweir         OD 2007-09-06 #i81002#
347*cdf0e10cSrcweir         The search for the preceding node is performed for the tree below the
348*cdf0e10cSrcweir         <this> node. To search the complete tree, the method has been called for
349*cdf0e10cSrcweir         the root of the tree.
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir         @author OD
352*cdf0e10cSrcweir     */
353*cdf0e10cSrcweir     const SwNumberTreeNode* GetPrecedingNodeOf( const SwNumberTreeNode& rNode ) const;
354*cdf0e10cSrcweir 
355*cdf0e10cSrcweir //    /**
356*cdf0e10cSrcweir //       Returns a string representation of this node.
357*cdf0e10cSrcweir 
358*cdf0e10cSrcweir //       @return the string representation of this node
359*cdf0e10cSrcweir //     */
360*cdf0e10cSrcweir //    virtual String ToString() const = 0;
361*cdf0e10cSrcweir 
362*cdf0e10cSrcweir //    /**
363*cdf0e10cSrcweir //       Print this subtree.
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir //       @param o              output stream to direct output to
366*cdf0e10cSrcweir //       @param rIndent        additional indent for the children of this node
367*cdf0e10cSrcweir //       @param rMyIndent      indent to use for this node
368*cdf0e10cSrcweir //       @param nDepth         number of levels to print (-1 means all levels)
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir //       @return output stream after output of this subtree
371*cdf0e10cSrcweir //     */
372*cdf0e10cSrcweir //    String print(const String & rIndent = String("  ",
373*cdf0e10cSrcweir //                                                 RTL_TEXTENCODING_ASCII_US),
374*cdf0e10cSrcweir //                 const String & rMyIndent = String("  ",
375*cdf0e10cSrcweir //                                                   RTL_TEXTENCODING_ASCII_US),
376*cdf0e10cSrcweir //                 int nDepth = -1) const;
377*cdf0e10cSrcweir 
378*cdf0e10cSrcweir #ifdef DBG_UTIL
379*cdf0e10cSrcweir     static unsigned long GetInstances();
380*cdf0e10cSrcweir     unsigned long GetSerial();
381*cdf0e10cSrcweir #endif
382*cdf0e10cSrcweir 
383*cdf0e10cSrcweir #ifdef __SW_NUMBER_TREE_SANITY_CHECK
384*cdf0e10cSrcweir     /**
385*cdf0e10cSrcweir        Sanity check.
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir        @param bRecursive    descend to children
388*cdf0e10cSrcweir 
389*cdf0e10cSrcweir        @retval true   the structure of this node is sane
390*cdf0e10cSrcweir        @retval false  else
391*cdf0e10cSrcweir      */
392*cdf0e10cSrcweir     bool IsSane(bool bRecursive) const;
393*cdf0e10cSrcweir #endif // __SW_NUMBER_TREE_SANITY_CHECK
394*cdf0e10cSrcweir 
395*cdf0e10cSrcweir protected:
396*cdf0e10cSrcweir     /**
397*cdf0e10cSrcweir        the children
398*cdf0e10cSrcweir     */
399*cdf0e10cSrcweir     tSwNumberTreeChildren mChildren;
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir     /**
402*cdf0e10cSrcweir        Returns the root node of the tree this node is part of.
403*cdf0e10cSrcweir 
404*cdf0e10cSrcweir        Important note: method call <GetRoot()->GetRoot()> returns NULL.
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir        @return the root
407*cdf0e10cSrcweir      */
408*cdf0e10cSrcweir     SwNumberTreeNode* GetRoot() const;
409*cdf0e10cSrcweir 
410*cdf0e10cSrcweir      /**
411*cdf0e10cSrcweir        Return if the notification is not disabled on global conditions
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir        @retval true   Notification enabled in general.
414*cdf0e10cSrcweir        @retval false  else
415*cdf0e10cSrcweir      */
416*cdf0e10cSrcweir     virtual bool IsNotificationEnabled() const = 0;
417*cdf0e10cSrcweir 
418*cdf0e10cSrcweir     /**
419*cdf0e10cSrcweir        Returns how many children this node has got.
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir        @return number of children
422*cdf0e10cSrcweir      */
423*cdf0e10cSrcweir     tSwNumberTreeChildren::size_type GetChildCount() const;
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir     // --> OD 2006-04-26 #i64010# - made pure virtual
426*cdf0e10cSrcweir     virtual bool HasCountedChildren() const = 0;
427*cdf0e10cSrcweir     // <--
428*cdf0e10cSrcweir 
429*cdf0e10cSrcweir     // --> OD 2006-04-26 #i64010#
430*cdf0e10cSrcweir     virtual bool IsCountedForNumbering() const = 0;
431*cdf0e10cSrcweir     // <--
432*cdf0e10cSrcweir 
433*cdf0e10cSrcweir     // --> OD 2008-02-19 #refactorlists#
434*cdf0e10cSrcweir     // method called before this tree node has been added to the list tree
435*cdf0e10cSrcweir     virtual void PreAdd() = 0;
436*cdf0e10cSrcweir     // method called after this tree node has been removed from the list tree
437*cdf0e10cSrcweir     virtual void PostRemove() = 0;
438*cdf0e10cSrcweir     // <--
439*cdf0e10cSrcweir 
440*cdf0e10cSrcweir #ifdef __SW_NUMBER_TREE_SANITY_CHECK
441*cdf0e10cSrcweir     /**
442*cdf0e10cSrcweir        Sanity check with loop detection.
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir        @param bRecursive   descend to children
445*cdf0e10cSrcweir        @param rParents     vector for recording path
446*cdf0e10cSrcweir 
447*cdf0e10cSrcweir        @retval true     this node is sane
448*cdf0e10cSrcweir        @retval false    else     */
449*cdf0e10cSrcweir     virtual bool IsSane
450*cdf0e10cSrcweir     (bool bRecursive, std::vector<const SwNumberTreeNode *> rParents) const;
451*cdf0e10cSrcweir #endif // __SW_NUMBER_TREE_SANITY_CHECK
452*cdf0e10cSrcweir 
453*cdf0e10cSrcweir     /**
454*cdf0e10cSrcweir        the parent node
455*cdf0e10cSrcweir     */
456*cdf0e10cSrcweir     SwNumberTreeNode * mpParent;
457*cdf0e10cSrcweir 
458*cdf0e10cSrcweir     /**
459*cdf0e10cSrcweir        the number of the node
460*cdf0e10cSrcweir     */
461*cdf0e10cSrcweir     mutable SwNumberTree::tSwNumTreeNumber mnNumber;
462*cdf0e10cSrcweir 
463*cdf0e10cSrcweir     // --> OD 2008-11-26 #158694#
464*cdf0e10cSrcweir     // boolean indicating, that a node of a not counted parent node is continueing
465*cdf0e10cSrcweir     // the numbering of parent's previous node sub tree.
466*cdf0e10cSrcweir     // Example:
467*cdf0e10cSrcweir     //   1. kshdkjfs
468*cdf0e10cSrcweir     //     1.1. lskjf
469*cdf0e10cSrcweir     //      sdfjlksaf <-- not counted parent node
470*cdf0e10cSrcweir     //     1.2. lfjlaskf <-- <mbContinueingPreviousSubTree = true>
471*cdf0e10cSrcweir     mutable bool mbContinueingPreviousSubTree;
472*cdf0e10cSrcweir     // <--
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir     /**
475*cdf0e10cSrcweir        true     this node is a phantom
476*cdf0e10cSrcweir        false    this node is NOT a phantom
477*cdf0e10cSrcweir      */
478*cdf0e10cSrcweir     bool mbPhantom;
479*cdf0e10cSrcweir 
480*cdf0e10cSrcweir     /**
481*cdf0e10cSrcweir        Iterator to the last valid element. All children that are less
482*cdf0e10cSrcweir        than or equal to the referenced child are valid. All children
483*cdf0e10cSrcweir        greater than the referenced child are invalid.
484*cdf0e10cSrcweir      */
485*cdf0e10cSrcweir     mutable tSwNumberTreeChildren::iterator mItLastValid;
486*cdf0e10cSrcweir 
487*cdf0e10cSrcweir #ifdef DBG_UTIL
488*cdf0e10cSrcweir     /**
489*cdf0e10cSrcweir        Counter for the number of created instances.
490*cdf0e10cSrcweir      */
491*cdf0e10cSrcweir     static unsigned long nInstances;
492*cdf0e10cSrcweir 
493*cdf0e10cSrcweir     /**
494*cdf0e10cSrcweir        Serial number.
495*cdf0e10cSrcweir     */
496*cdf0e10cSrcweir     unsigned long mnSerial;
497*cdf0e10cSrcweir #endif
498*cdf0e10cSrcweir 
499*cdf0e10cSrcweir     SwNumberTreeNode(const SwNumberTreeNode& );
500*cdf0e10cSrcweir     SwNumberTreeNode& operator=( const SwNumberTreeNode& );
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir     /**
503*cdf0e10cSrcweir        Calls _GetNumberVector on parent and adds number of this node
504*cdf0e10cSrcweir        at the end.
505*cdf0e10cSrcweir 
506*cdf0e10cSrcweir        @param rVector     return value
507*cdf0e10cSrcweir        @param bValidate   validate the number?
508*cdf0e10cSrcweir      */
509*cdf0e10cSrcweir     void _GetNumberVector( SwNumberTree::tNumberVector& rVector,
510*cdf0e10cSrcweir                            bool bValidate = true ) const;
511*cdf0e10cSrcweir 
512*cdf0e10cSrcweir     /**
513*cdf0e10cSrcweir        Invalidates a child.
514*cdf0e10cSrcweir 
515*cdf0e10cSrcweir        Calls SetLastValid for the preceeding sibling of the child and
516*cdf0e10cSrcweir        notifies all invalid children.
517*cdf0e10cSrcweir 
518*cdf0e10cSrcweir        @param pChild      the child to invalidate
519*cdf0e10cSrcweir      */
520*cdf0e10cSrcweir     void Invalidate( SwNumberTreeNode * pChild );
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir     /** Invalidation of all children
523*cdf0e10cSrcweir 
524*cdf0e10cSrcweir         OD 2005-10-19 #126009#
525*cdf0e10cSrcweir         Usage: on <IsCounted()> state change the children have to be invalidated
526*cdf0e10cSrcweir     */
527*cdf0e10cSrcweir     inline void InvalidateChildren()
528*cdf0e10cSrcweir     {
529*cdf0e10cSrcweir         SetLastValid( mChildren.end() );
530*cdf0e10cSrcweir     }
531*cdf0e10cSrcweir 
532*cdf0e10cSrcweir     /** Invalidation of parent node, if its not counted.
533*cdf0e10cSrcweir 
534*cdf0e10cSrcweir         OD 2005-10-19 #126009#
535*cdf0e10cSrcweir         Usage: on <IsCounted()> state change the parent have to be invalidated
536*cdf0e10cSrcweir     */
537*cdf0e10cSrcweir     inline void InvalidateNotCountedParent()
538*cdf0e10cSrcweir     {
539*cdf0e10cSrcweir         if ( GetParent() && !GetParent()->IsCountedForNumbering() )
540*cdf0e10cSrcweir         {
541*cdf0e10cSrcweir             GetParent()->InvalidateMe();
542*cdf0e10cSrcweir         }
543*cdf0e10cSrcweir     }
544*cdf0e10cSrcweir 
545*cdf0e10cSrcweir     /**
546*cdf0e10cSrcweir        Set the last valid child of this node.
547*cdf0e10cSrcweir 
548*cdf0e10cSrcweir        @param aItLastValid    iterator pointing to the new last valid child
549*cdf0e10cSrcweir        @param bValidating     - true    always set the last valid node to
550*cdf0e10cSrcweir                                         aItLastValid
551*cdf0e10cSrcweir                               - false   only set if aItLastValid is preceeding
552*cdf0e10cSrcweir                                         the current last valid node
553*cdf0e10cSrcweir      */
554*cdf0e10cSrcweir     void SetLastValid(tSwNumberTreeChildren::iterator aItLastValid,
555*cdf0e10cSrcweir                       bool bValidating = false) const;
556*cdf0e10cSrcweir 
557*cdf0e10cSrcweir     /**
558*cdf0e10cSrcweir        Set this node as last valid child of its parent.
559*cdf0e10cSrcweir 
560*cdf0e10cSrcweir        @param bValidation    see aboce
561*cdf0e10cSrcweir      */
562*cdf0e10cSrcweir     void SetLastValid(bool bValidating) const;
563*cdf0e10cSrcweir 
564*cdf0e10cSrcweir     /**
565*cdf0e10cSrcweir        Return if this node is notifiable.
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir        @attention If a not is not notifiable a notify request is *not*
568*cdf0e10cSrcweir        forwarded to its descendants.
569*cdf0e10cSrcweir 
570*cdf0e10cSrcweir        @retval true   This node is notifiable.
571*cdf0e10cSrcweir        @retval false  else
572*cdf0e10cSrcweir      */
573*cdf0e10cSrcweir     virtual bool IsNotifiable() const = 0;
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir     /**
576*cdf0e10cSrcweir        Notifies the node.
577*cdf0e10cSrcweir 
578*cdf0e10cSrcweir        Called when the number of the node got invalid.
579*cdf0e10cSrcweir      */
580*cdf0e10cSrcweir     virtual void NotifyNode() = 0;
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir     /**
583*cdf0e10cSrcweir        Notifies this node (NotifyNode) and all descendants.
584*cdf0e10cSrcweir      */
585*cdf0e10cSrcweir     void Notify();
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir     /** Notification of parent node siblings, if its not counted.
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir         OD 2005-10-19 #126009#
590*cdf0e10cSrcweir         Usage: on <IsCounted()> state change the parent node and its siblings
591*cdf0e10cSrcweir                have to be notified.
592*cdf0e10cSrcweir     */
593*cdf0e10cSrcweir     inline void NotifyNotCountedParentSiblings()
594*cdf0e10cSrcweir     {
595*cdf0e10cSrcweir         if ( GetParent() && !GetParent()->IsCountedForNumbering() )
596*cdf0e10cSrcweir         {
597*cdf0e10cSrcweir             GetParent()->NotifyInvalidSiblings();
598*cdf0e10cSrcweir         }
599*cdf0e10cSrcweir     }
600*cdf0e10cSrcweir 
601*cdf0e10cSrcweir     /** notification of children nodes on certain depth
602*cdf0e10cSrcweir 
603*cdf0e10cSrcweir         OD 2008-04-17 #refactorlists#
604*cdf0e10cSrcweir 
605*cdf0e10cSrcweir         @author OD
606*cdf0e10cSrcweir     */
607*cdf0e10cSrcweir     void NotifyChildrenOnDepth( const int nDepth );
608*cdf0e10cSrcweir 
609*cdf0e10cSrcweir     /**
610*cdf0e10cSrcweir        Returns if a child A this node is valid.
611*cdf0e10cSrcweir 
612*cdf0e10cSrcweir        A is valid if aItLastValid in parent refers to a node
613*cdf0e10cSrcweir        greater than of equal to A.
614*cdf0e10cSrcweir 
615*cdf0e10cSrcweir        @param pChild    child to be tested
616*cdf0e10cSrcweir 
617*cdf0e10cSrcweir        @retval true this node is valid
618*cdf0e10cSrcweir        @retval false this node is NOT valid
619*cdf0e10cSrcweir      */
620*cdf0e10cSrcweir     bool IsValid(const SwNumberTreeNode * pChild) const;
621*cdf0e10cSrcweir 
622*cdf0e10cSrcweir     /**
623*cdf0e10cSrcweir        Returns if this node is valid.
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir        @retval true    this node is valid
626*cdf0e10cSrcweir        @retval false   else
627*cdf0e10cSrcweir      */
628*cdf0e10cSrcweir     bool IsValid() const;
629*cdf0e10cSrcweir 
630*cdf0e10cSrcweir     /**
631*cdf0e10cSrcweir        Validates a child.
632*cdf0e10cSrcweir 
633*cdf0e10cSrcweir        @param pNode     child to be validated
634*cdf0e10cSrcweir 
635*cdf0e10cSrcweir        @attention All invalid children preceding pNode are validated, too.
636*cdf0e10cSrcweir      */
637*cdf0e10cSrcweir     void Validate(const SwNumberTreeNode * pNode) const;
638*cdf0e10cSrcweir 
639*cdf0e10cSrcweir     /**
640*cdf0e10cSrcweir        Validates a child using hierarchical numbering.
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir        @param pNode      child to be validated
643*cdf0e10cSrcweir 
644*cdf0e10cSrcweir        @attention All invalid children preceding pNode are validated, too.
645*cdf0e10cSrcweir      */
646*cdf0e10cSrcweir     void ValidateHierarchical(const SwNumberTreeNode * pNode) const;
647*cdf0e10cSrcweir 
648*cdf0e10cSrcweir     /**
649*cdf0e10cSrcweir        Validates a child using continuous numbering.
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir        @param pNode      child to be validated
652*cdf0e10cSrcweir 
653*cdf0e10cSrcweir        @attention All invalid children preceding pNode are validated, too.
654*cdf0e10cSrcweir      */
655*cdf0e10cSrcweir     void ValidateContinuous(const SwNumberTreeNode * pNode) const;
656*cdf0e10cSrcweir 
657*cdf0e10cSrcweir     /**
658*cdf0e10cSrcweir        Creates a new node of the same class.
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir        @return the new node
661*cdf0e10cSrcweir     */
662*cdf0e10cSrcweir     virtual SwNumberTreeNode * Create() const = 0;
663*cdf0e10cSrcweir 
664*cdf0e10cSrcweir     /**
665*cdf0e10cSrcweir        Creates a phantom.
666*cdf0e10cSrcweir 
667*cdf0e10cSrcweir        @return the created phantom
668*cdf0e10cSrcweir      */
669*cdf0e10cSrcweir     SwNumberTreeNode * CreatePhantom();
670*cdf0e10cSrcweir 
671*cdf0e10cSrcweir     /**
672*cdf0e10cSrcweir        Set if this node is a phantom.
673*cdf0e10cSrcweir 
674*cdf0e10cSrcweir        @param bPhantom   - true this node is a phantom
675*cdf0e10cSrcweir                          - false this node is a phantom
676*cdf0e10cSrcweir      */
677*cdf0e10cSrcweir     void SetPhantom(bool bPhantom = true);
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir     /**
680*cdf0e10cSrcweir        Return if phantoms are counted.
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir        OD 2008-02-19 #refactorlists# - pure virtual now
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir        @retval true phantoms are counted
685*cdf0e10cSrcweir        @retval false else
686*cdf0e10cSrcweir      */
687*cdf0e10cSrcweir     virtual bool IsCountPhantoms() const = 0;
688*cdf0e10cSrcweir 
689*cdf0e10cSrcweir     /**
690*cdf0e10cSrcweir        Return if all descendants of this node are phantoms.
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir        @retval true   all descendants are phantoms
693*cdf0e10cSrcweir        @retval false  else
694*cdf0e10cSrcweir      */
695*cdf0e10cSrcweir     bool HasOnlyPhantoms() const;
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir     // --> OD 2005-10-27 #126009#
698*cdf0e10cSrcweir     bool HasPhantomCountedParent() const;
699*cdf0e10cSrcweir     // <--
700*cdf0e10cSrcweir 
701*cdf0e10cSrcweir     /**
702*cdf0e10cSrcweir         HB, OD : return node, if it isn't a phantom, otherwise return first
703*cdf0e10cSrcweir                  non-phantom descendant.
704*cdf0e10cSrcweir         Returns the first child of this node that is NOT a phantom.
705*cdf0e10cSrcweir 
706*cdf0e10cSrcweir         @return  the first non phantom child
707*cdf0e10cSrcweir     */
708*cdf0e10cSrcweir     SwNumberTreeNode* GetFirstNonPhantomChild();
709*cdf0e10cSrcweir 
710*cdf0e10cSrcweir     /**
711*cdf0e10cSrcweir        Removes recursively phantoms that have no children.
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir        The resulting tree has no phantoms that either have no children or
714*cdf0e10cSrcweir        whose descendancy consist entirely of phantoms.
715*cdf0e10cSrcweir      */
716*cdf0e10cSrcweir     void ClearObsoletePhantoms();
717*cdf0e10cSrcweir 
718*cdf0e10cSrcweir     tSwNumberTreeChildren::iterator GetIterator(const SwNumberTreeNode * pChild) const;
719*cdf0e10cSrcweir 
720*cdf0e10cSrcweir     /**
721*cdf0e10cSrcweir        Moves all children to a given destination node.
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir        @param pDest    the destination node
724*cdf0e10cSrcweir      */
725*cdf0e10cSrcweir     void MoveChildren(SwNumberTreeNode * pDest);
726*cdf0e10cSrcweir 
727*cdf0e10cSrcweir     /** Moves all children of this node that are greater than a given node
728*cdf0e10cSrcweir         to the destination node.
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir         OD 2005-10-14 #125991#
731*cdf0e10cSrcweir         distinguish between node for comparing, whose children are greater,
732*cdf0e10cSrcweir         and the destination node.
733*cdf0e10cSrcweir 
734*cdf0e10cSrcweir         @param _rCompareNode
735*cdf0e10cSrcweir         input parameter - reference to the node, which is used to determine
736*cdf0e10cSrcweir         the greater children
737*cdf0e10cSrcweir 
738*cdf0e10cSrcweir         @param _rDestNode
739*cdf0e10cSrcweir         input parameter - reference to the node, which is the destination for
740*cdf0e10cSrcweir         the greater children
741*cdf0e10cSrcweir     */
742*cdf0e10cSrcweir     void MoveGreaterChildren( SwNumberTreeNode& _rCompareNode,
743*cdf0e10cSrcweir                               SwNumberTreeNode& _rDestNode );
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir     /**
746*cdf0e10cSrcweir        Returns the last descendant of a node, if it has children.
747*cdf0e10cSrcweir 
748*cdf0e10cSrcweir        @return last descendant of the node
749*cdf0e10cSrcweir     */
750*cdf0e10cSrcweir     SwNumberTreeNode* GetLastDescendant() const;
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir };
753*cdf0e10cSrcweir 
754*cdf0e10cSrcweir /**
755*cdf0e10cSrcweir    Functor. Checks if a certain node is less than the functor's member.
756*cdf0e10cSrcweir  */
757*cdf0e10cSrcweir struct SwNumberTreeNodeIsLessThan
758*cdf0e10cSrcweir {
759*cdf0e10cSrcweir     const SwNumberTreeNode * pNode;
760*cdf0e10cSrcweir 
761*cdf0e10cSrcweir     SwNumberTreeNodeIsLessThan(const SwNumberTreeNode * _pNode)
762*cdf0e10cSrcweir         : pNode(_pNode) {}
763*cdf0e10cSrcweir 
764*cdf0e10cSrcweir     bool operator()(const SwNumberTreeNode * _pNode) const
765*cdf0e10cSrcweir     { return SwNumberTreeNodeLessThan(_pNode, pNode); }
766*cdf0e10cSrcweir };
767*cdf0e10cSrcweir #endif // _SW_NUMBER_TREE_HXX
768