diff --git a/editeng/inc/editeng/svxrtf.hxx b/editeng/inc/editeng/svxrtf.hxx index c79f2bd..4d255da 100644 --- a/editeng/inc/editeng/svxrtf.hxx +++ b/editeng/inc/editeng/svxrtf.hxx @@ -29,7 +29,6 @@ #ifndef _SVXRTF_HXX #define _SVXRTF_HXX -#include #include #include #include @@ -39,6 +38,8 @@ #include #include #include +#include "boost/ptr_container/ptr_map.hpp" + class Font; class Color; class Graphic; @@ -85,8 +86,8 @@ public: typedef Color* ColorPtr; typedef std::deque< ColorPtr > SvxRTFColorTbl; -DECLARE_TABLE( SvxRTFFontTbl, Font* ) -DECLARE_TABLE( SvxRTFStyleTbl, SvxRTFStyleType* ) +typedef boost::ptr_map SvxRTFFontTbl; +typedef boost::ptr_map SvxRTFStyleTbl; typedef SvxRTFItemStackType* SvxRTFItemStackTypePtr; SV_DECL_PTRARR_DEL( SvxRTFItemStackList, SvxRTFItemStackTypePtr, 1 ) diff --git a/editeng/source/editeng/eertfpar.cxx b/editeng/source/editeng/eertfpar.cxx index d508716..4e7254f 100644 --- a/editeng/source/editeng/eertfpar.cxx +++ b/editeng/source/editeng/eertfpar.cxx @@ -371,10 +371,11 @@ void EditRTFParser::SetAttrInDoc( SvxRTFItemStackType &rSet ) if ( rSet.StyleNo() && pImpEditEngine->GetStyleSheetPool() && pImpEditEngine->GetStatus().DoImportRTFStyleSheets() ) { - SvxRTFStyleType* pS = GetStyleTbl().Get( rSet.StyleNo() ); - DBG_ASSERT( pS, "Template not defined in RTF!" ); - if ( pS ) + SvxRTFStyleTbl::iterator it = GetStyleTbl().find( rSet.StyleNo() ); + DBG_ASSERT( it != GetStyleTbl().end(), "Template not defined in RTF!" ); + if ( it != GetStyleTbl().end() ) { + SvxRTFStyleType* pS = it->second; pImpEditEngine->SetStyleSheet( EditSelection( aStartPaM, aEndPaM ), (SfxStyleSheet*)pImpEditEngine->GetStyleSheetPool()->Find( pS->sName, SFX_STYLE_FAMILY_ALL ) ); nOutlLevel = pS->nOutlineNo; } @@ -433,11 +434,17 @@ void EditRTFParser::SetAttrInDoc( SvxRTFItemStackType &rSet ) SvxRTFStyleType* EditRTFParser::FindStyleSheet( const XubString& rName ) { - SvxRTFStyleType* pS = GetStyleTbl().First(); - while ( pS && ( pS->sName != rName ) ) - pS = GetStyleTbl().Next(); + SvxRTFStyleTbl aTable = GetStyleTbl(); + SvxRTFStyleTbl::iterator it = aTable.begin(); + while ( it != aTable.end() ) + { + SvxRTFStyleType* pS = it->second; + if ( pS->sName == rName ) + return pS; + ++it; + } - return pS; + return NULL; } SfxStyleSheet* EditRTFParser::CreateStyleSheet( SvxRTFStyleType* pRTFStyle ) @@ -451,9 +458,13 @@ SfxStyleSheet* EditRTFParser::CreateStyleSheet( SvxRTFStyleType* pRTFStyle ) String aParent; if ( pRTFStyle->nBasedOn ) { - SvxRTFStyleType* pS = GetStyleTbl().Get( pRTFStyle->nBasedOn ); - if ( pS && ( pS !=pRTFStyle ) ) - aParent = pS->sName; + SvxRTFStyleTbl::iterator it = GetStyleTbl().find( pRTFStyle->nBasedOn ); + if ( it != GetStyleTbl().end()) + { + SvxRTFStyleType* pS = it->second; + if ( pS && ( pS !=pRTFStyle ) ) + aParent = pS->sName; + } } pStyle = (SfxStyleSheet*) &pImpEditEngine->GetStyleSheetPool()->Make( aName, SFX_STYLE_FAMILY_PARA ); @@ -484,12 +495,10 @@ void EditRTFParser::CreateStyleSheets() // the SvxRTFParser haa now created the template... if ( pImpEditEngine->GetStyleSheetPool() && pImpEditEngine->GetStatus().DoImportRTFStyleSheets() ) { - SvxRTFStyleType* pRTFStyle = GetStyleTbl().First(); - while ( pRTFStyle ) + for (SvxRTFStyleTbl::iterator it = GetStyleTbl().begin(); it != GetStyleTbl().end(); ++it) { + SvxRTFStyleType* pRTFStyle = it->second; CreateStyleSheet( pRTFStyle ); - - pRTFStyle = GetStyleTbl().Next(); } } } diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx index 8b9d93c..165c3c3 100644 --- a/editeng/source/rtf/svxrtf.cxx +++ b/editeng/source/rtf/svxrtf.cxx @@ -77,7 +77,6 @@ SvxRTFParser::SvxRTFParser( SfxItemPool& rPool, SvStream& rIn, int bReadNewDoc ) : SvRTFParser( rIn, 5 ), rStrm(rIn), - aFontTbl( 16, 4 ), pInsPos( 0 ), pAttrPool( &rPool ), m_xDocProps( i_xDocProps ), @@ -119,10 +118,6 @@ SvxRTFParser::~SvxRTFParser() { if( !aColorTbl.empty() ) ClearColorTbl(); - if( aFontTbl.Count() ) - ClearFontTbl(); - if( aStyleTbl.Count() ) - ClearStyleTbl(); if( !aAttrStack.empty() ) ClearAttrStack(); @@ -149,9 +144,9 @@ SvParserState SvxRTFParser::CallParser() if( !aColorTbl.empty() ) ClearColorTbl(); - if( aFontTbl.Count() ) + if( !aFontTbl.empty() ) ClearFontTbl(); - if( aStyleTbl.Count() ) + if( !aStyleTbl.empty() ) ClearStyleTbl(); if( !aAttrStack.empty() ) ClearAttrStack(); @@ -194,7 +189,7 @@ void SvxRTFParser::NextToken( int nToken ) case RTF_DEFF: if( bNewDoc ) { - if( aFontTbl.Count() ) + if( !aFontTbl.empty() ) // Can immediately be set SetDefault( nToken, nTokenValue ); else @@ -335,7 +330,7 @@ INSINGLECHAR: void SvxRTFParser::ReadStyleTable() { int nToken, bSaveChkStyleAttr = bChkStyleAttr; - short nStyleNo = 0; + sal_uInt16 nStyleNo = 0; int _nOpenBrakets = 1; // the first was already detected earlier!! SvxRTFStyleType* pStyle = new SvxRTFStyleType( *pAttrPool, &aWhichMap[0] ); pStyle->aAttrSet.Put( GetRTFDefaults() ); @@ -385,14 +380,12 @@ void SvxRTFParser::ReadStyleTable() { pStyle->sName = DelCharAtEnd( aToken, ';' ); - if( aStyleTbl.Count() ) + if( !aStyleTbl.empty() ) { - SvxRTFStyleType* pOldSt = aStyleTbl.Remove( nStyleNo ); - if( pOldSt ) - delete pOldSt; + aStyleTbl.erase(nStyleNo); } // All data from the font is available, so off to the table - aStyleTbl.Insert( nStyleNo, pStyle ); + aStyleTbl.insert( nStyleNo , pStyle); pStyle = new SvxRTFStyleType( *pAttrPool, &aWhichMap[0] ); pStyle->aAttrSet.Put( GetRTFDefaults() ); nStyleNo = 0; @@ -596,7 +589,7 @@ void SvxRTFParser::ReadFontTable() (sFntNm += ';' ) += sAltNm; pFont->SetName( sFntNm ); - aFontTbl.Insert( nInsFontNo, pFont ); + aFontTbl.insert( nInsFontNo, pFont ); pFont = new Font(); pFont->SetCharSet( nSystemChar ); sAltNm.Erase(); @@ -798,14 +791,12 @@ void SvxRTFParser::ClearColorTbl() void SvxRTFParser::ClearFontTbl() { - for( sal_uInt32 nCnt = aFontTbl.Count(); nCnt; ) - delete aFontTbl.GetObject( --nCnt ); + aFontTbl.clear(); } void SvxRTFParser::ClearStyleTbl() { - for( sal_uInt32 nCnt = aStyleTbl.Count(); nCnt; ) - delete aStyleTbl.GetObject( --nCnt ); + aStyleTbl.clear(); } void SvxRTFParser::ClearAttrStack() @@ -833,8 +824,9 @@ String& SvxRTFParser::DelCharAtEnd( String& rStr, const sal_Unicode cDel ) const Font& SvxRTFParser::GetFont( sal_uInt16 nId ) { - const Font* pFont = aFontTbl.Get( nId ); - if( !pFont ) + SvxRTFFontTbl::const_iterator it = aFontTbl.find( nId ); + const Font* pFont; + if( it == aFontTbl.end() ) { const SvxFontItem& rDfltFont = (const SvxFontItem&) pAttrPool->GetDefaultItem( @@ -843,6 +835,8 @@ const Font& SvxRTFParser::GetFont( sal_uInt16 nId ) pDfltFont->SetFamily( rDfltFont.GetFamily() ); pFont = pDfltFont; } + else + pFont = it->second; return *pFont; } @@ -872,10 +866,9 @@ void SvxRTFParser::_ClearStyleAttr( SvxRTFItemStackType& rStkType ) const SfxPoolItem* pItem; SfxWhichIter aIter( rSet ); - SvxRTFStyleType* pStyle; if( !IsChkStyleAttr() || !rStkType.GetAttrSet().Count() || - 0 == ( pStyle = aStyleTbl.Get( rStkType.nStyleNo ) )) + aStyleTbl.count( rStkType.nStyleNo ) == 0 ) { for( sal_uInt16 nWhich = aIter.GetCurWhich(); nWhich; nWhich = aIter.NextWhich() ) { @@ -889,6 +882,7 @@ void SvxRTFParser::_ClearStyleAttr( SvxRTFItemStackType& rStkType ) { // Delete all Attributes, which are already defined in the Style, // from the current AttrSet. + SvxRTFStyleType* pStyle = aStyleTbl.find( rStkType.nStyleNo )->second; SfxItemSet &rStyleSet = pStyle->aAttrSet; const SfxPoolItem* pSItem; for( sal_uInt16 nWhich = aIter.GetCurWhich(); nWhich; nWhich = aIter.NextWhich() ) diff --git a/sw/source/filter/rtf/rtffld.cxx b/sw/source/filter/rtf/rtffld.cxx index 51741e1..1be8e49 100644 --- a/sw/source/filter/rtf/rtffld.cxx +++ b/sw/source/filter/rtf/rtffld.cxx @@ -595,8 +595,11 @@ int SwRTFParser::MakeFieldInst( String& rFieldStr ) // Font setzen { SvxRTFFontTbl& rTbl = GetFontTbl(); - for( Font* pFont = rTbl.First(); pFont; - pFont = rTbl.Next() ) + + for( SvxRTFFontTbl::iterator it = rTbl.begin(); + it != rTbl.end(); ++it ) + { + Font* pFont = it->second; if( pFont->GetName() == sParam ) { rSet.Put( SvxFontItem( @@ -608,6 +611,7 @@ int SwRTFParser::MakeFieldInst( String& rFieldStr ) RES_CHRATR_FONT )); break; } + } } break; case 'h': case 'H': diff --git a/sw/source/filter/rtf/rtfnum.cxx b/sw/source/filter/rtf/rtfnum.cxx index 07b3319..dc283be 100644 --- a/sw/source/filter/rtf/rtfnum.cxx +++ b/sw/source/filter/rtf/rtfnum.cxx @@ -585,7 +585,7 @@ void SwRTFParser::ReadListOverrideTable() } // search the outline numrule and set it into the doc - if( GetStyleTbl().Count() ) + if( !GetStyleTbl().empty() ) { if( !bStyleTabValid ) MakeStyleTab(); @@ -594,11 +594,12 @@ void SwRTFParser::ReadListOverrideTable() std::map::const_iterator iterColl; sal_uInt16 nRulePos( USHRT_MAX ); const SwNumRule *pNumRule = 0; - SvxRTFStyleType* pStyle = GetStyleTbl().First(); + SvxRTFStyleTbl::iterator it = GetStyleTbl().begin(); do { + SvxRTFStyleType* pStyle = it->second; if ( MAXLEVEL > pStyle->nOutlineNo ) { - iterColl = aTxtCollTbl.find( (sal_uInt16)GetStyleTbl().GetCurKey() ); + iterColl = aTxtCollTbl.find( it->first ); if ( iterColl != aTxtCollTbl.end() ) { const SfxItemState eItemState = @@ -634,8 +635,9 @@ void SwRTFParser::ReadListOverrideTable() } pStyle->aAttrSet.ClearItem( FN_PARAM_NUM_LEVEL ); - - } while( 0 != (pStyle = GetStyleTbl().Next()) ); + + ++it; + } while( it != GetStyleTbl().end() ); } SkipToken( -1 ); // die schliesende Klammer wird "oben" ausgewertet @@ -723,17 +725,15 @@ void SwRTFParser::RemoveUnusedNumRules() const Font* SwRTFParser::FindFontOfItem( const SvxFontItem& rItem ) const { SvxRTFFontTbl& rFntTbl = ((SwRTFParser*)this)->GetFontTbl(); - const Font* pFnt = rFntTbl.First(); - while( pFnt ) + for (SvxRTFFontTbl::iterator it = rFntTbl.begin(); it != rFntTbl.end(); ++it) { + const Font* pFnt = it->second; if( pFnt->GetFamily() == rItem.GetFamily() && pFnt->GetName() == rItem.GetFamilyName() && pFnt->GetStyleName() == rItem.GetStyleName() && pFnt->GetPitch() == rItem.GetPitch() && pFnt->GetCharSet() == rItem.GetCharSet() ) return pFnt; - - pFnt = rFntTbl.Next(); } return 0; } diff --git a/sw/source/filter/rtf/swparrtf.cxx b/sw/source/filter/rtf/swparrtf.cxx index 81abb16..2a2359b 100644 --- a/sw/source/filter/rtf/swparrtf.cxx +++ b/sw/source/filter/rtf/swparrtf.cxx @@ -2195,8 +2195,9 @@ void SwRTFParser::SetAttrInDoc( SvxRTFItemStackType &rSet ) ((SwFmtCharFmt*)pCharFmt)->GetCharFmt() ) { const String& rName = ((SwFmtCharFmt*)pCharFmt)->GetCharFmt()->GetName(); - SvxRTFStyleType* pStyle = GetStyleTbl().First(); - do { + for (SvxRTFStyleTbl::iterator it = GetStyleTbl().begin(); it != GetStyleTbl().end(); ++it) + { + SvxRTFStyleType* pStyle = it->second; if( pStyle->bIsCharFmt && pStyle->sName == rName ) { // alle Attribute, die schon vom Style definiert sind, aus dem @@ -2218,7 +2219,7 @@ void SwRTFParser::SetAttrInDoc( SvxRTFItemStackType &rSet ) } break; } - } while( 0 != (pStyle = GetStyleTbl().Next()) ); + } pDoc->InsertPoolItem(aPam, *pCharFmt, 0); rSet.GetAttrSet().ClearItem(RES_TXTATR_CHARFMT); //test hack @@ -2734,7 +2735,7 @@ void SwRTFParser::ReadDocControls( int nToken ) void SwRTFParser::MakeStyleTab() { // dann erzeuge aus der SvxStyle-Tabelle die Swg-Collections - if( GetStyleTbl().Count() ) + if( !GetStyleTbl().empty() ) { sal_uInt16 nValidOutlineLevels = 0; if( !IsNewDoc() ) @@ -2746,9 +2747,10 @@ void SwRTFParser::MakeStyleTab() nValidOutlineLevels |= 1 << rColls[ n ]->GetAssignedOutlineStyleLevel();//<-end,zhaojianwei } - SvxRTFStyleType* pStyle = GetStyleTbl().First(); - do { - sal_uInt16 nNo = sal_uInt16( GetStyleTbl().GetCurKey() ); + for (SvxRTFStyleTbl::iterator it = GetStyleTbl().begin(); it != GetStyleTbl().end(); ++it) + { + sal_uInt16 nNo = it->first; + SvxRTFStyleType* pStyle = it->second; if( pStyle->bIsCharFmt ) { if(aCharFmtTbl.find( nNo ) == aCharFmtTbl.end()) @@ -2761,7 +2763,7 @@ void SwRTFParser::MakeStyleTab() MakeStyle( nNo, *pStyle ); } - } while( 0 != (pStyle = GetStyleTbl().Next()) ); + } bStyleTabValid = sal_True; } } @@ -3996,7 +3998,10 @@ SwTxtFmtColl* SwRTFParser::MakeStyle( sal_uInt16 nNo, const SvxRTFStyleType& rSt sal_uInt16 nStyleNo = rStyle.nBasedOn; if( rStyle.bBasedOnIsSet && nStyleNo != nNo ) { - SvxRTFStyleType* pDerivedStyle = GetStyleTbl().Get( nStyleNo ); + SvxRTFStyleTbl::iterator styleIter = GetStyleTbl().find( nStyleNo ); + SvxRTFStyleType* pDerivedStyle = NULL; + if ( styleIter != GetStyleTbl().end() ) + pDerivedStyle = styleIter->second; SwTxtFmtColl* pDerivedColl = NULL; std::map::iterator iter = aTxtCollTbl.find(nStyleNo); @@ -4041,10 +4046,11 @@ SwTxtFmtColl* SwRTFParser::MakeStyle( sal_uInt16 nNo, const SvxRTFStyleType& rSt if( iter == aTxtCollTbl.end()) // noch nicht vorhanden, also anlegen { // ist die ueberhaupt als Style vorhanden ? - SvxRTFStyleType* pMkStyle = GetStyleTbl().Get( nStyleNo ); - pNext = pMkStyle - ? MakeStyle( nStyleNo, *pMkStyle ) - : pDoc->GetTxtCollFromPool( RES_POOLCOLL_STANDARD, false ); + SvxRTFStyleTbl::iterator styleIter = GetStyleTbl().find( nStyleNo ); + if ( styleIter != GetStyleTbl().end() ) + pNext = MakeStyle( nStyleNo, *styleIter->second ); + else + pNext = pDoc->GetTxtCollFromPool( RES_POOLCOLL_STANDARD, false ); } else pNext = iter->second; @@ -4067,7 +4073,11 @@ SwCharFmt* SwRTFParser::MakeCharStyle( sal_uInt16 nNo, const SvxRTFStyleType& rS sal_uInt16 nStyleNo = rStyle.nBasedOn; if( rStyle.bBasedOnIsSet && nStyleNo != nNo ) { - SvxRTFStyleType* pDerivedStyle = GetStyleTbl().Get( nStyleNo ); + SvxRTFStyleTbl::iterator styleIter = GetStyleTbl().find( nStyleNo ); + SvxRTFStyleType* pDerivedStyle = NULL; + if ( styleIter != GetStyleTbl().end() ) + pDerivedStyle = styleIter->second; + SwCharFmt* pDerivedFmt = NULL; std::map::iterator iter = aCharFmtTbl.find( nStyleNo );