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 .
21 #include <paralist.hxx>
23 #include <editeng/outliner.hxx>
24 #include <editeng/numdef.hxx>
26 #include <osl/diagnose.h>
27 #include <tools/debug.hxx>
29 ParagraphData::ParagraphData()
31 , mnNumberingStartValue( -1 )
32 , mbParaIsNumberingRestart( false )
36 ParagraphData::ParagraphData( const ParagraphData
& r
)
38 , mnNumberingStartValue( r
.mnNumberingStartValue
)
39 , mbParaIsNumberingRestart( r
.mbParaIsNumberingRestart
)
43 ParagraphData
& ParagraphData::operator=( const ParagraphData
& r
)
46 mnNumberingStartValue
= r
.mnNumberingStartValue
;
47 mbParaIsNumberingRestart
= r
.mbParaIsNumberingRestart
;
51 bool ParagraphData::operator==(const ParagraphData
& rCandidate
) const
53 return (nDepth
== rCandidate
.nDepth
54 && mnNumberingStartValue
== rCandidate
.mnNumberingStartValue
55 && mbParaIsNumberingRestart
== rCandidate
.mbParaIsNumberingRestart
);
58 Paragraph::Paragraph( sal_Int16 nDDepth
)
62 DBG_ASSERT( ( nDDepth
>= -1 ) && ( nDDepth
< SVX_MAX_NUM
), "Paragraph-CTOR: nDepth invalid!" );
65 nFlags
= ParaFlag::NONE
;
69 Paragraph::Paragraph( const ParagraphData
& rData
)
70 : nFlags( ParaFlag::NONE
)
74 nDepth
= rData
.nDepth
;
75 mnNumberingStartValue
= rData
.mnNumberingStartValue
;
76 mbParaIsNumberingRestart
= rData
.mbParaIsNumberingRestart
;
79 Paragraph::~Paragraph()
83 void Paragraph::SetNumberingStartValue( sal_Int16 nNumberingStartValue
)
85 mnNumberingStartValue
= nNumberingStartValue
;
86 if( mnNumberingStartValue
!= -1 )
87 mbParaIsNumberingRestart
= true;
90 void Paragraph::SetParaIsNumberingRestart( bool bParaIsNumberingRestart
)
92 mbParaIsNumberingRestart
= bParaIsNumberingRestart
;
93 if( !mbParaIsNumberingRestart
)
94 mnNumberingStartValue
= -1;
97 void ParagraphList::Clear( bool bDestroyParagraphs
)
99 if ( bDestroyParagraphs
)
101 std::vector
<Paragraph
*>::iterator iter
;
102 for (iter
= maEntries
.begin(); iter
!= maEntries
.end(); ++iter
)
109 void ParagraphList::Append( Paragraph
* pPara
)
111 SAL_WARN_IF( maEntries
.size() >= EE_PARA_MAX_COUNT
, "editeng", "ParagraphList::Append - overflow");
112 maEntries
.push_back(pPara
);
115 void ParagraphList::Insert( Paragraph
* pPara
, sal_Int32 nAbsPos
)
117 SAL_WARN_IF( nAbsPos
< 0 || (maEntries
.size() < static_cast<size_t>(nAbsPos
) && nAbsPos
!= EE_PARA_APPEND
),
118 "editeng", "ParagraphList::Insert - bad insert position " << nAbsPos
);
119 SAL_WARN_IF( maEntries
.size() >= EE_PARA_MAX_COUNT
, "editeng", "ParagraphList::Insert - overflow");
121 if (nAbsPos
< 0 || maEntries
.size() <= static_cast<size_t>(nAbsPos
))
124 maEntries
.insert(maEntries
.begin()+nAbsPos
,pPara
);
127 void ParagraphList::Remove( sal_Int32 nPara
)
129 if (nPara
< 0 || maEntries
.size() <= static_cast<size_t>(nPara
))
131 SAL_WARN( "editeng", "ParagraphList::Remove - out of bounds " << nPara
);
135 maEntries
.erase(maEntries
.begin() + nPara
);
138 void ParagraphList::MoveParagraphs( sal_Int32 nStart
, sal_Int32 nDest
, sal_Int32 _nCount
)
140 OSL_ASSERT(static_cast<size_t>(nStart
) < maEntries
.size() && static_cast<size_t>(nDest
) < maEntries
.size());
142 if ( (( nDest
< nStart
) || ( nDest
>= ( nStart
+ _nCount
) )) && nStart
>= 0 && nDest
>= 0 && _nCount
>= 0 )
144 std::vector
<Paragraph
*> aParas
;
145 std::vector
<Paragraph
*>::iterator iterBeg
= maEntries
.begin() + nStart
;
146 std::vector
<Paragraph
*>::iterator iterEnd
= iterBeg
+ _nCount
;
148 std::copy(iterBeg
,iterEnd
,std::back_inserter(aParas
));
150 maEntries
.erase(iterBeg
,iterEnd
);
152 if ( nDest
> nStart
)
155 std::vector
<Paragraph
*>::iterator iterIns
= maEntries
.begin() + nDest
;
157 std::copy(aParas
.begin(),aParas
.end(),std::inserter(maEntries
,iterIns
));
161 OSL_FAIL( "MoveParagraphs: Invalid Parameters" );
165 bool ParagraphList::HasChildren( Paragraph
* pParagraph
) const
167 sal_Int32 n
= GetAbsPos( pParagraph
);
168 Paragraph
* pNext
= GetParagraph( ++n
);
169 return pNext
&& ( pNext
->GetDepth() > pParagraph
->GetDepth() );
172 bool ParagraphList::HasHiddenChildren( Paragraph
* pParagraph
) const
174 sal_Int32 n
= GetAbsPos( pParagraph
);
175 Paragraph
* pNext
= GetParagraph( ++n
);
176 return pNext
&& ( pNext
->GetDepth() > pParagraph
->GetDepth() ) && !pNext
->IsVisible();
179 bool ParagraphList::HasVisibleChildren( Paragraph
* pParagraph
) const
181 sal_Int32 n
= GetAbsPos( pParagraph
);
182 Paragraph
* pNext
= GetParagraph( ++n
);
183 return pNext
&& ( pNext
->GetDepth() > pParagraph
->GetDepth() ) && pNext
->IsVisible();
186 sal_Int32
ParagraphList::GetChildCount( Paragraph
* pParent
) const
188 sal_Int32 nChildCount
= 0;
189 sal_Int32 n
= GetAbsPos( pParent
);
190 Paragraph
* pPara
= GetParagraph( ++n
);
191 while ( pPara
&& ( pPara
->GetDepth() > pParent
->GetDepth() ) )
194 pPara
= GetParagraph( ++n
);
199 Paragraph
* ParagraphList::GetParent( Paragraph
* pParagraph
/*, sal_uInt16& rRelPos */ ) const
202 sal_Int32 n
= GetAbsPos( pParagraph
);
203 Paragraph
* pPrev
= GetParagraph( --n
);
204 while ( pPrev
&& ( pPrev
->GetDepth() >= pParagraph
->GetDepth() ) )
206 // if ( pPrev->GetDepth() == pParagraph->GetDepth() )
208 pPrev
= GetParagraph( --n
);
214 void ParagraphList::Expand( Paragraph
* pParent
)
216 sal_Int32 nChildCount
= GetChildCount( pParent
);
217 sal_Int32 nPos
= GetAbsPos( pParent
);
219 for ( sal_Int32 n
= 1; n
<= nChildCount
; n
++ )
221 Paragraph
* pPara
= GetParagraph( nPos
+n
);
222 if ( !( pPara
->IsVisible() ) )
224 pPara
->bVisible
= true;
225 aVisibleStateChangedHdl
.Call( pPara
);
230 void ParagraphList::Collapse( Paragraph
* pParent
)
232 sal_Int32 nChildCount
= GetChildCount( pParent
);
233 sal_Int32 nPos
= GetAbsPos( pParent
);
235 for ( sal_Int32 n
= 1; n
<= nChildCount
; n
++ )
237 Paragraph
* pPara
= GetParagraph( nPos
+n
);
238 if ( pPara
->IsVisible() )
240 pPara
->bVisible
= false;
241 aVisibleStateChangedHdl
.Call( pPara
);
246 sal_Int32
ParagraphList::GetAbsPos( Paragraph
* pParent
) const
249 std::vector
<Paragraph
*>::const_iterator iter
;
250 for (iter
= maEntries
.begin(); iter
!= maEntries
.end(); ++iter
, ++pos
)
252 if (*iter
== pParent
)
256 return EE_PARA_NOT_FOUND
;
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */