From f5ec08d4d8ff64cbae83e47ac2159eb3a546bc79 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Mon, 13 Aug 2012 09:57:31 +0200 Subject: Convert ParagraphObj from tools/list.hxx to std::vector Also convert mpList to maList in ImplTextObject because its lifecycle is completely tied to it's containing struct. Change-Id: Ie1a35b604bbe539f3ae1303e3873e47ddae38cbc --- sd/source/filter/eppt/eppt.hxx | 1 + sd/source/filter/eppt/epptso.cxx | 56 ++++++++++++++++++++++--------------- sd/source/filter/eppt/pptx-text.cxx | 38 +++++++++++-------------- sd/source/filter/eppt/text.hxx | 9 +++--- 4 files changed, 55 insertions(+), 49 deletions(-) (limited to 'sd') diff --git a/sd/source/filter/eppt/eppt.hxx b/sd/source/filter/eppt/eppt.hxx index f4b60b236c4f..d368bb9ff853 100644 --- a/sd/source/filter/eppt/eppt.hxx +++ b/sd/source/filter/eppt/eppt.hxx @@ -36,6 +36,7 @@ #include #include #include +#include #include "pptexanimations.hxx" #include diff --git a/sd/source/filter/eppt/epptso.cxx b/sd/source/filter/eppt/epptso.cxx index dcb752f6a9ed..857619337640 100644 --- a/sd/source/filter/eppt/epptso.cxx +++ b/sd/source/filter/eppt/epptso.cxx @@ -739,10 +739,11 @@ void PPTWriter::ImplWriteParagraphs( SvStream& rOut, TextObj& rTextObj ) sal_Int16 nLineSpacing; int nInstance = rTextObj.GetInstance(); - for ( ParagraphObj* pPara = rTextObj.First() ; pPara; pPara = rTextObj.Next(), bFirstParagraph = sal_False ) + for ( sal_uInt32 i = 0; i < rTextObj.ParagraphCount(); ++i, bFirstParagraph = sal_False ) { - PortionObj* pPortion = (PortionObj*)pPara->First(); - nCharCount = pPara->Count(); + ParagraphObj* pPara = rTextObj.GetParagraph(i); + PortionObj* pPortion = pPara->front(); + nCharCount = pPara->size(); nDepth = pPara->nDepth; if ( nDepth > 4) @@ -866,13 +867,15 @@ void PPTWriter::ImplWriteParagraphs( SvStream& rOut, TextObj& rTextObj ) void PPTWriter::ImplWritePortions( SvStream& rOut, TextObj& rTextObj ) { - sal_uInt32 nPropertyFlags, i = 0; + sal_uInt32 nPropertyFlags; int nInstance = rTextObj.GetInstance(); - for ( ParagraphObj* pPara = rTextObj.First(); pPara; pPara = rTextObj.Next(), i++ ) + for ( sal_uInt32 i = 0; i < rTextObj.ParagraphCount(); ++i ) { - for ( PortionObj* pPortion = (PortionObj*)pPara->First(); pPortion; pPortion = (PortionObj*)pPara->Next() ) + ParagraphObj* pPara = rTextObj.GetParagraph(i); + for ( ParagraphObj::const_iterator it = pPara->begin(); it != pPara->end(); ++it ) { + PortionObj* pPortion = *it; nPropertyFlags = 0; sal_uInt32 nCharAttr = pPortion->mnCharAttr; sal_uInt32 nCharColor = pPortion->mnCharColor; @@ -1109,12 +1112,12 @@ void PPTWriter::ImplAdjustFirstLineLineSpacing( TextObj& rTextObj, EscherPropert { if ( !mbFontIndependentLineSpacing ) { - ParagraphObj* pPara = rTextObj.First(); - if ( pPara ) + if ( rTextObj.ParagraphCount() ) { - PortionObj* pPortion = (PortionObj*)pPara->First(); - if ( pPortion ) + ParagraphObj* pPara = rTextObj.GetParagraph(0); + if ( !pPara->empty() ) { + PortionObj* pPortion = pPara->front(); sal_Int16 nLineSpacing = pPara->mnLineSpacing; const FontCollectionEntry* pDesc = maFontCollection.GetById( pPortion->mnFont ); if ( pDesc ) @@ -1172,10 +1175,12 @@ void PPTWriter::ImplWriteTextStyleAtom( SvStream& rOut, int nTextInstance, sal_u rOut << (sal_uInt32)( nSize - 8 ); rOut.SeekRel( nSize - 8 ); - for ( pPara = aTextObj.First(); pPara; pPara = aTextObj.Next() ) + for ( sal_uInt32 i = 0; i < aTextObj.ParagraphCount(); ++i ) { - for ( PortionObj* pPortion = (PortionObj*)pPara->First(); pPortion; pPortion = (PortionObj*)pPara->Next() ) + pPara = aTextObj.GetParagraph(i); + for ( ParagraphObj::const_iterator it = pPara->begin(); it != pPara->end(); ++it ) { + PortionObj* pPortion = *it; if ( pPortion->mpFieldEntry ) { const FieldEntry* pFieldEntry = pPortion->mpFieldEntry; @@ -1282,17 +1287,18 @@ void PPTWriter::ImplWriteTextStyleAtom( SvStream& rOut, int nTextInstance, sal_u aTextObj.WriteTextSpecInfo( &rOut ); // Star Office Default TabSizes schreiben ( wenn noetig ) - pPara = aTextObj.First(); - if ( pPara ) + if ( aTextObj.ParagraphCount() ) { + pPara = aTextObj.GetParagraph(0); sal_uInt32 nParaFlags = 0x1f; sal_Int16 nDepth, nMask, nNumberingRule[ 10 ]; sal_uInt32 nTextOfs = pPara->nTextOfs; sal_uInt32 nTabs = pPara->maTabStop.getLength(); const ::com::sun::star::style::TabStop* pTabStop = ( const ::com::sun::star::style::TabStop* )pPara->maTabStop.getConstArray(); - for ( ; pPara; pPara = aTextObj.Next() ) + for ( sal_uInt32 i = 0; i < aTextObj.ParagraphCount(); ++i ) { + pPara = aTextObj.GetParagraph(i); if ( pPara->bExtendedParameters ) { nDepth = pPara->nDepth; @@ -1381,16 +1387,17 @@ void PPTWriter::ImplWriteTextStyleAtom( SvStream& rOut, int nTextInstance, sal_u } if ( aTextObj.HasExtendedBullets() ) { - ParagraphObj* pBulletPara = aTextObj.First(); - if ( pBulletPara ) + if ( aTextObj.ParagraphCount() ) { + ParagraphObj* pBulletPara = aTextObj.GetParagraph(0); sal_uInt32 nBulletFlags = 0; sal_uInt32 nNumberingType = 0, nPos2 = rExtBuStr.Tell(); rExtBuStr << (sal_uInt32)( EPP_PST_ExtendedParagraphAtom << 16 ) << (sal_uInt32)0; - for ( ; pBulletPara; pBulletPara = aTextObj.Next() ) + for ( sal_uInt32 i = 0; i < aTextObj.ParagraphCount(); ++i ) { + pBulletPara = aTextObj.GetParagraph(i); nBulletFlags = 0; sal_uInt16 nBulletId = pBulletPara->nBulletId; if ( pBulletPara->bExtendedBulletsUsed ) @@ -2972,8 +2979,9 @@ void PPTWriter::ImplWritePage( const PHLayout& rLayout, EscherSolverContainer& a mnTextSize = aTextObj.Count(); aTextObj.Write( mpStrm ); mpPptEscherEx->BeginAtom(); - for ( ParagraphObj* pPara = aTextObj.First() ; pPara; pPara = aTextObj.Next() ) + for ( sal_uInt32 i = 0; i < aTextObj.ParagraphCount() ; ++i ) { + ParagraphObj* pPara = aTextObj.GetParagraph(i); sal_uInt32 nCharCount = pPara->Count(); sal_uInt16 nDepth = pPara->nDepth; if ( nDepth > 4) @@ -3830,8 +3838,8 @@ void TextObjBinary::Write( SvStream* pStrm ) { sal_uInt32 nSize, nPos = pStrm->Tell(); *pStrm << (sal_uInt32)( EPP_TextCharsAtom << 16 ) << (sal_uInt32)0; - for ( void* pPtr = First(); pPtr; pPtr = Next() ) - ((ParagraphObj*)pPtr)->Write( pStrm ); + for ( sal_uInt32 i = 0; i < ParagraphCount(); ++i ) + GetParagraph(i)->Write( pStrm ); nSize = pStrm->Tell() - nPos; pStrm->SeekRel( - ( (sal_Int32)nSize - 4 ) ); *pStrm << (sal_uInt32)( nSize - 8 ); @@ -3844,10 +3852,12 @@ void TextObjBinary::WriteTextSpecInfo( SvStream* pStrm ) if ( nCharactersLeft >= 1 ) { EscherExAtom aAnimationInfoAtom( *pStrm, EPP_TextSpecInfoAtom, 0, 0 ); - for ( ParagraphObj* pPtr = static_cast < ParagraphObj * >( First() ); nCharactersLeft && pPtr; pPtr = static_cast< ParagraphObj* >( Next() ) ) + for ( sal_uInt32 i = 0; nCharactersLeft && i < ParagraphCount(); ++i ) { - for ( PortionObj* pPortion = static_cast< PortionObj* >( pPtr->First() ); nCharactersLeft && pPortion; pPortion = static_cast< PortionObj* >( pPtr->Next() ) ) + ParagraphObj* pPtr = GetParagraph(i); + for ( ParagraphObj::const_iterator it = pPtr->begin(); nCharactersLeft && it != pPtr->end(); ++it ) { + PortionObj* pPortion = *it; sal_Int32 nPortionSize = pPortion->mnTextSize >= nCharactersLeft ? nCharactersLeft : pPortion->mnTextSize; sal_Int32 nFlags = 7; nCharactersLeft -= nPortionSize; diff --git a/sd/source/filter/eppt/pptx-text.cxx b/sd/source/filter/eppt/pptx-text.cxx index f264c7c4c8c1..f1bc0dd32e1f 100644 --- a/sd/source/filter/eppt/pptx-text.cxx +++ b/sd/source/filter/eppt/pptx-text.cxx @@ -692,7 +692,7 @@ ParagraphObj::ParagraphObj( const ::com::sun::star::uno::Reference< ::com::sun:: { PortionObj* pPortionObj = new PortionObj( aXCursorText, !aXTextPortionE->hasMoreElements(), rFontCollection ); if ( pPortionObj->Count() ) - Insert( pPortionObj, LIST_APPEND ); + push_back( pPortionObj ); else delete pPortionObj; } @@ -704,7 +704,7 @@ ParagraphObj::ParagraphObj( const ::com::sun::star::uno::Reference< ::com::sun:: } ParagraphObj::ParagraphObj( const ParagraphObj& rObj ) -: List() +: std::vector() , PropStateValue() , SOParagraph() { @@ -718,14 +718,14 @@ ParagraphObj::~ParagraphObj() void ParagraphObj::Write( SvStream* pStrm ) { - for ( void* pPtr = First(); pPtr; pPtr = Next() ) - ((PortionObj*)pPtr)->Write( pStrm, mbLastParagraph ); + for ( const_iterator it = begin(); it != end(); ++it ) + (*it)->Write( pStrm, mbLastParagraph ); } void ParagraphObj::ImplClear() { - for ( void* pPtr = First(); pPtr; pPtr = Next() ) - delete (PortionObj*)pPtr; + for ( const_iterator it = begin(); it != end(); ++it ) + delete *it; } void ParagraphObj::CalculateGraphicBulletSize( sal_uInt16 nFontHeight ) @@ -884,7 +884,7 @@ void ParagraphObj::ImplGetNumberingLevel( PPTExBulletProvider& rBuProv, sal_Int1 } } - PortionObj* pPortion = (PortionObj*)First(); + PortionObj* pPortion = front(); CalculateGraphicBulletSize( ( pPortion ) ? pPortion->mnCharHeight : 24 ); switch( (SvxExtNumType)nNumberingType ) @@ -1145,11 +1145,8 @@ void ParagraphObj::ImplConstruct( const ParagraphObj& rParagraphObj ) mbForbiddenRules = rParagraphObj.mbForbiddenRules; mnBiDi = rParagraphObj.mnBiDi; - { - ParagraphObj& rConstApiLossage = const_cast(rParagraphObj); - for ( const void* pPtr = rConstApiLossage.First(); pPtr; pPtr = rConstApiLossage.Next() ) - Insert( new PortionObj( *static_cast(pPtr) ), LIST_APPEND ); - } + for ( ParagraphObj::const_iterator it = rParagraphObj.begin(); it != rParagraphObj.end(); ++it ) + push_back( new PortionObj( **it ) ); maTabStop = rParagraphObj.maTabStop; bExtendedParameters = rParagraphObj.bExtendedParameters; @@ -1177,8 +1174,8 @@ void ParagraphObj::ImplConstruct( const ParagraphObj& rParagraphObj ) sal_uInt32 ParagraphObj::ImplCalculateTextPositions( sal_uInt32 nCurrentTextPosition ) { mnTextSize = 0; - for ( void* pPtr = First(); pPtr; pPtr = Next() ) - mnTextSize += ((PortionObj*)pPtr)->ImplCalculateTextPositions( nCurrentTextPosition + mnTextSize ); + for ( const_iterator it = begin(); it != end(); ++it ) + mnTextSize += (*it)->ImplCalculateTextPositions( nCurrentTextPosition + mnTextSize ); return mnTextSize; } @@ -1193,20 +1190,19 @@ ParagraphObj& ParagraphObj::operator=( const ParagraphObj& rParagraphObj ) } ImplTextObj::ImplTextObj( int nInstance ) + : maList() { mnRefCount = 1; mnTextSize = 0; mnInstance = nInstance; - mpList = new List; mbHasExtendedBullets = sal_False; mbFixedCellHeightUsed = sal_False; } ImplTextObj::~ImplTextObj() { - for ( ParagraphObj* pPtr = (ParagraphObj*)mpList->First(); pPtr; pPtr = (ParagraphObj*)mpList->Next() ) - delete pPtr; - delete mpList; + for ( std::vector::const_iterator it = maList.begin(); it != maList.end(); ++it ) + delete *it; } TextObj::TextObj( ::com::sun::star::uno::Reference< ::com::sun::star::text::XSimpleText > & rXTextRef, @@ -1234,7 +1230,7 @@ TextObj::TextObj( ::com::sun::star::uno::Reference< ::com::sun::star::text::XSim aParaFlags.bLastParagraph = sal_True; ParagraphObj* pPara = new ParagraphObj( aXParagraph, aParaFlags, rFontCollection, rProv ); mpImplTextObj->mbHasExtendedBullets |= pPara->bExtendedBulletsUsed; - mpImplTextObj->mpList->Insert( pPara, LIST_APPEND ); + mpImplTextObj->maList.push_back( pPara ); aParaFlags.bFirstParagraph = sal_False; } } @@ -1258,8 +1254,8 @@ TextObj::~TextObj() void TextObj::ImplCalculateTextPositions() { mpImplTextObj->mnTextSize = 0; - for ( void* pPtr = First(); pPtr; pPtr = Next() ) - mpImplTextObj->mnTextSize += ((ParagraphObj*)pPtr)->ImplCalculateTextPositions( mpImplTextObj->mnTextSize ); + for ( sal_uInt32 i = 0; i < ParagraphCount(); ++i ) + mpImplTextObj->mnTextSize += GetParagraph(i)->ImplCalculateTextPositions( mpImplTextObj->mnTextSize ); } TextObj& TextObj::operator=( TextObj& rTextObj ) diff --git a/sd/source/filter/eppt/text.hxx b/sd/source/filter/eppt/text.hxx index 8f5c257d6ea6..40ffa57f6077 100644 --- a/sd/source/filter/eppt/text.hxx +++ b/sd/source/filter/eppt/text.hxx @@ -35,7 +35,6 @@ #include #include #include -#include namespace com { namespace sun { namespace star { namespace awt { struct FontDescriptor; } @@ -169,7 +168,7 @@ struct ParaFlags ParaFlags() { bFirstParagraph = sal_True; bLastParagraph = sal_False; }; }; -class ParagraphObj : public List, public PropStateValue, public SOParagraph +class ParagraphObj : public std::vector, public PropStateValue, public SOParagraph { friend class TextObj; friend struct PPTExParaSheet; @@ -234,7 +233,7 @@ struct ImplTextObj sal_uInt32 mnRefCount; sal_uInt32 mnTextSize; int mnInstance; - List* mpList; + std::vector maList; sal_Bool mbHasExtendedBullets; sal_Bool mbFixedCellHeightUsed; @@ -253,8 +252,8 @@ class TextObj TextObj( const TextObj& rTextObj ); ~TextObj(); - ParagraphObj* First(){ return (ParagraphObj*)mpImplTextObj->mpList->First(); }; - ParagraphObj* Next(){ return(ParagraphObj*)mpImplTextObj->mpList->Next(); }; + ParagraphObj* GetParagraph(int idx) { return mpImplTextObj->maList[idx]; }; + sal_uInt32 ParagraphCount() const { return mpImplTextObj->maList.size(); }; sal_uInt32 Count() const { return mpImplTextObj->mnTextSize; }; int GetInstance() const { return mpImplTextObj->mnInstance; }; sal_Bool HasExtendedBullets(){ return mpImplTextObj->mbHasExtendedBullets; }; -- cgit v1.2.3