xref: /aoo42x/main/sw/source/core/doc/list.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_sw.hxx"
25 
26 #include <list.hxx>
27 
28 #include <vector>
29 #include <numrule.hxx>
30 #include <ndarr.hxx>
31 #include <node.hxx>
32 #include <pam.hxx>
33 #include <SwNodeNum.hxx>
34 
35 // ----------------------------------------------------------------------------
36 // SwListImpl
37 // implementation class for SwList
38 // ----------------------------------------------------------------------------
39 class SwListImpl
40 {
41     public:
42         SwListImpl( const String sListId,
43                     SwNumRule& rDefaultListStyle,
44                     const SwNodes& rNodes );
45         ~SwListImpl();
46 
47         const String GetListId() const;
48 
49         const String GetDefaultListStyleName() const;
50 
51         void InsertListItem( SwNodeNum& rNodeNum,
52                              const int nLevel );
53         void RemoveListItem( SwNodeNum& rNodeNum );
54 
55         void InvalidateListTree();
56         void ValidateListTree();
57 
58         void MarkListLevel( const int nListLevel,
59                             const sal_Bool bValue );
60 
61         bool IsListLevelMarked( const int nListLevel ) const;
62 
63     private:
64         // unique identifier of the list
65         const String msListId;
66         // default list style for the list items, identified by the list style name
67         String msDefaultListStyleName;
68 
69         // list trees for certain document ranges
70         typedef std::pair<SwNodeNum*, SwPaM*> tListTreeForRange;
71         typedef std::vector<tListTreeForRange> tListTrees;
72         tListTrees maListTrees;
73 
74         int mnMarkedListLevel;
75 
76         void NotifyItemsOnListLevel( const int nLevel );
77 };
78 
SwListImpl(const String sListId,SwNumRule & rDefaultListStyle,const SwNodes & rNodes)79 SwListImpl::SwListImpl( const String sListId,
80                         SwNumRule& rDefaultListStyle,
81                         const SwNodes& rNodes )
82     : msListId( sListId ),
83       msDefaultListStyleName( rDefaultListStyle.GetName() ),
84       maListTrees(),
85       mnMarkedListLevel( MAXLEVEL )
86 {
87     // create empty list trees for the document ranges
88     const SwNode* pNode = rNodes[0];
89     do
90     {
91         SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
92 
93         SwNodeNum* pNumberTreeRootNode = new SwNodeNum( &rDefaultListStyle );
94         SwPaM* pPam = new SwPaM( *(aPam.Start()), *(aPam.End()) );
95         tListTreeForRange aListTreeForRange( pNumberTreeRootNode, pPam );
96         maListTrees.push_back( aListTreeForRange );
97 
98         pNode = pNode->EndOfSectionNode();
99         if (pNode != &rNodes.GetEndOfContent())
100         {
101             sal_uLong nIndex = pNode->GetIndex();
102             nIndex++;
103             pNode = rNodes[nIndex];
104         }
105     }
106     while ( pNode != &rNodes.GetEndOfContent() );
107 }
108 
~SwListImpl()109 SwListImpl::~SwListImpl()
110 {
111     tListTrees::iterator aNumberTreeIter;
112     for ( aNumberTreeIter = maListTrees.begin();
113           aNumberTreeIter != maListTrees.end();
114           ++aNumberTreeIter )
115     {
116         SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter).first) );
117         delete (*aNumberTreeIter).first;
118         delete (*aNumberTreeIter).second;
119     }
120 }
121 
GetListId() const122 const String SwListImpl::GetListId() const
123 {
124     return msListId;
125 }
126 
GetDefaultListStyleName() const127 const String SwListImpl::GetDefaultListStyleName() const
128 {
129     return msDefaultListStyleName;
130 }
131 
InsertListItem(SwNodeNum & rNodeNum,const int nLevel)132 void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
133                                  const int nLevel )
134 {
135     const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
136     const SwNodes* pNodesOfNodeNum = &(aPosOfNodeNum.nNode.GetNode().GetNodes());
137 
138     tListTrees::const_iterator aNumberTreeIter;
139     for ( aNumberTreeIter = maListTrees.begin();
140           aNumberTreeIter != maListTrees.end();
141           ++aNumberTreeIter )
142     {
143         const SwPosition* pStart = (*aNumberTreeIter).second->Start();
144         const SwPosition* pEnd = (*aNumberTreeIter).second->End();
145         const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
146 
147         if ( pRangeNodes == pNodesOfNodeNum &&
148              *pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
149         {
150             (*aNumberTreeIter).first->AddChild( &rNodeNum, nLevel );
151 
152             break;
153         }
154     }
155 }
156 
RemoveListItem(SwNodeNum & rNodeNum)157 void SwListImpl::RemoveListItem( SwNodeNum& rNodeNum )
158 {
159     rNodeNum.RemoveMe();
160 }
161 
InvalidateListTree()162 void SwListImpl::InvalidateListTree()
163 {
164     tListTrees::iterator aNumberTreeIter;
165     for ( aNumberTreeIter = maListTrees.begin();
166           aNumberTreeIter != maListTrees.end();
167           ++aNumberTreeIter )
168     {
169         (*aNumberTreeIter).first->InvalidateTree();
170     }
171 }
172 
ValidateListTree()173 void SwListImpl::ValidateListTree()
174 {
175     tListTrees::iterator aNumberTreeIter;
176     for ( aNumberTreeIter = maListTrees.begin();
177           aNumberTreeIter != maListTrees.end();
178           ++aNumberTreeIter )
179     {
180         (*aNumberTreeIter).first->NotifyInvalidChildren();
181     }
182 }
183 
MarkListLevel(const int nListLevel,const sal_Bool bValue)184 void SwListImpl::MarkListLevel( const int nListLevel,
185                                 const sal_Bool bValue )
186 {
187     if ( bValue )
188     {
189         if ( nListLevel != mnMarkedListLevel )
190         {
191             if ( mnMarkedListLevel != MAXLEVEL )
192             {
193                 // notify former marked list nodes
194                 NotifyItemsOnListLevel( mnMarkedListLevel );
195             }
196 
197             mnMarkedListLevel = nListLevel;
198 
199             // notify new marked list nodes
200             NotifyItemsOnListLevel( mnMarkedListLevel );
201         }
202     }
203     else
204     {
205         if ( mnMarkedListLevel != MAXLEVEL )
206         {
207             // notify former marked list nodes
208             NotifyItemsOnListLevel( mnMarkedListLevel );
209         }
210 
211         mnMarkedListLevel = MAXLEVEL;
212     }
213 }
214 
IsListLevelMarked(const int nListLevel) const215 bool SwListImpl::IsListLevelMarked( const int nListLevel ) const
216 {
217     return nListLevel == mnMarkedListLevel;
218 }
219 
NotifyItemsOnListLevel(const int nLevel)220 void SwListImpl::NotifyItemsOnListLevel( const int nLevel )
221 {
222     tListTrees::iterator aNumberTreeIter;
223     for ( aNumberTreeIter = maListTrees.begin();
224           aNumberTreeIter != maListTrees.end();
225           ++aNumberTreeIter )
226     {
227         (*aNumberTreeIter).first->NotifyNodesOnListLevel( nLevel );
228     }
229 }
230 
231 // ----------------------------------------------------------------------------
232 // SwList
233 // ----------------------------------------------------------------------------
SwList(const String sListId,SwNumRule & rDefaultListStyle,const SwNodes & rNodes)234 SwList::SwList( const String sListId,
235                 SwNumRule& rDefaultListStyle,
236                 const SwNodes& rNodes )
237     : mpListImpl( new SwListImpl( sListId, rDefaultListStyle, rNodes ) )
238 {
239 }
240 
~SwList()241 SwList::~SwList()
242 {
243     delete mpListImpl;
244 }
245 
GetListId() const246 const String SwList::GetListId() const
247 {
248     return mpListImpl->GetListId();
249 }
250 
GetDefaultListStyleName() const251 const String SwList::GetDefaultListStyleName() const
252 {
253     return mpListImpl->GetDefaultListStyleName();
254 }
255 
InsertListItem(SwNodeNum & rNodeNum,const int nLevel)256 void SwList::InsertListItem( SwNodeNum& rNodeNum,
257                              const int nLevel )
258 {
259     mpListImpl->InsertListItem( rNodeNum, nLevel );
260 }
261 
RemoveListItem(SwNodeNum & rNodeNum)262 void SwList::RemoveListItem( SwNodeNum& rNodeNum )
263 {
264     mpListImpl->RemoveListItem( rNodeNum );
265 }
266 
InvalidateListTree()267 void SwList::InvalidateListTree()
268 {
269     mpListImpl->InvalidateListTree();
270 }
271 
ValidateListTree()272 void SwList::ValidateListTree()
273 {
274     mpListImpl->ValidateListTree();
275 }
276 
MarkListLevel(const int nListLevel,const sal_Bool bValue)277 void SwList::MarkListLevel( const int nListLevel,
278                                   const sal_Bool bValue )
279 {
280     mpListImpl->MarkListLevel( nListLevel, bValue );
281 }
282 
IsListLevelMarked(const int nListLevel) const283 bool SwList::IsListLevelMarked( const int nListLevel ) const
284 {
285     return mpListImpl->IsListLevelMarked( nListLevel );
286 }
287 
288 //void SwList::ContinueList( SwList& rList )
289 //{
290 //    mpListImpl->ContinueList( rList );
291 //}
292 //const SwList* SwList::GetContinuedList() const
293 //{
294 //    return mpListImpl->GetContinuedList();
295 //}
296 //void SwList::ClearContinuation()
297 //{
298 //    mpListImpl->ClearContinuation();
299 //}
300