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