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  assert(IsDocNodes()); // no point in m_pOutlineNodes for undo nodes
42 
43  SwTextNode * pTextNd = rNd.GetTextNode();
44 
45  if (!pTextNd || !pTextNd->IsOutlineStateChanged())
46  return;
47 
48  bool bFound = m_pOutlineNodes->find(pTextNd) != m_pOutlineNodes->end();
49 
50  if (pTextNd->IsOutline())
51  {
52  if (! bFound)
53  {
54  // assure that text is in the correct nodes array
55  if ( &(pTextNd->GetNodes()) == this )
56  {
57  m_pOutlineNodes->insert(pTextNd);
58  }
59  else
60  {
61  OSL_FAIL( "<SwNodes::UpdateOutlineNode(..)> - given text node isn't in the correct nodes array. This is a serious defect" );
62  }
63  }
64  }
65  else
66  {
67  if (bFound)
68  m_pOutlineNodes->erase(pTextNd);
69  }
70 
71  pTextNd->UpdateOutlineState();
72 
73  // update the structure fields
75 }
76 
78 {
79  if( m_pOutlineNodes->empty() ) // no OutlineNodes present ?
80  return;
81 
82  SwNode* const pSrch = const_cast<SwNode*>(&rNd);
83 
85  if (!m_pOutlineNodes->Seek_Entry(pSrch, &nPos))
86  return;
87  if( nPos == m_pOutlineNodes->size() ) // none present for updating ?
88  return;
89 
90  if( nPos )
91  --nPos;
92 
93  if( !GetDoc().IsInDtor() && IsDocNodes() )
94  UpdateOutlineNode( *(*m_pOutlineNodes)[ nPos ]);
95 }
96 
97 
98 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const_iterator lower_bound(const SwNode * &x) const
bool IsOutline() const
Returns if this text node is an outline.
Definition: ndtxt.cxx:4006
SwDoc & GetDoc()
Which Doc contains the nodes-array?
Definition: ndarr.hxx:301
void UpdateOutlineIdx(const SwNode &)
Update all OutlineNodes starting from Node.
Definition: ndnum.cxx:77
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:357
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:109
virtual void UpdateFields()
Definition: fldbas.cxx:213
bool IsOutlineStateChanged() const
Definition: ndtxt.cxx:4026
void UpdateOutlineNode(SwNode &rNd)
Update all Nodes - Rule/Format-Change.
Definition: ndnum.cxx:39
SwNodeOffset GetIndex() const
Definition: node.hxx:292
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:703
void UpdateOutlineState()
Definition: ndtxt.cxx:4031
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
bool IsInDtor() const
Definition: doc.hxx:403
bool IsDocNodes() const
Is the NodesArray the regular one of Doc? (and not the UndoNds, ...) Implementation in doc...
Definition: nodes.cxx:2380
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_uInt16 nPos
std::vector< SwNode * >::const_iterator const_iterator
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:856
Base class of the Writer document model elements.
Definition: node.hxx:81