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