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