1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
24 #include <numrule.hxx>
28 #include <SwNodeNum.hxx>
30 // implementation class for SwList
34 SwListImpl( const String sListId
,
35 SwNumRule
& rDefaultListStyle
,
36 const SwNodes
& rNodes
);
39 const String
GetListId() const;
41 const String
GetDefaultListStyleName() const;
43 void InsertListItem( SwNodeNum
& rNodeNum
,
45 void RemoveListItem( SwNodeNum
& rNodeNum
);
47 void InvalidateListTree();
48 void ValidateListTree();
50 void MarkListLevel( const int nListLevel
,
53 bool IsListLevelMarked( const int nListLevel
) const;
56 // unique identifier of the list
57 const String msListId
;
58 // default list style for the list items, identified by the list style name
59 String msDefaultListStyleName
;
61 // list trees for certain document ranges
62 typedef std::pair
<SwNodeNum
*, SwPaM
*> tListTreeForRange
;
63 typedef std::vector
<tListTreeForRange
> tListTrees
;
64 tListTrees maListTrees
;
66 int mnMarkedListLevel
;
68 void NotifyItemsOnListLevel( const int nLevel
);
71 SwListImpl::SwListImpl( const String sListId
,
72 SwNumRule
& rDefaultListStyle
,
73 const SwNodes
& rNodes
)
74 : msListId( sListId
),
75 msDefaultListStyleName( rDefaultListStyle
.GetName() ),
77 mnMarkedListLevel( MAXLEVEL
)
79 // create empty list trees for the document ranges
80 const SwNode
* pNode
= rNodes
[0];
83 SwPaM
aPam( *pNode
, *pNode
->EndOfSectionNode() );
85 SwNodeNum
* pNumberTreeRootNode
= new SwNodeNum( &rDefaultListStyle
);
86 SwPaM
* pPam
= new SwPaM( *(aPam
.Start()), *(aPam
.End()) );
87 tListTreeForRange
aListTreeForRange( pNumberTreeRootNode
, pPam
);
88 maListTrees
.push_back( aListTreeForRange
);
90 pNode
= pNode
->EndOfSectionNode();
91 if (pNode
!= &rNodes
.GetEndOfContent())
93 sal_uLong nIndex
= pNode
->GetIndex();
95 pNode
= rNodes
[nIndex
];
98 while ( pNode
!= &rNodes
.GetEndOfContent() );
101 SwListImpl::~SwListImpl()
103 tListTrees::iterator aNumberTreeIter
;
104 for ( aNumberTreeIter
= maListTrees
.begin();
105 aNumberTreeIter
!= maListTrees
.end();
108 SwNodeNum::HandleNumberTreeRootNodeDelete( *((*aNumberTreeIter
).first
) );
109 delete (*aNumberTreeIter
).first
;
110 delete (*aNumberTreeIter
).second
;
114 const String
SwListImpl::GetListId() const
119 const String
SwListImpl::GetDefaultListStyleName() const
121 return msDefaultListStyleName
;
124 void SwListImpl::InsertListItem( SwNodeNum
& rNodeNum
,
127 const SwPosition
aPosOfNodeNum( rNodeNum
.GetPosition() );
128 const SwNodes
* pNodesOfNodeNum
= &(aPosOfNodeNum
.nNode
.GetNode().GetNodes());
130 tListTrees::const_iterator aNumberTreeIter
;
131 for ( aNumberTreeIter
= maListTrees
.begin();
132 aNumberTreeIter
!= maListTrees
.end();
135 const SwPosition
* pStart
= (*aNumberTreeIter
).second
->Start();
136 const SwPosition
* pEnd
= (*aNumberTreeIter
).second
->End();
137 const SwNodes
* pRangeNodes
= &(pStart
->nNode
.GetNode().GetNodes());
139 if ( pRangeNodes
== pNodesOfNodeNum
&&
140 *pStart
<= aPosOfNodeNum
&& aPosOfNodeNum
<= *pEnd
)
142 (*aNumberTreeIter
).first
->AddChild( &rNodeNum
, nLevel
);
149 void SwListImpl::RemoveListItem( SwNodeNum
& rNodeNum
)
154 void SwListImpl::InvalidateListTree()
156 tListTrees::iterator aNumberTreeIter
;
157 for ( aNumberTreeIter
= maListTrees
.begin();
158 aNumberTreeIter
!= maListTrees
.end();
161 (*aNumberTreeIter
).first
->InvalidateTree();
165 void SwListImpl::ValidateListTree()
167 tListTrees::iterator aNumberTreeIter
;
168 for ( aNumberTreeIter
= maListTrees
.begin();
169 aNumberTreeIter
!= maListTrees
.end();
172 (*aNumberTreeIter
).first
->NotifyInvalidChildren();
176 void SwListImpl::MarkListLevel( const int nListLevel
,
181 if ( nListLevel
!= mnMarkedListLevel
)
183 if ( mnMarkedListLevel
!= MAXLEVEL
)
185 // notify former marked list nodes
186 NotifyItemsOnListLevel( mnMarkedListLevel
);
189 mnMarkedListLevel
= nListLevel
;
191 // notify new marked list nodes
192 NotifyItemsOnListLevel( mnMarkedListLevel
);
197 if ( mnMarkedListLevel
!= MAXLEVEL
)
199 // notify former marked list nodes
200 NotifyItemsOnListLevel( mnMarkedListLevel
);
203 mnMarkedListLevel
= MAXLEVEL
;
207 bool SwListImpl::IsListLevelMarked( const int nListLevel
) const
209 return nListLevel
== mnMarkedListLevel
;
212 void SwListImpl::NotifyItemsOnListLevel( const int nLevel
)
214 tListTrees::iterator aNumberTreeIter
;
215 for ( aNumberTreeIter
= maListTrees
.begin();
216 aNumberTreeIter
!= maListTrees
.end();
219 (*aNumberTreeIter
).first
->NotifyNodesOnListLevel( nLevel
);
223 // SwList ---------------------------------------------------------------------
224 SwList::SwList( const String sListId
,
225 SwNumRule
& rDefaultListStyle
,
226 const SwNodes
& rNodes
)
227 : mpListImpl( new SwListImpl( sListId
, rDefaultListStyle
, rNodes
) )
236 const String
SwList::GetListId() const
238 return mpListImpl
->GetListId();
241 const String
SwList::GetDefaultListStyleName() const
243 return mpListImpl
->GetDefaultListStyleName();
246 void SwList::InsertListItem( SwNodeNum
& rNodeNum
,
249 mpListImpl
->InsertListItem( rNodeNum
, nLevel
);
252 void SwList::RemoveListItem( SwNodeNum
& rNodeNum
)
254 mpListImpl
->RemoveListItem( rNodeNum
);
257 void SwList::InvalidateListTree()
259 mpListImpl
->InvalidateListTree();
262 void SwList::ValidateListTree()
264 mpListImpl
->ValidateListTree();
267 void SwList::MarkListLevel( const int nListLevel
,
270 mpListImpl
->MarkListLevel( nListLevel
, bValue
);
273 bool SwList::IsListLevelMarked( const int nListLevel
) const
275 return mpListImpl
->IsListLevelMarked( nListLevel
);
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */