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