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.cxx131
1 files changed, 88 insertions, 43 deletions
diff --git a/editeng/source/outliner/paralist.cxx b/editeng/source/outliner/paralist.cxx
index e1fc065a3f39..ee7d518b4137 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()
@@ -123,74 +126,100 @@ void ParagraphList::Clear( 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::Append( Paragraph* pPara)
+{
+ maEntries.push_back(pPara);
+}
+
+void ParagraphList::Insert( Paragraph* pPara, ULONG nAbsPos)
+{
+ OSL_ASSERT(nAbsPos != ULONG_MAX && nAbsPos <= maEntries.size());
+
+ maEntries.insert(maEntries.begin()+nAbsPos,pPara);
+}
+
+void ParagraphList::Remove( ULONG nPara )
+{
+ OSL_ASSERT(nPara < maEntries.size());
+
+ maEntries.erase(maEntries.begin() + nPara );
}
void ParagraphList::MoveParagraphs( ULONG nStart, ULONG nDest, 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 );
+ std::vector<Paragraph*>::const_iterator iter = std::find(maEntries.begin(),
+ maEntries.end(),
+ pPara);
- Paragraph* p = GetParagraph( ++n );
- while ( p && !p->IsVisible() )
- p = GetParagraph( ++n );
+ 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 );
+ std::vector<Paragraph*>::const_reverse_iterator iter = std::find(maEntries.rbegin(),
+ maEntries.rend(),
+ pPara);
- Paragraph* p = n ? GetParagraph( --n ) : NULL;
- while ( p && !p->IsVisible() )
- p = n ? GetParagraph( --n ) : NULL;
+ 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
@@ -274,16 +303,32 @@ void ParagraphList::Collapse( Paragraph* pParent )
}
}
-ULONG ParagraphList::GetVisPos( Paragraph* pPara )
+ULONG ParagraphList::GetAbsPos( Paragraph* pParent ) const
+{
+ 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;
+}
+
+ULONG ParagraphList::GetVisPos( Paragraph* pPara ) const
{
ULONG nVisPos = 0;
- ULONG nPos = GetAbsPos( pPara );
- for ( ULONG n = 0; n < nPos; n++ )
+ 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;
}