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 42684 : const OUString GetListId() const { return msListId;}
39 :
40 5814 : const OUString GetDefaultListStyleName() const { return msDefaultListStyleName;}
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 42646 : SwListImpl::SwListImpl( const OUString& sListId,
71 : SwNumRule& rDefaultListStyle,
72 : const SwNodes& rNodes )
73 : : msListId( sListId ),
74 : msDefaultListStyleName( rDefaultListStyle.GetName() ),
75 : maListTrees(),
76 42646 : mnMarkedListLevel( MAXLEVEL )
77 : {
78 : // create empty list trees for the document ranges
79 42646 : const SwNode* pNode = rNodes[0];
80 213230 : do
81 : {
82 213230 : SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
83 :
84 213230 : SwNodeNum* pNumberTreeRootNode = new SwNodeNum( &rDefaultListStyle );
85 213230 : SwPaM* pPam = new SwPaM( *(aPam.Start()), *(aPam.End()) );
86 213230 : tListTreeForRange aListTreeForRange( pNumberTreeRootNode, pPam );
87 213230 : maListTrees.push_back( aListTreeForRange );
88 :
89 213230 : pNode = pNode->EndOfSectionNode();
90 213230 : if (pNode != &rNodes.GetEndOfContent())
91 : {
92 170584 : sal_uLong nIndex = pNode->GetIndex();
93 170584 : nIndex++;
94 170584 : pNode = rNodes[nIndex];
95 213230 : }
96 : }
97 213230 : while ( pNode != &rNodes.GetEndOfContent() );
98 42646 : }
99 :
100 85278 : SwListImpl::~SwListImpl()
101 : {
102 42639 : tListTrees::iterator aNumberTreeIter;
103 767502 : for ( aNumberTreeIter = maListTrees.begin();
104 511668 : aNumberTreeIter != maListTrees.end();
105 : ++aNumberTreeIter )
106 : {
107 213195 : SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter).first) );
108 213195 : delete (*aNumberTreeIter).first;
109 213195 : delete (*aNumberTreeIter).second;
110 : }
111 42639 : }
112 :
113 :
114 :
115 6758 : void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
116 : const int nLevel )
117 : {
118 6758 : const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
119 6758 : const SwNodes* pNodesOfNodeNum = &(aPosOfNodeNum.nNode.GetNode().GetNodes());
120 :
121 6758 : tListTrees::const_iterator aNumberTreeIter;
122 101118 : for ( aNumberTreeIter = maListTrees.begin();
123 67412 : aNumberTreeIter != maListTrees.end();
124 : ++aNumberTreeIter )
125 : {
126 33706 : const SwPosition* pStart = (*aNumberTreeIter).second->Start();
127 33706 : const SwPosition* pEnd = (*aNumberTreeIter).second->End();
128 33706 : const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
129 :
130 67412 : if ( pRangeNodes == pNodesOfNodeNum &&
131 67412 : *pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
132 : {
133 6758 : (*aNumberTreeIter).first->AddChild( &rNodeNum, nLevel );
134 :
135 6758 : break;
136 : }
137 6758 : }
138 6758 : }
139 :
140 6758 : void SwListImpl::RemoveListItem( SwNodeNum& rNodeNum )
141 : {
142 6758 : rNodeNum.RemoveMe();
143 6758 : }
144 :
145 312 : void SwListImpl::InvalidateListTree()
146 : {
147 312 : tListTrees::iterator aNumberTreeIter;
148 5616 : for ( aNumberTreeIter = maListTrees.begin();
149 3744 : aNumberTreeIter != maListTrees.end();
150 : ++aNumberTreeIter )
151 : {
152 1560 : (*aNumberTreeIter).first->InvalidateTree();
153 : }
154 312 : }
155 :
156 260 : void SwListImpl::ValidateListTree()
157 : {
158 260 : tListTrees::iterator aNumberTreeIter;
159 4680 : for ( aNumberTreeIter = maListTrees.begin();
160 3120 : aNumberTreeIter != maListTrees.end();
161 : ++aNumberTreeIter )
162 : {
163 1300 : (*aNumberTreeIter).first->NotifyInvalidChildren();
164 : }
165 260 : }
166 :
167 0 : void SwListImpl::MarkListLevel( const int nListLevel,
168 : const bool bValue )
169 : {
170 0 : if ( bValue )
171 : {
172 0 : if ( nListLevel != mnMarkedListLevel )
173 : {
174 0 : if ( mnMarkedListLevel != MAXLEVEL )
175 : {
176 : // notify former marked list nodes
177 0 : NotifyItemsOnListLevel( mnMarkedListLevel );
178 : }
179 :
180 0 : mnMarkedListLevel = nListLevel;
181 :
182 : // notify new marked list nodes
183 0 : NotifyItemsOnListLevel( mnMarkedListLevel );
184 : }
185 : }
186 : else
187 : {
188 0 : if ( mnMarkedListLevel != MAXLEVEL )
189 : {
190 : // notify former marked list nodes
191 0 : NotifyItemsOnListLevel( mnMarkedListLevel );
192 : }
193 :
194 0 : mnMarkedListLevel = MAXLEVEL;
195 : }
196 0 : }
197 :
198 648 : bool SwListImpl::IsListLevelMarked( const int nListLevel ) const
199 : {
200 648 : return nListLevel == mnMarkedListLevel;
201 : }
202 :
203 0 : void SwListImpl::NotifyItemsOnListLevel( const int nLevel )
204 : {
205 0 : tListTrees::iterator aNumberTreeIter;
206 0 : for ( aNumberTreeIter = maListTrees.begin();
207 0 : aNumberTreeIter != maListTrees.end();
208 : ++aNumberTreeIter )
209 : {
210 0 : (*aNumberTreeIter).first->NotifyNodesOnListLevel( nLevel );
211 : }
212 0 : }
213 :
214 42646 : SwList::SwList( const OUString& sListId,
215 : SwNumRule& rDefaultListStyle,
216 : const SwNodes& rNodes )
217 42646 : : mpListImpl( new SwListImpl( sListId, rDefaultListStyle, rNodes ) )
218 : {
219 42646 : }
220 :
221 42639 : SwList::~SwList()
222 : {
223 42639 : delete mpListImpl;
224 42639 : }
225 :
226 42684 : const OUString SwList::GetListId() const
227 : {
228 42684 : return mpListImpl->GetListId();
229 : }
230 :
231 5814 : const OUString SwList::GetDefaultListStyleName() const
232 : {
233 5814 : return mpListImpl->GetDefaultListStyleName();
234 : }
235 :
236 6758 : void SwList::InsertListItem( SwNodeNum& rNodeNum,
237 : const int nLevel )
238 : {
239 6758 : mpListImpl->InsertListItem( rNodeNum, nLevel );
240 6758 : }
241 :
242 6758 : void SwList::RemoveListItem( SwNodeNum& rNodeNum )
243 : {
244 6758 : mpListImpl->RemoveListItem( rNodeNum );
245 6758 : }
246 :
247 312 : void SwList::InvalidateListTree()
248 : {
249 312 : mpListImpl->InvalidateListTree();
250 312 : }
251 :
252 260 : void SwList::ValidateListTree()
253 : {
254 260 : mpListImpl->ValidateListTree();
255 260 : }
256 :
257 0 : void SwList::MarkListLevel( const int nListLevel,
258 : const bool bValue )
259 : {
260 0 : mpListImpl->MarkListLevel( nListLevel, bValue );
261 0 : }
262 :
263 648 : bool SwList::IsListLevelMarked( const int nListLevel ) const
264 : {
265 648 : return mpListImpl->IsListLevelMarked( nListLevel );
266 270 : }
267 :
268 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|