LibreOffice Module sw (master)  1
list.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 <list.hxx>
21 
22 #include <vector>
23 #include <numrule.hxx>
24 #include <ndarr.hxx>
25 #include <node.hxx>
26 
27 SwList::SwList( const OUString& sListId,
28  SwNumRule& rDefaultListStyle,
29  const SwNodes& rNodes )
30  : msListId( sListId ),
31  msDefaultListStyleName( rDefaultListStyle.GetName() ),
32  maListTrees(),
33  mnMarkedListLevel( MAXLEVEL )
34 {
35  // create empty list trees for the document ranges
36  const SwNode* pNode = rNodes[0];
37  do
38  {
39  SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
40 
41  maListTrees.emplace_back(
42  std::make_unique<SwNodeNum>( &rDefaultListStyle ),
43  std::make_unique<SwNodeNum>( &rDefaultListStyle ),
44  std::make_unique<SwPaM>( *(aPam.Start()), *(aPam.End()) ));
45 
46  pNode = pNode->EndOfSectionNode();
47  if (pNode != &rNodes.GetEndOfContent())
48  {
49  sal_uLong nIndex = pNode->GetIndex();
50  nIndex++;
51  pNode = rNodes[nIndex];
52  }
53  }
54  while ( pNode != &rNodes.GetEndOfContent() );
55 }
56 
57 SwList::~SwList() COVERITY_NOEXCEPT_FALSE
58 {
59  for ( auto& rNumberTree : maListTrees )
60  {
61  SwNodeNum::HandleNumberTreeRootNodeDelete(*(rNumberTree.pRoot));
62  SwNodeNum::HandleNumberTreeRootNodeDelete(*(rNumberTree.pRootRLHidden));
63  }
64 }
65 
66 bool SwList::HasNodes() const
67 {
68  for (auto const& rNumberTree : maListTrees)
69  {
70  if (rNumberTree.pRoot->GetChildCount() != 0)
71  {
72  return true;
73  }
74  }
75  return false;
76 }
77 
78 void SwList::InsertListItem(SwNodeNum& rNodeNum, bool const isHiddenRedlines,
79  const int nLevel, const SwDoc& rDoc)
80 {
81  const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
82  const SwNodes* pNodesOfNodeNum = &(aPosOfNodeNum.nNode.GetNode().GetNodes());
83 
84  for ( const auto& rNumberTree : maListTrees )
85  {
86  const SwPosition* pStart = rNumberTree.pSection->Start();
87  const SwPosition* pEnd = rNumberTree.pSection->End();
88  const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
89 
90  if ( pRangeNodes == pNodesOfNodeNum &&
91  *pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
92  {
93  auto const& pRoot(isHiddenRedlines
94  ? rNumberTree.pRootRLHidden
95  : rNumberTree.pRoot);
96  pRoot->AddChild(&rNodeNum, nLevel, rDoc);
97  break;
98  }
99  }
100 }
101 
102 void SwList::RemoveListItem(SwNodeNum& rNodeNum, const SwDoc& rDoc)
103 {
104  rNodeNum.RemoveMe(rDoc);
105 }
106 
108 {
109  for ( const auto& rNumberTree : maListTrees )
110  {
111  rNumberTree.pRoot->InvalidateTree();
112  rNumberTree.pRootRLHidden->InvalidateTree();
113  }
114 }
115 
117 {
118  for ( auto& rNumberTree : maListTrees )
119  {
120  rNumberTree.pRoot->NotifyInvalidChildren(rDoc);
121  rNumberTree.pRootRLHidden->NotifyInvalidChildren(rDoc);
122  }
123 }
124 
125 void SwList::MarkListLevel( const int nListLevel,
126  const bool bValue )
127 {
128  if ( bValue )
129  {
130  if ( nListLevel != mnMarkedListLevel )
131  {
132  if ( mnMarkedListLevel != MAXLEVEL )
133  {
134  // notify former marked list nodes
136  }
137 
138  mnMarkedListLevel = nListLevel;
139 
140  // notify new marked list nodes
142  }
143  }
144  else
145  {
146  if ( mnMarkedListLevel != MAXLEVEL )
147  {
148  // notify former marked list nodes
150  }
151 
153  }
154 }
155 
156 bool SwList::IsListLevelMarked( const int nListLevel ) const
157 {
158  return nListLevel == mnMarkedListLevel;
159 }
160 
161 void SwList::NotifyItemsOnListLevel( const int nLevel )
162 {
163  for ( auto& rNumberTree : maListTrees )
164  {
165  rNumberTree.pRoot->NotifyNodesOnListLevel( nLevel );
166  rNumberTree.pRootRLHidden->NotifyNodesOnListLevel( nLevel );
167  }
168 }
169 
170 void SwList::SetDefaultListStyleName(OUString const& rNew)
171 {
172  msDefaultListStyleName = rNew;
173 }
174 
175 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:683
static void HandleNumberTreeRootNodeDelete(SwNodeNum &rNodeNum)
Definition: SwNodeNum.cxx:291
sal_uLong GetIndex() const
Definition: node.hxx:291
sal_Int32 nIndex
Marks a position in the document model.
Definition: pam.hxx:35
SwNodeIndex nNode
Definition: pam.hxx:37
OUString msDefaultListStyleName
Definition: list.hxx:74
SwList(const OUString &sListId, SwNumRule &rDefaultListStyle, const SwNodes &rNodes)
Definition: list.cxx:27
sal_uIntPtr sal_uLong
SwPosition GetPosition() const
Definition: SwNodeNum.cxx:64
void RemoveMe(const SwDoc &rDoc)
Remove this child from the tree.
Definition: doc.hxx:188
constexpr sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:90
SwNode & GetNode() const
Definition: ndindex.hxx:119
~SwList() COVERITY_NOEXCEPT_FALSE
Definition: list.cxx:57
void NotifyItemsOnListLevel(const int nLevel)
Definition: list.cxx:161
void SetDefaultListStyleName(OUString const &)
Definition: list.cxx:170
void MarkListLevel(const int nListLevel, const bool bValue)
Definition: list.cxx:125
std::vector< tListTreeForRange > maListTrees
Definition: list.hxx:95
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:163
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool IsListLevelMarked(const int nListLevel) const
Definition: list.cxx:156
void InvalidateListTree()
Definition: list.cxx:107
void ValidateListTree(const SwDoc &rDoc)
Definition: list.cxx:116
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:694
void InsertListItem(SwNodeNum &rNodeNum, bool isHiddenRedlines, const int nLevel, const SwDoc &rDoc)
Definition: list.cxx:78
bool HasNodes() const
Definition: list.cxx:66
int mnMarkedListLevel
Definition: list.hxx:97
static void RemoveListItem(SwNodeNum &rNodeNum, const SwDoc &rDoc)
Definition: list.cxx:102
Base class of the Writer document model elements.
Definition: node.hxx:80