summaryrefslogtreecommitdiff
path: root/editeng/source/outliner/paralist.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'editeng/source/outliner/paralist.cxx')
-rw-r--r--editeng/source/outliner/paralist.cxx187
1 files changed, 115 insertions, 72 deletions
diff --git a/editeng/source/outliner/paralist.cxx b/editeng/source/outliner/paralist.cxx
index 938db521c2..c646710c4d 100644
--- a/editeng/source/outliner/paralist.cxx
+++ b/editeng/source/outliner/paralist.cxx
@@ -30,9 +30,12 @@
#include "precompiled_editeng.hxx"
#include <paralist.hxx>
-#include <editeng/outliner.hxx> // nur wegen Paragraph, muss geaendert werden!
+
+#include <editeng/outliner.hxx> // only because of Paragraph, this must be changed!
#include <editeng/numdef.hxx>
+#include <osl/diagnose.h>
+
DBG_NAME(Paragraph)
ParagraphData::ParagraphData()
@@ -73,7 +76,7 @@ Paragraph::Paragraph( sal_Int16 nDDepth )
nDepth = nDDepth;
nFlags = 0;
- bVisible = TRUE;
+ bVisible = sal_True;
}
Paragraph::Paragraph( const Paragraph& rPara )
@@ -91,7 +94,7 @@ Paragraph::Paragraph( const Paragraph& rPara )
Paragraph::Paragraph( const ParagraphData& rData )
: nFlags( 0 )
, aBulSize( -1, -1)
-, bVisible( TRUE )
+, bVisible( sal_True )
{
DBG_CTOR( Paragraph, 0 );
@@ -119,105 +122,129 @@ void Paragraph::SetParaIsNumberingRestart( sal_Bool bParaIsNumberingRestart )
mnNumberingStartValue = -1;
}
-void ParagraphList::Clear( BOOL bDestroyParagraphs )
+void ParagraphList::Clear( sal_Bool bDestroyParagraphs )
{
if ( bDestroyParagraphs )
{
- for ( ULONG n = GetParagraphCount(); n; )
- {
- Paragraph* pPara = GetParagraph( --n );
- delete pPara;
- }
+ std::vector<Paragraph*>::iterator iter;
+ for (iter = maEntries.begin(); iter != maEntries.end(); ++iter)
+ delete *iter;
}
- List::Clear();
+
+ maEntries.clear();
}
-void ParagraphList::MoveParagraphs( ULONG nStart, ULONG nDest, ULONG _nCount )
+void ParagraphList::Append( Paragraph* pPara)
{
+ maEntries.push_back(pPara);
+}
+
+void ParagraphList::Insert( Paragraph* pPara, sal_uLong nAbsPos)
+{
+ OSL_ASSERT(nAbsPos != ULONG_MAX && nAbsPos <= maEntries.size());
+
+ maEntries.insert(maEntries.begin()+nAbsPos,pPara);
+}
+
+void ParagraphList::Remove( sal_uLong nPara )
+{
+ OSL_ASSERT(nPara < maEntries.size());
+
+ maEntries.erase(maEntries.begin() + nPara );
+}
+
+void ParagraphList::MoveParagraphs( sal_uLong nStart, sal_uLong nDest, sal_uLong _nCount )
+{
+ OSL_ASSERT(nStart < maEntries.size() && nDest < maEntries.size());
+
if ( ( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) ) )
{
- ULONG n;
- ParagraphList aParas;
- for ( n = 0; n < _nCount; n++ )
- {
- Paragraph* pPara = GetParagraph( nStart );
- aParas.Insert( pPara, LIST_APPEND );
- Remove( nStart );
- }
+ std::vector<Paragraph*> aParas;
+ std::vector<Paragraph*>::iterator iterBeg = maEntries.begin() + nStart;
+ std::vector<Paragraph*>::iterator iterEnd = iterBeg + _nCount;
+
+ std::copy(iterBeg,iterEnd,std::back_inserter(aParas));
+
+ maEntries.erase(iterBeg,iterEnd);
if ( nDest > nStart )
nDest -= _nCount;
- for ( n = 0; n < _nCount; n++ )
- {
- Paragraph* pPara = aParas.GetParagraph( n );
- Insert( pPara, nDest++ );
- }
+ std::vector<Paragraph*>::iterator iterIns = maEntries.begin() + nDest;
+
+ std::copy(aParas.begin(),aParas.end(),std::inserter(maEntries,iterIns));
}
else
{
- DBG_ERROR( "MoveParagraphs: Invalid Parameters" );
+ OSL_FAIL( "MoveParagraphs: Invalid Parameters" );
}
}
Paragraph* ParagraphList::NextVisible( Paragraph* pPara ) const
{
- ULONG n = GetAbsPos( pPara );
-
- Paragraph* p = GetParagraph( ++n );
- while ( p && !p->IsVisible() )
- p = GetParagraph( ++n );
+ std::vector<Paragraph*>::const_iterator iter = std::find(maEntries.begin(),
+ maEntries.end(),
+ pPara);
+ for (; iter != maEntries.end(); ++iter)
+ {
+ if ((*iter)->IsVisible())
+ break;
+ }
- return p;
+ return iter != maEntries.end() ? *iter : NULL;
}
Paragraph* ParagraphList::PrevVisible( Paragraph* pPara ) const
{
- ULONG n = GetAbsPos( pPara );
-
- Paragraph* p = n ? GetParagraph( --n ) : NULL;
- while ( p && !p->IsVisible() )
- p = n ? GetParagraph( --n ) : NULL;
+ std::vector<Paragraph*>::const_reverse_iterator iter = std::find(maEntries.rbegin(),
+ maEntries.rend(),
+ pPara);
+ for (; iter != maEntries.rend(); ++iter)
+ {
+ if ((*iter)->IsVisible())
+ break;
+ }
- return p;
+ return iter != maEntries.rend() ? *iter : NULL;
}
Paragraph* ParagraphList::LastVisible() const
{
- ULONG n = GetParagraphCount();
-
- Paragraph* p = n ? GetParagraph( --n ) : NULL;
- while ( p && !p->IsVisible() )
- p = n ? GetParagraph( --n ) : NULL;
+ std::vector<Paragraph*>::const_reverse_iterator iter;
+ for (iter = maEntries.rbegin(); iter != maEntries.rend(); ++iter)
+ {
+ if ((*iter)->IsVisible())
+ break;
+ }
- return p;
+ return iter != maEntries.rend() ? *iter : NULL;
}
-BOOL ParagraphList::HasChilds( Paragraph* pParagraph ) const
+sal_Bool ParagraphList::HasChilds( Paragraph* pParagraph ) const
{
- ULONG n = GetAbsPos( pParagraph );
+ sal_uLong n = GetAbsPos( pParagraph );
Paragraph* pNext = GetParagraph( ++n );
- return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? TRUE : FALSE;
+ return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) ) ? sal_True : sal_False;
}
-BOOL ParagraphList::HasHiddenChilds( Paragraph* pParagraph ) const
+sal_Bool ParagraphList::HasHiddenChilds( Paragraph* pParagraph ) const
{
- ULONG n = GetAbsPos( pParagraph );
+ sal_uLong n = GetAbsPos( pParagraph );
Paragraph* pNext = GetParagraph( ++n );
- return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && !pNext->IsVisible() ) ? TRUE : FALSE;
+ return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && !pNext->IsVisible() ) ? sal_True : sal_False;
}
-BOOL ParagraphList::HasVisibleChilds( Paragraph* pParagraph ) const
+sal_Bool ParagraphList::HasVisibleChilds( Paragraph* pParagraph ) const
{
- ULONG n = GetAbsPos( pParagraph );
+ sal_uLong n = GetAbsPos( pParagraph );
Paragraph* pNext = GetParagraph( ++n );
- return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && pNext->IsVisible() ) ? TRUE : FALSE;
+ return ( pNext && ( pNext->GetDepth() > pParagraph->GetDepth() ) && pNext->IsVisible() ) ? sal_True : sal_False;
}
-ULONG ParagraphList::GetChildCount( Paragraph* pParent ) const
+sal_uLong ParagraphList::GetChildCount( Paragraph* pParent ) const
{
- ULONG nChildCount = 0;
- ULONG n = GetAbsPos( pParent );
+ sal_uLong nChildCount = 0;
+ sal_uLong n = GetAbsPos( pParent );
Paragraph* pPara = GetParagraph( ++n );
while ( pPara && ( pPara->GetDepth() > pParent->GetDepth() ) )
{
@@ -227,10 +254,10 @@ ULONG ParagraphList::GetChildCount( Paragraph* pParent ) const
return nChildCount;
}
-Paragraph* ParagraphList::GetParent( Paragraph* pParagraph /*, USHORT& rRelPos */ ) const
+Paragraph* ParagraphList::GetParent( Paragraph* pParagraph /*, sal_uInt16& rRelPos */ ) const
{
/* rRelPos = 0 */;
- ULONG n = GetAbsPos( pParagraph );
+ sal_uLong n = GetAbsPos( pParagraph );
Paragraph* pPrev = GetParagraph( --n );
while ( pPrev && ( pPrev->GetDepth() >= pParagraph->GetDepth() ) )
{
@@ -244,15 +271,15 @@ Paragraph* ParagraphList::GetParent( Paragraph* pParagraph /*, USHORT& rRelPos *
void ParagraphList::Expand( Paragraph* pParent )
{
- ULONG nChildCount = GetChildCount( pParent );
- ULONG nPos = GetAbsPos( pParent );
+ sal_uLong nChildCount = GetChildCount( pParent );
+ sal_uLong nPos = GetAbsPos( pParent );
- for ( ULONG n = 1; n <= nChildCount; n++ )
+ for ( sal_uLong n = 1; n <= nChildCount; n++ )
{
Paragraph* pPara = GetParagraph( nPos+n );
if ( !( pPara->IsVisible() ) )
{
- pPara->bVisible = TRUE;
+ pPara->bVisible = sal_True;
aVisibleStateChangedHdl.Call( pPara );
}
}
@@ -260,30 +287,46 @@ void ParagraphList::Expand( Paragraph* pParent )
void ParagraphList::Collapse( Paragraph* pParent )
{
- ULONG nChildCount = GetChildCount( pParent );
- ULONG nPos = GetAbsPos( pParent );
+ sal_uLong nChildCount = GetChildCount( pParent );
+ sal_uLong nPos = GetAbsPos( pParent );
- for ( ULONG n = 1; n <= nChildCount; n++ )
+ for ( sal_uLong n = 1; n <= nChildCount; n++ )
{
Paragraph* pPara = GetParagraph( nPos+n );
if ( pPara->IsVisible() )
{
- pPara->bVisible = FALSE;
+ pPara->bVisible = sal_False;
aVisibleStateChangedHdl.Call( pPara );
}
}
}
-ULONG ParagraphList::GetVisPos( Paragraph* pPara )
+sal_uLong ParagraphList::GetAbsPos( Paragraph* pParent ) const
+{
+ sal_uLong pos = 0;
+ std::vector<Paragraph*>::const_iterator iter;
+ for (iter = maEntries.begin(); iter != maEntries.end(); ++iter, ++pos)
+ {
+ if (*iter == pParent)
+ return pos;
+ }
+
+ return ~0;
+}
+
+sal_uLong ParagraphList::GetVisPos( Paragraph* pPara ) const
{
- ULONG nVisPos = 0;
- ULONG nPos = GetAbsPos( pPara );
- for ( ULONG n = 0; n < nPos; n++ )
+ sal_uLong nVisPos = 0;
+ std::vector<Paragraph*>::const_iterator iter;
+ for (iter = maEntries.begin(); iter != maEntries.end(); ++iter, ++nVisPos)
{
- Paragraph* _pPara = GetParagraph( n );
- if ( _pPara->IsVisible() )
- nVisPos++;
+ if (*iter == pPara)
+ break;
+
+ if ((*iter)->IsVisible())
+ ++nVisPos;
}
+
return nVisPos;
}