merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / doc / list.cxx
blob4aa146e8768f7c04c2e2108e7d2ef2f730b72953
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: list.cxx,v $
10 * $Revision: 1.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sw.hxx"
33 #include <list.hxx>
35 #include <vector>
36 #include <numrule.hxx>
37 #include <ndarr.hxx>
38 #include <node.hxx>
39 #include <pam.hxx>
40 #include <SwNodeNum.hxx>
42 // ----------------------------------------------------------------------------
43 // SwListImpl
44 // implementation class for SwList
45 // ----------------------------------------------------------------------------
46 class SwListImpl
48 public:
49 SwListImpl( const String sListId,
50 SwNumRule& rDefaultListStyle,
51 const SwNodes& rNodes );
52 ~SwListImpl();
54 const String GetListId() const;
56 const String GetDefaultListStyleName() const;
58 void InsertListItem( SwNodeNum& rNodeNum,
59 const int nLevel );
60 void RemoveListItem( SwNodeNum& rNodeNum );
62 void InvalidateListTree();
63 void ValidateListTree();
65 void MarkListLevel( const int nListLevel,
66 const BOOL bValue );
68 bool IsListLevelMarked( const int nListLevel ) const;
70 private:
71 // unique identifier of the list
72 const String msListId;
73 // default list style for the list items, identified by the list style name
74 String msDefaultListStyleName;
76 // list trees for certain document ranges
77 typedef std::pair<SwNodeNum*, SwPaM*> tListTreeForRange;
78 typedef std::vector<tListTreeForRange> tListTrees;
79 tListTrees maListTrees;
81 int mnMarkedListLevel;
83 void NotifyItemsOnListLevel( const int nLevel );
86 SwListImpl::SwListImpl( const String sListId,
87 SwNumRule& rDefaultListStyle,
88 const SwNodes& rNodes )
89 : msListId( sListId ),
90 msDefaultListStyleName( rDefaultListStyle.GetName() ),
91 maListTrees(),
92 mnMarkedListLevel( MAXLEVEL )
94 // create empty list trees for the document ranges
95 const SwNode* pNode = rNodes[0];
98 SwPaM aPam( *pNode, *pNode->EndOfSectionNode() );
100 SwNodeNum* pNumberTreeRootNode = new SwNodeNum( &rDefaultListStyle );
101 SwPaM* pPam = new SwPaM( *(aPam.Start()), *(aPam.End()) );
102 tListTreeForRange aListTreeForRange( pNumberTreeRootNode, pPam );
103 maListTrees.push_back( aListTreeForRange );
105 pNode = pNode->EndOfSectionNode();
106 if (pNode != &rNodes.GetEndOfContent())
108 ULONG nIndex = pNode->GetIndex();
109 nIndex++;
110 pNode = rNodes[nIndex];
113 while ( pNode != &rNodes.GetEndOfContent() );
116 SwListImpl::~SwListImpl()
118 tListTrees::iterator aNumberTreeIter;
119 for ( aNumberTreeIter = maListTrees.begin();
120 aNumberTreeIter != maListTrees.end();
121 ++aNumberTreeIter )
123 SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter).first) );
124 delete (*aNumberTreeIter).first;
125 delete (*aNumberTreeIter).second;
129 const String SwListImpl::GetListId() const
131 return msListId;
134 const String SwListImpl::GetDefaultListStyleName() const
136 return msDefaultListStyleName;
139 void SwListImpl::InsertListItem( SwNodeNum& rNodeNum,
140 const int nLevel )
142 const SwPosition aPosOfNodeNum( rNodeNum.GetPosition() );
143 const SwNodes* pNodesOfNodeNum = &(aPosOfNodeNum.nNode.GetNode().GetNodes());
145 tListTrees::const_iterator aNumberTreeIter;
146 for ( aNumberTreeIter = maListTrees.begin();
147 aNumberTreeIter != maListTrees.end();
148 ++aNumberTreeIter )
150 const SwPosition* pStart = (*aNumberTreeIter).second->Start();
151 const SwPosition* pEnd = (*aNumberTreeIter).second->End();
152 const SwNodes* pRangeNodes = &(pStart->nNode.GetNode().GetNodes());
154 if ( pRangeNodes == pNodesOfNodeNum &&
155 *pStart <= aPosOfNodeNum && aPosOfNodeNum <= *pEnd)
157 (*aNumberTreeIter).first->AddChild( &rNodeNum, nLevel );
159 break;
164 void SwListImpl::RemoveListItem( SwNodeNum& rNodeNum )
166 rNodeNum.RemoveMe();
169 void SwListImpl::InvalidateListTree()
171 tListTrees::iterator aNumberTreeIter;
172 for ( aNumberTreeIter = maListTrees.begin();
173 aNumberTreeIter != maListTrees.end();
174 ++aNumberTreeIter )
176 (*aNumberTreeIter).first->InvalidateTree();
180 void SwListImpl::ValidateListTree()
182 tListTrees::iterator aNumberTreeIter;
183 for ( aNumberTreeIter = maListTrees.begin();
184 aNumberTreeIter != maListTrees.end();
185 ++aNumberTreeIter )
187 (*aNumberTreeIter).first->NotifyInvalidChildren();
191 void SwListImpl::MarkListLevel( const int nListLevel,
192 const BOOL bValue )
194 if ( bValue )
196 if ( nListLevel != mnMarkedListLevel )
198 if ( mnMarkedListLevel != MAXLEVEL )
200 // notify former marked list nodes
201 NotifyItemsOnListLevel( mnMarkedListLevel );
204 mnMarkedListLevel = nListLevel;
206 // notify new marked list nodes
207 NotifyItemsOnListLevel( mnMarkedListLevel );
210 else
212 if ( mnMarkedListLevel != MAXLEVEL )
214 // notify former marked list nodes
215 NotifyItemsOnListLevel( mnMarkedListLevel );
218 mnMarkedListLevel = MAXLEVEL;
222 bool SwListImpl::IsListLevelMarked( const int nListLevel ) const
224 return nListLevel == mnMarkedListLevel;
227 void SwListImpl::NotifyItemsOnListLevel( const int nLevel )
229 tListTrees::iterator aNumberTreeIter;
230 for ( aNumberTreeIter = maListTrees.begin();
231 aNumberTreeIter != maListTrees.end();
232 ++aNumberTreeIter )
234 (*aNumberTreeIter).first->NotifyNodesOnListLevel( nLevel );
238 // ----------------------------------------------------------------------------
239 // SwList
240 // ----------------------------------------------------------------------------
241 SwList::SwList( const String sListId,
242 SwNumRule& rDefaultListStyle,
243 const SwNodes& rNodes )
244 : mpListImpl( new SwListImpl( sListId, rDefaultListStyle, rNodes ) )
248 SwList::~SwList()
250 delete mpListImpl;
253 const String SwList::GetListId() const
255 return mpListImpl->GetListId();
258 const String SwList::GetDefaultListStyleName() const
260 return mpListImpl->GetDefaultListStyleName();
263 void SwList::InsertListItem( SwNodeNum& rNodeNum,
264 const int nLevel )
266 mpListImpl->InsertListItem( rNodeNum, nLevel );
269 void SwList::RemoveListItem( SwNodeNum& rNodeNum )
271 mpListImpl->RemoveListItem( rNodeNum );
274 void SwList::InvalidateListTree()
276 mpListImpl->InvalidateListTree();
279 void SwList::ValidateListTree()
281 mpListImpl->ValidateListTree();
284 void SwList::MarkListLevel( const int nListLevel,
285 const BOOL bValue )
287 mpListImpl->MarkListLevel( nListLevel, bValue );
290 bool SwList::IsListLevelMarked( const int nListLevel ) const
292 return mpListImpl->IsListLevelMarked( nListLevel );
295 //void SwList::ContinueList( SwList& rList )
297 // mpListImpl->ContinueList( rList );
299 //const SwList* SwList::GetContinuedList() const
301 // return mpListImpl->GetContinuedList();
303 //void SwList::ClearContinuation()
305 // mpListImpl->ClearContinuation();