tdf#149609 release mouse before showing popups from calc grid window
[LibreOffice.git] / sw / inc / SwNumberTree.hxx
blobf9e3a2745bb9b6e45d6bf257cf8734bd73d0bdda
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #pragma once
22 #include <set>
23 #include <vector>
24 #include "SwNumberTreeTypes.hxx"
26 class SwDoc;
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);
39 /**
40 A tree of numbered nodes.
42 Simple example:
44 <pre>
45 1. kshdkjfs
46 1.1. lskjf
47 2. sdfjlksaf
48 3. fkaoslk
49 3.1. lfjlaskf
50 3.2. jaslkjflsf
51 3.2.1. hkljhkjhk
53 + R
54 + 1 kshdkjfs
55 | + 1 lskjf
56 + 2 sdfjlksaf
57 + 3 fkaoslk
58 + 1 lfjlaskf
59 + 2 jaslkjflsf
60 + 1 hkljhkjhk
61 </pre>
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 ------------------------------------------
72 Phantoms
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.
82 Uncounted Phantoms
84 0.1. dljflskjlasf
85 5. abcdagaha
86 5.1.
88 + R (nStart = 5)
89 + 0 (phantom, not counted)
90 | + 1 dljflskjlasf
91 + 5 abcdagaha
92 + 1
94 The phantom gets numbered with 0. The first non-phantom node gets
95 numbered with the start value.
97 -----------------------------------------
99 Counted Phantoms
101 5.1. lgkjjgklg
102 6. lkjfalskjflsaf
103 6.1. ljdflaksjflkjasflkjsf
105 + R (nStart = 5)
106 + 5 (phantom, counted)
107 | + 1 lgkjjgklg
108 + 6 lkjfalskjflsaf
109 + 1 ljdflaksjflkjasflkjsf
111 The phantom gets numbered with the start value.
113 class SAL_DLLPUBLIC_RTTI SwNumberTreeNode
115 protected:
116 typedef std::set<SwNumberTreeNode*, compSwNumberTreeNodeLessThan> tSwNumberTreeChildren;
118 public:
119 SwNumberTreeNode();
121 virtual ~SwNumberTreeNode();
124 Add a child.
126 @param pChild child to add
127 @param nDepth depth in which to add the child
129 void AddChild(SwNumberTreeNode* pChild, const int nDepth, const SwDoc& rDoc);
132 Remove a child.
134 @param pChild child to be removed
136 void RemoveChild(SwNumberTreeNode* pChild, const SwDoc& rDoc);
139 Remove this child from the tree.
141 void RemoveMe(const SwDoc& rDoc);
144 Returns the parent of this node.
146 @return the parent
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;
174 Return start value.
176 @return start value
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.
192 @retval false else
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
202 @retval false else
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
210 @retval false else
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, const SwDoc& rDoc);
229 Return level of this node.
231 The level of this node is the length of the path from the root
232 to this node.
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
244 respect to lessThan.
246 @retval true this node is less than rTreeNode
247 @retval false else
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(const SwDoc& rDoc);
268 Notifies the node.
270 Calls Invalidate(this) on parent.
272 void InvalidateMe();
275 Validates this node.
277 Calls Validate(this) on parent.
279 void ValidateMe();
281 /** Notifies all invalid siblings of this node. */
282 void NotifyInvalidSiblings(const SwDoc& rDoc);
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
289 #i64010#
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(const SwDoc& rDoc)
295 if (GetRoot())
297 GetRoot()->InvalidateTree();
298 GetRoot()->Notify(rDoc);
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
312 #i81002#
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;
319 #ifdef DBG_UTIL
321 Sanity check.
323 @param bRecursive descend to children
325 @retval true the structure of this node is sane
326 @retval false else
328 void IsSane(bool bRecursive) const;
329 #endif // DBG_UTIL
332 Returns how many children this node has got.
334 @return number of children
336 tSwNumberTreeChildren::size_type GetChildCount() const;
338 protected:
339 /** the children */
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.
347 @return the root
349 SwNumberTreeNode* GetRoot() const;
352 Return if the notification is not disabled on global conditions
354 @retval true Notification enabled in general.
355 @retval false else
357 virtual bool IsNotificationEnabled(const SwDoc& rDoc) const = 0;
359 // #i64010# - made pure virtual
360 virtual bool HasCountedChildren() const = 0;
362 // #i64010#
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;
370 #ifdef DBG_UTIL
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;
377 #endif // DBG_UTIL
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.
387 // Example:
388 // 1. kshdkjfs
389 // 1.1. lskjf
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
398 bool mbPhantom;
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
412 at the end.
414 @param rVector return value
415 @param bValidate validate the number?
417 void GetNumberVector_(SwNumberTree::tNumberVector& rVector, bool bValidate = true) const;
420 Invalidates a child.
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
440 aItLastValid
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.
454 @retval false else
456 virtual bool IsNotifiable(const SwDoc& rDoc) const = 0;
459 Notifies the node.
461 Called when the number of the node got invalid.
463 virtual void NotifyNode() = 0;
465 /** Notifies this node (NotifyNode) and all descendants.*/
466 void Notify(const SwDoc& rDoc);
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
488 @retval false else
490 bool IsValid() const;
493 Validates a child.
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.
522 @return the new node
524 virtual SwNumberTreeNode* Create() const = 0;
527 Creates a phantom.
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.
575 @param _rCompareNode
576 input parameter - reference to the node, which is used to determine
577 the greater children
579 @param _rDestNode
580 input parameter - reference to the node, which is the destination for
581 the greater children
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: */