Line data Source code
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 : #include <pam.hxx>
27 : #include <SwNodeNum.hxx>
28 :
29 : // implementation class for SwList
30 : class SwListImpl
31 : {
32 : public:
33 : SwListImpl( const OUString& sListId,
34 : SwNumRule& rDefaultListStyle,
35 : const SwNodes& rNodes );
36 : ~SwListImpl();
37 :
38 : const OUString GetListId() const;
39 :
40 : const OUString GetDefaultListStyleName() const;
41 :
42 : void InsertListItem( SwNodeNum& rNodeNum,
43 : const int nLevel );
44 : void RemoveListItem( SwNodeNum& rNodeNum );
45 :
46 : void InvalidateListTree();
47 : void ValidateListTree();
48 :
49 : void MarkListLevel( const int nListLevel,
50 : const bool bValue );
51 :
52 : bool IsListLevelMarked( const int nListLevel ) const;
53 :
54 : private:
55 : // unique identifier of the list
56 : const OUString msListId;
57 : // default list style for the list items, identified by the list style name
58 : OUString msDefaultListStyleName;
59 :
60 : // list trees for certain document ranges
61 : typedef std::pair<SwNodeNum*, SwPaM*> tListTreeForRange;
62 : typedef std::vector<tListTreeForRange> tListTrees;
63 : tListTrees maListTrees;
64 :
65 : int mnMarkedListLevel;
66 :
67 : void NotifyItemsOnListLevel( const int nLevel );
68 : };
69 :
70 17021 : SwListImpl::SwListImpl( const OUString& sListId,
71 : SwNumRule& rDefaultListStyle,
72 : const SwNodes& rNodes )
73 : : msListId( sListId ),
74 : msDefaultListStyleName( rDefaultListStyle.GetName() ),
75 : maListTrees(),
76 17021 : mnMarkedListLevel( MAXLEVEL )
77 : {
78 : // create empty list trees for the document ranges
79 17021 : const SwNode* pNode = rNodes[0];
80 85105 : do
81 : {
82 85105 : SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
83 :
84 85105 : SwNodeNum* pNumberTreeRootNode = new SwNodeNum( &rDefaultListStyle );
85 85105 : SwPaM* pPam = new SwPaM( *(aPam.Start()), *(aPam.End()) );
86 85105 : tListTreeForRange aListTreeForRange( pNumberTreeRootNode, pPam );
87 85105 : maListTrees.push_back( aListTreeForRange );
88 :
89 85105 : pNode = pNode->EndOfSectionNode();
90 85105 : if (pNode != &rNodes.GetEndOfContent())
91 : {
92 68084 : sal_uLong nIndex = pNode->GetIndex();
93 68084 : nIndex++;
94 68084 : pNode = rNodes[nIndex];
95 85105 : }
96 : }
97 85105 : while ( pNode != &rNodes.GetEndOfContent() );
98 17021 : }
99 :
100 34034 : SwListImpl::~SwListImpl()
101 : {
102 17017 : tListTrees::iterator aNumberTreeIter;
103 306306 : for ( aNumberTreeIter = maListTrees.begin();
104 204204 : aNumberTreeIter != maListTrees.end();
105 : ++aNumberTreeIter )
106 : {
107 85085 : SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter).first) );
108 85085 : delete (*aNumberTreeIter).first;
109 85085 : delete (*aNumberTreeIter).second;
110 : }
111 17017 : }
112 :
113 17023 : const OUString SwListImpl::GetListId() const
114 : {
115 17023 : return msListId;
116 : }
117 :
118 18 : const OUString SwListImpl::GetDefaultListStyleName() const
119 : {
120 18 : return msDefaultListStyleName;
121 : }
122 :
123 3514 : void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
124 : const int nLevel )
125 : {
126 3514 : const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
127 3514 : const SwNodes* pNodesOfNodeNum = &(aPosOfNodeNum.nNode.GetNode().GetNodes());
128 :
129 3514 : tListTrees::const_iterator aNumberTreeIter;
130 52587 : for ( aNumberTreeIter = maListTrees.begin();
131 35058 : aNumberTreeIter != maListTrees.end();
132 : ++aNumberTreeIter )
133 : {
134 17528 : const SwPosition* pStart = (*aNumberTreeIter).second->Start();
135 17528 : const SwPosition* pEnd = (*aNumberTreeIter).second->End();
136 17528 : const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
137 :
138 35051 : if ( pRangeNodes == pNodesOfNodeNum &&
139 35051 : *pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
140 : {
141 3513 : (*aNumberTreeIter).first->AddChild( &rNodeNum, nLevel );
142 :
143 3513 : break;
144 : }
145 3514 : }
146 3514 : }
147 :
148 3513 : void SwListImpl::RemoveListItem( SwNodeNum& rNodeNum )
149 : {
150 3513 : rNodeNum.RemoveMe();
151 3513 : }
152 :
153 154 : void SwListImpl::InvalidateListTree()
154 : {
155 154 : tListTrees::iterator aNumberTreeIter;
156 2772 : for ( aNumberTreeIter = maListTrees.begin();
157 1848 : aNumberTreeIter != maListTrees.end();
158 : ++aNumberTreeIter )
159 : {
160 770 : (*aNumberTreeIter).first->InvalidateTree();
161 : }
162 154 : }
163 :
164 128 : void SwListImpl::ValidateListTree()
165 : {
166 128 : tListTrees::iterator aNumberTreeIter;
167 2304 : for ( aNumberTreeIter = maListTrees.begin();
168 1536 : aNumberTreeIter != maListTrees.end();
169 : ++aNumberTreeIter )
170 : {
171 640 : (*aNumberTreeIter).first->NotifyInvalidChildren();
172 : }
173 128 : }
174 :
175 0 : void SwListImpl::MarkListLevel( const int nListLevel,
176 : const bool bValue )
177 : {
178 0 : if ( bValue )
179 : {
180 0 : if ( nListLevel != mnMarkedListLevel )
181 : {
182 0 : if ( mnMarkedListLevel != MAXLEVEL )
183 : {
184 : // notify former marked list nodes
185 0 : NotifyItemsOnListLevel( mnMarkedListLevel );
186 : }
187 :
188 0 : mnMarkedListLevel = nListLevel;
189 :
190 : // notify new marked list nodes
191 0 : NotifyItemsOnListLevel( mnMarkedListLevel );
192 : }
193 : }
194 : else
195 : {
196 0 : if ( mnMarkedListLevel != MAXLEVEL )
197 : {
198 : // notify former marked list nodes
199 0 : NotifyItemsOnListLevel( mnMarkedListLevel );
200 : }
201 :
202 0 : mnMarkedListLevel = MAXLEVEL;
203 : }
204 0 : }
205 :
206 138 : bool SwListImpl::IsListLevelMarked( const int nListLevel ) const
207 : {
208 138 : return nListLevel == mnMarkedListLevel;
209 : }
210 :
211 0 : void SwListImpl::NotifyItemsOnListLevel( const int nLevel )
212 : {
213 0 : tListTrees::iterator aNumberTreeIter;
214 0 : for ( aNumberTreeIter = maListTrees.begin();
215 0 : aNumberTreeIter != maListTrees.end();
216 : ++aNumberTreeIter )
217 : {
218 0 : (*aNumberTreeIter).first->NotifyNodesOnListLevel( nLevel );
219 : }
220 0 : }
221 :
222 : // SwList ---------------------------------------------------------------------
223 17021 : SwList::SwList( const OUString& sListId,
224 : SwNumRule& rDefaultListStyle,
225 : const SwNodes& rNodes )
226 17021 : : mpListImpl( new SwListImpl( sListId, rDefaultListStyle, rNodes ) )
227 : {
228 17021 : }
229 :
230 17017 : SwList::~SwList()
231 : {
232 17017 : delete mpListImpl;
233 17017 : }
234 :
235 17023 : const OUString SwList::GetListId() const
236 : {
237 17023 : return mpListImpl->GetListId();
238 : }
239 :
240 18 : const OUString SwList::GetDefaultListStyleName() const
241 : {
242 18 : return mpListImpl->GetDefaultListStyleName();
243 : }
244 :
245 3514 : void SwList::InsertListItem( SwNodeNum& rNodeNum,
246 : const int nLevel )
247 : {
248 3514 : mpListImpl->InsertListItem( rNodeNum, nLevel );
249 3514 : }
250 :
251 3513 : void SwList::RemoveListItem( SwNodeNum& rNodeNum )
252 : {
253 3513 : mpListImpl->RemoveListItem( rNodeNum );
254 3513 : }
255 :
256 154 : void SwList::InvalidateListTree()
257 : {
258 154 : mpListImpl->InvalidateListTree();
259 154 : }
260 :
261 128 : void SwList::ValidateListTree()
262 : {
263 128 : mpListImpl->ValidateListTree();
264 128 : }
265 :
266 0 : void SwList::MarkListLevel( const int nListLevel,
267 : const bool bValue )
268 : {
269 0 : mpListImpl->MarkListLevel( nListLevel, bValue );
270 0 : }
271 :
272 138 : bool SwList::IsListLevelMarked( const int nListLevel ) const
273 : {
274 138 : return mpListImpl->IsListLevelMarked( nListLevel );
275 : }
276 :
277 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|