summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuthu Subramanian <sumuthu@collabora.com>2014-02-13 21:54:19 +0530
committerMuthu Subramanian <sumuthu@collabora.com>2014-02-13 21:54:19 +0530
commit9f8baf0ed263889e3e77ea12ccb908020fee05a8 (patch)
treece54c58c34f831d2753b493b6b6e0f477e5e7c5b
parent9b172206c4054be233f3b363710b90aeb925ec9d (diff)
n#757432: Styles (rename &) copy to different decks.
Ported from: a4cd841541a729d7b8126d27d91fa28e30b01403 Change-Id: I73ebaec651a195afbf60f5338c487c7750298fef
-rw-r--r--sd/inc/stlpool.hxx5
-rw-r--r--sd/source/core/drawdoc3.cxx40
-rw-r--r--sd/source/core/stlpool.cxx93
-rw-r--r--svl/inc/svl/itemset.hxx2
-rw-r--r--svl/source/items/itemset.cxx23
5 files changed, 161 insertions, 2 deletions
diff --git a/sd/inc/stlpool.hxx b/sd/inc/stlpool.hxx
index 4833dd8f8197..e5f374fa9076 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 String& 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 7f493d8f5e54..38663eb33626 100644
--- a/sd/source/core/drawdoc3.cxx
+++ b/sd/source/core/drawdoc3.cxx
@@ -385,6 +385,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(OUString((*aIt)->GetName()).startsWith(aStyleName))
+ return (*aIt).get();
+ }
+ return NULL;
+}
+
}
sal_Bool SdDrawDocument::InsertBookmarkAsPage(
@@ -545,7 +555,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);
@@ -952,6 +965,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 7c06d27ef75a..bf8d0c31017c 100644
--- a/sd/source/core/stlpool.cxx
+++ b/sd/source/core/stlpool.cxx
@@ -70,6 +70,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(OUString((*aIt)->GetName()) == aStyleName)
+ return (*aIt).get();
+ }
+ return NULL;
+}
+
+}
+
// ----------------------------------------------------------
SdStyleSheetPool::SdStyleSheetPool(SfxItemPool const& _rPool, SdDrawDocument* pDocument)
@@ -521,6 +549,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 );
@@ -593,19 +626,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)
+{
String aHelpFile;
sal_uInt32 nCount = rSourcePool.aStyles.size();
std::vector< std::pair< rtl::Reference< SfxStyleSheetBase >, String > > aNewStyles;
+ std::vector< std::pair< OUString, OUString > > aRenamedList;
for (sal_uInt32 n = 0; n < nCount; n++)
{
@@ -613,8 +669,27 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily
if( xSheet->GetFamily() == eFamily )
{
+ bool bAddToList = false;
String 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 ) );
@@ -629,6 +704,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 ) );
}
}
}
@@ -637,6 +719,15 @@ void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily
std::vector< std::pair< rtl::Reference< SfxStyleSheetBase >, String > >::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/inc/svl/itemset.hxx b/svl/inc/svl/itemset.hxx
index 47ed7efe220e..89ad83d6e0cf 100644
--- a/svl/inc/svl/itemset.hxx
+++ b/svl/inc/svl/itemset.hxx
@@ -151,6 +151,8 @@ public:
virtual SvStream & Store( SvStream &, bool bDirect = false ) const;
virtual int operator==(const SfxItemSet &) const;
+ virtual sal_uInt64 getHash() const;
+ virtual OString stringify() const;
};
// --------------- Inline Implementierungen ------------------------
diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index c53104800078..0037552668c2 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 -----------------------------------------------------------
@@ -2051,4 +2052,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: */