LibreOffice Module sw (master)  1
ndnum.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <node.hxx>
21 #include <doc.hxx>
23 #include <ndtxt.hxx>
24 #include <fldbas.hxx>
25 #include <osl/diagnose.h>
26 
27 bool CompareSwOutlineNodes::operator()( SwNode* const& lhs, SwNode* const& rhs) const
28 {
29  return lhs->GetIndex() < rhs->GetIndex();
30 }
31 
33 {
34  const_iterator it = lower_bound(rP);
35  *pnPos = it - begin();
36  return it != end() && rP->GetIndex() == (*it)->GetIndex();
37 }
38 
40 {
41  SwTextNode * pTextNd = rNd.GetTextNode();
42 
43  if (pTextNd && pTextNd->IsOutlineStateChanged())
44  {
45  bool bFound = m_pOutlineNodes->find(pTextNd) != m_pOutlineNodes->end();
46 
47  if (pTextNd->IsOutline())
48  {
49  if (! bFound)
50  {
51  // assure that text is in the correct nodes array
52  if ( &(pTextNd->GetNodes()) == this )
53  {
54  m_pOutlineNodes->insert(pTextNd);
55  }
56  else
57  {
58  OSL_FAIL( "<SwNodes::UpdateOutlineNode(..)> - given text node isn't in the correct nodes array. This is a serious defect" );
59  }
60  }
61  }
62  else
63  {
64  if (bFound)
65  m_pOutlineNodes->erase(pTextNd);
66  }
67 
68  pTextNd->UpdateOutlineState();
69 
70  // update the structure fields
72  }
73 }
74 
76 {
77  if( m_pOutlineNodes->empty() ) // no OutlineNodes present ?
78  return;
79 
80  const SwNodePtr pSrch = const_cast<SwNodePtr>(&rNd);
81 
83  if (!m_pOutlineNodes->Seek_Entry(pSrch, &nPos))
84  return;
85  if( nPos == m_pOutlineNodes->size() ) // none present for updating ?
86  return;
87 
88  if( nPos )
89  --nPos;
90 
91  if( !GetDoc()->IsInDtor() && IsDocNodes() )
92  UpdateOutlineNode( *(*m_pOutlineNodes)[ nPos ]);
93 }
94 
95 
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const_iterator lower_bound(const SwNode * &x) const
sal_uLong GetIndex() const
Definition: node.hxx:282
bool IsOutline() const
Returns if this text node is an outline.
Definition: ndtxt.cxx:4002
void UpdateOutlineIdx(const SwNode &)
Update all OutlineNodes starting from Node.
Definition: ndnum.cxx:75
void UpdateFields() const
Definition: fldbas.hxx:272
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:356
bool operator()(SwNode *const &lhs, SwNode *const &rhs) const
Definition: ndnum.cxx:27
std::unique_ptr< SwOutlineNodes > m_pOutlineNodes
Array of all outline nodes.
Definition: ndarr.hxx:111
bool IsOutlineStateChanged() const
Definition: ndtxt.cxx:4022
void UpdateOutlineNode(SwNode &rNd)
Update all Nodes - Rule/Format-Change.
Definition: ndnum.cxx:39
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:693
SwDoc * GetDoc()
Which Doc contains the nodes-array?
Definition: ndarr.hxx:305
void UpdateOutlineState()
Definition: ndtxt.cxx:4027
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
bool IsInDtor() const
Definition: doc.hxx:397
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2334
virtual SwFieldType * GetSysFieldType(const SwFieldIds eWhich) const =0
bool Seek_Entry(SwNode *rP, size_type *pnPos) const
Definition: ndnum.cxx:32
std::vector< SwNode * >::size_type size_type
sal_Int32 nPos
std::vector< SwNode * >::const_iterator const_iterator
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:842
Base class of the Writer document model elements.
Definition: node.hxx:79