summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuthu Subramanian <sumuthu@collabora.com>2014-03-07 18:08:47 +0530
committerMuthu Subramanian <sumuthu@collabora.com>2014-03-07 18:08:47 +0530
commit1d0d89457fdbd4491ff4227d926b76c574f78f1f (patch)
treeb24683d2c704f8d170acdfac72b10f6506367db6
parent3096631b27f5ac6f320c704ccc26c1be31831b0b (diff)
n#757432: Styles (rename &) copy to different decks.
Ported from: 9f8baf0ed263889e3e77ea12ccb908020fee05a8 and a4cd841541a729d7b8126d27d91fa28e30b01403 Change-Id: If0e56cd8b2aab1ff4c6166b8c84a41b39c2f1414
-rw-r--r--include/svl/itemset.hxx2
-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/source/items/itemset.cxx23
5 files changed, 161 insertions, 2 deletions
diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 47ed7efe220e..89ad83d6e0cf 100644
--- a/include/svl/itemset.hxx
+++ b/include/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/sd/inc/stlpool.hxx b/sd/inc/stlpool.hxx
index 624d5da15a02..6276d8740ab8 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 6d64078d3dd3..2794f5b21148 100644
--- a/sd/source/core/drawdoc3.cxx
+++ b/sd/source/core/drawdoc3.cxx
@@ -358,6 +358,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(
@@ -511,7 +521,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);
@@ -909,6 +922,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 9abf9bab0ad7..2c44fb662b1b 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)
@@ -524,6 +552,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 );
@@ -596,19 +629,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 >, String > > aNewStyles;
+ std::vector< std::pair< OUString, OUString > > aRenamedList;
for (sal_uInt32 n = 0; n < nCount; n++)
{
@@ -616,8 +672,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 ) );
@@ -632,6 +707,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 ) );
}
}
}
@@ -640,6 +722,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/source/items/itemset.cxx b/svl/source/items/itemset.cxx
index 12e54539b003..33bc6217a019 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 -----------------------------------------------------------
@@ -2047,4 +2048,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: */