[Libreoffice-commits] core.git: include/svl sd/inc sd/source svl/source

Muthu Subramanian sumuthu at collabora.com
Thu Feb 13 11:35:01 CET 2014


 include/svl/itemset.hxx      |    2 
 sd/inc/stlpool.hxx           |    5 ++
 sd/source/core/drawdoc3.cxx  |   40 ++++++++++++++++++
 sd/source/core/stlpool.cxx   |   93 ++++++++++++++++++++++++++++++++++++++++++-
 svl/source/items/itemset.cxx |   23 ++++++++++
 5 files changed, 161 insertions(+), 2 deletions(-)

New commits:
commit a4cd841541a729d7b8126d27d91fa28e30b01403
Author: Muthu Subramanian <sumuthu at collabora.com>
Date:   Thu Feb 13 16:10:47 2014 +0530

    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

diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx
index 7157ecf..2284281 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 3d2cdc9..8c0e993 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 2622122..03c0cfd 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 00d38e9..3b89c28 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 842fc40..50498e3 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: */


More information about the Libreoffice-commits mailing list