1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <paralist.hxx>
32 #include <editeng/outliner.hxx> // only because of Paragraph, this must be changed!
33 #include <editeng/numdef.hxx>
35 #include <osl/diagnose.h>
36 #include <tools/debug.hxx>
40 ParagraphData::ParagraphData()
42 , mnNumberingStartValue( -1 )
43 , mbParaIsNumberingRestart( sal_False
)
47 ParagraphData::ParagraphData( const ParagraphData
& r
)
49 , mnNumberingStartValue( r
.mnNumberingStartValue
)
50 , mbParaIsNumberingRestart( r
.mbParaIsNumberingRestart
)
54 ParagraphData
& ParagraphData::operator=( const ParagraphData
& r
)
57 mnNumberingStartValue
= r
.mnNumberingStartValue
;
58 mbParaIsNumberingRestart
= r
.mbParaIsNumberingRestart
;
62 bool ParagraphData::operator==(const ParagraphData
& rCandidate
) const
64 return (nDepth
== rCandidate
.nDepth
65 && mnNumberingStartValue
== rCandidate
.mnNumberingStartValue
66 && mbParaIsNumberingRestart
== rCandidate
.mbParaIsNumberingRestart
);
69 Paragraph::Paragraph( sal_Int16 nDDepth
)
72 DBG_CTOR( Paragraph
, 0 );
74 DBG_ASSERT( ( nDDepth
>= -1 ) && ( nDDepth
< SVX_MAX_NUM
), "Paragraph-CTOR: nDepth invalid!" );
81 Paragraph::Paragraph( const Paragraph
& rPara
)
82 : ParagraphData( rPara
)
83 , aBulText( rPara
.aBulText
)
84 , aBulSize( rPara
.aBulSize
)
86 DBG_CTOR( Paragraph
, 0 );
88 nDepth
= rPara
.nDepth
;
89 nFlags
= rPara
.nFlags
;
90 bVisible
= rPara
.bVisible
;
93 Paragraph::Paragraph( const ParagraphData
& rData
)
96 , bVisible( sal_True
)
98 DBG_CTOR( Paragraph
, 0 );
100 nDepth
= rData
.nDepth
;
101 mnNumberingStartValue
= rData
.mnNumberingStartValue
;
102 mbParaIsNumberingRestart
= rData
.mbParaIsNumberingRestart
;
105 Paragraph::~Paragraph()
107 DBG_DTOR( Paragraph
, 0 );
110 void Paragraph::SetNumberingStartValue( sal_Int16 nNumberingStartValue
)
112 mnNumberingStartValue
= nNumberingStartValue
;
113 if( mnNumberingStartValue
!= -1 )
114 mbParaIsNumberingRestart
= true;
117 void Paragraph::SetParaIsNumberingRestart( sal_Bool bParaIsNumberingRestart
)
119 mbParaIsNumberingRestart
= bParaIsNumberingRestart
;
120 if( !mbParaIsNumberingRestart
)
121 mnNumberingStartValue
= -1;
124 void ParagraphList::Clear( sal_Bool bDestroyParagraphs
)
126 if ( bDestroyParagraphs
)
128 std::vector
<Paragraph
*>::iterator iter
;
129 for (iter
= maEntries
.begin(); iter
!= maEntries
.end(); ++iter
)
136 void ParagraphList::Append( Paragraph
* pPara
)
138 maEntries
.push_back(pPara
);
141 void ParagraphList::Insert( Paragraph
* pPara
, sal_uLong nAbsPos
)
143 OSL_ASSERT(nAbsPos
!= ULONG_MAX
&& nAbsPos
<= maEntries
.size());
145 maEntries
.insert(maEntries
.begin()+nAbsPos
,pPara
);
148 void ParagraphList::Remove( sal_uLong nPara
)
150 OSL_ASSERT(nPara
< maEntries
.size());
152 maEntries
.erase(maEntries
.begin() + nPara
);
155 void ParagraphList::MoveParagraphs( sal_uLong nStart
, sal_uLong nDest
, sal_uLong _nCount
)
157 OSL_ASSERT(nStart
< maEntries
.size() && nDest
< maEntries
.size());
159 if ( ( nDest
< nStart
) || ( nDest
>= ( nStart
+ _nCount
) ) )
161 std::vector
<Paragraph
*> aParas
;
162 std::vector
<Paragraph
*>::iterator iterBeg
= maEntries
.begin() + nStart
;
163 std::vector
<Paragraph
*>::iterator iterEnd
= iterBeg
+ _nCount
;
165 std::copy(iterBeg
,iterEnd
,std::back_inserter(aParas
));
167 maEntries
.erase(iterBeg
,iterEnd
);
169 if ( nDest
> nStart
)
172 std::vector
<Paragraph
*>::iterator iterIns
= maEntries
.begin() + nDest
;
174 std::copy(aParas
.begin(),aParas
.end(),std::inserter(maEntries
,iterIns
));
178 OSL_FAIL( "MoveParagraphs: Invalid Parameters" );
182 sal_Bool
ParagraphList::HasChildren( Paragraph
* pParagraph
) const
184 sal_uLong n
= GetAbsPos( pParagraph
);
185 Paragraph
* pNext
= GetParagraph( ++n
);
186 return ( pNext
&& ( pNext
->GetDepth() > pParagraph
->GetDepth() ) ) ? sal_True
: sal_False
;
189 sal_Bool
ParagraphList::HasHiddenChildren( Paragraph
* pParagraph
) const
191 sal_uLong n
= GetAbsPos( pParagraph
);
192 Paragraph
* pNext
= GetParagraph( ++n
);
193 return ( pNext
&& ( pNext
->GetDepth() > pParagraph
->GetDepth() ) && !pNext
->IsVisible() ) ? sal_True
: sal_False
;
196 sal_Bool
ParagraphList::HasVisibleChildren( Paragraph
* pParagraph
) const
198 sal_uLong n
= GetAbsPos( pParagraph
);
199 Paragraph
* pNext
= GetParagraph( ++n
);
200 return ( pNext
&& ( pNext
->GetDepth() > pParagraph
->GetDepth() ) && pNext
->IsVisible() ) ? sal_True
: sal_False
;
203 sal_uLong
ParagraphList::GetChildCount( Paragraph
* pParent
) const
205 sal_uLong nChildCount
= 0;
206 sal_uLong n
= GetAbsPos( pParent
);
207 Paragraph
* pPara
= GetParagraph( ++n
);
208 while ( pPara
&& ( pPara
->GetDepth() > pParent
->GetDepth() ) )
211 pPara
= GetParagraph( ++n
);
216 Paragraph
* ParagraphList::GetParent( Paragraph
* pParagraph
/*, sal_uInt16& rRelPos */ ) const
219 sal_uLong n
= GetAbsPos( pParagraph
);
220 Paragraph
* pPrev
= GetParagraph( --n
);
221 while ( pPrev
&& ( pPrev
->GetDepth() >= pParagraph
->GetDepth() ) )
223 // if ( pPrev->GetDepth() == pParagraph->GetDepth() )
225 pPrev
= GetParagraph( --n
);
231 void ParagraphList::Expand( Paragraph
* pParent
)
233 sal_uLong nChildCount
= GetChildCount( pParent
);
234 sal_uLong nPos
= GetAbsPos( pParent
);
236 for ( sal_uLong n
= 1; n
<= nChildCount
; n
++ )
238 Paragraph
* pPara
= GetParagraph( nPos
+n
);
239 if ( !( pPara
->IsVisible() ) )
241 pPara
->bVisible
= sal_True
;
242 aVisibleStateChangedHdl
.Call( pPara
);
247 void ParagraphList::Collapse( Paragraph
* pParent
)
249 sal_uLong nChildCount
= GetChildCount( pParent
);
250 sal_uLong nPos
= GetAbsPos( pParent
);
252 for ( sal_uLong n
= 1; n
<= nChildCount
; n
++ )
254 Paragraph
* pPara
= GetParagraph( nPos
+n
);
255 if ( pPara
->IsVisible() )
257 pPara
->bVisible
= sal_False
;
258 aVisibleStateChangedHdl
.Call( pPara
);
263 sal_uLong
ParagraphList::GetAbsPos( Paragraph
* pParent
) const
266 std::vector
<Paragraph
*>::const_iterator iter
;
267 for (iter
= maEntries
.begin(); iter
!= maEntries
.end(); ++iter
, ++pos
)
269 if (*iter
== pParent
)
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */