sd/source/core/stlpool.cxx |   53 +++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 32 deletions(-)

New commits:
commit 86c50d7d7de2e5c4be5f7c6931d87d1b17bcaf82
Author:     Maxim Monastirsky <momonas...@gmail.com>
AuthorDate: Sun Dec 4 16:26:55 2022 +0200
Commit:     Maxim Monastirsky <momonas...@gmail.com>
CommitDate: Mon Dec 5 07:26:20 2022 +0000

    sd: Don't replace table styles on page pasting
    
    i.e. insert a table, and set its style to anything except
    default. Then right click on the page in the page pane =>
    Copy. Right click again => Paste. The table on the first
    page will reset to the default table style.
    
    The problem is in SdStyleSheetPool::CopyTableStyles which
    attempts to replace existing styles with the pasted ones,
    causing the old ones to be destroyed. But in fact there's
    absolutely no case where we want to do anything like this.
    All we want is to keep the formatting of the pasted page,
    not to change existing styles which might be used in the
    rest of the document. (And if the pasted style has indeed
    a different formatting, it can be inserted under a
    different name. To be handled in a follow-up commit.)
    
    Change-Id: I7caaffc72265bb045bf21c831f2da27012e41845
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143644
    Tested-by: Jenkins
    Reviewed-by: Maxim Monastirsky <momonas...@gmail.com>

diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx
index ad4733f96189..738279e8a440 100644
--- a/sd/source/core/stlpool.cxx
+++ b/sd/source/core/stlpool.cxx
@@ -553,7 +553,7 @@ void SdStyleSheetPool::CopyTableStyles(SdStyleSheetPool 
const & rSourcePool)
 
         const OUString sName(Reference<XStyle>(xSourceTableStyle, 
UNO_QUERY_THROW)->getName());
         if( xTarget->hasByName( sName ) )
-            xTarget->replaceByName( sName, Any( xNewTableStyle ) );
+            Reference<XComponent>(xNewTableStyle, UNO_QUERY_THROW)->dispose();
         else
             xTarget->insertByName( sName, Any( xNewTableStyle ) );
     }
commit 1c3dc6cdc53a2463af12688918d222d44039a96c
Author:     Maxim Monastirsky <momonas...@gmail.com>
AuthorDate: Sun Dec 4 16:21:27 2022 +0200
Commit:     Maxim Monastirsky <momonas...@gmail.com>
CommitDate: Mon Dec 5 07:26:11 2022 +0000

    Simplify SdStyleSheetPool::CopyTableStyles a bit
    
    Change-Id: Ib8bbc8f71b310c1b968f36a94e99cce6019dd6cc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143643
    Tested-by: Jenkins
    Reviewed-by: Maxim Monastirsky <momonas...@gmail.com>

diff --git a/sd/source/core/stlpool.cxx b/sd/source/core/stlpool.cxx
index 79f07b0b614a..ad4733f96189 100644
--- a/sd/source/core/stlpool.cxx
+++ b/sd/source/core/stlpool.cxx
@@ -526,47 +526,36 @@ void SdStyleSheetPool::CopyTableStyles(SdStyleSheetPool 
const & rSourcePool)
     Reference< XNameContainer > xTarget( mxTableFamily, UNO_QUERY );
     Reference< XSingleServiceFactory > xFactory( mxTableFamily, UNO_QUERY );
 
-    if( !(xSource.is() && xFactory.is() && mxTableFamily.is()) )
+    if( !xSource || !xFactory )
         return;
 
     for( sal_Int32 nIndex = 0; nIndex < xSource->getCount(); nIndex++ ) try
     {
-        Reference< XStyle > xSourceTableStyle( xSource->getByIndex( nIndex ), 
UNO_QUERY );
-        if( xSourceTableStyle.is() )
+        Reference< XNameAccess > xSourceTableStyle( xSource->getByIndex( 
nIndex ), UNO_QUERY_THROW );
+        Reference< XNameReplace > xNewTableStyle( xFactory->createInstance(), 
UNO_QUERY_THROW );
+
+        const Sequence< OUString > aStyleNames( 
xSourceTableStyle->getElementNames() );
+        for( const OUString& aName : aStyleNames )
         {
-            Reference< XStyle > xNewTableStyle( xFactory->createInstance(), 
UNO_QUERY );
-            if( xNewTableStyle.is() )
+            Reference< XStyle > xSourceStyle( xSourceTableStyle->getByName( 
aName ), UNO_QUERY );
+            Reference< XStyle > xTargetStyle;
+            if( xSourceStyle.is() ) try
             {
-                Reference< XNameAccess> xSourceNames( xSourceTableStyle, 
UNO_QUERY_THROW );
-
-                const Sequence< OUString > aStyleNames( 
xSourceNames->getElementNames() );
-
-                Reference< XNameReplace > xTargetNames( xNewTableStyle, 
UNO_QUERY );
-
-                for( const OUString& aName : aStyleNames )
-                {
-                    Reference< XStyle > xSourceStyle( xSourceNames->getByName( 
aName ), UNO_QUERY );
-                    Reference< XStyle > xTargetStyle;
-                    if( xSourceStyle.is() ) try
-                    {
-                        mxCellFamily->getByName( xSourceStyle->getName() ) >>= 
xTargetStyle;
-                    }
-                    catch( Exception& )
-                    {
-                        TOOLS_WARN_EXCEPTION( "sd", 
"sd::SdStyleSheetPool::CopyTableStyles()" );
-                    }
-
-                    if( xTargetStyle.is() )
-                        xTargetNames->replaceByName( aName, Any( xTargetStyle 
) );
-                }
+                mxCellFamily->getByName( xSourceStyle->getName() ) >>= 
xTargetStyle;
+            }
+            catch( Exception& )
+            {
+                TOOLS_WARN_EXCEPTION( "sd", 
"sd::SdStyleSheetPool::CopyTableStyles()" );
             }
 
-            OUString sName( xSourceTableStyle->getName() );
-            if( xTarget->hasByName( sName ) )
-                xTarget->replaceByName( sName, Any( xNewTableStyle ) );
-            else
-                xTarget->insertByName( sName, Any( xNewTableStyle ) );
+            xNewTableStyle->replaceByName( aName, Any( xTargetStyle ) );
         }
+
+        const OUString sName(Reference<XStyle>(xSourceTableStyle, 
UNO_QUERY_THROW)->getName());
+        if( xTarget->hasByName( sName ) )
+            xTarget->replaceByName( sName, Any( xNewTableStyle ) );
+        else
+            xTarget->insertByName( sName, Any( xNewTableStyle ) );
     }
     catch( Exception& )
     {

Reply via email to