[Libreoffice-commits] core.git: sw/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Fri Jul 31 09:01:01 UTC 2020


 sw/source/core/unocore/unobkm.cxx        |   22 
 sw/source/core/unocore/unochart.cxx      |  324 ++++++-------
 sw/source/core/unocore/unocrsrhelper.cxx |   55 +-
 sw/source/core/unocore/unodraw.cxx       |  763 +++++++++++++++----------------
 sw/source/core/unocore/unoflatpara.cxx   |   28 -
 sw/source/core/unocore/unoframe.cxx      |   76 +--
 sw/source/core/unocore/unoobj.cxx        |  164 +++---
 sw/source/core/unocore/unoobj2.cxx       |   74 +--
 sw/source/core/unocore/unoparagraph.cxx  |   90 +--
 sw/source/core/unocore/unoportenum.cxx   |   76 +--
 sw/source/core/unocore/unorefmk.cxx      |   24 
 sw/source/core/unocore/unosect.cxx       |   42 -
 sw/source/core/unocore/unosett.cxx       |  127 ++---
 sw/source/core/unocore/unostyle.cxx      |  385 +++++++--------
 sw/source/core/unocore/unotbl.cxx        |  363 +++++++-------
 sw/source/core/unocore/unotext.cxx       |   50 +-
 16 files changed, 1331 insertions(+), 1332 deletions(-)

New commits:
commit 2bfd51eab364c6b00603e2fa1e9c354eec90dc7f
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 30 10:36:54 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Fri Jul 31 11:00:25 2020 +0200

    loplugin:flatten in sw/core/unocore
    
    Change-Id: If96b2484426f0d09119ca89943729c149675156f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99851
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx
index c8fa27faa896..97550fec41da 100644
--- a/sw/source/core/unocore/unobkm.cxx
+++ b/sw/source/core/unocore/unobkm.cxx
@@ -619,21 +619,21 @@ void SwXFieldmark::setFieldType(const OUString & fieldType)
     IFieldmark *pBkm = dynamic_cast<IFieldmark*>(GetBookmark());
     if(!pBkm)
         throw uno::RuntimeException();
-    if(fieldType != getFieldType())
+    if(fieldType == getFieldType())
+        return;
+
+    if(fieldType == ODF_FORMDROPDOWN || fieldType == ODF_FORMCHECKBOX || fieldType == ODF_FORMDATE)
     {
-        if(fieldType == ODF_FORMDROPDOWN || fieldType == ODF_FORMCHECKBOX || fieldType == ODF_FORMDATE)
+        ::sw::mark::IFieldmark* pNewFieldmark = GetIDocumentMarkAccess()->changeFormFieldmarkType(pBkm, fieldType);
+        if (pNewFieldmark)
         {
-            ::sw::mark::IFieldmark* pNewFieldmark = GetIDocumentMarkAccess()->changeFormFieldmarkType(pBkm, fieldType);
-            if (pNewFieldmark)
-            {
-                registerInMark(*this, pNewFieldmark);
-                return;
-            }
+            registerInMark(*this, pNewFieldmark);
+            return;
         }
-
-        // We did not generate a new fieldmark, so set the type ID
-        pBkm->SetFieldname(fieldType);
     }
+
+    // We did not generate a new fieldmark, so set the type ID
+    pBkm->SetFieldname(fieldType);
 }
 
 uno::Reference<container::XNameContainer> SwXFieldmark::getParameters()
diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx
index c2f9c915d43b..42c4b9876c53 100644
--- a/sw/source/core/unocore/unochart.cxx
+++ b/sw/source/core/unocore/unochart.cxx
@@ -1365,20 +1365,20 @@ void SAL_CALL SwChartDataProvider::dispose(  )
         if (!m_bDisposed)
             m_bDisposed = true;
     }
-    if (bMustDispose)
-    {
-        // dispose all data-sequences
-        for (const auto& rEntry : m_aDataSequences)
-        {
-            DisposeAllDataSequences( rEntry.first );
-        }
-        // release all references to data-sequences
-        m_aDataSequences.clear();
+    if (!bMustDispose)
+        return;
 
-        // require listeners to release references to this object
-        lang::EventObject aEvtObj( dynamic_cast< chart2::data::XDataProvider * >(this) );
-        m_aEventListeners.disposeAndClear( aEvtObj );
+    // dispose all data-sequences
+    for (const auto& rEntry : m_aDataSequences)
+    {
+        DisposeAllDataSequences( rEntry.first );
     }
+    // release all references to data-sequences
+    m_aDataSequences.clear();
+
+    // require listeners to release references to this object
+    lang::EventObject aEvtObj( dynamic_cast< chart2::data::XDataProvider * >(this) );
+    m_aEventListeners.disposeAndClear( aEvtObj );
 }
 
 void SAL_CALL SwChartDataProvider::addEventListener(
@@ -1425,21 +1425,21 @@ void SwChartDataProvider::RemoveDataSequence( const SwTable &rTable, uno::Refere
 void SwChartDataProvider::InvalidateTable( const SwTable *pTable )
 {
     OSL_ENSURE( pTable, "table pointer is NULL" );
-    if (pTable)
-    {
-        if (!m_bDisposed)
-           pTable->GetFrameFormat()->GetDoc()->getIDocumentChartDataProviderAccess().GetChartControllerHelper().StartOrContinueLocking();
+    if (!pTable)
+        return;
 
-        const Set_DataSequenceRef_t &rSet = m_aDataSequences[ pTable ];
-        for (const auto& rItem : rSet)
+    if (!m_bDisposed)
+       pTable->GetFrameFormat()->GetDoc()->getIDocumentChartDataProviderAccess().GetChartControllerHelper().StartOrContinueLocking();
+
+    const Set_DataSequenceRef_t &rSet = m_aDataSequences[ pTable ];
+    for (const auto& rItem : rSet)
+    {
+        uno::Reference< chart2::data::XDataSequence > xTemp(rItem);  // temporary needed for g++ 3.3.5
+        uno::Reference< util::XModifiable > xRef( xTemp, uno::UNO_QUERY );
+        if (xRef.is())
         {
-            uno::Reference< chart2::data::XDataSequence > xTemp(rItem);  // temporary needed for g++ 3.3.5
-            uno::Reference< util::XModifiable > xRef( xTemp, uno::UNO_QUERY );
-            if (xRef.is())
-            {
-                // mark the sequence as 'dirty' and notify listeners
-                xRef->setModified( true );
-            }
+            // mark the sequence as 'dirty' and notify listeners
+            xRef->setModified( true );
         }
     }
 }
@@ -1447,79 +1447,79 @@ void SwChartDataProvider::InvalidateTable( const SwTable *pTable )
 void SwChartDataProvider::DeleteBox( const SwTable *pTable, const SwTableBox &rBox )
 {
     OSL_ENSURE( pTable, "table pointer is NULL" );
-    if (pTable)
-    {
-        if (!m_bDisposed)
-            pTable->GetFrameFormat()->GetDoc()->getIDocumentChartDataProviderAccess().GetChartControllerHelper().StartOrContinueLocking();
+    if (!pTable)
+        return;
 
-        Set_DataSequenceRef_t &rSet = m_aDataSequences[ pTable ];
+    if (!m_bDisposed)
+        pTable->GetFrameFormat()->GetDoc()->getIDocumentChartDataProviderAccess().GetChartControllerHelper().StartOrContinueLocking();
 
-        // iterate over all data-sequences for that table...
-        Set_DataSequenceRef_t::iterator aIt( rSet.begin() );
-        Set_DataSequenceRef_t::iterator aEndIt( rSet.end() );
-        Set_DataSequenceRef_t::iterator aDelIt;     // iterator used for deletion when appropriate
-        while (aIt != aEndIt)
-        {
-            SwChartDataSequence *pDataSeq = nullptr;
-            bool bNowEmpty = false;
-            bool bSeqDisposed = false;
+    Set_DataSequenceRef_t &rSet = m_aDataSequences[ pTable ];
+
+    // iterate over all data-sequences for that table...
+    Set_DataSequenceRef_t::iterator aIt( rSet.begin() );
+    Set_DataSequenceRef_t::iterator aEndIt( rSet.end() );
+    Set_DataSequenceRef_t::iterator aDelIt;     // iterator used for deletion when appropriate
+    while (aIt != aEndIt)
+    {
+        SwChartDataSequence *pDataSeq = nullptr;
+        bool bNowEmpty = false;
+        bool bSeqDisposed = false;
 
-            // check if weak reference is still valid...
-            uno::Reference< chart2::data::XDataSequence > xTemp(*aIt);
-            if (xTemp.is())
+        // check if weak reference is still valid...
+        uno::Reference< chart2::data::XDataSequence > xTemp(*aIt);
+        if (xTemp.is())
+        {
+            // then delete that table box (check if implementation cursor needs to be adjusted)
+            pDataSeq = static_cast< SwChartDataSequence * >( xTemp.get() );
+            if (pDataSeq)
             {
-                // then delete that table box (check if implementation cursor needs to be adjusted)
-                pDataSeq = static_cast< SwChartDataSequence * >( xTemp.get() );
-                if (pDataSeq)
+                try
                 {
-                    try
-                    {
-                        bNowEmpty = pDataSeq->DeleteBox( rBox );
-                    }
-                    catch (const lang::DisposedException&)
-                    {
-                        bNowEmpty = true;
-                        bSeqDisposed = true;
-                    }
-
-                    if (bNowEmpty)
-                        aDelIt = aIt;
+                    bNowEmpty = pDataSeq->DeleteBox( rBox );
+                }
+                catch (const lang::DisposedException&)
+                {
+                    bNowEmpty = true;
+                    bSeqDisposed = true;
                 }
-            }
-            ++aIt;
 
-            if (bNowEmpty)
-            {
-                rSet.erase( aDelIt );
-                if (pDataSeq && !bSeqDisposed)
-                    pDataSeq->dispose();    // the current way to tell chart that sth. got removed
+                if (bNowEmpty)
+                    aDelIt = aIt;
             }
         }
+        ++aIt;
+
+        if (bNowEmpty)
+        {
+            rSet.erase( aDelIt );
+            if (pDataSeq && !bSeqDisposed)
+                pDataSeq->dispose();    // the current way to tell chart that sth. got removed
+        }
     }
 }
 
 void SwChartDataProvider::DisposeAllDataSequences( const SwTable *pTable )
 {
     OSL_ENSURE( pTable, "table pointer is NULL" );
-    if (pTable)
-    {
-        if (!m_bDisposed)
-            pTable->GetFrameFormat()->GetDoc()->getIDocumentChartDataProviderAccess().GetChartControllerHelper().StartOrContinueLocking();
+    if (!pTable)
+        return;
 
-        //! make a copy of the STL container!
-        //! This is necessary since calling 'dispose' will implicitly remove an element
-        //! of the original container, and thus any iterator in the original container
-        //! would become invalid.
-        const Set_DataSequenceRef_t aSet( m_aDataSequences[ pTable ] );
+    if (!m_bDisposed)
+        pTable->GetFrameFormat()->GetDoc()->getIDocumentChartDataProviderAccess().GetChartControllerHelper().StartOrContinueLocking();
 
-        for (const auto& rItem : aSet)
+    //! make a copy of the STL container!
+    //! This is necessary since calling 'dispose' will implicitly remove an element
+    //! of the original container, and thus any iterator in the original container
+    //! would become invalid.
+    const Set_DataSequenceRef_t aSet( m_aDataSequences[ pTable ] );
+
+    for (const auto& rItem : aSet)
+    {
+        uno::Reference< chart2::data::XDataSequence > xTemp(rItem);  // temporary needed for g++ 3.3.5
+        uno::Reference< lang::XComponent > xRef( xTemp, uno::UNO_QUERY );
+        if (xRef.is())
         {
-            uno::Reference< chart2::data::XDataSequence > xTemp(rItem);  // temporary needed for g++ 3.3.5
-            uno::Reference< lang::XComponent > xRef( xTemp, uno::UNO_QUERY );
-            if (xRef.is())
-            {
-                xRef->dispose();
-            }
+            xRef->dispose();
         }
     }
 }
@@ -1560,59 +1560,59 @@ void SwChartDataProvider::AddRowCols(
     SwTableBox* pFirstBox   = rBoxes[0];
     SwTableBox* pLastBox    = rBoxes.back();
 
-    if (pFirstBox && pLastBox)
+    if (!(pFirstBox && pLastBox))
+        return;
+
+    sal_Int32 nFirstCol = -1, nFirstRow = -1, nLastCol = -1, nLastRow = -1;
+    SwXTextTable::GetCellPosition( pFirstBox->GetName(), nFirstCol, nFirstRow  );
+    SwXTextTable::GetCellPosition( pLastBox->GetName(),  nLastCol,  nLastRow );
+
+    bool bAddCols = false;  // default; also to be used if nBoxes == 1 :-/
+    if (nFirstCol == nLastCol && nFirstRow != nLastRow)
+        bAddCols = true;
+    if (nFirstCol != nLastCol && nFirstRow != nLastRow)
+        return;
+
+    //get range of indices in col/rows for new cells
+    sal_Int32 nFirstNewCol = nFirstCol;
+    sal_Int32 nFirstNewRow = bBehind ?  nFirstRow + 1 : nFirstRow - nLines;
+    if (bAddCols)
     {
-        sal_Int32 nFirstCol = -1, nFirstRow = -1, nLastCol = -1, nLastRow = -1;
-        SwXTextTable::GetCellPosition( pFirstBox->GetName(), nFirstCol, nFirstRow  );
-        SwXTextTable::GetCellPosition( pLastBox->GetName(),  nLastCol,  nLastRow );
+        OSL_ENSURE( nFirstCol == nLastCol, "column indices seem broken" );
+        nFirstNewCol = bBehind ?  nFirstCol + 1 : nFirstCol - nLines;
+        nFirstNewRow = nFirstRow;
+    }
 
-        bool bAddCols = false;  // default; also to be used if nBoxes == 1 :-/
-        if (nFirstCol == nLastCol && nFirstRow != nLastRow)
-            bAddCols = true;
-        if (nFirstCol == nLastCol || nFirstRow == nLastRow)
+    // iterate over all data-sequences for the table
+    const Set_DataSequenceRef_t &rSet = m_aDataSequences[ &rTable ];
+    for (const auto& rItem : rSet)
+    {
+        uno::Reference< chart2::data::XDataSequence > xTemp(rItem);  // temporary needed for g++ 3.3.5
+        uno::Reference< chart2::data::XTextualDataSequence > xRef( xTemp, uno::UNO_QUERY );
+        if (xRef.is())
         {
-            //get range of indices in col/rows for new cells
-            sal_Int32 nFirstNewCol = nFirstCol;
-            sal_Int32 nFirstNewRow = bBehind ?  nFirstRow + 1 : nFirstRow - nLines;
-            if (bAddCols)
-            {
-                OSL_ENSURE( nFirstCol == nLastCol, "column indices seem broken" );
-                nFirstNewCol = bBehind ?  nFirstCol + 1 : nFirstCol - nLines;
-                nFirstNewRow = nFirstRow;
-            }
-
-            // iterate over all data-sequences for the table
-            const Set_DataSequenceRef_t &rSet = m_aDataSequences[ &rTable ];
-            for (const auto& rItem : rSet)
+            const sal_Int32 nLen = xRef->getTextualData().getLength();
+            if (nLen > 1) // value data-sequence ?
             {
-                uno::Reference< chart2::data::XDataSequence > xTemp(rItem);  // temporary needed for g++ 3.3.5
-                uno::Reference< chart2::data::XTextualDataSequence > xRef( xTemp, uno::UNO_QUERY );
-                if (xRef.is())
+                auto pDataSeq = comphelper::getUnoTunnelImplementation<SwChartDataSequence>(xRef);
+                if (pDataSeq)
                 {
-                    const sal_Int32 nLen = xRef->getTextualData().getLength();
-                    if (nLen > 1) // value data-sequence ?
-                    {
-                        auto pDataSeq = comphelper::getUnoTunnelImplementation<SwChartDataSequence>(xRef);
-                        if (pDataSeq)
-                        {
-                            SwRangeDescriptor aDesc;
-                            pDataSeq->FillRangeDesc( aDesc );
+                    SwRangeDescriptor aDesc;
+                    pDataSeq->FillRangeDesc( aDesc );
 
-                            chart::ChartDataRowSource eDRSource = chart::ChartDataRowSource_COLUMNS;
-                            if (aDesc.nTop == aDesc.nBottom && aDesc.nLeft != aDesc.nRight)
-                                eDRSource = chart::ChartDataRowSource_ROWS;
+                    chart::ChartDataRowSource eDRSource = chart::ChartDataRowSource_COLUMNS;
+                    if (aDesc.nTop == aDesc.nBottom && aDesc.nLeft != aDesc.nRight)
+                        eDRSource = chart::ChartDataRowSource_ROWS;
 
-                            if (!bAddCols && eDRSource == chart::ChartDataRowSource_COLUMNS)
-                            {
-                                // add rows: extend affected columns by newly added row cells
-                                pDataSeq->ExtendTo( true, nFirstNewRow, nLines );
-                            }
-                            else if (bAddCols && eDRSource == chart::ChartDataRowSource_ROWS)
-                            {
-                                // add cols: extend affected rows by newly added column cells
-                                pDataSeq->ExtendTo( false, nFirstNewCol, nLines );
-                            }
-                        }
+                    if (!bAddCols && eDRSource == chart::ChartDataRowSource_COLUMNS)
+                    {
+                        // add rows: extend affected columns by newly added row cells
+                        pDataSeq->ExtendTo( true, nFirstNewRow, nLines );
+                    }
+                    else if (bAddCols && eDRSource == chart::ChartDataRowSource_ROWS)
+                    {
+                        // add cols: extend affected rows by newly added column cells
+                        pDataSeq->ExtendTo( false, nFirstNewCol, nLines );
                     }
                 }
             }
@@ -2236,50 +2236,50 @@ void SAL_CALL SwChartDataSequence::dispose(  )
         if (!m_bDisposed)
             m_bDisposed = true;
     }
-    if (bMustDispose)
+    if (!bMustDispose)
+        return;
+
+    m_bDisposed = true;
+    if (m_xDataProvider.is())
     {
-        m_bDisposed = true;
-        if (m_xDataProvider.is())
+        const SwTable* pTable = SwTable::FindTable( GetFrameFormat() );
+        if (pTable)
         {
-            const SwTable* pTable = SwTable::FindTable( GetFrameFormat() );
-            if (pTable)
-            {
-                uno::Reference< chart2::data::XDataSequence > xRef( dynamic_cast< chart2::data::XDataSequence * >(this), uno::UNO_QUERY );
-                m_xDataProvider->RemoveDataSequence( *pTable, xRef );
-            }
-            else {
-                OSL_FAIL( "table missing" );
-            }
+            uno::Reference< chart2::data::XDataSequence > xRef( dynamic_cast< chart2::data::XDataSequence * >(this), uno::UNO_QUERY );
+            m_xDataProvider->RemoveDataSequence( *pTable, xRef );
+        }
+        else {
+            OSL_FAIL( "table missing" );
+        }
 
-            //#i119653# The bug is crashed for an exception thrown by
-            //SwCharDataSequence::setModified() because
-            //the SwCharDataSequence object has been disposed.
+        //#i119653# The bug is crashed for an exception thrown by
+        //SwCharDataSequence::setModified() because
+        //the SwCharDataSequence object has been disposed.
 
-            //Actually, the former design of SwClient will disconnect itself
-            //from the notification list in its destructor.
+        //Actually, the former design of SwClient will disconnect itself
+        //from the notification list in its destructor.
 
-            //But the SwCharDataSequence won't be destructed but disposed in code
-            //(the data member SwChartDataSequence::bDisposed will be set to
-            //TRUE), the relationship between client and modification is not
-            //released.
+        //But the SwCharDataSequence won't be destructed but disposed in code
+        //(the data member SwChartDataSequence::bDisposed will be set to
+        //TRUE), the relationship between client and modification is not
+        //released.
 
-            //So any notification from modify object will lead to said
-            //exception threw out.  Recorrect the logic of code in
-            //SwChartDataSequence::Dispose(), release the relationship
-            //here...
-            if (m_pFormat && m_pFormat->HasWriterListeners())
-            {
-                EndListeningAll();
-                m_pFormat = nullptr;
-                m_pTableCursor.reset(nullptr);
-            }
+        //So any notification from modify object will lead to said
+        //exception threw out.  Recorrect the logic of code in
+        //SwChartDataSequence::Dispose(), release the relationship
+        //here...
+        if (m_pFormat && m_pFormat->HasWriterListeners())
+        {
+            EndListeningAll();
+            m_pFormat = nullptr;
+            m_pTableCursor.reset(nullptr);
         }
-
-        // require listeners to release references to this object
-        lang::EventObject aEvtObj( dynamic_cast< chart2::data::XDataSequence * >(this) );
-        m_aModifyListeners.disposeAndClear( aEvtObj );
-        m_aEvtListeners.disposeAndClear( aEvtObj );
     }
+
+    // require listeners to release references to this object
+    lang::EventObject aEvtObj( dynamic_cast< chart2::data::XDataSequence * >(this) );
+    m_aModifyListeners.disposeAndClear( aEvtObj );
+    m_aEvtListeners.disposeAndClear( aEvtObj );
 }
 
 void SAL_CALL SwChartDataSequence::addEventListener(
diff --git a/sw/source/core/unocore/unocrsrhelper.cxx b/sw/source/core/unocore/unocrsrhelper.cxx
index a82e7a1c2308..451c9cce7fa4 100644
--- a/sw/source/core/unocore/unocrsrhelper.cxx
+++ b/sw/source/core/unocore/unocrsrhelper.cxx
@@ -1116,39 +1116,38 @@ void InsertFile(SwUnoCursor* pUnoCursor, const OUString& rURL,
     SfxObjectShellRef aRef( pDocSh );
 
     pMed->Download();   // if necessary: start the download
-    if( aRef.is() && 1 < aRef->GetRefCount() )  // Ref still valid?
-    {
-        SwReaderPtr pRdr;
-        SfxItemSet* pSet =  pMed->GetItemSet();
-        pSet->Put(SfxBoolItem(FN_API_CALL, true));
-        if(!sPassword.isEmpty())
-            pSet->Put(SfxStringItem(SID_PASSWORD, sPassword));
-        Reader *pRead = pDocSh->StartConvertFrom( *pMed, pRdr, nullptr, pUnoCursor);
-        if( pRead )
-        {
+    if( !(aRef.is() && 1 < aRef->GetRefCount()) )  // Ref still valid?
+        return;
 
-            UnoActionContext aContext(pDoc);
+    SwReaderPtr pRdr;
+    SfxItemSet* pSet =  pMed->GetItemSet();
+    pSet->Put(SfxBoolItem(FN_API_CALL, true));
+    if(!sPassword.isEmpty())
+        pSet->Put(SfxStringItem(SID_PASSWORD, sPassword));
+    Reader *pRead = pDocSh->StartConvertFrom( *pMed, pRdr, nullptr, pUnoCursor);
+    if( !pRead )
+        return;
 
-            if(pUnoCursor->HasMark())
-                pDoc->getIDocumentContentOperations().DeleteAndJoin(*pUnoCursor);
+    UnoActionContext aContext(pDoc);
 
-            SwNodeIndex aSave(  pUnoCursor->GetPoint()->nNode, -1 );
-            sal_Int32 nContent = pUnoCursor->GetPoint()->nContent.GetIndex();
+    if(pUnoCursor->HasMark())
+        pDoc->getIDocumentContentOperations().DeleteAndJoin(*pUnoCursor);
 
-            ErrCode nErrno = pRdr->Read( *pRead );   // and paste the document
+    SwNodeIndex aSave(  pUnoCursor->GetPoint()->nNode, -1 );
+    sal_Int32 nContent = pUnoCursor->GetPoint()->nContent.GetIndex();
 
-            if(!nErrno)
-            {
-                ++aSave;
-                pUnoCursor->SetMark();
-                pUnoCursor->GetMark()->nNode = aSave;
-
-                SwContentNode* pCntNode = aSave.GetNode().GetContentNode();
-                if( !pCntNode )
-                    nContent = 0;
-                pUnoCursor->GetMark()->nContent.Assign( pCntNode, nContent );
-            }
-        }
+    ErrCode nErrno = pRdr->Read( *pRead );   // and paste the document
+
+    if(!nErrno)
+    {
+        ++aSave;
+        pUnoCursor->SetMark();
+        pUnoCursor->GetMark()->nNode = aSave;
+
+        SwContentNode* pCntNode = aSave.GetNode().GetContentNode();
+        if( !pCntNode )
+            nContent = 0;
+        pUnoCursor->GetMark()->nContent.Assign( pCntNode, nContent );
     }
 }
 
diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx
index d21756c65720..43fed7b070ef 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -789,23 +789,23 @@ void SwXDrawPage::ungroup(const uno::Reference< drawing::XShapeGroup > & rShapeG
     SolarMutexGuard aGuard;
     if(!pDoc)
         throw uno::RuntimeException();
-    if(xPageAgg.is())
-    {
-        SwFmDrawPage* pPage = GetSvxPage();
-        if(pPage) //TODO: can this be Null?
-        {
-            pPage->PreUnGroup(rShapeGroup);
-            UnoActionContext aContext(pDoc);
-            pDoc->GetIDocumentUndoRedo().StartUndo( SwUndoId::START, nullptr );
+    if(!xPageAgg.is())
+        return;
 
-            pDoc->UnGroupSelection( *pPage->GetDrawView() );
-            pDoc->ChgAnchor( pPage->GetDrawView()->GetMarkedObjectList(),
-                        RndStdIds::FLY_AT_PARA,
-                        true, false );
-            pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr );
-            pPage->RemovePageView();
-        }
-    }
+    SwFmDrawPage* pPage = GetSvxPage();
+    if(!pPage) //TODO: can this be Null?
+        return;
+
+    pPage->PreUnGroup(rShapeGroup);
+    UnoActionContext aContext(pDoc);
+    pDoc->GetIDocumentUndoRedo().StartUndo( SwUndoId::START, nullptr );
+
+    pDoc->UnGroupSelection( *pPage->GetDrawView() );
+    pDoc->ChgAnchor( pPage->GetDrawView()->GetMarkedObjectList(),
+                RndStdIds::FLY_AT_PARA,
+                true, false );
+    pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr );
+    pPage->RemovePageView();
 }
 
 SwFmDrawPage*   SwXDrawPage::GetSvxPage()
@@ -1038,390 +1038,390 @@ void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& a
     SolarMutexGuard aGuard;
     SwFrameFormat*   pFormat = GetFrameFormat();
     const SfxItemPropertySimpleEntry*  pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName );
-    if(xShapeAgg.is())
+    if(!xShapeAgg.is())
+        return;
+
+    if(pEntry)
     {
-        if(pEntry)
+        if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
+            throw beans::PropertyVetoException ("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+        // with the layout it is possible to move the anchor without changing the position
+        if(pFormat)
         {
-            if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
-                throw beans::PropertyVetoException ("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
-            // with the layout it is possible to move the anchor without changing the position
-            if(pFormat)
+            SwAttrSet aSet(pFormat->GetAttrSet());
+            SwDoc* pDoc = pFormat->GetDoc();
+            if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORFRAME == pEntry->nMemberId)
             {
-                SwAttrSet aSet(pFormat->GetAttrSet());
-                SwDoc* pDoc = pFormat->GetDoc();
-                if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORFRAME == pEntry->nMemberId)
+                bool bDone = false;
+                uno::Reference<text::XTextFrame> xFrame;
+                if(aValue >>= xFrame)
                 {
-                    bool bDone = false;
-                    uno::Reference<text::XTextFrame> xFrame;
-                    if(aValue >>= xFrame)
+                    SwXFrame* pFrame = comphelper::getUnoTunnelImplementation<SwXFrame>(xFrame);
+                    if(pFrame && pFrame->GetFrameFormat() &&
+                        pFrame->GetFrameFormat()->GetDoc() == pDoc)
                     {
-                        SwXFrame* pFrame = comphelper::getUnoTunnelImplementation<SwXFrame>(xFrame);
-                        if(pFrame && pFrame->GetFrameFormat() &&
-                            pFrame->GetFrameFormat()->GetDoc() == pDoc)
-                        {
-                            UnoActionContext aCtx(pDoc);
-                            SfxItemSet aItemSet( pDoc->GetAttrPool(),
-                                        svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>{} );
-                            aItemSet.SetParent(&pFormat->GetAttrSet());
-                            SwFormatAnchor aAnchor = static_cast<const SwFormatAnchor&>(aItemSet.Get(pEntry->nWID));
-                            SwPosition aPos(*pFrame->GetFrameFormat()->GetContent().GetContentIdx());
-                            aAnchor.SetAnchor(&aPos);
-                            aAnchor.SetType(RndStdIds::FLY_AT_FLY);
-                            aItemSet.Put(aAnchor);
-                            pFormat->SetFormatAttr(aItemSet);
-                            bDone = true;
-                        }
+                        UnoActionContext aCtx(pDoc);
+                        SfxItemSet aItemSet( pDoc->GetAttrPool(),
+                                    svl::Items<RES_FRMATR_BEGIN, RES_FRMATR_END - 1>{} );
+                        aItemSet.SetParent(&pFormat->GetAttrSet());
+                        SwFormatAnchor aAnchor = static_cast<const SwFormatAnchor&>(aItemSet.Get(pEntry->nWID));
+                        SwPosition aPos(*pFrame->GetFrameFormat()->GetContent().GetContentIdx());
+                        aAnchor.SetAnchor(&aPos);
+                        aAnchor.SetType(RndStdIds::FLY_AT_FLY);
+                        aItemSet.Put(aAnchor);
+                        pFormat->SetFormatAttr(aItemSet);
+                        bDone = true;
                     }
-                    if(!bDone)
-                        throw lang::IllegalArgumentException();
                 }
-                else if(RES_OPAQUE == pEntry->nWID)
+                if(!bDone)
+                    throw lang::IllegalArgumentException();
+            }
+            else if(RES_OPAQUE == pEntry->nWID)
+            {
+                SvxShape* pSvxShape = GetSvxShape();
+                SAL_WARN_IF(!pSvxShape, "sw.uno", "No SvxShape found!");
+                if(pSvxShape)
                 {
-                    SvxShape* pSvxShape = GetSvxShape();
-                    SAL_WARN_IF(!pSvxShape, "sw.uno", "No SvxShape found!");
-                    if(pSvxShape)
+                    SdrObject* pObj = pSvxShape->GetSdrObject();
+                    // set layer of new drawing
+                    // object to corresponding invisible layer.
+                    bool bIsVisible = pDoc->getIDocumentDrawModelAccess().IsVisibleLayerId( pObj->GetLayer() );
+                    if(SdrInventor::FmForm != pObj->GetObjInventor())
                     {
-                        SdrObject* pObj = pSvxShape->GetSdrObject();
-                        // set layer of new drawing
-                        // object to corresponding invisible layer.
-                        bool bIsVisible = pDoc->getIDocumentDrawModelAccess().IsVisibleLayerId( pObj->GetLayer() );
-                        if(SdrInventor::FmForm != pObj->GetObjInventor())
-                        {
-                            pObj->SetLayer( *o3tl::doAccess<bool>(aValue)
-                                            ? ( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetHeavenId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId() )
-                                            : ( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetHellId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() ));
-                        }
-                        else
-                        {
-                            pObj->SetLayer( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetControlsId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId());
-                        }
-
+                        pObj->SetLayer( *o3tl::doAccess<bool>(aValue)
+                                        ? ( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetHeavenId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId() )
+                                        : ( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetHellId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() ));
+                    }
+                    else
+                    {
+                        pObj->SetLayer( bIsVisible ? pDoc->getIDocumentDrawModelAccess().GetControlsId() : pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId());
                     }
 
                 }
-                // #i26791# - special handling for property FN_TEXT_RANGE
-                else if ( FN_TEXT_RANGE == pEntry->nWID )
+
+            }
+            // #i26791# - special handling for property FN_TEXT_RANGE
+            else if ( FN_TEXT_RANGE == pEntry->nWID )
+            {
+                SwFormatAnchor aAnchor( aSet.Get( RES_ANCHOR ) );
+                if (aAnchor.GetAnchorId() == RndStdIds::FLY_AT_PAGE)
                 {
-                    SwFormatAnchor aAnchor( aSet.Get( RES_ANCHOR ) );
-                    if (aAnchor.GetAnchorId() == RndStdIds::FLY_AT_PAGE)
-                    {
-                        // set property <TextRange> not valid for to-page anchored shapes
-                        throw lang::IllegalArgumentException();
-                    }
+                    // set property <TextRange> not valid for to-page anchored shapes
+                    throw lang::IllegalArgumentException();
+                }
+
+                std::unique_ptr<SwUnoInternalPaM> pInternalPam(
+                                new SwUnoInternalPaM( *(pFormat->GetDoc()) ));
+                uno::Reference< text::XTextRange > xRg;
+                aValue >>= xRg;
+                if (!::sw::XTextRangeToSwPaM(*pInternalPam, xRg) )
+                {
+                    throw uno::RuntimeException();
+                }
+
+                if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR)
+                {
+                    //delete old SwFormatFlyCnt
+                    //With AnchorAsCharacter the current TextAttribute has to be deleted.
+                    //Tbis removes the frame format too.
+                    //To prevent this the connection between format and attribute has to be broken before.
+                    const SwPosition *pPos = aAnchor.GetContentAnchor();
+                    SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
+                    SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." );
+                    const sal_Int32 nIdx = pPos->nContent.GetIndex();
+                    SwTextAttr * const pHint =
+                            pTextNode->GetTextAttrForCharAt(
+                            nIdx, RES_TXTATR_FLYCNT );
+                    assert(pHint && "Missing Hint.");
+                    SAL_WARN_IF( pHint->Which() != RES_TXTATR_FLYCNT,
+                                "sw.uno", "Missing FlyInCnt-Hint." );
+                    SAL_WARN_IF( pHint->GetFlyCnt().GetFrameFormat() != pFormat,
+                                "sw.uno", "Wrong TextFlyCnt-Hint." );
+                    const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt())
+                        .SetFlyFormat();
+
+                    //The connection is removed now the attribute can be deleted.
+                    pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx );
+                    //create a new one
+                    SwTextNode *pNd = pInternalPam->GetNode().GetTextNode();
+                    SAL_WARN_IF( !pNd, "sw.uno", "Cursor not at TextNode." );
+                    SwFormatFlyCnt aFormat( pFormat );
+                    pNd->InsertItem(aFormat, pInternalPam->GetPoint()
+                            ->nContent.GetIndex(), 0 );
+                }
+                else
+                {
+                    aAnchor.SetAnchor( pInternalPam->GetPoint() );
+                    aSet.Put(aAnchor);
+                    pFormat->SetFormatAttr(aSet);
+                }
+            }
+            else if (pEntry->nWID == FN_TEXT_BOX)
+            {
+                bool bValue(false);
+                aValue >>= bValue;
+                if (bValue)
+                    SwTextBoxHelper::create(pFormat);
+                else
+                    SwTextBoxHelper::destroy(pFormat);
 
-                    std::unique_ptr<SwUnoInternalPaM> pInternalPam(
-                                    new SwUnoInternalPaM( *(pFormat->GetDoc()) ));
-                    uno::Reference< text::XTextRange > xRg;
-                    aValue >>= xRg;
-                    if (!::sw::XTextRangeToSwPaM(*pInternalPam, xRg) )
+            }
+            else if (pEntry->nWID == RES_CHAIN)
+            {
+                if (pEntry->nMemberId == MID_CHAIN_NEXTNAME || pEntry->nMemberId == MID_CHAIN_PREVNAME)
+                    SwTextBoxHelper::syncProperty(pFormat, pEntry->nWID, pEntry->nMemberId, aValue);
+            }
+            // #i28749#
+            else if ( FN_SHAPE_POSITION_LAYOUT_DIR == pEntry->nWID )
+            {
+                sal_Int16 nPositionLayoutDir = 0;
+                aValue >>= nPositionLayoutDir;
+                pFormat->SetPositionLayoutDir( nPositionLayoutDir );
+            }
+            else if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout())
+            {
+                UnoActionContext aCtx(pDoc);
+                if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
+                {
+                    SdrObject* pObj = pFormat->FindSdrObject();
+                    SdrMarkList aList;
+                    SdrMark aMark(pObj);
+                    aList.InsertEntry(aMark);
+                    sal_Int32 nAnchor = 0;
+                    cppu::enum2int( nAnchor, aValue );
+                    pDoc->ChgAnchor( aList, static_cast<RndStdIds>(nAnchor),
+                                            false, true );
+                }
+                else
+                {
+                    m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
+                    pFormat->SetFormatAttr(aSet);
+                }
+            }
+            else if( RES_FRM_SIZE == pEntry->nWID &&
+                    ( pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT || pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH
+                      || pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT_RELATION
+                      || pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH_RELATION ) )
+            {
+                SvxShape* pSvxShape = GetSvxShape();
+                SAL_WARN_IF(!pSvxShape, "sw.uno", "No SvxShape found!");
+                if(pSvxShape)
+                {
+                    SdrObject* pObj = pSvxShape->GetSdrObject();
+                    sal_Int16 nPercent(100);
+                    aValue >>= nPercent;
+                    switch (pEntry->nMemberId)
                     {
-                        throw uno::RuntimeException();
+                    case MID_FRMSIZE_REL_WIDTH:
+                        pObj->SetRelativeWidth( nPercent / 100.0 );
+                    break;
+                    case MID_FRMSIZE_REL_HEIGHT:
+                        pObj->SetRelativeHeight( nPercent / 100.0 );
+                    break;
+                    case MID_FRMSIZE_REL_WIDTH_RELATION:
+                        pObj->SetRelativeWidthRelation(nPercent);
+                    break;
+                    case MID_FRMSIZE_REL_HEIGHT_RELATION:
+                        pObj->SetRelativeHeightRelation(nPercent);
+                    break;
                     }
+                }
+            }
+            else
+            {
+                m_pPropSet->setPropertyValue( *pEntry, aValue, aSet );
 
-                    if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR)
+                if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
+                {
+                    bool bSetAttr = true;
+                    text::TextContentAnchorType eNewAnchor = static_cast<text::TextContentAnchorType>(SWUnoHelper::GetEnumAsInt32( aValue ));
+
+                    //if old anchor was in_cntnt the related text attribute has to be removed
+                    const SwFormatAnchor& rOldAnchor = pFormat->GetAnchor();
+                    RndStdIds eOldAnchorId = rOldAnchor.GetAnchorId();
+                    SdrObject* pObj = pFormat->FindSdrObject();
+                    SwFrameFormat *pFlyFormat = FindFrameFormat( pObj );
+                    pFlyFormat->DelFrames();
+                    if( text::TextContentAnchorType_AS_CHARACTER != eNewAnchor &&
+                        (RndStdIds::FLY_AS_CHAR == eOldAnchorId))
                     {
-                        //delete old SwFormatFlyCnt
                         //With AnchorAsCharacter the current TextAttribute has to be deleted.
                         //Tbis removes the frame format too.
                         //To prevent this the connection between format and attribute has to be broken before.
-                        const SwPosition *pPos = aAnchor.GetContentAnchor();
+                        const SwPosition *pPos = rOldAnchor.GetContentAnchor();
                         SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
                         SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." );
                         const sal_Int32 nIdx = pPos->nContent.GetIndex();
                         SwTextAttr * const pHint =
-                                pTextNode->GetTextAttrForCharAt(
+                            pTextNode->GetTextAttrForCharAt(
                                 nIdx, RES_TXTATR_FLYCNT );
                         assert(pHint && "Missing Hint.");
                         SAL_WARN_IF( pHint->Which() != RES_TXTATR_FLYCNT,
                                     "sw.uno", "Missing FlyInCnt-Hint." );
-                        SAL_WARN_IF( pHint->GetFlyCnt().GetFrameFormat() != pFormat,
+                        SAL_WARN_IF( pHint->GetFlyCnt().GetFrameFormat() != pFlyFormat,
                                     "sw.uno", "Wrong TextFlyCnt-Hint." );
                         const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt())
                             .SetFlyFormat();
 
                         //The connection is removed now the attribute can be deleted.
-                        pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx );
-                        //create a new one
-                        SwTextNode *pNd = pInternalPam->GetNode().GetTextNode();
-                        SAL_WARN_IF( !pNd, "sw.uno", "Cursor not at TextNode." );
-                        SwFormatFlyCnt aFormat( pFormat );
-                        pNd->InsertItem(aFormat, pInternalPam->GetPoint()
-                                ->nContent.GetIndex(), 0 );
-                    }
-                    else
-                    {
-                        aAnchor.SetAnchor( pInternalPam->GetPoint() );
-                        aSet.Put(aAnchor);
-                        pFormat->SetFormatAttr(aSet);
+                        pTextNode->DeleteAttributes(RES_TXTATR_FLYCNT, nIdx);
                     }
-                }
-                else if (pEntry->nWID == FN_TEXT_BOX)
-                {
-                    bool bValue(false);
-                    aValue >>= bValue;
-                    if (bValue)
-                        SwTextBoxHelper::create(pFormat);
-                    else
-                        SwTextBoxHelper::destroy(pFormat);
-
-                }
-                else if (pEntry->nWID == RES_CHAIN)
-                {
-                    if (pEntry->nMemberId == MID_CHAIN_NEXTNAME || pEntry->nMemberId == MID_CHAIN_PREVNAME)
-                        SwTextBoxHelper::syncProperty(pFormat, pEntry->nWID, pEntry->nMemberId, aValue);
-                }
-                // #i28749#
-                else if ( FN_SHAPE_POSITION_LAYOUT_DIR == pEntry->nWID )
-                {
-                    sal_Int16 nPositionLayoutDir = 0;
-                    aValue >>= nPositionLayoutDir;
-                    pFormat->SetPositionLayoutDir( nPositionLayoutDir );
-                }
-                else if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout())
-                {
-                    UnoActionContext aCtx(pDoc);
-                    if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
-                    {
-                        SdrObject* pObj = pFormat->FindSdrObject();
-                        SdrMarkList aList;
-                        SdrMark aMark(pObj);
-                        aList.InsertEntry(aMark);
-                        sal_Int32 nAnchor = 0;
-                        cppu::enum2int( nAnchor, aValue );
-                        pDoc->ChgAnchor( aList, static_cast<RndStdIds>(nAnchor),
-                                                false, true );
-                    }
-                    else
-                    {
-                        m_pPropSet->setPropertyValue(*pEntry, aValue, aSet);
-                        pFormat->SetFormatAttr(aSet);
-                    }
-                }
-                else if( RES_FRM_SIZE == pEntry->nWID &&
-                        ( pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT || pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH
-                          || pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT_RELATION
-                          || pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH_RELATION ) )
-                {
-                    SvxShape* pSvxShape = GetSvxShape();
-                    SAL_WARN_IF(!pSvxShape, "sw.uno", "No SvxShape found!");
-                    if(pSvxShape)
+                    else if( text::TextContentAnchorType_AT_PAGE != eNewAnchor &&
+                            (RndStdIds::FLY_AT_PAGE == eOldAnchorId))
                     {
-                        SdrObject* pObj = pSvxShape->GetSdrObject();
-                        sal_Int16 nPercent(100);
-                        aValue >>= nPercent;
-                        switch (pEntry->nMemberId)
+                        SwFormatAnchor aNewAnchor( dynamic_cast< const SwFormatAnchor& >( aSet.Get( RES_ANCHOR ) ) );
+                        //if the fly has been anchored at page then it needs to be connected
+                        //to the content position
+                        SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
+                        if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() )
                         {
-                        case MID_FRMSIZE_REL_WIDTH:
-                            pObj->SetRelativeWidth( nPercent / 100.0 );
-                        break;
-                        case MID_FRMSIZE_REL_HEIGHT:
-                            pObj->SetRelativeHeight( nPercent / 100.0 );
-                        break;
-                        case MID_FRMSIZE_REL_WIDTH_RELATION:
-                            pObj->SetRelativeWidthRelation(nPercent);
-                        break;
-                        case MID_FRMSIZE_REL_HEIGHT_RELATION:
-                            pObj->SetRelativeHeightRelation(nPercent);
-                        break;
+                            SwCursorMoveState aState( CursorMoveState::SetOnlyText );
+                            Point aTmp( pObj->GetSnapRect().TopLeft() );
+                            pDoc->getIDocumentLayoutAccess().GetCurrentLayout()->GetModelPositionForViewPoint( aPam.GetPoint(), aTmp, &aState );
                         }
-                    }
-                }
-                else
-                {
-                    m_pPropSet->setPropertyValue( *pEntry, aValue, aSet );
-
-                    if(RES_ANCHOR == pEntry->nWID && MID_ANCHOR_ANCHORTYPE == pEntry->nMemberId)
-                    {
-                        bool bSetAttr = true;
-                        text::TextContentAnchorType eNewAnchor = static_cast<text::TextContentAnchorType>(SWUnoHelper::GetEnumAsInt32( aValue ));
-
-                        //if old anchor was in_cntnt the related text attribute has to be removed
-                        const SwFormatAnchor& rOldAnchor = pFormat->GetAnchor();
-                        RndStdIds eOldAnchorId = rOldAnchor.GetAnchorId();
-                        SdrObject* pObj = pFormat->FindSdrObject();
-                        SwFrameFormat *pFlyFormat = FindFrameFormat( pObj );
-                        pFlyFormat->DelFrames();
-                        if( text::TextContentAnchorType_AS_CHARACTER != eNewAnchor &&
-                            (RndStdIds::FLY_AS_CHAR == eOldAnchorId))
+                        else
                         {
-                            //With AnchorAsCharacter the current TextAttribute has to be deleted.
-                            //Tbis removes the frame format too.
-                            //To prevent this the connection between format and attribute has to be broken before.
-                            const SwPosition *pPos = rOldAnchor.GetContentAnchor();
-                            SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode();
-                            SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." );
-                            const sal_Int32 nIdx = pPos->nContent.GetIndex();
-                            SwTextAttr * const pHint =
-                                pTextNode->GetTextAttrForCharAt(
-                                    nIdx, RES_TXTATR_FLYCNT );
-                            assert(pHint && "Missing Hint.");
-                            SAL_WARN_IF( pHint->Which() != RES_TXTATR_FLYCNT,
-                                        "sw.uno", "Missing FlyInCnt-Hint." );
-                            SAL_WARN_IF( pHint->GetFlyCnt().GetFrameFormat() != pFlyFormat,
-                                        "sw.uno", "Wrong TextFlyCnt-Hint." );
-                            const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt())
-                                .SetFlyFormat();
-
-                            //The connection is removed now the attribute can be deleted.
-                            pTextNode->DeleteAttributes(RES_TXTATR_FLYCNT, nIdx);
+                            //without access to the layout the last node of the body will be used as anchor position
+                            aPam.Move( fnMoveBackward, GoInDoc );
                         }
-                        else if( text::TextContentAnchorType_AT_PAGE != eNewAnchor &&
-                                (RndStdIds::FLY_AT_PAGE == eOldAnchorId))
+                        //anchor position has to be inserted after the text attribute has been inserted
+                        aNewAnchor.SetAnchor( aPam.GetPoint() );
+                        aSet.Put( aNewAnchor );
+                        pFormat->SetFormatAttr(aSet);
+                        bSetAttr = false;
+                    }
+                    if( text::TextContentAnchorType_AS_CHARACTER == eNewAnchor &&
+                        (RndStdIds::FLY_AS_CHAR != eOldAnchorId))
+                    {
+                        SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
+                        if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() )
                         {
-                            SwFormatAnchor aNewAnchor( dynamic_cast< const SwFormatAnchor& >( aSet.Get( RES_ANCHOR ) ) );
-                            //if the fly has been anchored at page then it needs to be connected
-                            //to the content position
-                            SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
-                            if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() )
-                            {
-                                SwCursorMoveState aState( CursorMoveState::SetOnlyText );
-                                Point aTmp( pObj->GetSnapRect().TopLeft() );
-                                pDoc->getIDocumentLayoutAccess().GetCurrentLayout()->GetModelPositionForViewPoint( aPam.GetPoint(), aTmp, &aState );
-                            }
-                            else
-                            {
-                                //without access to the layout the last node of the body will be used as anchor position
-                                aPam.Move( fnMoveBackward, GoInDoc );
-                            }
-                            //anchor position has to be inserted after the text attribute has been inserted
-                            aNewAnchor.SetAnchor( aPam.GetPoint() );
-                            aSet.Put( aNewAnchor );
-                            pFormat->SetFormatAttr(aSet);
-                            bSetAttr = false;
+                            SwCursorMoveState aState( CursorMoveState::SetOnlyText );
+                            Point aTmp( pObj->GetSnapRect().TopLeft() );
+                            pDoc->getIDocumentLayoutAccess().GetCurrentLayout()->GetModelPositionForViewPoint( aPam.GetPoint(), aTmp, &aState );
                         }
-                        if( text::TextContentAnchorType_AS_CHARACTER == eNewAnchor &&
-                            (RndStdIds::FLY_AS_CHAR != eOldAnchorId))
+                        else
                         {
-                            SwPaM aPam(pDoc->GetNodes().GetEndOfContent());
-                            if( pDoc->getIDocumentLayoutAccess().GetCurrentLayout() )
-                            {
-                                SwCursorMoveState aState( CursorMoveState::SetOnlyText );
-                                Point aTmp( pObj->GetSnapRect().TopLeft() );
-                                pDoc->getIDocumentLayoutAccess().GetCurrentLayout()->GetModelPositionForViewPoint( aPam.GetPoint(), aTmp, &aState );
-                            }
-                            else
-                            {
-                                //without access to the layout the last node of the body will be used as anchor position
-                                aPam.Move( fnMoveBackward, GoInDoc );
-                            }
-                            //the RES_TXTATR_FLYCNT needs to be added now
-                            SwTextNode *pNd = aPam.GetNode().GetTextNode();
-                            SAL_WARN_IF( !pNd, "sw.uno", "Cursor is not in a TextNode." );
-                            SwFormatFlyCnt aFormat( pFlyFormat );
-                            pNd->InsertItem(aFormat,
-                                aPam.GetPoint()->nContent.GetIndex(), 0 );
-                            --aPam.GetPoint()->nContent; // InsertItem moved it
-                            SwFormatAnchor aNewAnchor(
-                                dynamic_cast<const SwFormatAnchor&>(
-                                    aSet.Get(RES_ANCHOR)));
-                            aNewAnchor.SetAnchor( aPam.GetPoint() );
-                            aSet.Put( aNewAnchor );
+                            //without access to the layout the last node of the body will be used as anchor position
+                            aPam.Move( fnMoveBackward, GoInDoc );
                         }
-                        if( bSetAttr )
-                            pFormat->SetFormatAttr(aSet);
+                        //the RES_TXTATR_FLYCNT needs to be added now
+                        SwTextNode *pNd = aPam.GetNode().GetTextNode();
+                        SAL_WARN_IF( !pNd, "sw.uno", "Cursor is not in a TextNode." );
+                        SwFormatFlyCnt aFormat( pFlyFormat );
+                        pNd->InsertItem(aFormat,
+                            aPam.GetPoint()->nContent.GetIndex(), 0 );
+                        --aPam.GetPoint()->nContent; // InsertItem moved it
+                        SwFormatAnchor aNewAnchor(
+                            dynamic_cast<const SwFormatAnchor&>(
+                                aSet.Get(RES_ANCHOR)));
+                        aNewAnchor.SetAnchor( aPam.GetPoint() );
+                        aSet.Put( aNewAnchor );
                     }
-                    else
+                    if( bSetAttr )
                         pFormat->SetFormatAttr(aSet);
                 }
-                // We have a pFormat and a pEntry as well: try to sync TextBox property.
-                SwTextBoxHelper::syncProperty(pFormat, pEntry->nWID, pEntry->nMemberId, aValue);
+                else
+                    pFormat->SetFormatAttr(aSet);
             }
-            else
+            // We have a pFormat and a pEntry as well: try to sync TextBox property.
+            SwTextBoxHelper::syncProperty(pFormat, pEntry->nWID, pEntry->nMemberId, aValue);
+        }
+        else
+        {
+            SfxPoolItem* pItem = nullptr;
+            switch(pEntry->nWID)
             {
-                SfxPoolItem* pItem = nullptr;
-                switch(pEntry->nWID)
-                {
-                    case RES_ANCHOR:
-                        pItem = pImpl->GetAnchor(true);
-                    break;
-                    case RES_HORI_ORIENT:
-                        pItem = pImpl->GetHOrient(true);
-                    break;
-                    case RES_VERT_ORIENT:
-                        pItem = pImpl->GetVOrient(true);
-                    break;
-                    case  RES_LR_SPACE:
-                        pItem = pImpl->GetLRSpace(true);
-                    break;
-                    case  RES_UL_SPACE:
-                        pItem = pImpl->GetULSpace(true);
-                    break;
-                    case  RES_SURROUND:
-                        pItem = pImpl->GetSurround(true);
-                    break;
-                    case  FN_TEXT_RANGE:
-                        if(auto tr = o3tl::tryAccess<
-                               uno::Reference<text::XTextRange>>(aValue))
-                        {
-                            uno::Reference< text::XTextRange > & rRange = pImpl->GetTextRange();
-                            rRange = *tr;
-                        }
-                    break;
-                    case RES_OPAQUE :
-                        pImpl->SetOpaque(*o3tl::doAccess<bool>(aValue));
-                    break;
-                    // #i26791#
-                    case RES_FOLLOW_TEXT_FLOW:
-                    {
-                        pItem = pImpl->GetFollowTextFlow( true );
-                    }
-                    break;
-                    // #i28701#
-                    case RES_WRAP_INFLUENCE_ON_OBJPOS:
-                    {
-                        pItem = pImpl->GetWrapInfluenceOnObjPos( true );
-                    }
-                    break;
-                    // #i28749#
-                    case FN_SHAPE_POSITION_LAYOUT_DIR :
+                case RES_ANCHOR:
+                    pItem = pImpl->GetAnchor(true);
+                break;
+                case RES_HORI_ORIENT:
+                    pItem = pImpl->GetHOrient(true);
+                break;
+                case RES_VERT_ORIENT:
+                    pItem = pImpl->GetVOrient(true);
+                break;
+                case  RES_LR_SPACE:
+                    pItem = pImpl->GetLRSpace(true);
+                break;
+                case  RES_UL_SPACE:
+                    pItem = pImpl->GetULSpace(true);
+                break;
+                case  RES_SURROUND:
+                    pItem = pImpl->GetSurround(true);
+                break;
+                case  FN_TEXT_RANGE:
+                    if(auto tr = o3tl::tryAccess<
+                           uno::Reference<text::XTextRange>>(aValue))
                     {
-                        sal_Int16 nPositionLayoutDir = 0;
-                        aValue >>= nPositionLayoutDir;
-                        pImpl->SetPositionLayoutDir( nPositionLayoutDir );
+                        uno::Reference< text::XTextRange > & rRange = pImpl->GetTextRange();
+                        rRange = *tr;
                     }
-                    break;
+                break;
+                case RES_OPAQUE :
+                    pImpl->SetOpaque(*o3tl::doAccess<bool>(aValue));
+                break;
+                // #i26791#
+                case RES_FOLLOW_TEXT_FLOW:
+                {
+                    pItem = pImpl->GetFollowTextFlow( true );
                 }
-                if(pItem)
-                    pItem->PutValue(aValue, pEntry->nMemberId);
+                break;
+                // #i28701#
+                case RES_WRAP_INFLUENCE_ON_OBJPOS:
+                {
+                    pItem = pImpl->GetWrapInfluenceOnObjPos( true );
+                }
+                break;
+                // #i28749#
+                case FN_SHAPE_POSITION_LAYOUT_DIR :
+                {
+                    sal_Int16 nPositionLayoutDir = 0;
+                    aValue >>= nPositionLayoutDir;
+                    pImpl->SetPositionLayoutDir( nPositionLayoutDir );
+                }
+                break;
             }
+            if(pItem)
+                pItem->PutValue(aValue, pEntry->nMemberId);
         }
-        else
+    }
+    else
+    {
+        const uno::Type& rPSetType =
+            cppu::UnoType<beans::XPropertySet>::get();
+        uno::Any aPSet = xShapeAgg->queryAggregation(rPSetType);
+        auto xPrSet = o3tl::tryAccess<uno::Reference<beans::XPropertySet>>(
+            aPSet);
+        if(!xPrSet)
+            throw uno::RuntimeException();
+        // #i31698# - setting the caption point of a
+        // caption object doesn't have to change the object position.
+        // Thus, keep the position, before the caption point is set and
+        // restore it afterwards.
+        awt::Point aKeepedPosition( 0, 0 );
+        if ( rPropertyName == "CaptionPoint" && getShapeType() == "com.sun.star.drawing.CaptionShape" )
         {
-            const uno::Type& rPSetType =
-                cppu::UnoType<beans::XPropertySet>::get();
-            uno::Any aPSet = xShapeAgg->queryAggregation(rPSetType);
-            auto xPrSet = o3tl::tryAccess<uno::Reference<beans::XPropertySet>>(
-                aPSet);
-            if(!xPrSet)
-                throw uno::RuntimeException();
-            // #i31698# - setting the caption point of a
-            // caption object doesn't have to change the object position.
-            // Thus, keep the position, before the caption point is set and
-            // restore it afterwards.
-            awt::Point aKeepedPosition( 0, 0 );
-            if ( rPropertyName == "CaptionPoint" && getShapeType() == "com.sun.star.drawing.CaptionShape" )
-            {
-                    aKeepedPosition = getPosition();
-            }
-            if( pFormat && pFormat->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell() )
-            {
-                UnoActionContext aCtx(pFormat->GetDoc());
-                (*xPrSet)->setPropertyValue(rPropertyName, aValue);
-            }
-            else
-                (*xPrSet)->setPropertyValue(rPropertyName, aValue);
+                aKeepedPosition = getPosition();
+        }
+        if( pFormat && pFormat->GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell() )
+        {
+            UnoActionContext aCtx(pFormat->GetDoc());
+            (*xPrSet)->setPropertyValue(rPropertyName, aValue);
+        }
+        else
+            (*xPrSet)->setPropertyValue(rPropertyName, aValue);
 
-            if (pFormat)
-            {
-                // We have a pFormat (but no pEntry): try to sync TextBox property.
-                SwTextBoxHelper::syncProperty(pFormat, rPropertyName, aValue);
-            }
+        if (pFormat)
+        {
+            // We have a pFormat (but no pEntry): try to sync TextBox property.
+            SwTextBoxHelper::syncProperty(pFormat, rPropertyName, aValue);
+        }
 
-            // #i31698# - restore object position, if caption point is set.
-            if ( rPropertyName == "CaptionPoint" && getShapeType() == "com.sun.star.drawing.CaptionShape" )
-            {
-                setPosition( aKeepedPosition );
-            }
+        // #i31698# - restore object position, if caption point is set.
+        if ( rPropertyName == "CaptionPoint" && getShapeType() == "com.sun.star.drawing.CaptionShape" )
+        {
+            setPosition( aKeepedPosition );
         }
     }
 }
@@ -2035,21 +2035,22 @@ void SwXShape::attach(const uno::Reference< text::XTextRange > & xTextRange)
 
     if(!pDoc)
         throw uno::RuntimeException();
-    if (const SwDocShell* pDocSh = pDoc->GetDocShell())
+    const SwDocShell* pDocSh = pDoc->GetDocShell();
+    if (!pDocSh)
+        return;
+
+    uno::Reference<frame::XModel> xModel = pDocSh->GetModel();
+    uno::Reference< drawing::XDrawPageSupplier > xDPS(xModel, uno::UNO_QUERY);
+    if (xDPS.is())
     {
-        uno::Reference<frame::XModel> xModel = pDocSh->GetModel();
-        uno::Reference< drawing::XDrawPageSupplier > xDPS(xModel, uno::UNO_QUERY);
-        if (xDPS.is())
+        uno::Reference< drawing::XDrawPage > xDP( xDPS->getDrawPage() );
+        if (xDP.is())
         {
-            uno::Reference< drawing::XDrawPage > xDP( xDPS->getDrawPage() );
-            if (xDP.is())
-            {
-                uno::Any aPos;
-                aPos <<= xTextRange;
-                setPropertyValue("TextRange", aPos);
-                uno::Reference< drawing::XShape > xTemp( static_cast<cppu::OWeakObject*>(this), uno::UNO_QUERY );
-                xDP->add( xTemp );
-            }
+            uno::Any aPos;
+            aPos <<= xTextRange;
+            setPropertyValue("TextRange", aPos);
+            uno::Reference< drawing::XShape > xTemp( static_cast<cppu::OWeakObject*>(this), uno::UNO_QUERY );
+            xDP->add( xTemp );
         }
     }
 }
@@ -2727,37 +2728,37 @@ void SwXGroupShape::add( const uno::Reference< XShape >& xShape )
     if(xShape.is())
         pSwShape = reinterpret_cast< SwXShape * >(
                 sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SwXShape::getUnoTunnelId()) ));
-    if(pSwShape && pSwShape->m_bDescriptor)
+    if(!(pSwShape && pSwShape->m_bDescriptor))
+        return;
+
+    SvxShape* pAddShape = reinterpret_cast< SvxShape * >(
+            sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
+    if(pAddShape)
     {
-        SvxShape* pAddShape = reinterpret_cast< SvxShape * >(
-                sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SvxShape::getUnoTunnelId()) ));
-        if(pAddShape)
+        SdrObject* pObj = pAddShape->GetSdrObject();
+        if(pObj)
         {
-            SdrObject* pObj = pAddShape->GetSdrObject();
-            if(pObj)
+            SwDoc* pDoc = pFormat->GetDoc();
+            // set layer of new drawing
+            // object to corresponding invisible layer.
+            if( SdrInventor::FmForm != pObj->GetObjInventor())
             {
-                SwDoc* pDoc = pFormat->GetDoc();
-                // set layer of new drawing
-                // object to corresponding invisible layer.
-                if( SdrInventor::FmForm != pObj->GetObjInventor())
-                {
-                    pObj->SetLayer( pSwShape->pImpl->GetOpaque()
-                                    ? pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId()
-                                    : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() );
-                }
-                else
-                {
-                    pObj->SetLayer(pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId());
-                }
+                pObj->SetLayer( pSwShape->pImpl->GetOpaque()
+                                ? pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId()
+                                : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() );
+            }
+            else
+            {
+                pObj->SetLayer(pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId());
             }
         }
-        pSwShape->m_bDescriptor = false;
-        //add the group member to the format of the group
-        SwFrameFormat* pShapeFormat = ::FindFrameFormat( pSvxShape->GetSdrObject() );
-
-        if(pShapeFormat)
-            pSwShape->SetFrameFormat(pShapeFormat);
     }
+    pSwShape->m_bDescriptor = false;
+    //add the group member to the format of the group
+    SwFrameFormat* pShapeFormat = ::FindFrameFormat( pSvxShape->GetSdrObject() );
+
+    if(pShapeFormat)
+        pSwShape->SetFrameFormat(pShapeFormat);
 
 }
 
diff --git a/sw/source/core/unocore/unoflatpara.cxx b/sw/source/core/unocore/unoflatpara.cxx
index 15ffb4441aa7..ea3ae869c62d 100644
--- a/sw/source/core/unocore/unoflatpara.cxx
+++ b/sw/source/core/unocore/unoflatpara.cxx
@@ -176,21 +176,21 @@ void SAL_CALL SwXFlatParagraph::setChecked( ::sal_Int32 nType, sal_Bool bVal )
 {
     SolarMutexGuard aGuard;
 
-    if (GetTextNode())
+    if (!GetTextNode())
+        return;
+
+    if ( text::TextMarkupType::SPELLCHECK == nType )
     {
-        if ( text::TextMarkupType::SPELLCHECK == nType )
-        {
-            GetTextNode()->SetWrongDirty(
-                bVal ? SwTextNode::WrongState::DONE : SwTextNode::WrongState::TODO);
-        }
-        else if ( text::TextMarkupType::SMARTTAG == nType )
-            GetTextNode()->SetSmartTagDirty( !bVal );
-        else if( text::TextMarkupType::PROOFREADING == nType )
-        {
-            GetTextNode()->SetGrammarCheckDirty( !bVal );
-            if( bVal )
-                ::finishGrammarCheck( *GetTextNode() );
-        }
+        GetTextNode()->SetWrongDirty(
+            bVal ? SwTextNode::WrongState::DONE : SwTextNode::WrongState::TODO);
+    }
+    else if ( text::TextMarkupType::SMARTTAG == nType )
+        GetTextNode()->SetSmartTagDirty( !bVal );
+    else if( text::TextMarkupType::PROOFREADING == nType )
+    {
+        GetTextNode()->SetGrammarCheckDirty( !bVal );
+        if( bVal )
+            ::finishGrammarCheck( *GetTextNode() );
     }
 }
 
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index c277d1179789..1c1e23094474 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2600,28 +2600,28 @@ void SwXFrame::dispose()
 {
     SolarMutexGuard aGuard;
     SwFrameFormat* pFormat = GetFrameFormat();
-    if (pFormat)
+    if (!pFormat)
+        return;
+
+    DisposeInternal();
+    SdrObject* pObj = pFormat->FindSdrObject();
+    // OD 11.09.2003 #112039# - add condition to perform delete of
+    // format/anchor sign, not only if the object is inserted, but also
+    // if a contact object is registered, which isn't in the destruction.
+    if ( pObj &&
+         ( pObj->IsInserted() ||
+           ( pObj->GetUserCall() &&
+             !static_cast<SwContact*>(pObj->GetUserCall())->IsInDTOR() ) ) )
     {
-        DisposeInternal();
-        SdrObject* pObj = pFormat->FindSdrObject();
-        // OD 11.09.2003 #112039# - add condition to perform delete of
-        // format/anchor sign, not only if the object is inserted, but also
-        // if a contact object is registered, which isn't in the destruction.
-        if ( pObj &&
-             ( pObj->IsInserted() ||
-               ( pObj->GetUserCall() &&
-                 !static_cast<SwContact*>(pObj->GetUserCall())->IsInDTOR() ) ) )
-        {
-            if (pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR)
-            {
-                const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor());
-                SwTextNode *pTextNode = rPos.nNode.GetNode().GetTextNode();
-                const sal_Int32 nIdx = rPos.nContent.GetIndex();
-                pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx, nIdx );
-            }
-            else
-                pFormat->GetDoc()->getIDocumentLayoutAccess().DelLayoutFormat(pFormat);
+        if (pFormat->GetAnchor().GetAnchorId() == RndStdIds::FLY_AS_CHAR)
+        {
+            const SwPosition &rPos = *(pFormat->GetAnchor().GetContentAnchor());
+            SwTextNode *pTextNode = rPos.nNode.GetNode().GetTextNode();
+            const sal_Int32 nIdx = rPos.nContent.GetIndex();
+            pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx, nIdx );
         }
+        else
+            pFormat->GetDoc()->getIDocumentLayoutAccess().DelLayoutFormat(pFormat);
     }
 
 }
@@ -3081,28 +3081,28 @@ void SwXFrame::attach(const uno::Reference< text::XTextRange > & xTextRange)
     }
 
     SwFrameFormat* pFormat = GetFrameFormat();
-    if( pFormat )
-    {
-        SwDoc* pDoc = pFormat->GetDoc();
-        SwUnoInternalPaM aIntPam(*pDoc);
-        if (!::sw::XTextRangeToSwPaM(aIntPam, xTextRange))
-            throw lang::IllegalArgumentException();
+    if( !pFormat )
+        return;
 
-        SfxItemSet aSet( pDoc->GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{} );
-        aSet.SetParent(&pFormat->GetAttrSet());
-        SwFormatAnchor aAnchor = aSet.Get(RES_ANCHOR);
+    SwDoc* pDoc = pFormat->GetDoc();
+    SwUnoInternalPaM aIntPam(*pDoc);
+    if (!::sw::XTextRangeToSwPaM(aIntPam, xTextRange))
+        throw lang::IllegalArgumentException();
 
-        if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR)
-        {
-            throw lang::IllegalArgumentException(
-                    "SwXFrame::attach(): re-anchoring AS_CHAR not supported",
-                    *this, 0);
-        }
+    SfxItemSet aSet( pDoc->GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{} );
+    aSet.SetParent(&pFormat->GetAttrSet());
+    SwFormatAnchor aAnchor = aSet.Get(RES_ANCHOR);
 
-        aAnchor.SetAnchor( aIntPam.Start() );
-        aSet.Put(aAnchor);
-        pDoc->SetFlyFrameAttr( *pFormat, aSet );
+    if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR)
+    {
+        throw lang::IllegalArgumentException(
+                "SwXFrame::attach(): re-anchoring AS_CHAR not supported",
+                *this, 0);
     }
+
+    aAnchor.SetAnchor( aIntPam.Start() );
+    aSet.Put(aAnchor);
+    pDoc->SetFlyFrameAttr( *pFormat, aSet );
 }
 
 awt::Point SwXFrame::getPosition()
diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx
index aa3fd65fc2f4..5ef447324dae 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -179,25 +179,25 @@ static void
 lcl_setCharStyle(SwDoc *const pDoc, const uno::Any & rValue, SfxItemSet & rSet)
 {
     SwDocShell *const pDocSh = pDoc->GetDocShell();
-    if(pDocSh)
+    if(!pDocSh)
+        return;
+
+    OUString uStyle;
+    if (!(rValue >>= uStyle))
     {
-        OUString uStyle;
-        if (!(rValue >>= uStyle))
-        {
-            throw lang::IllegalArgumentException();
-        }
-        OUString sStyle;
-        SwStyleNameMapper::FillUIName(uStyle, sStyle,
-                SwGetPoolIdFromName::ChrFmt);
-        SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>(
-            pDocSh->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char));
-        if (!pStyle)
-        {
-            throw lang::IllegalArgumentException();
-        }
-        const SwFormatCharFormat aFormat(pStyle->GetCharFormat());
-        rSet.Put(aFormat);
+        throw lang::IllegalArgumentException();
+    }
+    OUString sStyle;
+    SwStyleNameMapper::FillUIName(uStyle, sStyle,
+            SwGetPoolIdFromName::ChrFmt);
+    SwDocStyleSheet *const pStyle = static_cast<SwDocStyleSheet*>(
+        pDocSh->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char));
+    if (!pStyle)
+    {
+        throw lang::IllegalArgumentException();
     }
+    const SwFormatCharFormat aFormat(pStyle->GetCharFormat());
+    rSet.Put(aFormat);
 };
 
 /// @throws lang::IllegalArgumentException
@@ -719,34 +719,34 @@ void SwXTextCursor::DeleteAndInsert(const OUString& rText,
         const bool bForceExpandHints)
 {
     auto pUnoCursor = static_cast<SwCursor*>(m_pImpl->m_pUnoCursor.get());
-    if (pUnoCursor)
+    if (!pUnoCursor)
+        return;
+
+    // Start/EndAction
+    SwDoc* pDoc = pUnoCursor->GetDoc();
+    UnoActionContext aAction(pDoc);
+    const sal_Int32 nTextLen = rText.getLength();
+    pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr);
+    auto pCurrent = pUnoCursor;
+    do
     {
-        // Start/EndAction
-        SwDoc* pDoc = pUnoCursor->GetDoc();
-        UnoActionContext aAction(pDoc);
-        const sal_Int32 nTextLen = rText.getLength();
-        pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr);
-        auto pCurrent = pUnoCursor;
-        do
+        if (pCurrent->HasMark())
         {
-            if (pCurrent->HasMark())
-            {
-                pDoc->getIDocumentContentOperations().DeleteAndJoin(*pCurrent);
-            }
-            if(nTextLen)
-            {
-                const bool bSuccess(
-                    SwUnoCursorHelper::DocInsertStringSplitCR(
-                        *pDoc, *pCurrent, rText, bForceExpandHints ) );
-                OSL_ENSURE( bSuccess, "Doc->Insert(Str) failed." );
+            pDoc->getIDocumentContentOperations().DeleteAndJoin(*pCurrent);
+        }
+        if(nTextLen)
+        {
+            const bool bSuccess(
+                SwUnoCursorHelper::DocInsertStringSplitCR(
+                    *pDoc, *pCurrent, rText, bForceExpandHints ) );
+            OSL_ENSURE( bSuccess, "Doc->Insert(Str) failed." );
 
-                SwUnoCursorHelper::SelectPam(*pUnoCursor, true);
-                pCurrent->Left(rText.getLength());
-            }
-            pCurrent = pCurrent->GetNext();
-        } while (pCurrent != pUnoCursor);
-        pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
-    }
+            SwUnoCursorHelper::SelectPam(*pUnoCursor, true);
+            pCurrent->Left(rText.getLength());
+        }
+        pCurrent = pCurrent->GetNext();
+    } while (pCurrent != pUnoCursor);
+    pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
 }
 
 namespace {
@@ -2344,59 +2344,59 @@ SwXTextCursor::setPropertiesToDefault(
 
     SwUnoCursor & rUnoCursor( m_pImpl->GetCursorOrThrow() );
 
-    if ( rPropertyNames.hasElements() )
+    if ( !rPropertyNames.hasElements() )
+        return;
+
+    SwDoc & rDoc = *rUnoCursor.GetDoc();
+    std::set<sal_uInt16> aWhichIds;
+    std::set<sal_uInt16> aParaWhichIds;
+    for (const OUString& rName : rPropertyNames)
     {
-        SwDoc & rDoc = *rUnoCursor.GetDoc();
-        std::set<sal_uInt16> aWhichIds;
-        std::set<sal_uInt16> aParaWhichIds;
-        for (const OUString& rName : rPropertyNames)
+        SfxItemPropertySimpleEntry const*const  pEntry =
+            m_pImpl->m_rPropSet.getPropertyMap().getByName( rName );
+        if (!pEntry)
         {
-            SfxItemPropertySimpleEntry const*const  pEntry =
-                m_pImpl->m_rPropSet.getPropertyMap().getByName( rName );
-            if (!pEntry)
-            {
-                if (rName == UNO_NAME_IS_SKIP_HIDDEN_TEXT ||
-                    rName == UNO_NAME_IS_SKIP_PROTECTED_TEXT)
-                {
-                    continue;
-                }
-                throw beans::UnknownPropertyException(
-                    "Unknown property: " + rName,
-                    static_cast<cppu::OWeakObject *>(this));
-            }
-            if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
+            if (rName == UNO_NAME_IS_SKIP_HIDDEN_TEXT ||
+                rName == UNO_NAME_IS_SKIP_PROTECTED_TEXT)
             {
-                throw uno::RuntimeException(
-                    "setPropertiesToDefault: property is read-only: " + rName,
-                    static_cast<cppu::OWeakObject *>(this));
+                continue;
             }
+            throw beans::UnknownPropertyException(
+                "Unknown property: " + rName,
+                static_cast<cppu::OWeakObject *>(this));
+        }
+        if (pEntry->nFlags & beans::PropertyAttribute::READONLY)
+        {
+            throw uno::RuntimeException(
+                "setPropertiesToDefault: property is read-only: " + rName,
+                static_cast<cppu::OWeakObject *>(this));
+        }
 
-            if (pEntry->nWID < RES_FRMATR_END)
+        if (pEntry->nWID < RES_FRMATR_END)
+        {
+            if (pEntry->nWID < RES_PARATR_BEGIN)
             {
-                if (pEntry->nWID < RES_PARATR_BEGIN)
-                {
-                    aWhichIds.insert( pEntry->nWID );
-                }
-                else
-                {
-                    aParaWhichIds.insert( pEntry->nWID );
-                }
+                aWhichIds.insert( pEntry->nWID );
             }
-            else if (pEntry->nWID == FN_UNO_NUM_START_VALUE)
+            else
             {
-                SwUnoCursorHelper::resetCursorPropertyValue(*pEntry, rUnoCursor);
+                aParaWhichIds.insert( pEntry->nWID );
             }
         }
-
-        if (!aParaWhichIds.empty())
+        else if (pEntry->nWID == FN_UNO_NUM_START_VALUE)
         {
-            lcl_SelectParaAndReset(rUnoCursor, rDoc, aParaWhichIds);
-        }
-        if (!aWhichIds.empty())
-        {
-            rDoc.ResetAttrs(rUnoCursor, true, aWhichIds);
+            SwUnoCursorHelper::resetCursorPropertyValue(*pEntry, rUnoCursor);
         }
     }
+
+    if (!aParaWhichIds.empty())
+    {
+        lcl_SelectParaAndReset(rUnoCursor, rDoc, aParaWhichIds);
+    }
+    if (!aWhichIds.empty())
+    {
+        rDoc.ResetAttrs(rUnoCursor, true, aWhichIds);
+    }
 }
 
 uno::Sequence< uno::Any > SAL_CALL
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index 9f0dc5d8eb9e..4f280beb94cc 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -80,19 +80,19 @@ void DeepCopyPaM(SwPaM const & rSource, SwPaM & rTarget)
 {
     rTarget = rSource;
 
-    if (rSource.GetNext() != &rSource)
+    if (rSource.GetNext() == &rSource)
+        return;
+
+    SwPaM *pPam = const_cast<SwPaM*>(rSource.GetNext());
+    do
     {
-        SwPaM *pPam = const_cast<SwPaM*>(rSource.GetNext());
-        do
-        {
-            // create new PaM
-            SwPaM *const pNew = new SwPaM(*pPam, nullptr);
-            // insert into ring
-            pNew->MoveTo(&rTarget);
-            pPam = pPam->GetNext();
-        }
-        while (pPam != &rSource);
+        // create new PaM
+        SwPaM *const pNew = new SwPaM(*pPam, nullptr);
+        // insert into ring
+        pNew->MoveTo(&rTarget);
+        pPam = pPam->GetNext();
     }
+    while (pPam != &rSource);
 }
 
 } // namespace sw
@@ -764,26 +764,26 @@ void SwXTextRange::DeleteAndInsert(
 
     const SwPosition aPos(GetDoc().GetNodes().GetEndOfContent());
     SwCursor aCursor(aPos, nullptr);
-    if (GetPositions(aCursor))
+    if (!GetPositions(aCursor))
+        return;
+
+    UnoActionContext aAction(& m_pImpl->m_rDoc);
+    m_pImpl->m_rDoc.GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr);
+    if (aCursor.HasMark())
     {
-        UnoActionContext aAction(& m_pImpl->m_rDoc);
-        m_pImpl->m_rDoc.GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr);
-        if (aCursor.HasMark())
-        {
-            m_pImpl->m_rDoc.getIDocumentContentOperations().DeleteAndJoin(aCursor);
-        }
+        m_pImpl->m_rDoc.getIDocumentContentOperations().DeleteAndJoin(aCursor);
+    }
 
-        if (!rText.isEmpty())
-        {
-            SwUnoCursorHelper::DocInsertStringSplitCR(
-                    m_pImpl->m_rDoc, aCursor, rText, bForceExpandHints);
+    if (!rText.isEmpty())
+    {
+        SwUnoCursorHelper::DocInsertStringSplitCR(
+                m_pImpl->m_rDoc, aCursor, rText, bForceExpandHints);
 
-            SwUnoCursorHelper::SelectPam(aCursor, true);
-            aCursor.Left(rText.getLength());
-        }
-        SetPositions(aCursor);
-        m_pImpl->m_rDoc.GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
+        SwUnoCursorHelper::SelectPam(aCursor, true);
+        aCursor.Left(rText.getLength());
     }
+    SetPositions(aCursor);
+    m_pImpl->m_rDoc.GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr);
 }
 
 namespace
@@ -1441,18 +1441,18 @@ struct SwXTextRangesImpl final : public SwXTextRanges
 
 void SwXTextRangesImpl::MakeRanges()
 {
-    if (GetCursor())
+    if (!GetCursor())
+        return;
+
+    for(SwPaM& rTmpCursor : GetCursor()->GetRingContainer())
     {
-        for(SwPaM& rTmpCursor : GetCursor()->GetRingContainer())
+        const uno::Reference< text::XTextRange > xRange(
+                SwXTextRange::CreateXTextRange(
+                    *rTmpCursor.GetDoc(),
+                    *rTmpCursor.GetPoint(), rTmpCursor.GetMark()));
+        if (xRange.is())
         {
-            const uno::Reference< text::XTextRange > xRange(
-                    SwXTextRange::CreateXTextRange(
-                        *rTmpCursor.GetDoc(),
-                        *rTmpCursor.GetPoint(), rTmpCursor.GetMark()));
-            if (xRange.is())
-            {
-                m_Ranges.push_back(xRange);
-            }
+            m_Ranges.push_back(xRange);
         }
     }
 }
diff --git a/sw/source/core/unocore/unoparagraph.cxx b/sw/source/core/unocore/unoparagraph.cxx
index 3fef41218cad..d62ed4ab5710 100644
--- a/sw/source/core/unocore/unoparagraph.cxx
+++ b/sw/source/core/unocore/unoparagraph.cxx
@@ -331,19 +331,19 @@ void
 SwXParagraph::attachToText(SwXText & rParent, SwTextNode & rTextNode)
 {
     OSL_ENSURE(m_pImpl->m_bIsDescriptor, "Paragraph is not a descriptor");
-    if (m_pImpl->m_bIsDescriptor)
+    if (!m_pImpl->m_bIsDescriptor)
+        return;
+
+    m_pImpl->m_bIsDescriptor = false;
+    m_pImpl->EndListeningAll();
+    m_pImpl->StartListening(rTextNode.GetNotifier());
+    rTextNode.SetXParagraph(uno::Reference<text::XTextContent>(this));
+    m_pImpl->m_xParentText = &rParent;
+    if (!m_pImpl->m_sText.isEmpty())
     {
-        m_pImpl->m_bIsDescriptor = false;
-        m_pImpl->EndListeningAll();
-        m_pImpl->StartListening(rTextNode.GetNotifier());
-        rTextNode.SetXParagraph(uno::Reference<text::XTextContent>(this));
-        m_pImpl->m_xParentText = &rParent;
-        if (!m_pImpl->m_sText.isEmpty())
-        {
-            try { setString(m_pImpl->m_sText); }
-            catch(...){}
-            m_pImpl->m_sText.clear();
-        }
+        try { setString(m_pImpl->m_sText); }
+        catch(...){}
+        m_pImpl->m_sText.clear();
     }
 }
 
@@ -478,48 +478,48 @@ void SwXParagraph::Impl::GetSinglePropertyValue_Impl(
         default: break;
     }
 
-    if(!bDone)
+    if(bDone)
+        return;
+
+    // fallback to standard get value implementation used before this helper was created
+    m_rPropSet.getPropertyValue(rEntry, rSet, rAny);
+
+    if(rEntry.aType == cppu::UnoType<sal_Int16>::get() && rEntry.aType != rAny.getValueType())
     {
-        // fallback to standard get value implementation used before this helper was created
-        m_rPropSet.getPropertyValue(rEntry, rSet, rAny);
+        // since the sfx uInt16 item now exports a sal_Int32, we may have to fix this here
+        sal_Int32 nValue(0);
 
-        if(rEntry.aType == cppu::UnoType<sal_Int16>::get() && rEntry.aType != rAny.getValueType())
+        if (rAny >>= nValue)
         {
-            // since the sfx uInt16 item now exports a sal_Int32, we may have to fix this here
-            sal_Int32 nValue(0);
-
-            if (rAny >>= nValue)
-            {
-                rAny <<= static_cast<sal_Int16>(nValue);
-            }
+            rAny <<= static_cast<sal_Int16>(nValue);
         }
+    }
 
-        // check for needed metric translation
-        if(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM)
-        {
-            bool bDoIt(true);
+    // check for needed metric translation
+    if(!(rEntry.nMoreFlags & PropertyMoreFlags::METRIC_ITEM))
+        return;
 
-            if(XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID)
-            {
-                // exception: If these ItemTypes are used, do not convert when these are negative
-                // since this means they are intended as percent values
-                sal_Int32 nValue = 0;
+    bool bDoIt(true);
 
-                if(rAny >>= nValue)
-                {
-                    bDoIt = nValue > 0;
-                }
-            }
+    if(XATTR_FILLBMP_SIZEX == rEntry.nWID || XATTR_FILLBMP_SIZEY == rEntry.nWID)
+    {
+        // exception: If these ItemTypes are used, do not convert when these are negative
+        // since this means they are intended as percent values
+        sal_Int32 nValue = 0;
 
-            if(bDoIt)
-            {
-                const MapUnit eMapUnit(rSet.GetPool()->GetMetric(rEntry.nWID));
+        if(rAny >>= nValue)
+        {
+            bDoIt = nValue > 0;
+        }
+    }
 
-                if(eMapUnit != MapUnit::Map100thMM)
-                {
-                    SvxUnoConvertToMM(eMapUnit, rAny);
-                }
-            }
+    if(bDoIt)
+    {
+        const MapUnit eMapUnit(rSet.GetPool()->GetMetric(rEntry.nWID));
+
+        if(eMapUnit != MapUnit::Map100thMM)
+        {
+            SvxUnoConvertToMM(eMapUnit, rAny);
         }
     }
 }
diff --git a/sw/source/core/unocore/unoportenum.cxx b/sw/source/core/unocore/unoportenum.cxx
index 8b968bb82d40..17688f1a3351 100644
--- a/sw/source/core/unocore/unoportenum.cxx
+++ b/sw/source/core/unocore/unoportenum.cxx
@@ -144,28 +144,28 @@ namespace
         }
 
         const SwPosition& rEndPos = pBkmk->GetMarkEnd();
-        if(rEndPos.nNode == nOwnNode)
+        if(rEndPos.nNode != nOwnNode)
+            return;
+
+        unique_ptr<SwPosition> pCrossRefEndPos;
+        const SwPosition* pEndPos = nullptr;
+        ::sw::mark::CrossRefBookmark *const pCrossRefMark(dynamic_cast< ::sw::mark::CrossRefBookmark*>(pBkmk));
+        if(hasOther)
         {
-            unique_ptr<SwPosition> pCrossRefEndPos;
-            const SwPosition* pEndPos = nullptr;
-            ::sw::mark::CrossRefBookmark *const pCrossRefMark(dynamic_cast< ::sw::mark::CrossRefBookmark*>(pBkmk));
-            if(hasOther)
-            {
-                pEndPos = &rEndPos;
-            }
-            else if (pCrossRefMark)
-            {
-                // Crossrefbookmarks only remember the start position but have to span the whole paragraph
-                pCrossRefEndPos = std::make_unique<SwPosition>(rEndPos);
-                pCrossRefEndPos->nContent = pCrossRefEndPos->nNode.GetNode().GetTextNode()->Len();
-                pEndPos = pCrossRefEndPos.get();
-            }
-            if(pEndPos)
-            {
-                rBkmArr.insert(std::make_shared<SwXBookmarkPortion_Impl>(
-                            SwXBookmark::CreateXBookmark(rDoc, pBkmk),
-                            BkmType::End, *pEndPos));
-            }
+            pEndPos = &rEndPos;
+        }
+        else if (pCrossRefMark)
+        {
+            // Crossrefbookmarks only remember the start position but have to span the whole paragraph
+            pCrossRefEndPos = std::make_unique<SwPosition>(rEndPos);
+            pCrossRefEndPos->nContent = pCrossRefEndPos->nNode.GetNode().GetTextNode()->Len();
+            pEndPos = pCrossRefEndPos.get();
+        }
+        if(pEndPos)
+        {
+            rBkmArr.insert(std::make_shared<SwXBookmarkPortion_Impl>(
+                        SwXBookmark::CreateXBookmark(rDoc, pBkmk),
+                        BkmType::End, *pEndPos));
         }
     }
 
@@ -1080,24 +1080,24 @@ static void lcl_FillRedlineArray(
     const SwRedlineTable& rRedTable = rDoc.getIDocumentRedlineAccess().GetRedlineTable();
     const size_t nRedTableCount = rRedTable.size();
 
-    if ( nRedTableCount > 0 )
-    {
-        const SwPosition* pStart = rUnoCursor.GetPoint();
-        const SwNodeIndex nOwnNode = pStart->nNode;
+    if ( nRedTableCount <= 0 )
+        return;
 
-        for(size_t nRed = 0; nRed < nRedTableCount; ++nRed)
-        {
-            const SwRangeRedline* pRedline = rRedTable[nRed];
-            const SwPosition* pRedStart = pRedline->Start();
-            const SwNodeIndex nRedNode = pRedStart->nNode;
-            if ( nOwnNode == nRedNode )
-                rRedArr.insert( std::make_shared<SwXRedlinePortion_Impl>(
-                    pRedline, true ) );
-            if( pRedline->HasMark() && pRedline->End()->nNode == nOwnNode )
-                rRedArr.insert( std::make_shared<SwXRedlinePortion_Impl>(
-                    pRedline, false ) );
-       }
-    }
+    const SwPosition* pStart = rUnoCursor.GetPoint();
+    const SwNodeIndex nOwnNode = pStart->nNode;
+
+    for(size_t nRed = 0; nRed < nRedTableCount; ++nRed)
+    {
+        const SwRangeRedline* pRedline = rRedTable[nRed];
+        const SwPosition* pRedStart = pRedline->Start();
+        const SwNodeIndex nRedNode = pRedStart->nNode;
+        if ( nOwnNode == nRedNode )
+            rRedArr.insert( std::make_shared<SwXRedlinePortion_Impl>(
+                pRedline, true ) );
+        if( pRedline->HasMark() && pRedline->End()->nNode == nOwnNode )
+            rRedArr.insert( std::make_shared<SwXRedlinePortion_Impl>(
+                pRedline, false ) );
+   }
 }
 
 static void lcl_FillSoftPageBreakArray(
diff --git a/sw/source/core/unocore/unorefmk.cxx b/sw/source/core/unocore/unorefmk.cxx
index a69fd2cab70c..581e8c7656c1 100644
--- a/sw/source/core/unocore/unorefmk.cxx
+++ b/sw/source/core/unocore/unorefmk.cxx
@@ -656,19 +656,19 @@ inline const ::sw::Meta* SwXMeta::Impl::GetMeta() const
 void SwXMeta::Impl::Notify(const SfxHint& rHint)
 {
     m_pTextPortions.reset(); // throw away cache (SwTextNode changed)
-    if(rHint.GetId() == SfxHintId::Dying || rHint.GetId() == SfxHintId::Deinitializing)
-    {
-        m_bIsDisposed = true;
-        m_pMeta = nullptr;
-        m_xText->Invalidate();
-        uno::Reference<uno::XInterface> const xThis(m_wThis);
-        if (!xThis.is())
-        {   // fdo#72695: if UNO object is already dead, don't revive it with event
-            return;
-        }
-        lang::EventObject const ev(xThis);
-        m_EventListeners.disposeAndClear(ev);
+    if(rHint.GetId() != SfxHintId::Dying && rHint.GetId() != SfxHintId::Deinitializing)
+        return;
+
+    m_bIsDisposed = true;
+    m_pMeta = nullptr;
+    m_xText->Invalidate();
+    uno::Reference<uno::XInterface> const xThis(m_wThis);
+    if (!xThis.is())
+    {   // fdo#72695: if UNO object is already dead, don't revive it with event
+        return;
     }
+    lang::EventObject const ev(xThis);
+    m_EventListeners.disposeAndClear(ev);
 }
 
 uno::Reference<text::XText> const & SwXMeta::GetParentText() const
diff --git a/sw/source/core/unocore/unosect.cxx b/sw/source/core/unocore/unosect.cxx
index 831f0bda3e7c..3c0eb298b079 100644
--- a/sw/source/core/unocore/unosect.cxx
+++ b/sw/source/core/unocore/unosect.cxx
@@ -523,32 +523,32 @@ lcl_UpdateSection(SwSectionFormat *const pFormat,
     std::unique_ptr<SfxItemSet> const& pItemSet,
     bool const bLinkModeChanged, bool const bLinkUpdateAlways = true)
 {
-    if (pFormat)
+    if (!pFormat)
+        return;
+
+    SwSection & rSection = *pFormat->GetSection();
+    SwDoc *const pDoc = pFormat->GetDoc();
+    SwSectionFormats const& rFormats = pDoc->GetSections();
+    UnoActionContext aContext(pDoc);
+    for (size_t i = 0; i < rFormats.size(); ++i)
     {
-        SwSection & rSection = *pFormat->GetSection();
-        SwDoc *const pDoc = pFormat->GetDoc();
-        SwSectionFormats const& rFormats = pDoc->GetSections();
-        UnoActionContext aContext(pDoc);
-        for (size_t i = 0; i < rFormats.size(); ++i)
+        if (rFormats[i]->GetSection()->GetSectionName()
+                == rSection.GetSectionName())
         {
-            if (rFormats[i]->GetSection()->GetSectionName()
-                    == rSection.GetSectionName())
+            pDoc->UpdateSection(i, *pSectionData, pItemSet.get(),
+                    pDoc->IsInReading());
             {
-                pDoc->UpdateSection(i, *pSectionData, pItemSet.get(),
-                        pDoc->IsInReading());
-                {
-                    // temporarily remove actions to allow cursor update
-                    // TODO: why? no table cursor here!
-                    UnoActionRemoveContext aRemoveContext( pDoc );
-                }
+                // temporarily remove actions to allow cursor update
+                // TODO: why? no table cursor here!
+                UnoActionRemoveContext aRemoveContext( pDoc );
+            }
 
-                if (bLinkModeChanged)
-                {
-                    lcl_UpdateLinkType(rSection, bLinkUpdateAlways);
-                }
-                // section found and processed: break from loop
-                break;
+            if (bLinkModeChanged)
+            {
+                lcl_UpdateLinkType(rSection, bLinkUpdateAlways);
             }
+            // section found and processed: break from loop
+            break;
         }
     }
 }
diff --git a/sw/source/core/unocore/unosett.cxx b/sw/source/core/unocore/unosett.cxx
index b392c42f1b88..0fbf86e1e17d 100644
--- a/sw/source/core/unocore/unosett.cxx
+++ b/sw/source/core/unocore/unosett.cxx
@@ -583,76 +583,75 @@ uno::Reference< beans::XPropertySetInfo >  SwXEndnoteProperties::getPropertySetI
 void SwXEndnoteProperties::setPropertyValue(const OUString& rPropertyName, const uno::Any& aValue)
 {
     SolarMutexGuard aGuard;
-    if(m_pDoc)
-    {
-        const SfxItemPropertySimpleEntry*  pEntry = m_pPropertySet->getPropertyMap().getByName( rPropertyName );
-        if(!pEntry)
-            throw UnknownPropertyException("Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+    if(!m_pDoc)
+        return;
 
-        if ( pEntry->nFlags & PropertyAttribute::READONLY)
-            throw PropertyVetoException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
-        SwEndNoteInfo aEndInfo(m_pDoc->GetEndNoteInfo());
-        switch(pEntry->nWID)
+    const SfxItemPropertySimpleEntry*  pEntry = m_pPropertySet->getPropertyMap().getByName( rPropertyName );
+    if(!pEntry)
+        throw UnknownPropertyException("Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+
+    if ( pEntry->nFlags & PropertyAttribute::READONLY)
+        throw PropertyVetoException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
+    SwEndNoteInfo aEndInfo(m_pDoc->GetEndNoteInfo());
+    switch(pEntry->nWID)
+    {
+        case WID_PREFIX:
         {
-            case WID_PREFIX:
-            {
-                OUString uTmp;
-                aValue >>= uTmp;
-                aEndInfo.SetPrefix(uTmp);
-            }
-            break;
-            case WID_SUFFIX:
-            {
-                OUString uTmp;
-                aValue >>= uTmp;
-                aEndInfo.SetSuffix(uTmp);
-            }
-            break;
-            case  WID_NUMBERING_TYPE :
-            {
-                sal_Int16 nTmp = 0;
-                aValue >>= nTmp;
-                aEndInfo.m_aFormat.SetNumberingType(static_cast<SvxNumType>(nTmp));
-            }
-            break;
-            case  WID_START_AT:
-            {
-                sal_Int16 nTmp = 0;
-                aValue >>= nTmp;
-                aEndInfo.m_nFootnoteOffset = nTmp;
-            }
-            break;
-            case  WID_PARAGRAPH_STYLE    :
-            {
-                SwTextFormatColl* pColl = lcl_GetParaStyle(m_pDoc, aValue);
-                if(pColl)
-                    aEndInfo.SetFootnoteTextColl(*pColl);
-            }
-            break;
-            case  WID_PAGE_STYLE :
-            {
-                SwPageDesc* pDesc = lcl_GetPageDesc(m_pDoc, aValue);
-                if(pDesc)
-                    aEndInfo.ChgPageDesc( pDesc );
-            }
-            break;
-            case WID_ANCHOR_CHARACTER_STYLE:
-            case  WID_CHARACTER_STYLE    :
+            OUString uTmp;
+            aValue >>= uTmp;
+            aEndInfo.SetPrefix(uTmp);
+        }
+        break;
+        case WID_SUFFIX:
+        {
+            OUString uTmp;
+            aValue >>= uTmp;
+            aEndInfo.SetSuffix(uTmp);
+        }
+        break;
+        case  WID_NUMBERING_TYPE :
+        {
+            sal_Int16 nTmp = 0;
+            aValue >>= nTmp;
+            aEndInfo.m_aFormat.SetNumberingType(static_cast<SvxNumType>(nTmp));
+        }
+        break;
+        case  WID_START_AT:
+        {
+            sal_Int16 nTmp = 0;
+            aValue >>= nTmp;
+            aEndInfo.m_nFootnoteOffset = nTmp;
+        }
+        break;
+        case  WID_PARAGRAPH_STYLE    :
+        {
+            SwTextFormatColl* pColl = lcl_GetParaStyle(m_pDoc, aValue);
+            if(pColl)
+                aEndInfo.SetFootnoteTextColl(*pColl);
+        }
+        break;
+        case  WID_PAGE_STYLE :
+        {
+            SwPageDesc* pDesc = lcl_GetPageDesc(m_pDoc, aValue);
+            if(pDesc)
+                aEndInfo.ChgPageDesc( pDesc );
+        }
+        break;
+        case WID_ANCHOR_CHARACTER_STYLE:
+        case  WID_CHARACTER_STYLE    :
+        {
+            SwCharFormat* pFormat = lcl_getCharFormat(m_pDoc, aValue);
+            if(pFormat)
             {

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list