[Libreoffice-commits] core.git: Branch 'distro/suse/suse-4.0' - 2 commits - sal/inc sal/rtl sal/util sd/inc sd/source svl/inc svl/source

Muthu Subramanian sumuthu at collabora.com
Thu Feb 13 17:25:02 CET 2014


 sal/inc/rtl/string.h         |   18 ++++++++
 sal/inc/rtl/string.hxx       |   13 ++++++
 sal/inc/rtl/ustring.h        |   18 ++++++++
 sal/rtl/source/strtmpl.cxx   |   13 ++++++
 sal/util/sal.map             |    1 
 sd/inc/stlpool.hxx           |    5 ++
 sd/source/core/drawdoc3.cxx  |   40 ++++++++++++++++++
 sd/source/core/sdpage2.cxx   |   12 -----
 sd/source/core/stlpool.cxx   |   93 ++++++++++++++++++++++++++++++++++++++++++-
 svl/inc/svl/itemset.hxx      |    2 
 svl/source/items/itemset.cxx |   23 ++++++++++
 11 files changed, 225 insertions(+), 13 deletions(-)

New commits:
commit 9f8baf0ed263889e3e77ea12ccb908020fee05a8
Author: Muthu Subramanian <sumuthu at collabora.com>
Date:   Thu Feb 13 21:54:19 2014 +0530

    n#757432: Styles (rename &) copy to different decks.
    
    Ported from: a4cd841541a729d7b8126d27d91fa28e30b01403
    
    Change-Id: I73ebaec651a195afbf60f5338c487c7750298fef

diff --git a/sd/inc/stlpool.hxx b/sd/inc/stlpool.hxx
index 4833dd8..e5f374f 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 7f493d8..38663eb 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 7c06d27..bf8d0c3 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 47ed7ef..89ad83d 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 c531048..0037552 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: */
commit 9b172206c4054be233f3b363710b90aeb925ec9d
Author: Muthu Subramanian <sumuthu at collabora.com>
Date:   Thu Feb 13 21:49:18 2014 +0530

    Move string hash function into String class.
    
    Change-Id: If229f3a8c4b4fd1e5f0c28618e29eded7b7853da

diff --git a/sal/inc/rtl/string.h b/sal/inc/rtl/string.h
index 9f3c69a..3def4c1 100644
--- a/sal/inc/rtl/string.h
+++ b/sal/inc/rtl/string.h
@@ -277,6 +277,24 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_hashCode(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_str_hashCode_WithLength(
         const sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
 
+/** Return a hash code (64bit) for a string.
+
+    It is not allowed to store the hash code persistently, because later
+    versions could return other hash codes.
+
+    @param str
+    a string.  Need not be null-terminated, but must be at least as long as
+    the specified len.
+
+    @param len
+    the length of the string.
+
+    @return
+    a hash code for the given string.
+ */
+SAL_DLLPUBLIC sal_uInt64 SAL_CALL rtl_str_hashCode64_WithLength(
+        const sal_Char * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
+
 /** Search for the first occurrence of a character within a string.
 
     The string must be null-terminated.
diff --git a/sal/inc/rtl/string.hxx b/sal/inc/rtl/string.hxx
index cbd4b9a..4b7b072 100644
--- a/sal/inc/rtl/string.hxx
+++ b/sal/inc/rtl/string.hxx
@@ -866,6 +866,19 @@ public:
     }
 
     /**
+      Returns a 64bit hash of the string data.
+      This hashes the entire data, while hashCode would do sampling for larger string sizes.
+
+      @return   a hash code value of the string data
+
+      @see hashCode() for simple hashes
+    */
+    sal_uInt64 hashCode64() const SAL_THROW(())
+    {
+        return rtl_str_hashCode64_WithLength( pData->buffer, pData->length );
+    }
+
+    /**
       Returns a hashcode for this string.
 
       @return   a hash code value for this object.
diff --git a/sal/inc/rtl/ustring.h b/sal/inc/rtl/ustring.h
index 0352e59..24a7dd8 100644
--- a/sal/inc/rtl/ustring.h
+++ b/sal/inc/rtl/ustring.h
@@ -551,6 +551,24 @@ SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_hashCode(
 SAL_DLLPUBLIC sal_Int32 SAL_CALL rtl_ustr_hashCode_WithLength(
         const sal_Unicode * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
 
+/** Return a hash code (64bit) for a string.
+
+    It is not allowed to store the hash code persistently, because later
+    versions could return other hash codes.
+
+    @param str
+    a string.  Need not be null-terminated, but must be at least as long as
+    the specified len.
+
+    @param len
+    the length of the string.
+
+    @return
+    a hash code for the given string.
+ */
+SAL_DLLPUBLIC sal_uInt64 SAL_CALL rtl_ustr_hashCode64_WithLength(
+        const sal_Unicode * str, sal_Int32 len ) SAL_THROW_EXTERN_C();
+
 /** Search for the first occurrence of a character within a string.
 
     The string must be null-terminated.
diff --git a/sal/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx
index f9d7a5e..9b8fa51 100644
--- a/sal/rtl/source/strtmpl.cxx
+++ b/sal/rtl/source/strtmpl.cxx
@@ -272,6 +272,19 @@ sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode )( const IMPL_RTL_STRCODE* pStr )
 
 /* ----------------------------------------------------------------------- */
 
+sal_uInt64 SAL_CALL IMPL_RTL_STRNAME( hashCode64_WithLength )( const IMPL_RTL_STRCODE* pStr,
+                                                               sal_Int32 nLen )
+    SAL_THROW_EXTERN_C()
+{
+    sal_uInt64 nHash = 0;
+
+    for( sal_Int32 i = 0; i < nLen; i++ )
+        nHash = (nHash << 5) - nHash + *pStr++;
+    return nHash;
+}
+
+/* ----------------------------------------------------------------------- */
+
 sal_Int32 SAL_CALL IMPL_RTL_STRNAME( hashCode_WithLength )( const IMPL_RTL_STRCODE* pStr,
                                                             sal_Int32 nLen )
     SAL_THROW_EXTERN_C()
diff --git a/sal/util/sal.map b/sal/util/sal.map
index ade61cd..83d824c 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -221,6 +221,7 @@ UDK_3_0_0 {
         rtl_str_shortenedCompareIgnoreAsciiCase_WithLength;
         rtl_str_hashCode;
         rtl_str_hashCode_WithLength;
+        rtl_str_hashCode64_WithLength;
         rtl_str_indexOfChar;
         rtl_str_indexOfChar_WithLength;
         rtl_str_indexOfStr;
diff --git a/sd/source/core/sdpage2.cxx b/sd/source/core/sdpage2.cxx
index f61cab0..37b16e2 100644
--- a/sd/source/core/sdpage2.cxx
+++ b/sd/source/core/sdpage2.cxx
@@ -54,16 +54,6 @@ using namespace ::com::sun::star::office;
 
 extern void NotifyDocumentEvent( SdDrawDocument* pDocument, const rtl::OUString& rEventName, const Reference< XInterface >& xSource );
 
-static sal_uInt64 lcl_getHash( OString aString )
-{
-    sal_Int32  len = aString.getLength();
-    sal_uInt64 nHash = 0;
-
-    for( sal_Int32 i = 0; i < len; i++ )
-        nHash = (nHash << 5) - nHash + aString[i];
-    return nHash;
-}
-
 /*************************************************************************
 |*
 |* SetPresentationLayout, setzt: Layoutnamen, Masterpage-Verkn�pfung und
@@ -611,7 +601,7 @@ OString SdPage::stringify() const
 
 sal_uInt64 SdPage::getHash() const
 {
-    return lcl_getHash( stringify() );
+    return stringify().hashCode64();
 }
 
 


More information about the Libreoffice-commits mailing list