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 .
25 #include "SwNumberTreeTypes.hxx"
27 class SwNumberTreeNode
;
29 bool SwNumberTreeNodeLessThan(const SwNumberTreeNode
* pA
, const SwNumberTreeNode
* pB
);
31 struct compSwNumberTreeNodeLessThan
33 bool operator()(const SwNumberTreeNode
* pA
, const SwNumberTreeNode
* pB
) const
35 return SwNumberTreeNodeLessThan(pA
, pB
);
40 A tree of numbered nodes.
63 The root contains the nodes of the first level. Each node A of the
64 first level contains those nodes of the second level that have the
65 same first level number as A and so on for the subsidiary levels.
67 The numbering label of a node A is resolved by concatenating the
68 numbers of the nodes on the path from the root to A.
70 ------------------------------------------
74 A phantom is an auxiliary node that is used to emulate numberings
75 starting with nodes not at top level. The phantom contains the
76 number for the level but is not considered part of the numbering.
78 Constraint 1: A phantom is always the first child node.
79 Constraint 2: At each node there is at most one child that is a phantom.
80 Constraint 3: A phantom is the smallest of all numbering nodes.
89 + 0 (phantom, not counted)
94 The phantom gets numbered with 0. The first non-phantom node gets
95 numbered with the start value.
97 -----------------------------------------
103 6.1. ljdflaksjflkjasflkjsf
106 + 5 (phantom, counted)
109 + 1 ljdflaksjflkjasflkjsf
111 The phantom gets numbered with the start value.
113 class SAL_DLLPUBLIC_RTTI SwNumberTreeNode
116 typedef std::set
<SwNumberTreeNode
*, compSwNumberTreeNodeLessThan
> tSwNumberTreeChildren
;
121 virtual ~SwNumberTreeNode();
126 @param pChild child to add
127 @param nDepth depth in which to add the child
129 void AddChild(SwNumberTreeNode
* pChild
, const int nDepth
);
134 @param pChild child to be removed
136 void RemoveChild(SwNumberTreeNode
* pChild
);
139 Remove this child from the tree.
144 Returns the parent of this node.
148 SwNumberTreeNode
* GetParent() const { return mpParent
; }
151 Returns number of this node.
153 @param bValidate validate the number?
155 @return number of this node
157 SwNumberTree::tSwNumTreeNumber
GetNumber(bool bValidate
= true) const;
159 bool IsContinueingPreviousSubTree() const { return mbContinueingPreviousSubTree
; }
162 Returns level numbers of this node.
164 @return level numbers of this node
166 SwNumberTree::tNumberVector
GetNumberVector() const;
169 Return if numbering is restarted at this node.
171 virtual bool IsRestart() const = 0;
178 virtual SwNumberTree::tSwNumTreeNumber
GetStartValue() const = 0;
181 Return if this node is counted.
183 @retval true this node is counted
184 @retval false this node is NOT counted
186 virtual bool IsCounted() const;
189 Return if this node is counted continuous.
191 @retval true This node is counted continuous.
194 virtual bool IsContinuous() const = 0;
197 Return if a node is first non-phantom child of this node.
199 @param pNode the node to check
201 @retval true pNode is first child of this node
204 bool IsFirst(const SwNumberTreeNode
* pNode
) const;
207 Return if this node if the first non-phantom node in the tree.
209 @retval true this node is the first non-phantom node in the tree
212 bool IsFirst() const;
215 Return if this node is a phantom.
217 @retval true this node is a phantom
218 @retval false this node is NOT a phantom
220 bool IsPhantom() const { return mbPhantom
; }
222 /** set level of this node
224 precondition: node is already member of a list tree
226 void SetLevelInListTree(const int nLevel
);
229 Return level of this node.
231 The level of this node is the length of the path from the root
234 @return the level of this node
236 int GetLevelInListTree() const;
239 Returns if this node is less than another node.
241 @param rTreeNode node to compare with
243 @attention A phantom node is considered the least element with
246 @retval true this node is less than rTreeNode
249 virtual bool LessThan(const SwNumberTreeNode
& rTreeNode
) const;
252 Invalidate this node and all its descendants.
254 All iterators holding the last valid node in the according list
255 of children are set to the end of this list, thereby stating all
256 children in the list are invalid.
257 #i83479# - made public
259 void InvalidateTree() const;
262 Notifies all invalid children of this node.
263 #i83479# - made public
265 void NotifyInvalidChildren();
270 Calls Invalidate(this) on parent.
277 Calls Validate(this) on parent.
281 /** Notifies all invalid siblings of this node. */
282 void NotifyInvalidSiblings();
284 /** notification of all nodes in the list tree on certain list level */
285 void NotifyNodesOnListLevel(const int nListLevel
);
287 /** Invalidation and notification of complete numbering tree
290 Usage: on <IsCounted()> state change it's needed to invalidate the
291 complete numbering tree due to wide influence of this change.
293 void InvalidateAndNotifyTree()
297 GetRoot()->InvalidateTree();
303 Returns the greatest descendant of the root that is smaller than
304 this node, aka the predecessor of this node.
306 @return the predecessor
308 SwNumberTreeNode
* GetPred(bool bSibling
= false) const;
310 /** determines the node, which is preceding the node
313 The search for the preceding node is performed for the tree below the
314 <this> node. To search the complete tree, the method has been called for
315 the root of the tree.
317 const SwNumberTreeNode
* GetPrecedingNodeOf(const SwNumberTreeNode
& rNode
) const;
323 @param bRecursive descend to children
325 @retval true the structure of this node is sane
328 void IsSane(bool bRecursive
) const;
332 Returns how many children this node has got.
334 @return number of children
336 tSwNumberTreeChildren::size_type
GetChildCount() const;
340 tSwNumberTreeChildren mChildren
;
343 Returns the root node of the tree this node is part of.
345 Important note: method call <GetRoot()->GetRoot()> returns NULL.
349 SwNumberTreeNode
* GetRoot() const;
352 Return if the notification is not disabled on global conditions
354 @retval true Notification enabled in general.
357 virtual bool IsNotificationEnabled() const = 0;
359 // #i64010# - made pure virtual
360 virtual bool HasCountedChildren() const = 0;
363 virtual bool IsCountedForNumbering() const = 0;
365 // method called before this tree node has been added to the list tree
366 virtual void PreAdd() = 0;
367 // method called after this tree node has been removed from the list tree
368 virtual void PostRemove() = 0;
371 /** Sanity check with loop detection.
373 @param bRecursive descend to children
374 @param rParents vector for recording path
376 void IsSane(bool bRecursive
, std::vector
<const SwNumberTreeNode
*> rParents
) const;
379 /** he parent node */
380 SwNumberTreeNode
* mpParent
;
382 /** the number of the node */
383 mutable SwNumberTree::tSwNumTreeNumber mnNumber
;
385 // boolean indicating, that a node of a not counted parent node is continuing
386 // the numbering of parent's previous node sub tree.
390 // sdfjlksaf <-- not counted parent node
391 // 1.2. lfjlaskf <-- <mbContinueingPreviousSubTree = true>
392 mutable bool mbContinueingPreviousSubTree
;
395 true this node is a phantom
396 false this node is NOT a phantom
401 Iterator to the last valid element. All children that are less
402 than or equal to the referenced child are valid. All children
403 greater than the referenced child are invalid.
405 mutable tSwNumberTreeChildren::const_iterator mItLastValid
;
407 SwNumberTreeNode(const SwNumberTreeNode
&);
408 SwNumberTreeNode
& operator=(const SwNumberTreeNode
&);
411 Calls GetNumberVector_ on parent and adds number of this node
414 @param rVector return value
415 @param bValidate validate the number?
417 void GetNumberVector_(SwNumberTree::tNumberVector
& rVector
, bool bValidate
= true) const;
422 Calls SetLastValid for the preceding sibling of the child and
423 notifies all invalid children.
425 @param pChild the child to invalidate
427 void Invalidate(SwNumberTreeNode
const* pChild
);
429 /** Invalidation of all children
431 Usage: on <IsCounted()> state change the children have to be invalidated
433 void InvalidateChildren() { SetLastValid(mChildren
.end()); }
436 Set the last valid child of this node.
438 @param aItLastValid iterator pointing to the new last valid child
439 @param bValidating - true always set the last valid node to
441 - false only set if aItLastValid is preceding
442 the current last valid node
444 void SetLastValid(const tSwNumberTreeChildren::const_iterator
& aItLastValid
,
445 bool bValidating
= false) const;
448 Return if this node is notifiable.
450 @attention If a not is not notifiable a notify request is *not*
451 forwarded to its descendants.
453 @retval true This node is notifiable.
456 virtual bool IsNotifiable() const = 0;
461 Called when the number of the node got invalid.
463 virtual void NotifyNode() = 0;
465 /** Notifies this node (NotifyNode) and all descendants.*/
468 /** notification of children nodes on certain depth */
469 void NotifyChildrenOnDepth(const int nDepth
);
472 Returns if a child A this node is valid.
474 A is valid if aItLastValid in parent refers to a node
475 greater than of equal to A.
477 @param pChild child to be tested
479 @retval true this node is valid
480 @retval false this node is NOT valid
482 bool IsValid(const SwNumberTreeNode
* pChild
) const;
485 Returns if this node is valid.
487 @retval true this node is valid
490 bool IsValid() const;
495 @param pNode child to be validated
497 @attention All invalid children preceding pNode are validated, too.
499 void Validate(const SwNumberTreeNode
* pNode
) const;
502 Validates a child using hierarchical numbering.
504 @param pNode child to be validated
506 @attention All invalid children preceding pNode are validated, too.
508 void ValidateHierarchical(const SwNumberTreeNode
* pNode
) const;
511 Validates a child using continuous numbering.
513 @param pNode child to be validated
515 @attention All invalid children preceding pNode are validated, too.
517 void ValidateContinuous(const SwNumberTreeNode
* pNode
) const;
520 Creates a new node of the same class.
524 virtual SwNumberTreeNode
* Create() const = 0;
529 @return the created phantom
531 SwNumberTreeNode
* CreatePhantom();
534 Return if phantoms are counted.
536 virtual bool IsCountPhantoms() const = 0;
538 /** Return if all descendants of this node are phantoms. */
539 bool HasOnlyPhantoms() const;
541 bool HasPhantomCountedParent() const;
544 HB, OD : return node, if it isn't a phantom, otherwise return first
545 non-phantom descendant.
546 Returns the first child of this node that is NOT a phantom.
548 @return the first non phantom child
550 SwNumberTreeNode
* GetFirstNonPhantomChild();
553 Removes recursively phantoms that have no children.
555 The resulting tree has no phantoms that either have no children or
556 whose descendancy consist entirely of phantoms.
558 void ClearObsoletePhantoms();
560 tSwNumberTreeChildren::const_iterator
GetIterator(const SwNumberTreeNode
* pChild
) const;
563 Moves all children to a given destination node.
565 @param pDest the destination node
567 void MoveChildren(SwNumberTreeNode
* pDest
);
569 /** Moves all children of this node that are greater than a given node
570 to the destination node.
572 distinguish between node for comparing, whose children are greater,
573 and the destination node.
576 input parameter - reference to the node, which is used to determine
580 input parameter - reference to the node, which is the destination for
583 void MoveGreaterChildren(SwNumberTreeNode
& _rCompareNode
, SwNumberTreeNode
& _rDestNode
);
586 Returns the last descendant of a node, if it has children.
588 @return last descendant of the node
590 SwNumberTreeNode
* GetLastDescendant() const;
593 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */