diff options
author | npcdoom <venccsralph@gmail.com> | 2011-02-27 21:14:03 -0430 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2011-03-04 12:10:56 +0100 |
commit | bc25156521ee3f636ad702b5ae2d5972323a8a7b (patch) | |
tree | d0ddbfb29d8a48b0417abcab8fea4b2bce0fd5f1 /editeng/source/outliner | |
parent | 7ef6def27889f683e45199d45cc55d417ef1f0dd (diff) |
Remove deprecated List container.
- Converted List to std::vector<Paragraph*>.
- Added Append member function to ParagraphList.
- Updated needed functions from Insert to Append in
outliner/outliner.cxx.
Signed-off-by: Luboš Luňák <l.lunak@suse.cz>
Diffstat (limited to 'editeng/source/outliner')
-rw-r--r-- | editeng/source/outliner/outliner.cxx | 2 | ||||
-rw-r--r-- | editeng/source/outliner/paralist.cxx | 118 | ||||
-rw-r--r-- | editeng/source/outliner/paralist.hxx | 35 |
3 files changed, 101 insertions, 54 deletions
diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx index ea79c8e14371..a316cfefba40 100644 --- a/editeng/source/outliner/outliner.cxx +++ b/editeng/source/outliner/outliner.cxx @@ -603,7 +603,7 @@ void Outliner::SetText( const OutlinerParaObject& rPObj ) Paragraph* pPara = new Paragraph( rPObj.GetParagraphData(nCurPara)); ImplCheckDepth( pPara->nDepth ); - pParaList->Insert( pPara, LIST_APPEND ); + pParaList->Append(pPara); ImplCheckNumBulletItem( nCurPara ); } diff --git a/editeng/source/outliner/paralist.cxx b/editeng/source/outliner/paralist.cxx index 9e2763e55b34..300354f1340d 100644 --- a/editeng/source/outliner/paralist.cxx +++ b/editeng/source/outliner/paralist.cxx @@ -123,36 +123,47 @@ 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) +{ + maEntries.insert(maEntries.begin()+nAbsPos,pPara); +} + +void ParagraphList::Remove( ULONG nPara ) +{ + maEntries.erase(maEntries.begin() + nPara ); } void ParagraphList::MoveParagraphs( ULONG nStart, ULONG nDest, ULONG _nCount ) { 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 + 1; + + 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 { @@ -162,35 +173,44 @@ void ParagraphList::MoveParagraphs( ULONG nStart, ULONG nDest, ULONG _nCount ) 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 +294,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; } diff --git a/editeng/source/outliner/paralist.hxx b/editeng/source/outliner/paralist.hxx index e63c73c4fad7..f751c97aea9d 100644 --- a/editeng/source/outliner/paralist.hxx +++ b/editeng/source/outliner/paralist.hxx @@ -29,27 +29,33 @@ #ifndef _PARALIST_HXX #define _PARALIST_HXX -class Paragraph; +#include <vector> -#include <tools/list.hxx> #include <tools/link.hxx> -class ParagraphList : private List -{ -private: - Link aVisibleStateChangedHdl; +class Paragraph; +class ParagraphList +{ public: void Clear( BOOL bDestroyParagraphs ); - ULONG GetParagraphCount() const { return List::Count(); } - Paragraph* GetParagraph( ULONG nPos ) const { return (Paragraph*)List::GetObject( nPos ); } + sal_uInt32 GetParagraphCount() const + { + return maEntries.size(); + } - ULONG GetAbsPos( Paragraph* pParent ) const { return List::GetPos( pParent ); } - ULONG GetVisPos( Paragraph* pParagraph ); + Paragraph* GetParagraph( ULONG nPos ) const + { + return nPos < maEntries.size() ? maEntries[nPos] : NULL; + } - void Insert( Paragraph* pPara, ULONG nAbsPos = LIST_APPEND ) { List::Insert( pPara, nAbsPos ); } - void Remove( ULONG nPara ) { List::Remove( nPara ); } + ULONG GetAbsPos( Paragraph* pParent ) const; + ULONG GetVisPos( Paragraph* pParagraph ) const; + + void Append( Paragraph *pPara); + void Insert( Paragraph* pPara, ULONG nAbsPos); + void Remove( ULONG nPara ); void MoveParagraphs( ULONG nStart, ULONG nDest, ULONG nCount ); Paragraph* NextVisible( Paragraph* ) const; @@ -67,6 +73,11 @@ public: void SetVisibleStateChangedHdl( const Link& rLink ) { aVisibleStateChangedHdl = rLink; } Link GetVisibleStateChangedHdl() const { return aVisibleStateChangedHdl; } + +private: + + Link aVisibleStateChangedHdl; + std::vector<Paragraph*> maEntries; }; #endif |