1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SW_INC_SWNUMBERTREE_HXX
21 #define INCLUDED_SW_INC_SWNUMBERTREE_HXX
26 #include "SwNumberTreeTypes.hxx"
28 class SwNumberTreeNode
;
30 bool SwNumberTreeNodeLessThan (const SwNumberTreeNode
* pA
,
31 const SwNumberTreeNode
* pB
);
33 struct compSwNumberTreeNodeLessThan
35 bool operator()(const SwNumberTreeNode
* pA
,
36 const SwNumberTreeNode
* pB
) const
37 { return SwNumberTreeNodeLessThan(pA
, pB
); }
41 A tree of numbered nodes.
64 The root contains the nodes of the first level. Each node A of the
65 first level contains those nodes of the second level that have the
66 same first level number as A and so on for the subsidiary levels.
68 The numbering label of a node A is resolved by concatenating the
69 numbers of the nodes on the path from the root to A.
71 ------------------------------------------
75 A phantom is an auxiliary node that is used to emulate numberings
76 starting with nodes not at top level. The phantom contains the
77 number for the level but is not considered part of the numbering.
79 Constraint 1: A phantom is always the first child node.
80 Constraint 2: At each node there is at most one child that is a phantom.
81 Constraint 3: A phantom is the smallest of all numbering nodes.
90 + 0 (phantom, not counted)
95 The phantom gets numbered with 0. The first non-phantom node gets
96 numbered with the start value.
98 -----------------------------------------
104 6.1. ljdflaksjflkjasflkjsf
107 + 5 (phantom, counted)
110 + 1 ljdflaksjflkjasflkjsf
112 The phantom gets numbered with the start value.
114 class SAL_DLLPUBLIC_RTTI SwNumberTreeNode
117 typedef std::set
<SwNumberTreeNode
*, compSwNumberTreeNodeLessThan
>
118 tSwNumberTreeChildren
;
123 virtual ~SwNumberTreeNode();
128 @param pChild child to add
129 @param nDepth depth in which to add the child
131 void AddChild( SwNumberTreeNode
* pChild
,
137 @param pChild child to be removed
139 void RemoveChild( SwNumberTreeNode
* pChild
);
142 Remove this child from the tree.
147 Returns the parent of this node.
151 SwNumberTreeNode
* GetParent() const
157 Returns number of this node.
159 @param bValidate validate the number?
161 @return number of this node
163 SwNumberTree::tSwNumTreeNumber
GetNumber( bool bValidate
= true ) const;
165 bool IsContinueingPreviousSubTree() const { return mbContinueingPreviousSubTree
;}
168 Returns level numbers of this node.
170 @return level numbers of this node
172 SwNumberTree::tNumberVector
GetNumberVector() const;
175 Return if numbering is restarted at this node.
177 virtual bool IsRestart() const = 0;
184 virtual SwNumberTree::tSwNumTreeNumber
GetStartValue() const = 0;
187 Return if this node is counted.
189 @retval true this node is counted
190 @retval false this node is NOT counted
192 virtual bool IsCounted() const;
195 Return if this node is counted continuous.
197 @retval true This node is counted continuous.
200 virtual bool IsContinuous() const = 0;
203 Return if a node is first non-phantom child of this node.
205 @param pNode the node to check
207 @retval true pNode is first child of this node
210 bool IsFirst(const SwNumberTreeNode
* pNode
) const;
213 Return if this node if the first non-phantom node in the tree.
215 @retval true this node is the first non-phantom node in the tree
218 bool IsFirst() const;
221 Return if this node is a phantom.
223 @retval true this node is a phantom
224 @retval false this node is NOT a phantom
226 bool IsPhantom() const { return mbPhantom
;}
228 /** set level of this node
230 precondition: node is already member of a list tree
232 void SetLevelInListTree( const int nLevel
);
235 Return level of this node.
237 The level of this node is the length of the path from the root
240 @return the level of this node
242 int GetLevelInListTree() const;
245 Returns if this node is less than another node.
247 @param rTreeNode node to compare with
249 @attention A phantom node is considered the least element with
252 @retval true this node is less than rTreeNode
255 virtual bool LessThan(const SwNumberTreeNode
& rTreeNode
) const;
258 Invalidate this node and all its descendants.
260 All iterators holding the last valid node in the according list
261 of children are set to the end of this list, thereby stating all
262 children in the list are invalid.
263 #i83479# - made public
265 void InvalidateTree() const;
268 Notifies all invalid children of this node.
269 #i83479# - made public
271 void NotifyInvalidChildren();
276 Calls Invalidate(this) on parent.
283 Calls Validate(this) on parent.
287 /** Notifies all invalid siblings of this node. */
288 void NotifyInvalidSiblings();
290 /** notification of all nodes in the list tree on certain list level */
291 void NotifyNodesOnListLevel( const int nListLevel
);
293 /** Invalidation and notification of complete numbering tree
296 Usage: on <IsCounted()> state change it's needed to invalidate the
297 complete numbering tree due to wide influence of this change.
299 void InvalidateAndNotifyTree()
303 GetRoot()->InvalidateTree();
309 Returns the greatest descendant of the root that is smaller than
310 this node, aka the predecessor of this node.
312 @return the predecessor
314 SwNumberTreeNode
* GetPred( bool bSibling
= false ) const;
316 /** determines the node, which is preceding the node
319 The search for the preceding node is performed for the tree below the
320 <this> node. To search the complete tree, the method has been called for
321 the root of the tree.
323 const SwNumberTreeNode
* GetPrecedingNodeOf( const SwNumberTreeNode
& rNode
) const;
329 @param bRecursive descend to children
331 @retval true the structure of this node is sane
334 void IsSane(bool bRecursive
) const;
339 tSwNumberTreeChildren mChildren
;
342 Returns the root node of the tree this node is part of.
344 Important note: method call <GetRoot()->GetRoot()> returns NULL.
348 SwNumberTreeNode
* GetRoot() const;
351 Return if the notification is not disabled on global conditions
353 @retval true Notification enabled in general.
356 virtual bool IsNotificationEnabled() const = 0;
359 Returns how many children this node has got.
361 @return number of children
363 tSwNumberTreeChildren::size_type
GetChildCount() const;
365 // #i64010# - made pure virtual
366 virtual bool HasCountedChildren() const = 0;
369 virtual bool IsCountedForNumbering() const = 0;
371 // method called before this tree node has been added to the list tree
372 virtual void PreAdd() = 0;
373 // method called after this tree node has been removed from the list tree
374 virtual void PostRemove() = 0;
377 /** Sanity check with loop detection.
379 @param bRecursive descend to children
380 @param rParents vector for recording path
382 void IsSane(bool bRecursive
, std::vector
<const SwNumberTreeNode
*> rParents
) const;
385 /** he parent node */
386 SwNumberTreeNode
* mpParent
;
388 /** the number of the node */
389 mutable SwNumberTree::tSwNumTreeNumber mnNumber
;
391 // boolean indicating, that a node of a not counted parent node is continuing
392 // the numbering of parent's previous node sub tree.
396 // sdfjlksaf <-- not counted parent node
397 // 1.2. lfjlaskf <-- <mbContinueingPreviousSubTree = true>
398 mutable bool mbContinueingPreviousSubTree
;
401 true this node is a phantom
402 false this node is NOT a phantom
407 Iterator to the last valid element. All children that are less
408 than or equal to the referenced child are valid. All children
409 greater than the referenced child are invalid.
411 mutable tSwNumberTreeChildren::const_iterator mItLastValid
;
413 SwNumberTreeNode(const SwNumberTreeNode
& );
414 SwNumberTreeNode
& operator=( const SwNumberTreeNode
& );
417 Calls GetNumberVector_ on parent and adds number of this node
420 @param rVector return value
421 @param bValidate validate the number?
423 void GetNumberVector_( SwNumberTree::tNumberVector
& rVector
,
424 bool bValidate
= true ) const;
429 Calls SetLastValid for the preceding sibling of the child and
430 notifies all invalid children.
432 @param pChild the child to invalidate
434 void Invalidate( SwNumberTreeNode
const * pChild
);
436 /** Invalidation of all children
438 Usage: on <IsCounted()> state change the children have to be invalidated
440 void InvalidateChildren()
442 SetLastValid( mChildren
.end() );
446 Set the last valid child of this node.
448 @param aItLastValid iterator pointing to the new last valid child
449 @param bValidating - true always set the last valid node to
451 - false only set if aItLastValid is preceding
452 the current last valid node
454 void SetLastValid(const tSwNumberTreeChildren::const_iterator
& aItLastValid
,
455 bool bValidating
= false) const;
458 Return if this node is notifiable.
460 @attention If a not is not notifiable a notify request is *not*
461 forwarded to its descendants.
463 @retval true This node is notifiable.
466 virtual bool IsNotifiable() const = 0;
471 Called when the number of the node got invalid.
473 virtual void NotifyNode() = 0;
475 /** Notifies this node (NotifyNode) and all descendants.*/
478 /** notification of children nodes on certain depth */
479 void NotifyChildrenOnDepth( const int nDepth
);
482 Returns if a child A this node is valid.
484 A is valid if aItLastValid in parent refers to a node
485 greater than of equal to A.
487 @param pChild child to be tested
489 @retval true this node is valid
490 @retval false this node is NOT valid
492 bool IsValid(const SwNumberTreeNode
* pChild
) const;
495 Returns if this node is valid.
497 @retval true this node is valid
500 bool IsValid() const;
505 @param pNode child to be validated
507 @attention All invalid children preceding pNode are validated, too.
509 void Validate(const SwNumberTreeNode
* pNode
) const;
512 Validates a child using hierarchical numbering.
514 @param pNode child to be validated
516 @attention All invalid children preceding pNode are validated, too.
518 void ValidateHierarchical(const SwNumberTreeNode
* pNode
) const;
521 Validates a child using continuous numbering.
523 @param pNode child to be validated
525 @attention All invalid children preceding pNode are validated, too.
527 void ValidateContinuous(const SwNumberTreeNode
* pNode
) const;
530 Creates a new node of the same class.
534 virtual SwNumberTreeNode
* Create() const = 0;
539 @return the created phantom
541 SwNumberTreeNode
* CreatePhantom();
544 Return if phantoms are counted.
546 virtual bool IsCountPhantoms() const = 0;
548 /** Return if all descendants of this node are phantoms. */
549 bool HasOnlyPhantoms() const;
551 bool HasPhantomCountedParent() const;
554 HB, OD : return node, if it isn't a phantom, otherwise return first
555 non-phantom descendant.
556 Returns the first child of this node that is NOT a phantom.
558 @return the first non phantom child
560 SwNumberTreeNode
* GetFirstNonPhantomChild();
563 Removes recursively phantoms that have no children.
565 The resulting tree has no phantoms that either have no children or
566 whose descendancy consist entirely of phantoms.
568 void ClearObsoletePhantoms();
570 tSwNumberTreeChildren::const_iterator
GetIterator(const SwNumberTreeNode
* pChild
) const;
573 Moves all children to a given destination node.
575 @param pDest the destination node
577 void MoveChildren(SwNumberTreeNode
* pDest
);
579 /** Moves all children of this node that are greater than a given node
580 to the destination node.
582 distinguish between node for comparing, whose children are greater,
583 and the destination node.
586 input parameter - reference to the node, which is used to determine
590 input parameter - reference to the node, which is the destination for
593 void MoveGreaterChildren( SwNumberTreeNode
& _rCompareNode
,
594 SwNumberTreeNode
& _rDestNode
);
597 Returns the last descendant of a node, if it has children.
599 @return last descendant of the node
601 SwNumberTreeNode
* GetLastDescendant() const;
605 #endif // INCLUDED_SW_INC_SWNUMBERTREE_HXX
607 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */