Branch data 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 sal_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 : 2367 : SwListImpl::SwListImpl( const String sListId,
75 : : SwNumRule& rDefaultListStyle,
76 : : const SwNodes& rNodes )
77 : : : msListId( sListId ),
78 : 2367 : msDefaultListStyleName( rDefaultListStyle.GetName() ),
79 : : maListTrees(),
80 [ + - ][ + - ]: 4734 : mnMarkedListLevel( MAXLEVEL )
81 : : {
82 : : // create empty list trees for the document ranges
83 [ + - ]: 2367 : const SwNode* pNode = rNodes[0];
84 [ + + ]: 11835 : do
85 : : {
86 [ + - ]: 11835 : SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
87 : :
88 [ + - ][ + - ]: 11835 : SwNodeNum* pNumberTreeRootNode = new SwNodeNum( &rDefaultListStyle );
89 [ + - ][ + - ]: 11835 : SwPaM* pPam = new SwPaM( *(aPam.Start()), *(aPam.End()) );
[ + - ][ + - ]
90 [ + - ]: 11835 : tListTreeForRange aListTreeForRange( pNumberTreeRootNode, pPam );
91 [ + - ]: 11835 : maListTrees.push_back( aListTreeForRange );
92 : :
93 : 11835 : pNode = pNode->EndOfSectionNode();
94 [ + + ]: 11835 : if (pNode != &rNodes.GetEndOfContent())
95 : : {
96 : 9468 : sal_uLong nIndex = pNode->GetIndex();
97 : 9468 : nIndex++;
98 [ + - ]: 9468 : pNode = rNodes[nIndex];
99 [ + - ]: 11835 : }
100 : : }
101 : 11835 : while ( pNode != &rNodes.GetEndOfContent() );
102 : 2367 : }
103 : :
104 [ + - ]: 2270 : SwListImpl::~SwListImpl()
105 : : {
106 : 2270 : tListTrees::iterator aNumberTreeIter;
107 [ + - + - ]: 27240 : for ( aNumberTreeIter = maListTrees.begin();
[ + + ]
108 : 13620 : aNumberTreeIter != maListTrees.end();
109 : : ++aNumberTreeIter )
110 : : {
111 [ + - ][ + - ]: 11350 : SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter).first) );
112 [ + - ][ + - ]: 11350 : delete (*aNumberTreeIter).first;
[ + - ]
113 [ + - ][ + - ]: 11350 : delete (*aNumberTreeIter).second;
[ + - ]
114 : : }
115 : 2270 : }
116 : :
117 : 2370 : const String SwListImpl::GetListId() const
118 : : {
119 : 2370 : return msListId;
120 : : }
121 : :
122 : 30 : const String SwListImpl::GetDefaultListStyleName() const
123 : : {
124 : 30 : return msDefaultListStyleName;
125 : : }
126 : :
127 : 4050 : void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
128 : : const int nLevel )
129 : : {
130 [ + - ]: 4050 : const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
131 : 4050 : const SwNodes* pNodesOfNodeNum = &(aPosOfNodeNum.nNode.GetNode().GetNodes());
132 : :
133 : 4050 : tListTrees::const_iterator aNumberTreeIter;
134 [ + - + - ]: 40500 : for ( aNumberTreeIter = maListTrees.begin();
[ + - ][ + - ]
135 : 20250 : aNumberTreeIter != maListTrees.end();
136 : : ++aNumberTreeIter )
137 : : {
138 [ + - ][ + - ]: 20250 : const SwPosition* pStart = (*aNumberTreeIter).second->Start();
139 [ + - ][ + - ]: 20250 : const SwPosition* pEnd = (*aNumberTreeIter).second->End();
140 : 20250 : const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
141 : :
142 [ + - ][ + + ]: 60750 : if ( pRangeNodes == pNodesOfNodeNum &&
[ + + ][ + - ]
143 [ + - ][ + - ]: 40500 : *pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
144 : : {
145 [ + - ][ + - ]: 4050 : (*aNumberTreeIter).first->AddChild( &rNodeNum, nLevel );
146 : :
147 : 4050 : break;
148 : : }
149 [ + - ]: 4050 : }
150 : 4050 : }
151 : :
152 : 4050 : void SwListImpl::RemoveListItem( SwNodeNum& rNodeNum )
153 : : {
154 : 4050 : rNodeNum.RemoveMe();
155 : 4050 : }
156 : :
157 : 180 : void SwListImpl::InvalidateListTree()
158 : : {
159 : 180 : tListTrees::iterator aNumberTreeIter;
160 [ + - + - ]: 2160 : for ( aNumberTreeIter = maListTrees.begin();
[ + + ]
161 : 1080 : aNumberTreeIter != maListTrees.end();
162 : : ++aNumberTreeIter )
163 : : {
164 [ + - ][ + - ]: 900 : (*aNumberTreeIter).first->InvalidateTree();
165 : : }
166 : 180 : }
167 : :
168 : 180 : void SwListImpl::ValidateListTree()
169 : : {
170 : 180 : tListTrees::iterator aNumberTreeIter;
171 [ + - + - ]: 2160 : for ( aNumberTreeIter = maListTrees.begin();
[ + + ]
172 : 1080 : aNumberTreeIter != maListTrees.end();
173 : : ++aNumberTreeIter )
174 : : {
175 [ + - ][ + - ]: 900 : (*aNumberTreeIter).first->NotifyInvalidChildren();
176 : : }
177 : 180 : }
178 : :
179 : 0 : void SwListImpl::MarkListLevel( const int nListLevel,
180 : : const sal_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 : 94 : bool SwListImpl::IsListLevelMarked( const int nListLevel ) const
211 : : {
212 : 94 : 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 : 2367 : SwList::SwList( const String sListId,
230 : : SwNumRule& rDefaultListStyle,
231 : : const SwNodes& rNodes )
232 [ + - ][ + - ]: 2367 : : mpListImpl( new SwListImpl( sListId, rDefaultListStyle, rNodes ) )
233 : : {
234 : 2367 : }
235 : :
236 : 2270 : SwList::~SwList()
237 : : {
238 [ + - ]: 2270 : delete mpListImpl;
239 : 2270 : }
240 : :
241 : 2370 : const String SwList::GetListId() const
242 : : {
243 : 2370 : return mpListImpl->GetListId();
244 : : }
245 : :
246 : 30 : const String SwList::GetDefaultListStyleName() const
247 : : {
248 : 30 : return mpListImpl->GetDefaultListStyleName();
249 : : }
250 : :
251 : 4050 : void SwList::InsertListItem( SwNodeNum& rNodeNum,
252 : : const int nLevel )
253 : : {
254 : 4050 : mpListImpl->InsertListItem( rNodeNum, nLevel );
255 : 4050 : }
256 : :
257 : 4050 : void SwList::RemoveListItem( SwNodeNum& rNodeNum )
258 : : {
259 : 4050 : mpListImpl->RemoveListItem( rNodeNum );
260 : 4050 : }
261 : :
262 : 180 : void SwList::InvalidateListTree()
263 : : {
264 : 180 : mpListImpl->InvalidateListTree();
265 : 180 : }
266 : :
267 : 180 : void SwList::ValidateListTree()
268 : : {
269 : 180 : mpListImpl->ValidateListTree();
270 : 180 : }
271 : :
272 : 0 : void SwList::MarkListLevel( const int nListLevel,
273 : : const sal_Bool bValue )
274 : : {
275 : 0 : mpListImpl->MarkListLevel( nListLevel, bValue );
276 : 0 : }
277 : :
278 : 94 : bool SwList::IsListLevelMarked( const int nListLevel ) const
279 : : {
280 : 94 : return mpListImpl->IsListLevelMarked( nListLevel );
281 : : }
282 : :
283 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|