[Libreoffice-commits] core.git: package/source sc/inc sc/source

Caolán McNamara caolanm at redhat.com
Wed Feb 22 13:14:43 UTC 2017


 package/source/xstor/xstorage.cxx            |  255 +++++-------
 package/source/xstor/xstorage.hxx            |    7 
 sc/inc/funcuno.hxx                           |    7 
 sc/source/filter/inc/XclExpChangeTrack.hxx   |    2 
 sc/source/filter/xcl97/XclExpChangeTrack.cxx |   21 -
 sc/source/ui/inc/undoblk.hxx                 |   68 +--
 sc/source/ui/inc/undodat.hxx                 |  178 ++++----
 sc/source/ui/inc/undotab.hxx                 |    2 
 sc/source/ui/undo/undoblk.cxx                |   60 +-
 sc/source/ui/undo/undoblk3.cxx               |  114 ++---
 sc/source/ui/undo/undodat.cxx                |  545 +++++++++++----------------
 sc/source/ui/undo/undotab.cxx                |   56 +-
 sc/source/ui/unoobj/funcuno.cxx              |   18 
 13 files changed, 589 insertions(+), 744 deletions(-)

New commits:
commit 988ac73e57b7e7f171fb2543de90a9afc2aa3289
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed Feb 22 09:30:33 2017 +0000

    use std::unique_ptr
    
    Change-Id: I11a58aa38f931c7912e2e5ac6df46f98e6bb681e
    Reviewed-on: https://gerrit.libreoffice.org/34539
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx
index 424f2c7..aa30074 100644
--- a/package/source/xstor/xstorage.cxx
+++ b/package/source/xstor/xstorage.cxx
@@ -158,23 +158,15 @@ uno::Reference< io::XInputStream > GetSeekableTempCopy( const uno::Reference< io
     return xTempIn;
 }
 
-SotElement_Impl::SotElement_Impl( const OUString& rName, bool bStor, bool bNew )
-: m_aName( rName )
-, m_aOriginalName( rName )
-, m_bIsRemoved( false )
-, m_bIsInserted( bNew )
-, m_bIsStorage( bStor )
-, m_pStorage( nullptr )
-, m_pStream( nullptr )
+SotElement_Impl::SotElement_Impl(const OUString& rName, bool bStor, bool bNew)
+    : m_aName(rName)
+    , m_aOriginalName(rName)
+    , m_bIsRemoved(false)
+    , m_bIsInserted(bNew)
+    , m_bIsStorage(bStor)
 {
 }
 
-SotElement_Impl::~SotElement_Impl()
-{
-    delete m_pStorage;
-    delete m_pStream;
-}
-
 // most of properties are holt by the storage but are not used
 OStorage_Impl::OStorage_Impl(   uno::Reference< io::XInputStream > const & xInputStream,
                                 sal_Int32 nMode,
@@ -779,31 +771,31 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
 
         SAL_WARN_IF( !xSubDest.is(), "package.xstor", "No destination substorage!" );
 
-        if ( !pElement->m_pStorage )
+        if (!pElement->m_xStorage)
         {
             OpenSubStorage( pElement, embed::ElementModes::READ );
-            if ( !pElement->m_pStorage )
+            if (!pElement->m_xStorage)
                 throw io::IOException( THROW_WHERE );
         }
 
-        pElement->m_pStorage->CopyToStorage( xSubDest, bDirect );
+        pElement->m_xStorage->CopyToStorage(xSubDest, bDirect);
     }
     else
     {
-        if ( !pElement->m_pStream )
+        if (!pElement->m_xStream)
         {
             OpenSubStream( pElement );
-            if ( !pElement->m_pStream )
+            if (!pElement->m_xStream)
                 throw io::IOException( THROW_WHERE );
         }
 
-        if ( !pElement->m_pStream->IsEncrypted() )
+        if (!pElement->m_xStream->IsEncrypted())
         {
             if ( bDirect )
             {
                 // fill in the properties for the stream
                 uno::Sequence< beans::PropertyValue > aStrProps(0);
-                uno::Sequence< beans::PropertyValue > aSrcPkgProps = pElement->m_pStream->GetStreamProperties();
+                uno::Sequence< beans::PropertyValue > aSrcPkgProps = pElement->m_xStream->GetStreamProperties();
                 sal_Int32 nNum = 0;
                 for ( int ind = 0; ind < aSrcPkgProps.getLength(); ind++ )
                 {
@@ -819,7 +811,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
                 {
                     aStrProps.realloc( ++nNum );
                     aStrProps[nNum-1].Name = "UseCommonStoragePasswordEncryption";
-                    aStrProps[nNum-1].Value <<= pElement->m_pStream->UsesCommonEncryption_Impl();
+                    aStrProps[nNum-1].Value <<= pElement->m_xStream->UsesCommonEncryption_Impl();
                 }
                 else if ( m_nStorageType == embed::StorageFormats::OFOPXML )
                 {
@@ -842,19 +834,19 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
                 uno::Reference< embed::XOptimizedStorage > xOptDest( xDest, uno::UNO_QUERY_THROW );
                 uno::Reference < io::XInputStream > xInputToInsert;
 
-                if ( pElement->m_pStream->HasTempFile_Impl() || !pElement->m_pStream->m_xPackageStream.is() )
+                if (pElement->m_xStream->HasTempFile_Impl() || !pElement->m_xStream->m_xPackageStream.is())
                 {
-                    SAL_WARN_IF( !pElement->m_pStream->m_xPackageStream.is(), "package.xstor", "No package stream!" );
+                    SAL_WARN_IF(!pElement->m_xStream->m_xPackageStream.is(), "package.xstor", "No package stream!");
 
                     // if the stream is modified - the temporary file must be used for insertion
-                    xInputToInsert = pElement->m_pStream->GetTempFileAsInputStream();
+                    xInputToInsert = pElement->m_xStream->GetTempFileAsInputStream();
                 }
                 else
                 {
                     // for now get just nonseekable access to the stream
                     // TODO/LATER: the raw stream can be used
 
-                    xInputToInsert = pElement->m_pStream->m_xPackageStream->getDataStream();
+                    xInputToInsert = pElement->m_xStream->m_xPackageStream->getDataStream();
                 }
 
                 if ( !xInputToInsert.is() )
@@ -869,7 +861,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
                                             embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
                 SAL_WARN_IF( !xSubStr.is(), "package.xstor", "No destination substream!" );
 
-                pElement->m_pStream->CopyInternallyTo_Impl( xSubStr );
+                pElement->m_xStream->CopyInternallyTo_Impl(xSubStr);
             }
         }
         else if ( m_nStorageType != embed::StorageFormats::PACKAGE )
@@ -877,8 +869,8 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
             SAL_WARN( "package.xstor", "Encryption is only supported in package storage!" );
             throw io::IOException( THROW_WHERE );
         }
-        else if ( pElement->m_pStream->HasCachedEncryptionData()
-             && ( pElement->m_pStream->IsModified() || pElement->m_pStream->HasWriteOwner_Impl() ) )
+        else if ( pElement->m_xStream->HasCachedEncryptionData()
+             && ( pElement->m_xStream->IsModified() || pElement->m_xStream->HasWriteOwner_Impl() ) )
         {
             ::comphelper::SequenceAsHashMap aCommonEncryptionData;
             bool bHasCommonEncryptionData = false;
@@ -893,7 +885,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
                 AddLog( THROW_WHERE "No Encryption" );
             }
 
-            if ( bHasCommonEncryptionData && ::package::PackageEncryptionDatasEqual( pElement->m_pStream->GetCachedEncryptionData(), aCommonEncryptionData ) )
+            if (bHasCommonEncryptionData && ::package::PackageEncryptionDatasEqual(pElement->m_xStream->GetCachedEncryptionData(), aCommonEncryptionData))
             {
                 // If the stream can be opened with the common storage password
                 // it must be stored with the common storage password as well
@@ -901,7 +893,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
                                             xDest->openStreamElement( aName,
                                                 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
 
-                pElement->m_pStream->CopyInternallyTo_Impl( xDestStream );
+                pElement->m_xStream->CopyInternallyTo_Impl( xDestStream );
 
                 uno::Reference< beans::XPropertySet > xProps( xDestStream, uno::UNO_QUERY_THROW );
                 xProps->setPropertyValue(
@@ -915,10 +907,10 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
                 uno::Reference< io::XStream > xSubStr =
                                             xDest2->openEncryptedStream( aName,
                                                 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE,
-                                                pElement->m_pStream->GetCachedEncryptionData().getAsConstNamedValueList() );
+                                                pElement->m_xStream->GetCachedEncryptionData().getAsConstNamedValueList() );
                 SAL_WARN_IF( !xSubStr.is(), "package.xstor", "No destination substream!" );
 
-                pElement->m_pStream->CopyInternallyTo_Impl( xSubStr, pElement->m_pStream->GetCachedEncryptionData() );
+                pElement->m_xStream->CopyInternallyTo_Impl(xSubStr, pElement->m_xStream->GetCachedEncryptionData());
             }
         }
         else
@@ -929,8 +921,8 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
                 // If the stream can be opened with the common storage password
                 // it must be stored with the common storage password as well
 
-                uno::Reference< io::XStream > xOwnStream = pElement->m_pStream->GetStream( embed::ElementModes::READ,
-                                                                                            false );
+                uno::Reference< io::XStream > xOwnStream = pElement->m_xStream->GetStream(embed::ElementModes::READ,
+                                                                                          false);
                 uno::Reference< io::XStream > xDestStream =
                                             xDest->openStreamElement( aName,
                                                 embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE );
@@ -952,7 +944,7 @@ void OStorage_Impl::CopyStorageElement( SotElement_Impl* pElement,
                 // in the ODF1.2 package, so an invalid package could be produced if the stream
                 // is copied from ODF1.1 package, where it is allowed to have different StartKeys
                 uno::Reference< embed::XStorageRawAccess > xRawDest( xDest, uno::UNO_QUERY_THROW );
-                uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
+                uno::Reference< io::XInputStream > xRawInStream = pElement->m_xStream->GetRawInStream();
                 xRawDest->insertRawEncrStreamElement( aName, xRawInStream );
             }
         }
@@ -1098,13 +1090,13 @@ void OStorage_Impl::Commit()
             // following two steps are separated to allow easily implement transacted mode
             // for streams if we need it in future.
             // Only hierarchical access uses transacted streams currently
-            if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream
-              && !(*pElementIter)->m_pStream->IsTransacted() )
-                (*pElementIter)->m_pStream->Commit();
+            if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStream
+              && !(*pElementIter)->m_xStream->IsTransacted() )
+                (*pElementIter)->m_xStream->Commit();
 
             // if the storage was not open, there is no need to commit it ???
             // the storage should be checked that it is committed
-            if ( (*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStorage && (*pElementIter)->m_pStorage->m_bCommited )
+            if ((*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStorage && (*pElementIter)->m_xStorage->m_bCommited)
             {
                 // it's temporary PackageFolder should be inserted instead of current one
                 // also the new copy of PackageFolder should be used by the children storages
@@ -1113,9 +1105,9 @@ void OStorage_Impl::Commit()
                 if ( m_bCommited || m_bIsRoot )
                     xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
 
-                (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
+                (*pElementIter)->m_xStorage->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder);
             }
-            else if ( !(*pElementIter)->m_bIsStorage && (*pElementIter)->m_pStream && (*pElementIter)->m_pStream->m_bFlushed )
+            else if (!(*pElementIter)->m_bIsStorage && (*pElementIter)->m_xStream && (*pElementIter)->m_xStream->m_bFlushed)
             {
                 if ( m_nStorageType == embed::StorageFormats::OFOPXML )
                     CommitStreamRelInfo( *pElementIter );
@@ -1124,7 +1116,7 @@ void OStorage_Impl::Commit()
                 if ( m_bCommited || m_bIsRoot )
                     xNewPackageFolder->removeByName( (*pElementIter)->m_aOriginalName );
 
-                (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
+                (*pElementIter)->m_xStream->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder);
             }
             else if ( !m_bCommited && !m_bIsRoot )
             {
@@ -1145,10 +1137,10 @@ void OStorage_Impl::Commit()
 
                 if ( m_nStorageType == embed::StorageFormats::OFOPXML && !(*pElementIter)->m_bIsStorage )
                 {
-                    if ( !(*pElementIter)->m_pStream )
+                    if (!(*pElementIter)->m_xStream)
                     {
                         OpenSubStream( *pElementIter );
-                        if ( !(*pElementIter)->m_pStream )
+                        if (!(*pElementIter)->m_xStream)
                             throw uno::RuntimeException( THROW_WHERE );
                     }
 
@@ -1170,32 +1162,32 @@ void OStorage_Impl::Commit()
 
             if ( (*pElementIter)->m_bIsStorage )
             {
-                if ( (*pElementIter)->m_pStorage->m_bCommited )
+                if ((*pElementIter)->m_xStorage->m_bCommited)
                 {
-                    OSL_ENSURE( (*pElementIter)->m_pStorage, "An inserted storage is incomplete!\n" );
-                    if ( !(*pElementIter)->m_pStorage )
+                    OSL_ENSURE((*pElementIter)->m_xStorage, "An inserted storage is incomplete!\n");
+                    if (!(*pElementIter)->m_xStorage)
                         throw uno::RuntimeException( THROW_WHERE );
 
-                    (*pElementIter)->m_pStorage->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
+                    (*pElementIter)->m_xStorage->InsertIntoPackageFolder((*pElementIter)->m_aName, xNewPackageFolder);
 
                     (*pElementIter)->m_bIsInserted = false;
                 }
             }
             else
             {
-                OSL_ENSURE( (*pElementIter)->m_pStream, "An inserted stream is incomplete!\n" );
-                if ( !(*pElementIter)->m_pStream )
+                OSL_ENSURE((*pElementIter)->m_xStream, "An inserted stream is incomplete!\n");
+                if (!(*pElementIter)->m_xStream)
                     throw uno::RuntimeException( THROW_WHERE );
 
-                if ( !(*pElementIter)->m_pStream->IsTransacted() )
-                    (*pElementIter)->m_pStream->Commit();
+                if (!(*pElementIter)->m_xStream->IsTransacted())
+                    (*pElementIter)->m_xStream->Commit();
 
-                if ( (*pElementIter)->m_pStream->m_bFlushed )
+                if ((*pElementIter)->m_xStream->m_bFlushed)
                 {
                     if ( m_nStorageType == embed::StorageFormats::OFOPXML )
                         CommitStreamRelInfo( *pElementIter );
 
-                    (*pElementIter)->m_pStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
+                    (*pElementIter)->m_xStream->InsertIntoPackageFolder( (*pElementIter)->m_aName, xNewPackageFolder );
 
                     (*pElementIter)->m_bIsInserted = false;
                 }
@@ -1372,7 +1364,7 @@ SotElement_Impl* OStorage_Impl::InsertStream( const OUString& aName, bool bEncr
 
     // the mode is not needed for storage stream internal implementation
     SotElement_Impl* pNewElement = InsertElement( aName, false );
-    pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xContext, bEncr, m_nStorageType, true );
+    pNewElement->m_xStream.reset(new OWriteStream_Impl(this, xPackageSubStream, m_xPackage, m_xContext, bEncr, m_nStorageType, true));
 
     m_aChildrenList.push_back( pNewElement );
     m_bIsModified = true;
@@ -1409,9 +1401,9 @@ void OStorage_Impl::InsertRawStream( const OUString& aName, const uno::Reference
 
     // the mode is not needed for storage stream internal implementation
     SotElement_Impl* pNewElement = InsertElement( aName, false );
-    pNewElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xContext, true, m_nStorageType, false );
+    pNewElement->m_xStream.reset(new OWriteStream_Impl(this, xPackageSubStream, m_xPackage, m_xContext, true, m_nStorageType, false));
     // the stream is inserted and must be treated as a committed one
-    pNewElement->m_pStream->SetToBeCommited();
+    pNewElement->m_xStream->SetToBeCommited();
 
     m_aChildrenList.push_back( pNewElement );
     m_bIsModified = true;
@@ -1445,7 +1437,7 @@ SotElement_Impl* OStorage_Impl::InsertStorage( const OUString& aName, sal_Int32
 {
     SotElement_Impl* pNewElement = InsertElement( aName, true );
 
-    pNewElement->m_pStorage = CreateNewStorageImpl( nStorageMode );
+    pNewElement->m_xStorage.reset(CreateNewStorageImpl(nStorageMode));
 
     m_aChildrenList.push_back( pNewElement );
 
@@ -1497,7 +1489,7 @@ void OStorage_Impl::OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorag
 
     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
 
-    if ( !pElement->m_pStorage )
+    if (!pElement->m_xStorage)
     {
         SAL_WARN_IF( pElement->m_bIsInserted, "package.xstor", "Inserted element must be created already!" );
 
@@ -1507,7 +1499,7 @@ void OStorage_Impl::OpenSubStorage( SotElement_Impl* pElement, sal_Int32 nStorag
             throw container::NoSuchElementException( THROW_WHERE );
 
         uno::Reference< container::XNameContainer > xPackageSubFolder( xTunnel, uno::UNO_QUERY_THROW );
-        pElement->m_pStorage = new OStorage_Impl( this, nStorageMode, xPackageSubFolder, m_xPackage, m_xContext, m_nStorageType );
+        pElement->m_xStorage.reset(new OStorage_Impl(this, nStorageMode, xPackageSubFolder, m_xPackage, m_xContext, m_nStorageType));
     }
 }
 
@@ -1518,7 +1510,7 @@ void OStorage_Impl::OpenSubStream( SotElement_Impl* pElement )
 
     ::osl::MutexGuard aGuard( m_rMutexRef->GetMutex() );
 
-    if ( !pElement->m_pStream )
+    if (!pElement->m_xStream)
     {
         SAL_WARN_IF( pElement->m_bIsInserted, "package.xstor", "Inserted element must be created already!" );
 
@@ -1530,7 +1522,7 @@ void OStorage_Impl::OpenSubStream( SotElement_Impl* pElement )
         uno::Reference< packages::XDataSinkEncrSupport > xPackageSubStream( xTunnel, uno::UNO_QUERY_THROW );
 
         // the stream can never be inserted here, because inserted stream element holds the stream till commit or destruction
-        pElement->m_pStream = new OWriteStream_Impl( this, xPackageSubStream, m_xPackage, m_xContext, false, m_nStorageType, false, GetRelInfoStreamForName( pElement->m_aOriginalName ) );
+        pElement->m_xStream.reset(new OWriteStream_Impl(this, xPackageSubStream, m_xPackage, m_xContext, false, m_nStorageType, false, GetRelInfoStreamForName(pElement->m_aOriginalName)));
     }
 }
 
@@ -1562,8 +1554,8 @@ void OStorage_Impl::RemoveElement( SotElement_Impl* pElement )
     if ( !pElement )
         return;
 
-    if ( (pElement->m_pStorage && ( pElement->m_pStorage->m_pAntiImpl || !pElement->m_pStorage->m_aReadOnlyWrapList.empty() ))
-      || (pElement->m_pStream && ( pElement->m_pStream->m_pAntiImpl || !pElement->m_pStream->m_aInputStreamsList.empty() )) )
+    if ( (pElement->m_xStorage && ( pElement->m_xStorage->m_pAntiImpl || !pElement->m_xStorage->m_aReadOnlyWrapList.empty() ))
+      || (pElement->m_xStream && ( pElement->m_xStream->m_pAntiImpl || !pElement->m_xStream->m_aInputStreamsList.empty() )) )
         throw io::IOException( THROW_WHERE ); // TODO: Access denied
 
     if ( pElement->m_bIsInserted )
@@ -1582,17 +1574,8 @@ void OStorage_Impl::RemoveElement( SotElement_Impl* pElement )
 
 void OStorage_Impl::ClearElement( SotElement_Impl* pElement )
 {
-    if ( pElement->m_pStorage )
-    {
-        delete pElement->m_pStorage;
-        pElement->m_pStorage = nullptr;
-    }
-
-    if ( pElement->m_pStream )
-    {
-        delete pElement->m_pStream;
-        pElement->m_pStream = nullptr;
-    }
+    pElement->m_xStorage.reset();
+    pElement->m_xStream.reset();
 }
 
 void OStorage_Impl::CloneStreamElement( const OUString& aStreamName,
@@ -1609,10 +1592,10 @@ void OStorage_Impl::CloneStreamElement( const OUString& aStreamName,
     else if ( pElement->m_bIsStorage )
         throw io::IOException( THROW_WHERE );
 
-    if ( !pElement->m_pStream )
+    if (!pElement->m_xStream)
         OpenSubStream( pElement );
 
-    if ( pElement->m_pStream && pElement->m_pStream->m_xPackageStream.is() )
+    if (pElement->m_xStream && pElement->m_xStream->m_xPackageStream.is())
     {
         // the existence of m_pAntiImpl of the child is not interesting,
         // the copy will be created internally
@@ -1623,10 +1606,10 @@ void OStorage_Impl::CloneStreamElement( const OUString& aStreamName,
         // storage. The only problem is that some package streams can be accessed from outside
         // at the same time (now solved by wrappers that remember own position).
 
-        if ( bEncryptionDataProvided )
-            pElement->m_pStream->GetCopyOfLastCommit( xTargetStream, aEncryptionData );
+        if (bEncryptionDataProvided)
+            pElement->m_xStream->GetCopyOfLastCommit(xTargetStream, aEncryptionData);
         else
-            pElement->m_pStream->GetCopyOfLastCommit( xTargetStream );
+            pElement->m_xStream->GetCopyOfLastCommit(xTargetStream);
     }
     else
         throw io::IOException( THROW_WHERE ); // TODO: general_error
@@ -1657,18 +1640,18 @@ void OStorage_Impl::CreateRelStorage()
         if ( !m_pRelStorElement )
         {
             m_pRelStorElement = new SotElement_Impl( "_rels", true, true );
-            m_pRelStorElement->m_pStorage = CreateNewStorageImpl( embed::ElementModes::WRITE );
-            if ( m_pRelStorElement->m_pStorage )
-                m_pRelStorElement->m_pStorage->m_pParent = nullptr; // the relation storage is completely controlled by parent
+            m_pRelStorElement->m_xStorage.reset(CreateNewStorageImpl(embed::ElementModes::WRITE));
+            if (m_pRelStorElement->m_xStorage)
+                m_pRelStorElement->m_xStorage->m_pParent = nullptr; // the relation storage is completely controlled by parent
         }
 
-        if ( !m_pRelStorElement->m_pStorage )
+        if (!m_pRelStorElement->m_xStorage)
             OpenSubStorage( m_pRelStorElement, embed::ElementModes::WRITE );
 
-        if ( !m_pRelStorElement->m_pStorage )
+        if (!m_pRelStorElement->m_xStorage)
             throw uno::RuntimeException( THROW_WHERE );
 
-        OStorage* pResultStorage = new OStorage( m_pRelStorElement->m_pStorage, false );
+        OStorage* pResultStorage = new OStorage(m_pRelStorElement->m_xStorage.get(), false);
         m_xRelStorage.set( static_cast<embed::XStorage*>(pResultStorage) );
     }
 }
@@ -1681,7 +1664,7 @@ void OStorage_Impl::CommitStreamRelInfo( SotElement_Impl* pStreamElement )
     if ( !pStreamElement )
         throw uno::RuntimeException( THROW_WHERE );
 
-    if ( m_nStorageType == embed::StorageFormats::OFOPXML && pStreamElement->m_pStream )
+    if (m_nStorageType == embed::StorageFormats::OFOPXML && pStreamElement->m_xStream)
     {
         SAL_WARN_IF( pStreamElement->m_aName.isEmpty(), "package.xstor", "The name must not be empty!" );
 
@@ -1691,7 +1674,7 @@ void OStorage_Impl::CommitStreamRelInfo( SotElement_Impl* pStreamElement )
             CreateRelStorage();
         }
 
-        pStreamElement->m_pStream->CommitStreamRelInfo( m_xRelStorage, pStreamElement->m_aOriginalName, pStreamElement->m_aName );
+        pStreamElement->m_xStream->CommitStreamRelInfo(m_xRelStorage, pStreamElement->m_aOriginalName, pStreamElement->m_aName);
     }
 }
 
@@ -1813,8 +1796,8 @@ void OStorage_Impl::CommitRelInfo( const uno::Reference< container::XNameContain
                 m_pRelStorElement = nullptr;
                 m_xRelStorage.clear();
             }
-            else if ( m_pRelStorElement && m_pRelStorElement->m_pStorage && xNewPackageFolder.is() )
-                m_pRelStorElement->m_pStorage->InsertIntoPackageFolder( aRelsStorName, xNewPackageFolder );
+            else if ( m_pRelStorElement && m_pRelStorElement->m_xStorage && xNewPackageFolder.is() )
+                m_pRelStorElement->m_xStorage->InsertIntoPackageFolder( aRelsStorName, xNewPackageFolder );
         }
     }
 }
@@ -2081,10 +2064,10 @@ SotElement_Impl* OStorage::OpenStreamElement_Impl( const OUString& aStreamName,
 
     SAL_WARN_IF( !pElement, "package.xstor", "In case element can not be created an exception must be thrown!" );
 
-    if ( !pElement->m_pStream )
+    if (!pElement->m_xStream)
         m_pImpl->OpenSubStream( pElement );
 
-    if ( !pElement->m_pStream )
+    if (!pElement->m_xStream)
         throw io::IOException( THROW_WHERE );
 
     return pElement;
@@ -2335,9 +2318,9 @@ uno::Reference< io::XStream > SAL_CALL OStorage::openStreamElement(
     try
     {
         SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, false );
-        OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
+        OSL_ENSURE(pElement && pElement->m_xStream, "In case element can not be created an exception must be thrown!");
 
-        xResult = pElement->m_pStream->GetStream( nOpenMode, false );
+        xResult = pElement->m_xStream->GetStream(nOpenMode, false);
         SAL_WARN_IF( !xResult.is(), "package.xstor", "The method must throw exception instead of removing empty result!" );
 
         if ( m_pData->m_bReadOnlyWrap )
@@ -2453,14 +2436,14 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
         {
             throw io::IOException( THROW_WHERE );
         }
-        else if ( pElement->m_pStorage )
+        else if (pElement->m_xStorage)
         {
             // storage has already been opened; it may be opened another time, if it the mode allows to do so
-            if ( pElement->m_pStorage->m_pAntiImpl )
+            if (pElement->m_xStorage->m_pAntiImpl)
             {
                 throw io::IOException( THROW_WHERE ); // TODO: access_denied
             }
-            else if ( !pElement->m_pStorage->m_aReadOnlyWrapList.empty()
+            else if ( !pElement->m_xStorage->m_aReadOnlyWrapList.empty()
                     && ( nStorageMode & embed::ElementModes::WRITE ) )
             {
                 throw io::IOException( THROW_WHERE ); // TODO: access_denied
@@ -2470,36 +2453,36 @@ uno::Reference< embed::XStorage > SAL_CALL OStorage::openStorageElement(
                 // in case parent storage allows writing the readonly mode of the child storage is
                 // virtual, that means that it is just enough to change the flag to let it be writable
                 // and since there is no AntiImpl nobody should be notified about it
-                pElement->m_pStorage->m_nStorageMode = nStorageMode | embed::ElementModes::READ;
+                pElement->m_xStorage->m_nStorageMode = nStorageMode | embed::ElementModes::READ;
 
                 if ( ( nStorageMode & embed::ElementModes::TRUNCATE ) )
                 {
-                    for ( SotElementList_Impl::iterator pElementIter = pElement->m_pStorage->m_aChildrenList.begin();
-                           pElementIter != pElement->m_pStorage->m_aChildrenList.end(); )
-                       {
+                    for ( SotElementList_Impl::iterator pElementIter = pElement->m_xStorage->m_aChildrenList.begin();
+                           pElementIter != pElement->m_xStorage->m_aChildrenList.end(); )
+                    {
                         SotElement_Impl* pElementToDel = (*pElementIter);
                         ++pElementIter;
 
                         m_pImpl->RemoveElement( pElementToDel );
-                       }
+                    }
                 }
             }
         }
 
-        if ( !pElement->m_pStorage )
-            m_pImpl->OpenSubStorage( pElement, nStorageMode );
+        if (!pElement->m_xStorage)
+            m_pImpl->OpenSubStorage(pElement, nStorageMode);
 
-        if ( !pElement->m_pStorage )
+        if (!pElement->m_xStorage)
             throw io::IOException( THROW_WHERE ); // TODO: general_error
 
         bool bReadOnlyWrap = ( ( nStorageMode & embed::ElementModes::WRITE ) != embed::ElementModes::WRITE );
-        OStorage* pResultStorage = new OStorage( pElement->m_pStorage, bReadOnlyWrap );
+        OStorage* pResultStorage = new OStorage(pElement->m_xStorage.get(), bReadOnlyWrap);
         xResult.set( static_cast<embed::XStorage*>(pResultStorage) );
 
         if ( bReadOnlyWrap )
         {
             // Before this call is done the object must be refcounted already
-            pElement->m_pStorage->SetReadOnlyWrap( *pResultStorage );
+            pElement->m_xStorage->SetReadOnlyWrap(*pResultStorage);
 
             // before the storage disposes the stream it must deregister itself as listener
             uno::Reference< lang::XComponent > xStorageComponent( xResult, uno::UNO_QUERY_THROW );
@@ -2721,16 +2704,16 @@ void SAL_CALL OStorage::copyStorageElementLastCommitTo(
             throw io::IOException( THROW_WHERE );
         }
 
-        if ( !pElement->m_pStorage )
+        if (!pElement->m_xStorage)
             m_pImpl->OpenSubStorage( pElement, nStorageMode );
 
         uno::Reference< embed::XStorage > xResult;
-        if ( pElement->m_pStorage )
+        if (pElement->m_xStorage)
         {
             // the existence of m_pAntiImpl of the child is not interesting,
             // the copy will be created internally
 
-            pElement->m_pStorage->CopyLastCommitTo( xTargetStorage );
+            pElement->m_xStorage->CopyLastCommitTo(xTargetStorage);
         }
         else
             throw io::IOException( THROW_WHERE ); // TODO: general_error
@@ -3293,9 +3276,9 @@ uno::Reference< io::XStream > SAL_CALL OStorage::openEncryptedStream(
     try
     {
         SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamName, nOpenMode, true );
-        OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
+        OSL_ENSURE(pElement && pElement->m_xStream, "In case element can not be created an exception must be thrown!");
 
-        xResult = pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, false );
+        xResult = pElement->m_xStream->GetStream(nOpenMode, aEncryptionData, false);
         SAL_WARN_IF( !xResult.is(), "package.xstor", "The method must throw exception instead of removing empty result!" );
 
         if ( m_pData->m_bReadOnlyWrap )
@@ -3470,14 +3453,14 @@ uno::Reference< io::XInputStream > SAL_CALL OStorage::getPlainRawStreamElement(
         if ( !pElement )
             throw container::NoSuchElementException( THROW_WHERE );
 
-        if ( !pElement->m_pStream )
+        if (!pElement->m_xStream)
         {
             m_pImpl->OpenSubStream( pElement );
-            if ( !pElement->m_pStream )
+            if (!pElement->m_xStream)
                 throw io::IOException( THROW_WHERE );
         }
 
-        uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetPlainRawInStream();
+        uno::Reference<io::XInputStream> xRawInStream = pElement->m_xStream->GetPlainRawInStream();
         if ( !xRawInStream.is() )
             throw io::IOException( THROW_WHERE );
 
@@ -3568,17 +3551,17 @@ uno::Reference< io::XInputStream > SAL_CALL OStorage::getRawEncrStreamElement(
         if ( !pElement )
             throw container::NoSuchElementException( THROW_WHERE );
 
-        if ( !pElement->m_pStream )
+        if (!pElement->m_xStream)
         {
             m_pImpl->OpenSubStream( pElement );
-            if ( !pElement->m_pStream )
+            if (!pElement->m_xStream)
                 throw io::IOException( THROW_WHERE );
         }
 
-        if ( !pElement->m_pStream->IsEncrypted() )
+        if (!pElement->m_xStream->IsEncrypted())
             throw packages::NoEncryptionException( THROW_WHERE );
 
-        uno::Reference< io::XInputStream > xRawInStream = pElement->m_pStream->GetRawInStream();
+        uno::Reference< io::XInputStream > xRawInStream = pElement->m_xStream->GetRawInStream();
         if ( !xRawInStream.is() )
             throw io::IOException( THROW_WHERE );
 
@@ -3815,10 +3798,10 @@ void SAL_CALL OStorage::revert()
     for ( SotElementList_Impl::iterator pElementIter = m_pImpl->m_aChildrenList.begin();
           pElementIter != m_pImpl->m_aChildrenList.end(); ++pElementIter )
     {
-        if ( ((*pElementIter)->m_pStorage
-                && ( (*pElementIter)->m_pStorage->m_pAntiImpl || !(*pElementIter)->m_pStorage->m_aReadOnlyWrapList.empty() ))
-          || ((*pElementIter)->m_pStream
-                  && ( (*pElementIter)->m_pStream->m_pAntiImpl || !(*pElementIter)->m_pStream->m_aInputStreamsList.empty()) ) )
+        if ( ((*pElementIter)->m_xStorage
+                && ( (*pElementIter)->m_xStorage->m_pAntiImpl || !(*pElementIter)->m_xStorage->m_aReadOnlyWrapList.empty() ))
+          || ((*pElementIter)->m_xStream
+                  && ( (*pElementIter)->m_xStream->m_pAntiImpl || !(*pElementIter)->m_xStream->m_aInputStreamsList.empty()) ) )
             throw io::IOException( THROW_WHERE ); // TODO: access denied
     }
 
@@ -5165,9 +5148,9 @@ void SAL_CALL OStorage::insertStreamElementDirect(
             throw container::ElementExistException( THROW_WHERE );
 
         pElement = OpenStreamElement_Impl( aStreamName, embed::ElementModes::READWRITE, false );
-        OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
+        OSL_ENSURE(pElement && pElement->m_xStream, "In case element can not be created an exception must be thrown!");
 
-        pElement->m_pStream->InsertStreamDirectly( xInStream, aProps );
+        pElement->m_xStream->InsertStreamDirectly(xInStream, aProps);
     }
     catch( const embed::InvalidStorageException& rInvalidStorageException )
     {
@@ -5472,14 +5455,14 @@ uno::Any SAL_CALL OStorage::getElementPropertyValue( const OUString& aElementNam
         if ( !pElement->m_bIsStorage || m_pData->m_nStorageType != embed::StorageFormats::PACKAGE || aPropertyName != "MediaType" )
             throw beans::PropertyVetoException( THROW_WHERE );
 
-        if ( !pElement->m_pStorage )
+        if (!pElement->m_xStorage)
             m_pImpl->OpenSubStorage( pElement, embed::ElementModes::READ );
 
-        if ( !pElement->m_pStorage )
+        if (!pElement->m_xStorage)
             throw io::IOException( THROW_WHERE ); // TODO: general_error
 
-        pElement->m_pStorage->ReadContents();
-        return uno::makeAny( pElement->m_pStorage->m_aMediaType );
+        pElement->m_xStorage->ReadContents();
+        return uno::makeAny(pElement->m_xStorage->m_aMediaType);
     }
     catch( const embed::InvalidStorageException& rInvalidStorageException )
     {
@@ -5648,10 +5631,10 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openStreamEle
             // the transacted version of the stream should be opened
 
             SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, false );
-            assert(pElement && pElement->m_pStream && "In case element can not be created an exception must be thrown!");
+            assert(pElement && pElement->m_xStream && "In case element can not be created an exception must be thrown!");
 
-            xResult.set( pElement->m_pStream->GetStream( nOpenMode, true ),
-                         uno::UNO_QUERY_THROW );
+            xResult.set(pElement->m_xStream->GetStream(nOpenMode, true),
+                        uno::UNO_QUERY_THROW);
         }
         catch ( const container::NoSuchElementException & )
         {
@@ -5742,10 +5725,10 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted
         // the transacted version of the stream should be opened
 
         SotElement_Impl *pElement = OpenStreamElement_Impl( aStreamPath, nOpenMode, true );
-        OSL_ENSURE( pElement && pElement->m_pStream, "In case element can not be created an exception must be thrown!" );
+        OSL_ENSURE(pElement && pElement->m_xStream, "In case element can not be created an exception must be thrown!");
 
-        xResult.set( pElement->m_pStream->GetStream( nOpenMode, aEncryptionData, true ),
-                     uno::UNO_QUERY_THROW );
+        xResult.set(pElement->m_xStream->GetStream(nOpenMode, aEncryptionData, true),
+                    uno::UNO_QUERY_THROW);
     }
     else
     {
diff --git a/package/source/xstor/xstorage.hxx b/package/source/xstor/xstorage.hxx
index 6bb5bc6..568caf3 100644
--- a/package/source/xstor/xstorage.hxx
+++ b/package/source/xstor/xstorage.hxx
@@ -85,12 +85,11 @@ struct SotElement_Impl
     bool                    m_bIsInserted;
     bool                    m_bIsStorage;
 
-    OStorage_Impl*              m_pStorage;
-    OWriteStream_Impl*          m_pStream;
+    std::unique_ptr<OStorage_Impl> m_xStorage;
+    std::unique_ptr<OWriteStream_Impl> m_xStream;
 
 public:
-                                SotElement_Impl( const OUString& rName, bool bStor, bool bNew );
-                                ~SotElement_Impl();
+    SotElement_Impl(const OUString& rName, bool bStor, bool bNew);
 };
 
 typedef ::std::list< SotElement_Impl* > SotElementList_Impl;
diff --git a/sc/inc/funcuno.hxx b/sc/inc/funcuno.hxx
index ad32fb6..b7c87ff 100644
--- a/sc/inc/funcuno.hxx
+++ b/sc/inc/funcuno.hxx
@@ -36,14 +36,13 @@ css::uno::Reference< css::uno::XInterface > SAL_CALL
 class ScTempDocCache
 {
 private:
-    ScDocument*     pDoc;
+    std::unique_ptr<ScDocument> xDoc;
     bool            bInUse;
 
 public:
-                ScTempDocCache();
-                ~ScTempDocCache();
+    ScTempDocCache();
 
-    ScDocument* GetDocument() const     { return pDoc; }
+    ScDocument* GetDocument() const     { return xDoc.get(); }
     bool        IsInUse() const         { return bInUse; }
     void        SetInUse( bool bSet )   { bInUse = bSet; }
 
diff --git a/sc/source/filter/inc/XclExpChangeTrack.hxx b/sc/source/filter/inc/XclExpChangeTrack.hxx
index 6f633dc..65d8dd4 100644
--- a/sc/source/filter/inc/XclExpChangeTrack.hxx
+++ b/sc/source/filter/inc/XclExpChangeTrack.hxx
@@ -596,7 +596,7 @@ class XclExpChangeTrack : protected XclExpRoot
     XclExpChTrTabIdBuffer*        pTabIdBuffer;
     TabIdBufferType maBuffers;
 
-    ScDocument*                 pTempDoc;           // empty document
+    std::unique_ptr<ScDocument> xTempDoc;           // empty document
 
     XclExpChTrHeader*           pHeader;            // header record for last GUID
     sal_uInt8                   aGUID[ 16 ];        // GUID for action info records
diff --git a/sc/source/filter/xcl97/XclExpChangeTrack.cxx b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
index a9cce7f..c959ab4 100644
--- a/sc/source/filter/xcl97/XclExpChangeTrack.cxx
+++ b/sc/source/filter/xcl97/XclExpChangeTrack.cxx
@@ -1408,7 +1408,6 @@ XclExpChangeTrack::XclExpChangeTrack( const XclExpRoot& rRoot ) :
     XclExpRoot( rRoot ),
     aActionStack(),
     pTabIdBuffer( nullptr ),
-    pTempDoc( nullptr ),
     pHeader( nullptr ),
     bValidGUID( false )
 {
@@ -1528,8 +1527,6 @@ XclExpChangeTrack::~XclExpChangeTrack()
         delete aActionStack.top();
         aActionStack.pop();
     }
-
-    delete pTempDoc;
 }
 
 ScChangeTrack* XclExpChangeTrack::CreateTempChangeTrack()
@@ -1540,30 +1537,30 @@ ScChangeTrack* XclExpChangeTrack::CreateTempChangeTrack()
     if( !pOrigChangeTrack )
         return nullptr;
 
-    assert(!pTempDoc);
+    assert(!xTempDoc);
     // create empty document
-    pTempDoc = new ScDocument;
+    xTempDoc.reset(new ScDocument);
 
     // adjust table count
     SCTAB nOrigCount = GetDoc().GetTableCount();
     OUString sTabName;
     for( sal_Int32 nIndex = 0; nIndex < nOrigCount; nIndex++ )
     {
-        pTempDoc->CreateValidTabName( sTabName );
-        pTempDoc->InsertTab( SC_TAB_APPEND, sTabName );
+        xTempDoc->CreateValidTabName(sTabName);
+        xTempDoc->InsertTab(SC_TAB_APPEND, sTabName);
     }
-    OSL_ENSURE( nOrigCount == pTempDoc->GetTableCount(),
-        "XclExpChangeTrack::CreateTempChangeTrack - table count mismatch" );
-    if( nOrigCount != pTempDoc->GetTableCount() )
+    OSL_ENSURE(nOrigCount == xTempDoc->GetTableCount(),
+        "XclExpChangeTrack::CreateTempChangeTrack - table count mismatch");
+    if(nOrigCount != xTempDoc->GetTableCount())
         return nullptr;
 
-    return pOrigChangeTrack->Clone(pTempDoc);
+    return pOrigChangeTrack->Clone(xTempDoc.get());
 }
 
 void XclExpChangeTrack::PushActionRecord( const ScChangeAction& rAction )
 {
     XclExpChTrAction* pXclAction = nullptr;
-    ScChangeTrack* pTempChangeTrack = pTempDoc->GetChangeTrack();
+    ScChangeTrack* pTempChangeTrack = xTempDoc->GetChangeTrack();
     switch( rAction.GetType() )
     {
         case SC_CAT_CONTENT:
diff --git a/sc/source/ui/inc/undoblk.hxx b/sc/source/ui/inc/undoblk.hxx
index 6dd755f..4be768e 100644
--- a/sc/source/ui/inc/undoblk.hxx
+++ b/sc/source/ui/inc/undoblk.hxx
@@ -439,7 +439,7 @@ public:
 private:
     ScCellMergeOption maOption;
     bool            mbMergeContents;        // Merge contents in Redo().
-    ScDocument*     mpUndoDoc;              // when data is merged
+    std::unique_ptr<ScDocument> mxUndoDoc;              // when data is merged
     SdrUndoAction*  mpDrawUndo;
 
     void            DoChange( bool bUndo ) const;
@@ -592,10 +592,9 @@ private:
 class ScUndoListNames: public ScBlockUndo
 {
 public:
-                    ScUndoListNames( ScDocShell* pNewDocShell,
-                                     const ScRange& rRange,
-                                     ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc );
-    virtual         ~ScUndoListNames() override;
+    ScUndoListNames(ScDocShell* pNewDocShell,
+                    const ScRange& rRange,
+                    ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -605,8 +604,8 @@ public:
     virtual OUString GetComment() const override;
 
 private:
-    ScDocument*     pUndoDoc;
-    ScDocument*     pRedoDoc;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScDocument> xRedoDoc;
 
     void            DoChange( ScDocument* pSrcDoc ) const;
 };
@@ -687,9 +686,8 @@ private:
 class ScUndoRefreshLink: public ScSimpleUndo
 {
 public:
-                    ScUndoRefreshLink( ScDocShell* pNewDocShell,
-                                       ScDocument* pNewUndoDoc );
-    virtual         ~ScUndoRefreshLink() override;
+    ScUndoRefreshLink(ScDocShell* pNewDocShell,
+                      ScDocument* pNewUndoDoc);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -699,8 +697,8 @@ public:
     virtual OUString GetComment() const override;
 
 private:
-    ScDocument*     pUndoDoc;
-    ScDocument*     pRedoDoc;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScDocument> xRedoDoc;
 };
 
 class ScUndoEnterMatrix: public ScBlockUndo
@@ -784,18 +782,17 @@ private:
 class ScUndoUpdateAreaLink : public ScSimpleUndo        //! also change BlockUndo?
 {
 public:
-                    ScUndoUpdateAreaLink( ScDocShell* pShell,
-                                          const OUString& rOldD,
-                                          const OUString& rOldF, const OUString& rOldO,
-                                          const OUString& rOldA, const ScRange& rOldR,
-                                          sal_uLong nOldRD,
-                                          const OUString& rNewD,
-                                          const OUString& rNewF, const OUString& rNewO,
-                                          const OUString& rNewA, const ScRange& rNewR,
-                                          sal_uLong nNewRD,
-                                          ScDocument* pUndo, ScDocument* pRedo,
-                                          bool bDoInsert );
-    virtual         ~ScUndoUpdateAreaLink() override;
+    ScUndoUpdateAreaLink(ScDocShell* pShell,
+                         const OUString& rOldD,
+                         const OUString& rOldF, const OUString& rOldO,
+                         const OUString& rOldA, const ScRange& rOldR,
+                         sal_uLong nOldRD,
+                         const OUString& rNewD,
+                         const OUString& rNewF, const OUString& rNewO,
+                         const OUString& rNewA, const ScRange& rNewR,
+                         sal_uLong nNewRD,
+                         ScDocument* pUndo, ScDocument* pRedo,
+                         bool bDoInsert);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -815,8 +812,8 @@ private:
     OUString        aNewOpt;
     OUString        aNewArea;
     ScRange         aNewRange;
-    ScDocument*     pUndoDoc;
-    ScDocument*     pRedoDoc;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScDocument> xRedoDoc;
     sal_uLong       nOldRefresh;
     sal_uLong       nNewRefresh;
     bool            bWithInsert;
@@ -937,12 +934,11 @@ private:
 class ScUndoBorder: public ScBlockUndo
 {
 public:
-                    ScUndoBorder( ScDocShell* pNewDocShell,
-                                    const ScRangeList& rRangeList,
-                                    ScDocument* pNewUndoDoc,
-                                    const SvxBoxItem& rNewOuter,
-                                    const SvxBoxInfoItem& rNewInner );
-    virtual         ~ScUndoBorder() override;
+    ScUndoBorder(ScDocShell* pNewDocShell,
+                 const ScRangeList& rRangeList,
+                 ScDocument* pNewUndoDoc,
+                 const SvxBoxItem& rNewOuter,
+                 const SvxBoxInfoItem& rNewInner);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -952,10 +948,10 @@ public:
     virtual OUString GetComment() const override;
 
 private:
-    ScDocument*     pUndoDoc;
-    ScRangeList*    pRanges;
-    SvxBoxItem*     pOuter;
-    SvxBoxInfoItem* pInner;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScRangeList> xRanges;
+    std::unique_ptr<SvxBoxItem> xOuter;
+    std::unique_ptr<SvxBoxInfoItem> xInner;
 };
 
 #endif
diff --git a/sc/source/ui/inc/undodat.hxx b/sc/source/ui/inc/undodat.hxx
index ae55159..fdb6f3c 100644
--- a/sc/source/ui/inc/undodat.hxx
+++ b/sc/source/ui/inc/undodat.hxx
@@ -97,11 +97,10 @@ private:
 class ScUndoOutlineLevel: public ScSimpleUndo
 {
 public:
-                    ScUndoOutlineLevel( ScDocShell* pNewDocShell,
-                            SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
-                            ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
-                            bool bNewColumns, sal_uInt16 nNewLevel );
-    virtual         ~ScUndoOutlineLevel() override;
+    ScUndoOutlineLevel(ScDocShell* pNewDocShell,
+                       SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
+                       ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
+                       bool bNewColumns, sal_uInt16 nNewLevel);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -114,8 +113,8 @@ private:
     SCCOLROW        nStart;
     SCCOLROW        nEnd;
     SCTAB           nTab;
-    ScDocument*     pUndoDoc;
-    ScOutlineTable* pUndoTable;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScOutlineTable> xUndoTable;
     bool            bColumns;
     sal_uInt16      nLevel;
 };
@@ -123,12 +122,11 @@ private:
 class ScUndoOutlineBlock: public ScSimpleUndo
 {
 public:
-                    ScUndoOutlineBlock( ScDocShell* pNewDocShell,
-                            SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
-                            SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
-                            ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
-                            bool bNewShow );
-    virtual         ~ScUndoOutlineBlock() override;
+    ScUndoOutlineBlock(ScDocShell* pNewDocShell,
+                       SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
+                       SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
+                       ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
+                       bool bNewShow);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -140,19 +138,18 @@ public:
 private:
     ScAddress       aBlockStart;
     ScAddress       aBlockEnd;
-    ScDocument*     pUndoDoc;
-    ScOutlineTable* pUndoTable;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScOutlineTable> xUndoTable;
     bool            bShow;
 };
 
 class ScUndoRemoveAllOutlines: public ScSimpleUndo
 {
 public:
-                    ScUndoRemoveAllOutlines( ScDocShell* pNewDocShell,
-                            SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
-                            SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
-                            ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab );
-    virtual         ~ScUndoRemoveAllOutlines() override;
+    ScUndoRemoveAllOutlines(ScDocShell* pNewDocShell,
+            SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
+            SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
+            ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -164,18 +161,17 @@ public:
 private:
     ScAddress       aBlockStart;
     ScAddress       aBlockEnd;
-    ScDocument*     pUndoDoc;
-    ScOutlineTable* pUndoTable;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScOutlineTable> xUndoTable;
 };
 
 class ScUndoAutoOutline: public ScSimpleUndo
 {
 public:
-                    ScUndoAutoOutline( ScDocShell* pNewDocShell,
-                            SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
-                            SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
-                            ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab );
-    virtual         ~ScUndoAutoOutline() override;
+    ScUndoAutoOutline(ScDocShell* pNewDocShell,
+                      SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
+                      SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
+                      ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -187,19 +183,17 @@ public:
 private:
     ScAddress       aBlockStart;
     ScAddress       aBlockEnd;
-    ScDocument*     pUndoDoc;
-    ScOutlineTable* pUndoTable;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScOutlineTable> xUndoTable;
 };
 
 class ScUndoSubTotals: public ScDBFuncUndo
 {
 public:
-                    ScUndoSubTotals( ScDocShell* pNewDocShell, SCTAB nNewTab,
-                            const ScSubTotalParam& rNewParam, SCROW nNewEndY,
-                            ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
-//                          ScDBData* pNewData,
-                            ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB );
-    virtual         ~ScUndoSubTotals() override;
+    ScUndoSubTotals(ScDocShell* pNewDocShell, SCTAB nNewTab,
+                    const ScSubTotalParam& rNewParam, SCROW nNewEndY,
+                    ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
+                    ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -212,11 +206,10 @@ private:
     SCTAB           nTab;
     ScSubTotalParam aParam;                         // The original passed parameter
     SCROW           nNewEndRow;                     // Size of result
-    ScDocument*     pUndoDoc;
-    ScOutlineTable* pUndoTable;
-//  ScDBData*       pUndoDBData;
-    ScRangeName*    pUndoRange;
-    ScDBCollection* pUndoDB;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScOutlineTable> xUndoTable;
+    std::unique_ptr<ScRangeName> xUndoRange;
+    std::unique_ptr<ScDBCollection> xUndoDB;
 };
 
 class ScUndoQuery: public ScDBFuncUndo
@@ -239,8 +232,8 @@ private:
     SdrUndoAction*  pDrawUndo;
     SCTAB           nTab;
     ScQueryParam    aQueryParam;
-    ScDocument*     pUndoDoc;
-    ScDBCollection* pUndoDB;                // due to source and target range
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScDBCollection> xUndoDB;                // due to source and target range
     ScRange         aOldDest;
     ScRange         aAdvSource;
     bool            bIsAdvanced;
@@ -291,12 +284,11 @@ private:
 class ScUndoImportData: public ScSimpleUndo
 {
 public:
-                    ScUndoImportData( ScDocShell* pNewDocShell, SCTAB nNewTab,
-                            const ScImportParam& rParam, SCCOL nNewEndX, SCROW nNewEndY,
-                            SCCOL nNewFormula,
-                            ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
-                            ScDBData* pNewUndoData, ScDBData* pNewRedoData );
-    virtual         ~ScUndoImportData() override;
+    ScUndoImportData(ScDocShell* pNewDocShell, SCTAB nNewTab,
+                     const ScImportParam& rParam, SCCOL nNewEndX, SCROW nNewEndY,
+                     SCCOL nNewFormula,
+                     ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
+                     ScDBData* pNewUndoData, ScDBData* pNewRedoData);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -310,10 +302,10 @@ private:
     ScImportParam   aImportParam;
     SCCOL           nEndCol;
     SCROW           nEndRow;
-    ScDocument*     pUndoDoc;
-    ScDocument*     pRedoDoc;
-    ScDBData*       pUndoDBData;
-    ScDBData*       pRedoDBData;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScDocument> xRedoDoc;
+    std::unique_ptr<ScDBData> xUndoDBData;
+    std::unique_ptr<ScDBData> xRedoDBData;
     SCCOL           nFormulaCols;
     bool            bRedoFilled;
 };
@@ -321,13 +313,12 @@ private:
 class ScUndoRepeatDB: public ScSimpleUndo
 {
 public:
-                    ScUndoRepeatDB( ScDocShell* pNewDocShell, SCTAB nNewTab,
-                            SCCOL nStartX, SCROW nStartY, SCCOL nEndX, SCROW nEndY,
-                            SCROW nResultEndRow, SCCOL nCurX, SCROW nCurY,
-                            ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
-                            ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB,
-                            const ScRange* pOldQ, const ScRange* pNewQ );
-    virtual         ~ScUndoRepeatDB() override;
+    ScUndoRepeatDB(ScDocShell* pNewDocShell, SCTAB nNewTab,
+                   SCCOL nStartX, SCROW nStartY, SCCOL nEndX, SCROW nEndY,
+                   SCROW nResultEndRow, SCCOL nCurX, SCROW nCurY,
+                   ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
+                   ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB,
+                   const ScRange* pOldQ, const ScRange* pNewQ);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -341,10 +332,10 @@ private:
     ScAddress       aBlockEnd;
     SCROW           nNewEndRow;
     ScAddress       aCursorPos;
-    ScDocument*     pUndoDoc;
-    ScOutlineTable* pUndoTable;
-    ScRangeName*    pUndoRange;
-    ScDBCollection* pUndoDB;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScOutlineTable> xUndoTable;
+    std::unique_ptr<ScRangeName> xUndoRange;
+    std::unique_ptr<ScDBCollection> xUndoDB;
     ScRange         aOldQuery;
     ScRange         aNewQuery;
     bool            bQuerySize;
@@ -353,11 +344,10 @@ private:
 class ScUndoDataPilot: public ScSimpleUndo
 {
 public:
-                    ScUndoDataPilot( ScDocShell* pNewDocShell,
-                            ScDocument* pOldDoc, ScDocument* pNewDoc,
-                            const ScDPObject* pOldObj, const ScDPObject* pNewObj,
-                            bool bMove );
-    virtual         ~ScUndoDataPilot() override;
+    ScUndoDataPilot(ScDocShell* pNewDocShell,
+                    ScDocument* pOldDoc, ScDocument* pNewDoc,
+                    const ScDPObject* pOldObj, const ScDPObject* pNewObj,
+                    bool bMove);
 
     virtual void    Undo() override;
     virtual void    Redo() override;
@@ -367,22 +357,21 @@ public:
     virtual OUString GetComment() const override;
 
 private:
-    ScDocument*     pOldUndoDoc;
-    ScDocument*     pNewUndoDoc;
-    ScDPObject*     pOldDPObject;
-    ScDPObject*     pNewDPObject;
+    std::unique_ptr<ScDocument> xOldUndoDoc;
+    std::unique_ptr<ScDocument> xNewUndoDoc;
+    std::unique_ptr<ScDPObject> xOldDPObject;
+    std::unique_ptr<ScDPObject> xNewDPObject;
     bool            bAllowMove;
 };
 
 class ScUndoConsolidate: public ScSimpleUndo
 {
 public:
-                        ScUndoConsolidate( ScDocShell* pNewDocShell,
-                                const ScArea& rArea, const ScConsolidateParam& rPar,
-                                ScDocument* pNewUndoDoc, bool bReference,
-                                SCROW nInsCount, ScOutlineTable* pTab,
-                                ScDBData* pData );
-    virtual             ~ScUndoConsolidate() override;
+    ScUndoConsolidate(ScDocShell* pNewDocShell,
+                      const ScArea& rArea, const ScConsolidateParam& rPar,
+                      ScDocument* pNewUndoDoc, bool bReference,
+                      SCROW nInsCount, ScOutlineTable* pTab,
+                      ScDBData* pData);
 
     virtual void        Undo() override;
     virtual void        Redo() override;
@@ -393,12 +382,12 @@ public:
 
 private:
     ScArea              aDestArea;
-    ScDocument*         pUndoDoc;
+    std::unique_ptr<ScDocument> xUndoDoc;
     ScConsolidateParam  aParam;
     bool                bInsRef;
     SCSIZE              nInsertCount;
-    ScOutlineTable*     pUndoTab;
-    ScDBData*           pUndoData;
+    std::unique_ptr<ScOutlineTable> xUndoTab;
+    std::unique_ptr<ScDBData> xUndoData;
 };
 
 class ScUndoChartData: public ScSimpleUndo
@@ -436,16 +425,13 @@ private:
 class ScUndoDataForm: public ScBlockUndo
 {
 public:
-                    ScUndoDataForm( ScDocShell* pNewDocShell,
-                                SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
-                                SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
-                                const ScMarkData& rMark,
-                                ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
-                                InsertDeleteFlags nNewFlags,
-                                ScRefUndoData* pRefData
-                                 );
-    virtual     ~ScUndoDataForm() override;
-
+    ScUndoDataForm(ScDocShell* pNewDocShell,
+                   SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
+                   SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
+                   const ScMarkData& rMark,
+                   ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc,
+                   InsertDeleteFlags nNewFlags,
+                   ScRefUndoData* pRefData);
     virtual void    Undo() override;
     virtual void    Redo() override;
     virtual void    Repeat(SfxRepeatTarget& rTarget) override;
@@ -454,12 +440,12 @@ public:
     virtual OUString GetComment() const override;
 
 private:
-    std::unique_ptr<ScMarkData> mpMarkData;
-    ScDocument*     pUndoDoc;
-    ScDocument*     pRedoDoc;
+    std::unique_ptr<ScMarkData> mxMarkData;
+    std::unique_ptr<ScDocument> xUndoDoc;
+    std::unique_ptr<ScDocument> xRedoDoc;
     InsertDeleteFlags nFlags;
-    ScRefUndoData*  pRefUndoData;
-    ScRefUndoData*  pRefRedoData;
+    std::unique_ptr<ScRefUndoData> xRefUndoData;
+    std::unique_ptr<ScRefUndoData> xRefRedoData;
     sal_uLong       nStartChangeAction;
     sal_uLong       nEndChangeAction;
     bool            bRedoFilled;
diff --git a/sc/source/ui/inc/undotab.hxx b/sc/source/ui/inc/undotab.hxx
index 2148814..662dd03 100644
--- a/sc/source/ui/inc/undotab.hxx
+++ b/sc/source/ui/inc/undotab.hxx
@@ -271,7 +271,7 @@ public:
 private:
     SCTAB       nTab;
     SCTAB       nCount;
-    ScDocument* pRedoDoc;
+    std::unique_ptr<ScDocument> xRedoDoc;
     SdrUndoAction*  pDrawUndo;
 
     void DoChange() const;
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 3bbe625..46b5d47 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -1432,20 +1432,14 @@ bool ScUndoDragDrop::CanRepeat(SfxRepeatTarget& /* rTarget */) const
     return false;           // not possible
 }
 
-//      Insert list containing range names
-//      (Insert|Name|Insert =>[List])
-ScUndoListNames::ScUndoListNames( ScDocShell* pNewDocShell, const ScRange& rRange,
-                ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc ) :
-    ScBlockUndo( pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT ),
-    pUndoDoc( pNewUndoDoc ),
-    pRedoDoc( pNewRedoDoc )
-{
-}
-
-ScUndoListNames::~ScUndoListNames()
+// Insert list containing range names
+// (Insert|Name|Insert =>[List])
+ScUndoListNames::ScUndoListNames(ScDocShell* pNewDocShell, const ScRange& rRange,
+                                 ScDocument* pNewUndoDoc, ScDocument* pNewRedoDoc)
+    : ScBlockUndo(pNewDocShell, rRange, SC_UNDO_AUTOHEIGHT)
+    , xUndoDoc(pNewUndoDoc)
+    , xRedoDoc(pNewRedoDoc)
 {
-    delete pUndoDoc;
-    delete pRedoDoc;
 }
 
 OUString ScUndoListNames::GetComment() const
@@ -1469,14 +1463,14 @@ void ScUndoListNames::DoChange( ScDocument* pSrcDoc ) const
 void ScUndoListNames::Undo()
 {
     BeginUndo();
-    DoChange(pUndoDoc);
+    DoChange(xUndoDoc.get());
     EndUndo();
 }
 
 void ScUndoListNames::Redo()
 {
     BeginRedo();
-    DoChange(pRedoDoc);
+    DoChange(xRedoDoc.get());
     EndRedo();
 }
 
@@ -2258,23 +2252,15 @@ static ScRange lcl_TotalRange( const ScRangeList& rRanges )
     return aTotal;
 }
 
-ScUndoBorder::ScUndoBorder( ScDocShell* pNewDocShell,
-                            const ScRangeList& rRangeList, ScDocument* pNewUndoDoc,
-                            const SvxBoxItem& rNewOuter, const SvxBoxInfoItem& rNewInner ) :
-    ScBlockUndo( pNewDocShell, lcl_TotalRange(rRangeList), SC_UNDO_SIMPLE ),
-    pUndoDoc( pNewUndoDoc )
-{
-    pRanges = new ScRangeList(rRangeList);
-    pOuter = new SvxBoxItem(rNewOuter);
-    pInner = new SvxBoxInfoItem(rNewInner);
-}
-
-ScUndoBorder::~ScUndoBorder()
+ScUndoBorder::ScUndoBorder(ScDocShell* pNewDocShell,
+                           const ScRangeList& rRangeList, ScDocument* pNewUndoDoc,
+                           const SvxBoxItem& rNewOuter, const SvxBoxInfoItem& rNewInner)
+    : ScBlockUndo(pNewDocShell, lcl_TotalRange(rRangeList), SC_UNDO_SIMPLE)
+    , xUndoDoc(pNewUndoDoc)
 {
-    delete pUndoDoc;
-    delete pRanges;
-    delete pOuter;
-    delete pInner;
+    xRanges.reset(new ScRangeList(rRangeList));
+    xOuter.reset(new SvxBoxItem(rNewOuter));
+    xInner.reset(new SvxBoxInfoItem(rNewInner));
 }
 
 OUString ScUndoBorder::GetComment() const
@@ -2288,8 +2274,8 @@ void ScUndoBorder::Undo()
 
     ScDocument& rDoc = pDocShell->GetDocument();
     ScMarkData aMarkData;
-    aMarkData.MarkFromRangeList( *pRanges, false );
-    pUndoDoc->CopyToDocument(aBlockRange, InsertDeleteFlags::ATTRIB, true, rDoc, &aMarkData);
+    aMarkData.MarkFromRangeList(*xRanges, false);
+    xUndoDoc->CopyToDocument(aBlockRange, InsertDeleteFlags::ATTRIB, true, rDoc, &aMarkData);
     pDocShell->PostPaint( aBlockRange, PaintPartFlags::Grid, SC_PF_LINES | SC_PF_TESTMERGE );
 
     EndUndo();
@@ -2300,20 +2286,20 @@ void ScUndoBorder::Redo()
     BeginRedo();
 
     ScDocument& rDoc = pDocShell->GetDocument();        // call function at docfunc
-    size_t nCount = pRanges->size();
+    size_t nCount = xRanges->size();
     for (size_t i = 0; i < nCount; ++i )
     {
-        ScRange aRange = *(*pRanges)[i];
+        ScRange aRange = *(*xRanges)[i];
         SCTAB nTab = aRange.aStart.Tab();
 
         ScMarkData aMark;
         aMark.SetMarkArea( aRange );
         aMark.SelectTable( nTab, true );
 
-        rDoc.ApplySelectionFrame( aMark, pOuter, pInner );
+        rDoc.ApplySelectionFrame(aMark, xOuter.get(), xInner.get());
     }
     for (size_t i = 0; i < nCount; ++i)
-        pDocShell->PostPaint( *(*pRanges)[i], PaintPartFlags::Grid, SC_PF_LINES | SC_PF_TESTMERGE );
+        pDocShell->PostPaint( *(*xRanges)[i], PaintPartFlags::Grid, SC_PF_LINES | SC_PF_TESTMERGE );
 
     EndRedo();
 }
diff --git a/sc/source/ui/undo/undoblk3.cxx b/sc/source/ui/undo/undoblk3.cxx
index 5fe6c5e..d5690e2 100644
--- a/sc/source/ui/undo/undoblk3.cxx
+++ b/sc/source/ui/undo/undoblk3.cxx
@@ -634,19 +634,18 @@ bool ScUndoAutoFill::CanRepeat(SfxRepeatTarget& rTarget) const
     return dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr;
 }
 
-ScUndoMerge::ScUndoMerge( ScDocShell* pNewDocShell, const ScCellMergeOption& rOption,
-                          bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo )
-    :   ScSimpleUndo( pNewDocShell ),
-        maOption(rOption),
-        mbMergeContents( bMergeContents ),
-        mpUndoDoc( pUndoDoc ),
-        mpDrawUndo( pDrawUndo )
+ScUndoMerge::ScUndoMerge(ScDocShell* pNewDocShell, const ScCellMergeOption& rOption,
+                         bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo)
+    : ScSimpleUndo(pNewDocShell)
+    , maOption(rOption)
+    , mbMergeContents(bMergeContents)
+    , mxUndoDoc(pUndoDoc)
+    , mpDrawUndo(pDrawUndo)
 {
 }
 
 ScUndoMerge::~ScUndoMerge()
 {
-    delete mpUndoDoc;
     DeleteSdrUndoAction( mpDrawUndo );
 }
 
@@ -697,7 +696,7 @@ void ScUndoMerge::DoChange( bool bUndo ) const
         }
 
         // undo -> copy back deleted contents
-        if (bUndo && mpUndoDoc)
+        if (bUndo && mxUndoDoc)
         {
             // If there are note captions to be deleted during Undo they were
             // kept or moved during the merge and copied to the Undo document
@@ -706,7 +705,7 @@ void ScUndoMerge::DoChange( bool bUndo ) const
             // instead of deleting it.
             rDoc.DeleteAreaTab( aRange,
                     InsertDeleteFlags::CONTENTS | InsertDeleteFlags::NOCAPTIONS | InsertDeleteFlags::FORGETCAPTIONS );
-            mpUndoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL|InsertDeleteFlags::NOCAPTIONS, false, rDoc);
+            mxUndoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL|InsertDeleteFlags::NOCAPTIONS, false, rDoc);
         }
 
         // redo -> merge contents again
@@ -1364,18 +1363,11 @@ bool ScUndoRefConversion::CanRepeat(SfxRepeatTarget& rTarget) const
     return dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr;
 }
 
-ScUndoRefreshLink::ScUndoRefreshLink( ScDocShell* pNewDocShell,
-                                    ScDocument* pNewUndoDoc )
-    :   ScSimpleUndo( pNewDocShell ),
-        pUndoDoc( pNewUndoDoc ),
-        pRedoDoc( nullptr )
-{
-}
-
-ScUndoRefreshLink::~ScUndoRefreshLink()
+ScUndoRefreshLink::ScUndoRefreshLink(ScDocShell* pNewDocShell,
+                                     ScDocument* pNewUndoDoc)
+    : ScSimpleUndo(pNewDocShell)
+    , xUndoDoc(pNewUndoDoc)
 {
-    delete pUndoDoc;
-    delete pRedoDoc;
 }
 
 OUString ScUndoRefreshLink::GetComment() const
@@ -1387,42 +1379,42 @@ void ScUndoRefreshLink::Undo()
 {
     BeginUndo();
 
-    bool bMakeRedo = !pRedoDoc;
+    bool bMakeRedo = !xRedoDoc;
     if (bMakeRedo)
-        pRedoDoc = new ScDocument( SCDOCMODE_UNDO );
+        xRedoDoc.reset(new ScDocument(SCDOCMODE_UNDO));
 
     bool bFirst = true;
     ScDocument& rDoc = pDocShell->GetDocument();
     SCTAB nCount = rDoc.GetTableCount();
     for (SCTAB nTab=0; nTab<nCount; nTab++)
-        if (pUndoDoc->HasTable(nTab))
+        if (xUndoDoc->HasTable(nTab))
         {
             ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
             if (bMakeRedo)
             {
                 if (bFirst)
-                    pRedoDoc->InitUndo( &rDoc, nTab, nTab, true, true );
+                    xRedoDoc->InitUndo(&rDoc, nTab, nTab, true, true);
                 else
-                    pRedoDoc->AddUndoTab( nTab, nTab, true, true );
+                    xRedoDoc->AddUndoTab(nTab, nTab, true, true);
                 bFirst = false;
-                rDoc.CopyToDocument(aRange, InsertDeleteFlags::ALL, false, *pRedoDoc);
-                pRedoDoc->SetLink( nTab,
-                                   rDoc.GetLinkMode(nTab),
-                                   rDoc.GetLinkDoc(nTab),
-                                   rDoc.GetLinkFlt(nTab),
-                                   rDoc.GetLinkOpt(nTab),
-                                   rDoc.GetLinkTab(nTab),
-                                   rDoc.GetLinkRefreshDelay(nTab) );
-                pRedoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) );
+                rDoc.CopyToDocument(aRange, InsertDeleteFlags::ALL, false, *xRedoDoc);
+                xRedoDoc->SetLink(nTab,
+                                  rDoc.GetLinkMode(nTab),
+                                  rDoc.GetLinkDoc(nTab),
+                                  rDoc.GetLinkFlt(nTab),
+                                  rDoc.GetLinkOpt(nTab),
+                                  rDoc.GetLinkTab(nTab),
+                                  rDoc.GetLinkRefreshDelay(nTab));
+                xRedoDoc->SetTabBgColor( nTab, rDoc.GetTabBgColor(nTab) );
             }
 
             rDoc.DeleteAreaTab( aRange,InsertDeleteFlags::ALL );
-            pUndoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL, false, rDoc);
-            rDoc.SetLink( nTab, pUndoDoc->GetLinkMode(nTab), pUndoDoc->GetLinkDoc(nTab),
-                                 pUndoDoc->GetLinkFlt(nTab),  pUndoDoc->GetLinkOpt(nTab),
-                                 pUndoDoc->GetLinkTab(nTab),
-                                 pUndoDoc->GetLinkRefreshDelay(nTab) );
-            rDoc.SetTabBgColor( nTab, pUndoDoc->GetTabBgColor(nTab) );
+            xUndoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL, false, rDoc);
+            rDoc.SetLink(nTab, xUndoDoc->GetLinkMode(nTab), xUndoDoc->GetLinkDoc(nTab),
+                               xUndoDoc->GetLinkFlt(nTab),  xUndoDoc->GetLinkOpt(nTab),
+                               xUndoDoc->GetLinkTab(nTab),
+                               xUndoDoc->GetLinkRefreshDelay(nTab) );
+            rDoc.SetTabBgColor(nTab, xUndoDoc->GetTabBgColor(nTab));
         }
 
     pDocShell->PostPaintGridAll();
@@ -1433,27 +1425,27 @@ void ScUndoRefreshLink::Undo()
 
 void ScUndoRefreshLink::Redo()
 {
-    OSL_ENSURE(pRedoDoc, "No RedoDoc for ScUndoRefreshLink::Redo");
+    OSL_ENSURE(xRedoDoc, "No RedoDoc for ScUndoRefreshLink::Redo");
 
     BeginUndo();
 
     ScDocument& rDoc = pDocShell->GetDocument();
     SCTAB nCount = rDoc.GetTableCount();
     for (SCTAB nTab=0; nTab<nCount; nTab++)
-        if (pRedoDoc->HasTable(nTab))
+        if (xRedoDoc->HasTable(nTab))
         {
             ScRange aRange(0,0,nTab,MAXCOL,MAXROW,nTab);
 
             rDoc.DeleteAreaTab( aRange, InsertDeleteFlags::ALL );
-            pRedoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL, false, rDoc);
-            rDoc.SetLink( nTab,
-                           pRedoDoc->GetLinkMode(nTab),
-                           pRedoDoc->GetLinkDoc(nTab),
-                           pRedoDoc->GetLinkFlt(nTab),
-                           pRedoDoc->GetLinkOpt(nTab),
-                           pRedoDoc->GetLinkTab(nTab),
-                           pRedoDoc->GetLinkRefreshDelay(nTab) );
-            rDoc.SetTabBgColor( nTab, pRedoDoc->GetTabBgColor(nTab) );
+            xRedoDoc->CopyToDocument(aRange, InsertDeleteFlags::ALL, false, rDoc);
+            rDoc.SetLink(nTab,
+                         xRedoDoc->GetLinkMode(nTab),
+                         xRedoDoc->GetLinkDoc(nTab),
+                         xRedoDoc->GetLinkFlt(nTab),
+                         xRedoDoc->GetLinkOpt(nTab),
+                         xRedoDoc->GetLinkTab(nTab),
+                         xRedoDoc->GetLinkRefreshDelay(nTab) );
+            rDoc.SetTabBgColor(nTab, xRedoDoc->GetTabBgColor(nTab));
         }
 
     pDocShell->PostPaintGridAll();
@@ -1632,8 +1624,8 @@ ScUndoUpdateAreaLink::ScUndoUpdateAreaLink( ScDocShell* pShell,
         aNewOpt     ( rNewO ),
         aNewArea    ( rNewA ),
         aNewRange   ( rNewR ),
-        pUndoDoc    ( pUndo ),
-        pRedoDoc    ( pRedo ),
+        xUndoDoc    ( pUndo ),
+        xRedoDoc    ( pRedo ),
         nOldRefresh ( nOldRD ),
         nNewRefresh ( nNewRD ),
         bWithInsert ( bDoInsert )
@@ -1641,12 +1633,6 @@ ScUndoUpdateAreaLink::ScUndoUpdateAreaLink( ScDocShell* pShell,
     OSL_ENSURE( aOldRange.aStart == aNewRange.aStart, "AreaLink moved ?" );
 }
 
-ScUndoUpdateAreaLink::~ScUndoUpdateAreaLink()
-{
-    delete pUndoDoc;
-    delete pRedoDoc;
-}
-
 OUString ScUndoUpdateAreaLink::GetComment() const
 {
     return ScGlobal::GetRscString( STR_UNDO_UPDATELINK );   //! own text ??
@@ -1666,13 +1652,13 @@ void ScUndoUpdateAreaLink::DoChange( const bool bUndo ) const
         {
             rDoc.FitBlock( aNewRange, aOldRange );
             rDoc.DeleteAreaTab( aOldRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
-            pUndoDoc->UndoToDocument( aOldRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc );
+            xUndoDoc->UndoToDocument(aOldRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc);
         }
         else
         {
             ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
             rDoc.DeleteAreaTab( aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
-            pUndoDoc->CopyToDocument( aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc );
+            xUndoDoc->CopyToDocument(aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc);
         }
     }
     else
@@ -1681,13 +1667,13 @@ void ScUndoUpdateAreaLink::DoChange( const bool bUndo ) const
         {
             rDoc.FitBlock( aOldRange, aNewRange );
             rDoc.DeleteAreaTab( aNewRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
-            pRedoDoc->CopyToDocument( aNewRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc );
+            xRedoDoc->CopyToDocument(aNewRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc);
         }
         else
         {
             ScRange aCopyRange( aOldRange.aStart, ScAddress(nEndX,nEndY,nEndZ) );
             rDoc.DeleteAreaTab( aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
-            pRedoDoc->CopyToDocument( aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc );
+            xRedoDoc->CopyToDocument(aCopyRange, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc);
         }
     }
 
diff --git a/sc/source/ui/undo/undodat.cxx b/sc/source/ui/undo/undodat.cxx
index b6527a5..3720338 100644
--- a/sc/source/ui/undo/undodat.cxx
+++ b/sc/source/ui/undo/undodat.cxx
@@ -222,22 +222,16 @@ bool ScUndoMakeOutline::CanRepeat(SfxRepeatTarget& rTarget) const
 ScUndoOutlineLevel::ScUndoOutlineLevel( ScDocShell* pNewDocShell,
                         SCCOLROW nNewStart, SCCOLROW nNewEnd, SCTAB nNewTab,
                         ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
-                        bool bNewColumns, sal_uInt16 nNewLevel ) :
-    ScSimpleUndo( pNewDocShell ),
-    nStart( nNewStart ),
-    nEnd( nNewEnd ),
-    nTab( nNewTab ),
-    pUndoDoc( pNewUndoDoc ),
-    pUndoTable( pNewUndoTab ),
-    bColumns( bNewColumns ),
-    nLevel( nNewLevel )
-{
-}
-
-ScUndoOutlineLevel::~ScUndoOutlineLevel()
+                        bool bNewColumns, sal_uInt16 nNewLevel )
+    : ScSimpleUndo(pNewDocShell)
+    , nStart(nNewStart)
+    , nEnd(nNewEnd)
+    , nTab(nNewTab)
+    , xUndoDoc(pNewUndoDoc)
+    , xUndoTable(pNewUndoTab)
+    , bColumns(bNewColumns)
+    , nLevel(nNewLevel)
 {
-    delete pUndoDoc;
-    delete pUndoTable;
 }
 
 OUString ScUndoOutlineLevel::GetComment() const
@@ -254,15 +248,15 @@ void ScUndoOutlineLevel::Undo()
 
     //  Original Outline table
 
-    rDoc.SetOutlineTable( nTab, pUndoTable );
+    rDoc.SetOutlineTable(nTab, xUndoTable.get());
 
     //  Original column/row status
 
     if (bColumns)
-        pUndoDoc->CopyToDocument(static_cast<SCCOL>(nStart), 0, nTab,
+        xUndoDoc->CopyToDocument(static_cast<SCCOL>(nStart), 0, nTab,
                                  static_cast<SCCOL>(nEnd), MAXROW, nTab, InsertDeleteFlags::NONE, false, rDoc);
     else
-        pUndoDoc->CopyToDocument(0, nStart, nTab, MAXCOL, nEnd, nTab, InsertDeleteFlags::NONE, false, rDoc);
+        xUndoDoc->CopyToDocument(0, nStart, nTab, MAXCOL, nEnd, nTab, InsertDeleteFlags::NONE, false, rDoc);
 
     rDoc.UpdatePageBreaks( nTab );
 
@@ -313,18 +307,12 @@ ScUndoOutlineBlock::ScUndoOutlineBlock( ScDocShell* pNewDocShell,
     ScSimpleUndo( pNewDocShell ),
     aBlockStart( nStartX, nStartY, nStartZ ),
     aBlockEnd( nEndX, nEndY, nEndZ ),
-    pUndoDoc( pNewUndoDoc ),
-    pUndoTable( pNewUndoTab ),
+    xUndoDoc(pNewUndoDoc),
+    xUndoTable(pNewUndoTab),
     bShow( bNewShow )
 {
 }
 
-ScUndoOutlineBlock::~ScUndoOutlineBlock()
-{
-    delete pUndoDoc;
-    delete pUndoTable;
-}
-
 OUString ScUndoOutlineBlock::GetComment() const
 {   // "Show outline" "Hide outline"
     return bShow ?
@@ -341,7 +329,7 @@ void ScUndoOutlineBlock::Undo()
     SCTAB nTab = aBlockStart.Tab();
 
     //  Original Outline table
-    rDoc.SetOutlineTable( nTab, pUndoTable );
+    rDoc.SetOutlineTable(nTab, xUndoTable.get());
 
     //  Original column/row status
     SCCOLROW    nStartCol = aBlockStart.Col();
@@ -352,15 +340,15 @@ void ScUndoOutlineBlock::Undo()
     if (!bShow)
     {                               // Size of the hidden blocks
         size_t nLevel;
-        pUndoTable->GetColArray().FindTouchedLevel( nStartCol, nEndCol, nLevel );
-        pUndoTable->GetColArray().ExtendBlock( nLevel, nStartCol, nEndCol );
-        pUndoTable->GetRowArray().FindTouchedLevel( nStartRow, nEndRow, nLevel );
-        pUndoTable->GetRowArray().ExtendBlock( nLevel, nStartRow, nEndRow );
+        xUndoTable->GetColArray().FindTouchedLevel(nStartCol, nEndCol, nLevel);
+        xUndoTable->GetColArray().ExtendBlock(nLevel, nStartCol, nEndCol);
+        xUndoTable->GetRowArray().FindTouchedLevel(nStartRow, nEndRow, nLevel);
+        xUndoTable->GetRowArray().ExtendBlock(nLevel, nStartRow, nEndRow);
     }
 
-    pUndoDoc->CopyToDocument(static_cast<SCCOL>(nStartCol), 0, nTab,
+    xUndoDoc->CopyToDocument(static_cast<SCCOL>(nStartCol), 0, nTab,
                              static_cast<SCCOL>(nEndCol), MAXROW, nTab, InsertDeleteFlags::NONE, false, rDoc);
-    pUndoDoc->CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, rDoc);
+    xUndoDoc->CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, rDoc);
 
     rDoc.UpdatePageBreaks( nTab );
 
@@ -408,22 +396,16 @@ bool ScUndoOutlineBlock::CanRepeat(SfxRepeatTarget& rTarget) const
     return dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr;
 }
 
-ScUndoRemoveAllOutlines::ScUndoRemoveAllOutlines( ScDocShell* pNewDocShell,
+ScUndoRemoveAllOutlines::ScUndoRemoveAllOutlines(ScDocShell* pNewDocShell,
                                     SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
                                     SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
-                                    ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
-    ScSimpleUndo( pNewDocShell ),
-    aBlockStart( nStartX, nStartY, nStartZ ),
-    aBlockEnd( nEndX, nEndY, nEndZ ),
-    pUndoDoc( pNewUndoDoc ),
-    pUndoTable( pNewUndoTab )
-{
-}
-
-ScUndoRemoveAllOutlines::~ScUndoRemoveAllOutlines()
+                                    ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab)
+    : ScSimpleUndo(pNewDocShell)
+    , aBlockStart(nStartX, nStartY, nStartZ)
+    , aBlockEnd(nEndX, nEndY, nEndZ)
+    , xUndoDoc(pNewUndoDoc)
+    , xUndoTable(pNewUndoTab)
 {
-    delete pUndoDoc;
-    delete pUndoTable;
 }
 
 OUString ScUndoRemoveAllOutlines::GetComment() const
@@ -440,7 +422,7 @@ void ScUndoRemoveAllOutlines::Undo()
     SCTAB nTab = aBlockStart.Tab();
 
     //  Original Outline table
-    rDoc.SetOutlineTable( nTab, pUndoTable );
+    rDoc.SetOutlineTable(nTab, xUndoTable.get());
 
     //  Original column/row status
     SCCOL   nStartCol = aBlockStart.Col();
@@ -448,8 +430,8 @@ void ScUndoRemoveAllOutlines::Undo()
     SCROW   nStartRow = aBlockStart.Row();
     SCROW   nEndRow = aBlockEnd.Row();
 
-    pUndoDoc->CopyToDocument(nStartCol, 0, nTab, nEndCol, MAXROW, nTab, InsertDeleteFlags::NONE, false, rDoc);
-    pUndoDoc->CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, rDoc);
+    xUndoDoc->CopyToDocument(nStartCol, 0, nTab, nEndCol, MAXROW, nTab, InsertDeleteFlags::NONE, false, rDoc);
+    xUndoDoc->CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, rDoc);
 
     rDoc.UpdatePageBreaks( nTab );
 
@@ -493,24 +475,18 @@ bool ScUndoRemoveAllOutlines::CanRepeat(SfxRepeatTarget& rTarget) const
     return dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr;
 }
 
-ScUndoAutoOutline::ScUndoAutoOutline( ScDocShell* pNewDocShell,
-                                    SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
-                                    SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
-                                    ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab ) :
-    ScSimpleUndo( pNewDocShell ),
-    aBlockStart( nStartX, nStartY, nStartZ ),
-    aBlockEnd( nEndX, nEndY, nEndZ ),
-    pUndoDoc( pNewUndoDoc ),
-    pUndoTable( pNewUndoTab )
+ScUndoAutoOutline::ScUndoAutoOutline(ScDocShell* pNewDocShell,
+                                     SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
+                                     SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
+                                     ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab)
+    : ScSimpleUndo(pNewDocShell)
+    , aBlockStart(nStartX, nStartY, nStartZ)
+    , aBlockEnd(nEndX, nEndY, nEndZ)
+    , xUndoDoc(pNewUndoDoc)
+    , xUndoTable(pNewUndoTab)
 {
 }
 
-ScUndoAutoOutline::~ScUndoAutoOutline()
-{
-    delete pUndoDoc;
-    delete pUndoTable;
-}
-
 OUString ScUndoAutoOutline::GetComment() const
 {
     return ScGlobal::GetRscString( STR_UNDO_AUTOOUTLINE );
@@ -525,22 +501,22 @@ void ScUndoAutoOutline::Undo()
     SCTAB nTab = aBlockStart.Tab();
 
     // Original outline table
-    rDoc.SetOutlineTable( nTab, pUndoTable );
+    rDoc.SetOutlineTable(nTab, xUndoTable.get());
 
     // Original column/row status
-    if (pUndoDoc && pUndoTable)
+    if (xUndoDoc && xUndoTable)
     {
         SCCOLROW nStartCol;
         SCCOLROW nStartRow;
         SCCOLROW nEndCol;
         SCCOLROW nEndRow;
-        pUndoTable->GetColArray().GetRange( nStartCol, nEndCol );
-        pUndoTable->GetRowArray().GetRange( nStartRow, nEndRow );
+        xUndoTable->GetColArray().GetRange(nStartCol, nEndCol);
+        xUndoTable->GetRowArray().GetRange(nStartRow, nEndRow);
 
-        pUndoDoc->CopyToDocument(static_cast<SCCOL>(nStartCol), 0, nTab,
+        xUndoDoc->CopyToDocument(static_cast<SCCOL>(nStartCol), 0, nTab,
                                  static_cast<SCCOL>(nEndCol), MAXROW, nTab, InsertDeleteFlags::NONE, false,
                                  rDoc);
-        pUndoDoc->CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, rDoc);
+        xUndoDoc->CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, rDoc);
 
         pViewShell->UpdateScrollBars();
     }
@@ -596,30 +572,22 @@ bool ScUndoAutoOutline::CanRepeat(SfxRepeatTarget& rTarget) const
     return dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr;
 }
 
-ScUndoSubTotals::ScUndoSubTotals( ScDocShell* pNewDocShell, SCTAB nNewTab,
-                                const ScSubTotalParam& rNewParam, SCROW nNewEndY,
-                                ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
-                                ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB ) :
-    ScDBFuncUndo( pNewDocShell, ScRange( rNewParam.nCol1, rNewParam.nRow1, nNewTab,
-                                         rNewParam.nCol2, rNewParam.nRow2, nNewTab ) ),
-    nTab( nNewTab ),
-    aParam( rNewParam ),
-    nNewEndRow( nNewEndY ),
-    pUndoDoc( pNewUndoDoc ),
-    pUndoTable( pNewUndoTab ),
-    pUndoRange( pNewUndoRange ),
-    pUndoDB( pNewUndoDB )
+ScUndoSubTotals::ScUndoSubTotals(ScDocShell* pNewDocShell, SCTAB nNewTab,
+                                 const ScSubTotalParam& rNewParam, SCROW nNewEndY,
+                                 ScDocument* pNewUndoDoc, ScOutlineTable* pNewUndoTab,
+                                 ScRangeName* pNewUndoRange, ScDBCollection* pNewUndoDB)
+    : ScDBFuncUndo(pNewDocShell, ScRange(rNewParam.nCol1, rNewParam.nRow1, nNewTab,
+                                         rNewParam.nCol2, rNewParam.nRow2, nNewTab))
+    , nTab(nNewTab)
+    , aParam(rNewParam)
+    , nNewEndRow(nNewEndY)
+    , xUndoDoc(pNewUndoDoc)
+    , xUndoTable(pNewUndoTab)
+    , xUndoRange(pNewUndoRange)
+    , xUndoDB(pNewUndoDB)
 {
 }
 
-ScUndoSubTotals::~ScUndoSubTotals()
-{
-    delete pUndoDoc;
-    delete pUndoTable;
-    delete pUndoRange;
-    delete pUndoDB;
-}
-
 OUString ScUndoSubTotals::GetComment() const
 {   // "Subtotals"
     return ScGlobal::GetRscString( STR_UNDO_SUBTOTALS );
@@ -642,22 +610,22 @@ void ScUndoSubTotals::Undo()
     }
 
     // Original Outline table
-    rDoc.SetOutlineTable( nTab, pUndoTable );
+    rDoc.SetOutlineTable(nTab, xUndoTable.get());
 
     // Original column/row status
-    if (pUndoTable)
+    if (xUndoTable)
     {
         SCCOLROW nStartCol;
         SCCOLROW nStartRow;
         SCCOLROW nEndCol;
         SCCOLROW nEndRow;
-        pUndoTable->GetColArray().GetRange( nStartCol, nEndCol );
-        pUndoTable->GetRowArray().GetRange( nStartRow, nEndRow );
+        xUndoTable->GetColArray().GetRange(nStartCol, nEndCol);
+        xUndoTable->GetRowArray().GetRange(nStartRow, nEndRow);
 
-        pUndoDoc->CopyToDocument(static_cast<SCCOL>(nStartCol), 0, nTab,
+        xUndoDoc->CopyToDocument(static_cast<SCCOL>(nStartCol), 0, nTab,
                                  static_cast<SCCOL>(nEndCol), MAXROW, nTab, InsertDeleteFlags::NONE, false,
                                  rDoc);
-        pUndoDoc->CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, rDoc);
+        xUndoDoc->CopyToDocument(0, nStartRow, nTab, MAXCOL, nEndRow, nTab, InsertDeleteFlags::NONE, false, rDoc);
 
         pViewShell->UpdateScrollBars();
     }
@@ -669,18 +637,18 @@ void ScUndoSubTotals::Undo()
 
     rDoc.DeleteAreaTab( 0,aParam.nRow1+1, MAXCOL,aParam.nRow2, nTab, InsertDeleteFlags::ALL );
 
-    pUndoDoc->CopyToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
-                                                            InsertDeleteFlags::NONE, false, rDoc );    // Flags
-    pUndoDoc->UndoToDocument( 0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
-                                                            InsertDeleteFlags::ALL, false, rDoc );
+    xUndoDoc->CopyToDocument(0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
+                                                            InsertDeleteFlags::NONE, false, rDoc);    // Flags
+    xUndoDoc->UndoToDocument(0, aParam.nRow1+1, nTab, MAXCOL, aParam.nRow2, nTab,
+                                                            InsertDeleteFlags::ALL, false, rDoc);
 
     ScUndoUtil::MarkSimpleBlock( pDocShell, aParam.nCol1,aParam.nRow1,nTab,
                                             aParam.nCol2,aParam.nRow2,nTab );
 
-    if (pUndoRange)
-        rDoc.SetRangeName( new ScRangeName( *pUndoRange ) );
-    if (pUndoDB)
-        rDoc.SetDBCollection( new ScDBCollection( *pUndoDB ), true );
+    if (xUndoRange)
+        rDoc.SetRangeName(new ScRangeName(*xUndoRange));
+    if (xUndoDB)
+        rDoc.SetDBCollection(new ScDBCollection(*xUndoDB), true);
 
     SCTAB nVisTab = pViewShell->GetViewData().GetTabNo();
     if ( nVisTab != nTab )
@@ -726,8 +694,8 @@ ScUndoQuery::ScUndoQuery( ScDocShell* pNewDocShell, SCTAB nNewTab, const ScQuery
     pDrawUndo( nullptr ),
     nTab( nNewTab ),
     aQueryParam( rParam ),
-    pUndoDoc( pNewUndoDoc ),
-    pUndoDB( pNewUndoDB ),
+    xUndoDoc( pNewUndoDoc ),
+    xUndoDB( pNewUndoDB ),
     bIsAdvanced( false ),
     bDestArea( false ),
     bDoSize( bSize )
@@ -748,8 +716,6 @@ ScUndoQuery::ScUndoQuery( ScDocShell* pNewDocShell, SCTAB nNewTab, const ScQuery
 
 ScUndoQuery::~ScUndoQuery()
 {
-    delete pUndoDoc;
-    delete pUndoDB;
     DeleteSdrUndoAction( pDrawUndo );
 }
 
@@ -800,24 +766,24 @@ void ScUndoQuery::Undo()
 
         pViewShell->DoneBlockMode();
 
-        pUndoDoc->CopyToDocument( aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
-                                    nDestEndCol, nDestEndRow, aQueryParam.nDestTab,
-                                    InsertDeleteFlags::ALL, false, rDoc );
+        xUndoDoc->CopyToDocument(aQueryParam.nDestCol, aQueryParam.nDestRow, aQueryParam.nDestTab,
+                                 nDestEndCol, nDestEndRow, aQueryParam.nDestTab,
+                                 InsertDeleteFlags::ALL, false, rDoc);
         //  Attributes are always copied (#49287#)
 
         // rest of the old range
         if ( bDestArea && !bDoSize )
         {
             rDoc.DeleteAreaTab( aOldDest, InsertDeleteFlags::ALL );
-            pUndoDoc->CopyToDocument(aOldDest, InsertDeleteFlags::ALL, false, rDoc);
+            xUndoDoc->CopyToDocument(aOldDest, InsertDeleteFlags::ALL, false, rDoc);
         }
     }
     else
-        pUndoDoc->CopyToDocument(0, aQueryParam.nRow1, nTab, MAXCOL, aQueryParam.nRow2, nTab,
+        xUndoDoc->CopyToDocument(0, aQueryParam.nRow1, nTab, MAXCOL, aQueryParam.nRow2, nTab,
                                  InsertDeleteFlags::NONE, false, rDoc);
 
-    if (pUndoDB)
-        rDoc.SetDBCollection( new ScDBCollection( *pUndoDB ), true );
+    if (xUndoDB)
+        rDoc.SetDBCollection(new ScDBCollection(*xUndoDB ), true);
 
     if (!bCopy)
     {
@@ -1042,24 +1008,16 @@ ScUndoImportData::ScUndoImportData( ScDocShell* pNewDocShell, SCTAB nNewTab,
     aImportParam( rParam ),
     nEndCol( nNewEndX ),
     nEndRow( nNewEndY ),
-    pUndoDoc( pNewUndoDoc ),
-    pRedoDoc( pNewRedoDoc ),
-    pUndoDBData( pNewUndoData ),
-    pRedoDBData( pNewRedoData ),
+    xUndoDoc(pNewUndoDoc),
+    xRedoDoc(pNewRedoDoc),
+    xUndoDBData(pNewUndoData),
+    xRedoDBData(pNewRedoData),
     nFormulaCols( nNewFormula ),
     bRedoFilled( false )
 {
     // redo doc doesn't contain imported data (but everything else)
 }
 
-ScUndoImportData::~ScUndoImportData()
-{
-    delete pUndoDoc;
-    delete pRedoDoc;
-    delete pUndoDBData;
-    delete pRedoDBData;
-}
-
 OUString ScUndoImportData::GetComment() const
 {
     return ScGlobal::GetRscString( STR_UNDO_IMPORTDATA );
@@ -1079,11 +1037,11 @@ void ScUndoImportData::Undo()
     SCCOL nCol1, nCol2;
     SCROW nRow1, nRow2;
     ScDBData* pCurrentData = nullptr;
-    if (pUndoDBData && pRedoDBData)
+    if (xUndoDBData && xRedoDBData)
     {
-        pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
-        pCurrentData = ScUndoUtil::GetOldDBData( pRedoDBData, &rDoc, nTab,
-                                                    nCol1, nRow1, nCol2, nRow2 );
+        xRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
+        pCurrentData = ScUndoUtil::GetOldDBData(xRedoDBData.get(), &rDoc, nTab,
+                                                nCol1, nRow1, nCol2, nRow2);
 
         if ( !bRedoFilled )
         {
@@ -1096,22 +1054,22 @@ void ScUndoImportData::Undo()
             for (SCCOL nCopyCol = nCol1; nCopyCol <= nCol2; nCopyCol++)
             {
                 rDoc.CopyToDocument(nCopyCol,nRow1,nTab, nCopyCol,nRow2,nTab,
-                                    InsertDeleteFlags::CONTENTS & ~InsertDeleteFlags::NOTE, false, *pRedoDoc);
-                rDoc.DeleteAreaTab(nCopyCol,nRow1, nCopyCol,nRow2, nTab, InsertDeleteFlags::CONTENTS & ~InsertDeleteFlags::NOTE);
+                                    InsertDeleteFlags::CONTENTS & ~InsertDeleteFlags::NOTE, false, *xRedoDoc);
+                rDoc.DeleteAreaTab(nCopyCol, nRow1, nCopyCol, nRow2, nTab, InsertDeleteFlags::CONTENTS & ~InsertDeleteFlags::NOTE);
             }
             rDoc.SetAutoCalc( bOldAutoCalc );
             bRedoFilled = true;
         }
     }
-    bool bMoveCells = pUndoDBData && pRedoDBData &&
-                        pRedoDBData->IsDoSize();        // the same in old and new
+    bool bMoveCells = xUndoDBData && xRedoDBData &&
+                        xRedoDBData->IsDoSize();        // the same in old and new
     if (bMoveCells)
     {
         //  Undo: first delete the new data, then FitBlock backwards
 
         ScRange aOld, aNew;
-        pUndoDBData->GetArea( aOld );
-        pRedoDBData->GetArea( aNew );
+        xUndoDBData->GetArea(aOld);
+        xRedoDBData->GetArea(aNew);
 
         rDoc.DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
                                 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
@@ -1124,15 +1082,15 @@ void ScUndoImportData::Undo()
         rDoc.DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
                                 nEndCol,nEndRow, nTab, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
 
-    pUndoDoc->CopyToDocument(aImportParam.nCol1,aImportParam.nRow1,nTab,
+    xUndoDoc->CopyToDocument(aImportParam.nCol1,aImportParam.nRow1,nTab,
                              nEndCol+nFormulaCols,nEndRow,nTab,
                              InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc);
 
     if (pCurrentData)
     {
-        *pCurrentData = *pUndoDBData;
+        *pCurrentData = *xUndoDBData;
 
-        pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
+        xUndoDBData->GetArea(nTable, nCol1, nRow1, nCol2, nRow2);
         ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
     }
 
@@ -1164,21 +1122,21 @@ void ScUndoImportData::Redo()
     SCCOL nCol1, nCol2;
     SCROW nRow1, nRow2;
     ScDBData* pCurrentData = nullptr;
-    if (pUndoDBData && pRedoDBData)
+    if (xUndoDBData && xRedoDBData)
     {
-        pUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
-        pCurrentData = ScUndoUtil::GetOldDBData( pUndoDBData, &rDoc, nTab,
-                                                    nCol1, nRow1, nCol2, nRow2 );
+        xUndoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
+        pCurrentData = ScUndoUtil::GetOldDBData(xUndoDBData.get(), &rDoc, nTab,
+                                                nCol1, nRow1, nCol2, nRow2);
     }
-    bool bMoveCells = pUndoDBData && pRedoDBData &&
-                        pRedoDBData->IsDoSize();        // the same in old and new
+    bool bMoveCells = xUndoDBData && xRedoDBData &&
+                        xRedoDBData->IsDoSize();        // the same in old and new
     if (bMoveCells)
     {
         //  Redo: FitBlock, then delete data (needed for CopyToDocument)
 
         ScRange aOld, aNew;
-        pUndoDBData->GetArea( aOld );
-        pRedoDBData->GetArea( aNew );
+        xUndoDBData->GetArea(aOld);
+        xRedoDBData->GetArea(aNew);
 
         aOld.aEnd.SetCol( aOld.aEnd.Col() + nFormulaCols );     // FitBlock also for formulas
         aNew.aEnd.SetCol( aNew.aEnd.Col() + nFormulaCols );
@@ -1187,21 +1145,21 @@ void ScUndoImportData::Redo()
         rDoc.DeleteAreaTab( aNew.aStart.Col(), aNew.aStart.Row(),
                                 aNew.aEnd.Col(), aNew.aEnd.Row(), nTab, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
 
-        pRedoDoc->CopyToDocument(aNew, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc);        // including formulas
+        xRedoDoc->CopyToDocument(aNew, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc);        // including formulas
     }
     else
     {
         rDoc.DeleteAreaTab( aImportParam.nCol1,aImportParam.nRow1,
                                 nEndCol,nEndRow, nTab, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE );
-        pRedoDoc->CopyToDocument(aImportParam.nCol1,aImportParam.nRow1,nTab,
+        xRedoDoc->CopyToDocument(aImportParam.nCol1,aImportParam.nRow1,nTab,
                                  nEndCol,nEndRow,nTab, InsertDeleteFlags::ALL & ~InsertDeleteFlags::NOTE, false, rDoc);
     }
 
     if (pCurrentData)
     {
-        *pCurrentData = *pRedoDBData;
+        *pCurrentData = *xRedoDBData;
 
-        pRedoDBData->GetArea( nTable, nCol1, nRow1, nCol2, nRow2 );
+        xRedoDBData->GetArea(nTable, nCol1, nRow1, nCol2, nRow2);
         ScUndoUtil::MarkSimpleBlock( pDocShell, nCol1, nRow1, nTable, nCol2, nRow2, nTable );
     }
 
@@ -1236,9 +1194,9 @@ void ScUndoImportData::Repeat(SfxRepeatTarget& rTarget)
 
 bool ScUndoImportData::CanRepeat(SfxRepeatTarget& rTarget) const
 {
-    //  Repeat only for import using a database range, then pUndoDBData is set
+    //  Repeat only for import using a database range, then xUndoDBData is set
 
-    if (pUndoDBData)
+    if (xUndoDBData)
         return dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr;
     else
         return false;       // Address book
@@ -1255,10 +1213,10 @@ ScUndoRepeatDB::ScUndoRepeatDB( ScDocShell* pNewDocShell, SCTAB nNewTab,
     aBlockEnd( nEndX,nEndY,nNewTab ),
     nNewEndRow( nResultEndRow ),
     aCursorPos( nCurX,nCurY,nNewTab ),
-    pUndoDoc( pNewUndoDoc ),
-    pUndoTable( pNewUndoTab ),
-    pUndoRange( pNewUndoRange ),
-    pUndoDB( pNewUndoDB ),
+    xUndoDoc(pNewUndoDoc),
+    xUndoTable(pNewUndoTab),
+    xUndoRange(pNewUndoRange),
+    xUndoDB(pNewUndoDB),
     bQuerySize( false )
 {
     if ( pOldQ && pNewQ )
@@ -1269,14 +1227,6 @@ ScUndoRepeatDB::ScUndoRepeatDB( ScDocShell* pNewDocShell, SCTAB nNewTab,
     }
 }
 
-ScUndoRepeatDB::~ScUndoRepeatDB()
-{
-    delete pUndoDoc;
-    delete pUndoTable;
-    delete pUndoRange;
-    delete pUndoDB;
-}
-
 OUString ScUndoRepeatDB::GetComment() const
 {
     return ScGlobal::GetRscString( STR_UNDO_REPEATDB );
@@ -1330,22 +1280,22 @@ void ScUndoRepeatDB::Undo()
     }
 
     // Original Outline table
-    rDoc.SetOutlineTable( nTab, pUndoTable );
+    rDoc.SetOutlineTable(nTab, xUndoTable.get());
 
     // Original column/row status
-    if (pUndoTable)
+    if (xUndoTable)
     {
         SCCOLROW nStartCol;
         SCCOLROW nStartRow;
         SCCOLROW nEndCol;
         SCCOLROW nEndRow;
-        pUndoTable->GetColArray().GetRange( nStartCol, nEndCol );
-        pUndoTable->GetRowArray().GetRange( nStartRow, nEndRow );
+        xUndoTable->GetColArray().GetRange(nStartCol, nEndCol);

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list