diff options
author | Muthu Subramanian <sumuthu@collabora.com> | 2014-02-13 16:10:47 +0530 |
---|---|---|
committer | Muthu Subramanian <sumuthu@collabora.com> | 2014-02-13 16:13:01 +0530 |
commit | a4cd841541a729d7b8126d27d91fa28e30b01403 (patch) | |
tree | f8be9dc829674972b0e634c337ae1701b65350b9 | |
parent | c388071c4d1bee70e41f9ff72d50e5966bb8f237 (diff) |
n#757432: Styles (rename &) copy to different decks.
While copying slides to different slide decks,
styles were not being copied if there is already one
with the same name. This patch renames and copies those
to keep the formatting intact.
Change-Id: I66f71493f1fd658eed43e39aa7ae7ee7b5463b34
-rw-r--r-- | include/svl/itemset.hxx | 2 | ||||
-rw-r--r-- | sd/inc/stlpool.hxx | 5 | ||||
-rw-r--r-- | sd/source/core/drawdoc3.cxx | 40 | ||||
-rw-r--r-- | sd/source/core/stlpool.cxx | 93 | ||||
-rw-r--r-- | svl/source/items/itemset.cxx | 23 |
5 files changed, 161 insertions, 2 deletions
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx index 7157ecfabf56..228428158fc4 100644 --- a/include/svl/itemset.hxx +++ b/include/svl/itemset.hxx @@ -144,6 +144,8 @@ public: virtual SvStream & Store( SvStream &, bool bDirect = false ) const; bool operator==(const SfxItemSet &) const; + virtual sal_uInt64 getHash() const; + virtual OString stringify() const; }; inline void SfxItemSet::SetParent( const SfxItemSet* pNew ) diff --git a/sd/inc/stlpool.hxx b/sd/inc/stlpool.hxx index 3d2cdc9cedf8..8c0e993d2146 100644 --- a/sd/inc/stlpool.hxx +++ b/sd/inc/stlpool.hxx @@ -82,6 +82,8 @@ public: void CopyTableStyles(SdStyleSheetPool& rSourcePool); void CopyGraphicSheets(SdStyleSheetPool& rSourcePool, SdStyleSheetVector& rCreatedSheets); void CopyCellSheets(SdStyleSheetPool& rSourcePool, SdStyleSheetVector& rCreatedSheets); + void RenameAndCopyGraphicSheets(SdStyleSheetPool& rSourcePool, OUString &rRenameSuffix); + void RenameAndCopyGraphicSheets(SdStyleSheetPool& rSourcePool, SdStyleSheetVector& rCreatedSheets, OUString &rRenameSuffix); void CreatePseudosIfNecessary(); void UpdateStdNames(); @@ -122,8 +124,11 @@ public: virtual void SAL_CALL acquire (void) throw (); virtual void SAL_CALL release (void) throw (); protected: + void RenameAndCopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, SdStyleSheetVector& rCreatedSheets, OUString &rRenameSuffix); + void RenameAndCopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, OUString &rRenameSuffix); void CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily ); void CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, SdStyleSheetVector& rCreatedSheets ); + void CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, SdStyleSheetVector& rCreatedSheets, OUString &rRenameSuffix ); virtual SfxStyleSheetBase* Create(const OUString& rName, SfxStyleFamily eFamily, sal_uInt16 nMask); virtual SfxStyleSheetBase* Create(const SdStyleSheet& rStyle); diff --git a/sd/source/core/drawdoc3.cxx b/sd/source/core/drawdoc3.cxx index 2622122f192d..03c0cfdf33ee 100644 --- a/sd/source/core/drawdoc3.cxx +++ b/sd/source/core/drawdoc3.cxx @@ -357,6 +357,16 @@ lcl_removeUnusedStyles(SfxStyleSheetBasePool* const pStyleSheetPool, SdStyleShee rStyles = aUsedStyles; } +SfxStyleSheet *lcl_findStyle(SdStyleSheetVector& rStyles, OUString aStyleName) +{ + for(SdStyleSheetVector::const_iterator aIt(rStyles.begin()), aLast(rStyles.end()); aIt != aLast; ++aIt) + { + if((*aIt)->GetName().startsWith(aStyleName)) + return (*aIt).get(); + } + return NULL; +} + } sal_Bool SdDrawDocument::InsertBookmarkAsPage( @@ -510,7 +520,10 @@ sal_Bool SdDrawDocument::InsertBookmarkAsPage( // are then removed at the end of the function, where we also create // undo records for the inserted styles. SdStyleSheetVector aNewGraphicStyles; - pStyleSheetPool->CopyGraphicSheets(*pBookmarkStyleSheetPool, aNewGraphicStyles); + OUString aRenameStr; + if(!bReplace && !bNoDialogs) + aRenameStr = OUString("_"); + pStyleSheetPool->RenameAndCopyGraphicSheets(*pBookmarkStyleSheetPool, aNewGraphicStyles, aRenameStr); SdStyleSheetVector aNewCellStyles; pStyleSheetPool->CopyCellSheets(*pBookmarkStyleSheetPool, aNewCellStyles); @@ -910,6 +923,31 @@ sal_Bool SdDrawDocument::InsertBookmarkAsPage( // Make absolutely sure no double masterpages are there RemoveUnnecessaryMasterPages(NULL, sal_True, sal_True); + // Rename object styles if necessary + if(!aRenameStr.isEmpty()) + { + try + { + for(sal_uInt32 p = nInsertPos; p < (nInsertPos + nBMSdPageCount); p++) + { + SdPage *pPg = (SdPage *) GetPage(p); + for(sal_uIntPtr i = 0; i < pPg->GetObjCount(); i++) + { + if(pPg->GetObj(i)->GetStyleSheet()) + { + OUString aStyleName = pPg->GetObj(i)->GetStyleSheet()->GetName(); + SfxStyleSheet *pSheet = lcl_findStyle(aNewGraphicStyles, aStyleName + aRenameStr); + if(pSheet != NULL) + pPg->GetObj(i)->SetStyleSheet(pSheet, true); + } + } + } + } + catch(...) + { + OSL_FAIL("Exception while renaming styles @ SdDrawDocument::InsertBookmarkAsPage"); + } + } // remove copied styles not used on any inserted page and create // undo records // WARNING: SdMoveStyleSheetsUndoAction clears the passed list of diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx index 00d38e94e5e1..3b89c2893a64 100644 --- a/sd/source/core/stlpool.cxx +++ b/sd/source/core/stlpool.cxx @@ -71,6 +71,34 @@ using namespace ::com::sun::star::lang; using namespace ::com::sun::star::style; using namespace ::com::sun::star::container; +namespace +{ + +OUString lcl_findRenamedStyleName(std::vector< std::pair< OUString, OUString > > &rRenamedList, OUString& aOriginalName ) +{ + std::vector< std::pair< OUString, OUString > >::iterator aIter; + for( aIter = rRenamedList.begin(); aIter != rRenamedList.end(); ++aIter ) + { + if((*aIter).first == aOriginalName ) + return (*aIter).second; + } + return OUString(); +} + +SfxStyleSheet *lcl_findStyle(SdStyleSheetVector& rStyles, OUString aStyleName) +{ + if( aStyleName.isEmpty() ) + return NULL; + for(SdStyleSheetVector::const_iterator aIt(rStyles.begin()), aLast(rStyles.end()); aIt != aLast; ++aIt) + { + if((*aIt)->GetName() == aStyleName) + return (*aIt).get(); + } + return NULL; +} + +} + // ---------------------------------------------------------- SdStyleSheetPool::SdStyleSheetPool(SfxItemPool const& _rPool, SdDrawDocument* pDocument) @@ -507,6 +535,11 @@ void SdStyleSheetPool::CopyGraphicSheets(SdStyleSheetPool& rSourcePool) CopySheets( rSourcePool, SD_STYLE_FAMILY_GRAPHICS ); } +void SdStyleSheetPool::RenameAndCopyGraphicSheets(SdStyleSheetPool& rSourcePool, OUString &rRenameSuffix) +{ + RenameAndCopySheets( rSourcePool, SD_STYLE_FAMILY_GRAPHICS, rRenameSuffix ); +} + void SdStyleSheetPool::CopyCellSheets(SdStyleSheetPool& rSourcePool) { CopySheets( rSourcePool, SD_STYLE_FAMILY_CELL ); @@ -579,19 +612,42 @@ void SdStyleSheetPool::CopyCellSheets(SdStyleSheetPool& rSourcePool, SdStyleShee CopySheets( rSourcePool, SD_STYLE_FAMILY_CELL, rCreatedSheets ); } +void SdStyleSheetPool::RenameAndCopyGraphicSheets(SdStyleSheetPool& rSourcePool, SdStyleSheetVector& rCreatedSheets, OUString &rRenameSuffix) +{ + RenameAndCopySheets( rSourcePool, SD_STYLE_FAMILY_GRAPHICS, rCreatedSheets, rRenameSuffix ); +} + +void SdStyleSheetPool::RenameAndCopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, OUString &rRenameSuffix) +{ + SdStyleSheetVector aTmpSheets; + RenameAndCopySheets( rSourcePool, eFamily, aTmpSheets, rRenameSuffix ); +} + void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily ) { SdStyleSheetVector aTmpSheets; CopySheets(rSourcePool, eFamily, aTmpSheets); } +void SdStyleSheetPool::RenameAndCopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, SdStyleSheetVector& rCreatedSheets, OUString &rRenameSuffix) +{ + CopySheets( rSourcePool, eFamily, rCreatedSheets, rRenameSuffix ); +} + void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, SdStyleSheetVector& rCreatedSheets) { + OUString emptyName; + CopySheets(rSourcePool, eFamily, rCreatedSheets, emptyName); +} + +void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, SdStyleSheetVector& rCreatedSheets, OUString& rRenameSuffix) +{ OUString aHelpFile; sal_uInt32 nCount = rSourcePool.aStyles.size(); std::vector< std::pair< rtl::Reference< SfxStyleSheetBase >, OUString > > aNewStyles; + std::vector< std::pair< OUString, OUString > > aRenamedList; for (sal_uInt32 n = 0; n < nCount; n++) { @@ -599,8 +655,27 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily if( xSheet->GetFamily() == eFamily ) { + bool bAddToList = false; OUString aName( xSheet->GetName() ); - if ( !Find( aName, eFamily ) ) + SfxStyleSheetBase* pExistingSheet = Find(aName, eFamily); + if( pExistingSheet && !rRenameSuffix.isEmpty() ) + { + sal_uInt64 nHash = xSheet->GetItemSet().getHash(); + if( pExistingSheet->GetItemSet().getHash() != nHash ) + { + OUString aTmpName = aName + rRenameSuffix; + sal_Int32 nSuffix = 1; + do + { + aTmpName = aName + rRenameSuffix + OUString::valueOf(nSuffix); + pExistingSheet = Find(aTmpName, eFamily); + nSuffix++; + } while( pExistingSheet && pExistingSheet->GetItemSet().getHash() != nHash ); + aName = aTmpName; + bAddToList = true; + } + } + if ( !pExistingSheet ) { rtl::Reference< SfxStyleSheetBase > xNewSheet( &Make( aName, eFamily ) ); @@ -615,6 +690,13 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily xNewSheet->GetItemSet().Put( xSheet->GetItemSet() ); rCreatedSheets.push_back( SdStyleSheetRef( static_cast< SdStyleSheet* >( xNewSheet.get() ) ) ); + aRenamedList.push_back( std::pair< OUString, OUString >( xSheet->GetName(), aName ) ); + } + else if( bAddToList ) + { + // Add to list - used for renaming + rCreatedSheets.push_back( SdStyleSheetRef( static_cast< SdStyleSheet* >( pExistingSheet ) ) ); + aRenamedList.push_back( std::pair< OUString, OUString >( xSheet->GetName(), aName ) ); } } } @@ -623,6 +705,15 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily std::vector< std::pair< rtl::Reference< SfxStyleSheetBase >, OUString > >::iterator aIter; for( aIter = aNewStyles.begin(); aIter != aNewStyles.end(); ++aIter ) { + if( !rRenameSuffix.isEmpty() ) + { + SfxStyleSheet *pParent = lcl_findStyle(rCreatedSheets, lcl_findRenamedStyleName(aRenamedList, (*aIter).second)); + if( pParent ) + { + (*aIter).first->SetParent( pParent->GetName() ); + continue; + } + } DBG_ASSERT( rSourcePool.Find( (*aIter).second, eFamily ), "StyleSheet has invalid parent: Family mismatch" ); (*aIter).first->SetParent( (*aIter).second ); } diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx index 842fc4060786..50498e396922 100644 --- a/svl/source/items/itemset.cxx +++ b/svl/source/items/itemset.cxx @@ -31,6 +31,7 @@ #include <tools/stream.hxx> #include <tools/solar.h> +#include <rtl/strbuf.hxx> // STATIC DATA ----------------------------------------------------------- @@ -2029,4 +2030,26 @@ SfxItemSet *SfxAllItemSet::Clone(sal_Bool bItems, SfxItemPool *pToPool ) const return bItems ? new SfxAllItemSet(*this) : new SfxAllItemSet(*_pPool); } +// ----------------------------------------------------------------------- + +sal_uInt64 SfxItemSet::getHash() const +{ + return stringify().hashCode64(); +} + +// ----------------------------------------------------------------------- + +OString SfxItemSet::stringify() const +{ + rtl::OStringBuffer aString(100); + SvMemoryStream aStream; + OString aLine; + SfxItemSet aSet(*this); + aSet.InvalidateDefaultItems(); + aSet.Store(aStream, true); + aStream.Flush(); + aString.append((const char *)aStream.GetData(), aStream.GetEndOfData()); + + return aString.makeStringAndClear(); +} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |