[Libreoffice-commits] core.git: Branch 'aoo/trunk' - editeng/source sc/source sd/source svl/inc svl/source

Armin Le Grand alg at apache.org
Sun Jun 23 05:07:13 PDT 2013


 editeng/source/editeng/impedit2.cxx                     |   44 +++++++++---
 sc/source/ui/inc/undobase.hxx                           |    4 -
 sc/source/ui/inc/undodraw.hxx                           |    4 -
 sc/source/ui/undo/undobase.cxx                          |   12 ---
 sc/source/ui/undo/undodraw.cxx                          |   12 ---
 sd/source/ui/slidesorter/controller/SlsPageSelector.cxx |    6 +
 svl/inc/svl/undo.hxx                                    |   13 ++-
 svl/source/undo/undo.cxx                                |   57 +++++++---------
 8 files changed, 88 insertions(+), 64 deletions(-)

New commits:
commit e58fe7afee5163833479b76a474416a77d95f075
Author: Armin Le Grand <alg at apache.org>
Date:   Sun Jun 23 11:25:32 2013 +0000

    i120020 corected paragraph merge, corresponding undo and ownership of linked undo actions

diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx
index a4204d3..31b52ab 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -2298,6 +2298,16 @@ EditPaM ImpEditEngine::ImpConnectParagraphs( ContentNode* pLeft, ContentNode* pR
     DBG_ASSERT( aEditDoc.GetPos( pLeft ) != USHRT_MAX, "Einzufuegenden Node nicht gefunden(1)" );
     DBG_ASSERT( aEditDoc.GetPos( pRight ) != USHRT_MAX, "Einzufuegenden Node nicht gefunden(2)" );
 
+    // #120020# it is possible that left and right are *not* in the desired order (left/right)
+    // so correct it. This correction is needed, else an invalid SfxLinkUndoAction will be
+    // created from ConnectParagraphs below. Assert this situation, it should be corrected by the
+    // caller.
+    if(aEditDoc.GetPos( pLeft ) > aEditDoc.GetPos( pRight ))
+    {
+        OSL_ENSURE(false, "ImpConnectParagraphs wit wrong order of pLeft/pRight nodes (!)");
+        std::swap(pLeft, pRight);
+    }
+
     sal_uInt16 nParagraphTobeDeleted = aEditDoc.GetPos( pRight );
     DeletedNodeInfo* pInf = new DeletedNodeInfo( (sal_uLong)pRight, nParagraphTobeDeleted );
     aDeletedNodes.Insert( pInf, aDeletedNodes.Count() );
@@ -2424,18 +2434,34 @@ EditPaM ImpEditEngine::DeleteLeftOrRight( const EditSelection& rSel, sal_uInt8 n
         else if ( nDelMode == DELMODE_RESTOFWORD )
         {
             aDelEnd = EndOfWord( aCurPos );
+
             if (aDelEnd.GetIndex() == aCurPos.GetIndex())
             {
-                xub_StrLen nLen = aCurPos.GetNode()->Len();
-                // end of para?
-                if (aDelEnd.GetIndex() == nLen)
-                    aDelEnd = WordLeft( aCurPos );
-                else // there's still sth to delete on the right
+                const xub_StrLen nLen(aCurPos.GetNode()->Len());
+
+                // #120020# when 0 == nLen, aDelStart needs to be adapted, not
+                // aDelEnd. This would (and did) lead to a wrong order in the
+                // ImpConnectParagraphs call later.
+                if(nLen)
+                {
+                    // end of para?
+                    if (aDelEnd.GetIndex() == nLen)
+                    {
+                        aDelEnd = WordLeft( aCurPos );
+                    }
+                    else // there's still sth to delete on the right
+                    {
+                        aDelEnd = EndOfWord( WordRight( aCurPos ) );
+                        // if there'n no next word...
+                        if (aDelEnd.GetIndex() == nLen )
+                        {
+                            aDelEnd.SetIndex( nLen );
+                        }
+                    }
+                }
+                else
                 {
-                    aDelEnd = EndOfWord( WordRight( aCurPos ) );
-                    // if there'n no next word...
-                    if (aDelEnd.GetIndex() == nLen )
-                        aDelEnd.SetIndex( nLen );
+                    aDelStart = WordLeft(aCurPos);
                 }
             }
         }
diff --git a/sc/source/ui/inc/undobase.hxx b/sc/source/ui/inc/undobase.hxx
index a9238cf..64d82ba 100644
--- a/sc/source/ui/inc/undobase.hxx
+++ b/sc/source/ui/inc/undobase.hxx
@@ -155,8 +155,8 @@ public:
     SfxUndoAction*          GetWrappedUndo()        { return pWrappedUndo; }
     void                    ForgetWrappedUndo();
 
-    virtual sal_Bool            IsLinked();
-    virtual void            SetLinked( sal_Bool bIsLinked );
+    virtual void SetLinkToSfxLinkUndoAction(SfxLinkUndoAction* pSfxLinkUndoAction);
+
     virtual void            Undo();
     virtual void            Redo();
     virtual void            Repeat(SfxRepeatTarget& rTarget);
diff --git a/sc/source/ui/inc/undodraw.hxx b/sc/source/ui/inc/undodraw.hxx
index d84b6f1..1888576 100644
--- a/sc/source/ui/inc/undodraw.hxx
+++ b/sc/source/ui/inc/undodraw.hxx
@@ -43,8 +43,8 @@ public:
     SfxUndoAction*          GetDrawUndo()       { return pDrawUndo; }
     void                    ForgetDrawUndo();
 
-    virtual sal_Bool            IsLinked();
-    virtual void            SetLinked( sal_Bool bIsLinked );
+    virtual void SetLinkToSfxLinkUndoAction(SfxLinkUndoAction* pSfxLinkUndoAction);
+
     virtual void            Undo();
     virtual void            Redo();
     virtual void            Repeat(SfxRepeatTarget& rTarget);
diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx
index 7483828..fb708a1 100644
--- a/sc/source/ui/undo/undobase.cxx
+++ b/sc/source/ui/undo/undobase.cxx
@@ -519,18 +519,12 @@ sal_uInt16 ScUndoWrapper::GetId() const
         return 0;
 }
 
-sal_Bool ScUndoWrapper::IsLinked()
+void ScUndoWrapper::SetLinkToSfxLinkUndoAction(SfxLinkUndoAction* pSfxLinkUndoAction)
 {
     if (pWrappedUndo)
-        return pWrappedUndo->IsLinked();
+        pWrappedUndo->SetLinkToSfxLinkUndoAction(pSfxLinkUndoAction);
     else
-        return sal_False;
-}
-
-void ScUndoWrapper::SetLinked( sal_Bool bIsLinked )
-{
-    if (pWrappedUndo)
-        pWrappedUndo->SetLinked(bIsLinked);
+        SetLinkToSfxLinkUndoAction(pSfxLinkUndoAction);
 }
 
 sal_Bool ScUndoWrapper::Merge( SfxUndoAction* pNextAction )
diff --git a/sc/source/ui/undo/undodraw.cxx b/sc/source/ui/undo/undodraw.cxx
index db02d58..3e33ae8 100644
--- a/sc/source/ui/undo/undodraw.cxx
+++ b/sc/source/ui/undo/undodraw.cxx
@@ -79,18 +79,12 @@ sal_uInt16 __EXPORT ScUndoDraw::GetId() const
         return 0;
 }
 
-sal_Bool __EXPORT ScUndoDraw::IsLinked()
+void __EXPORT ScUndoDraw::SetLinkToSfxLinkUndoAction(SfxLinkUndoAction* pSfxLinkUndoAction)
 {
     if (pDrawUndo)
-        return pDrawUndo->IsLinked();
+        pDrawUndo->SetLinkToSfxLinkUndoAction(pSfxLinkUndoAction);
     else
-        return sal_False;
-}
-
-void __EXPORT ScUndoDraw::SetLinked( sal_Bool bIsLinked )
-{
-    if (pDrawUndo)
-        pDrawUndo->SetLinked(bIsLinked);
+        SetLinkToSfxLinkUndoAction(pSfxLinkUndoAction);
 }
 
 sal_Bool  __EXPORT ScUndoDraw::Merge( SfxUndoAction* pNextAction )
diff --git a/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx b/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx
index 363e67c..a0578eb 100644
--- a/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsPageSelector.cxx
@@ -262,7 +262,11 @@ void PageSelector::CheckConsistency (void) const
     }
     if (nSelectionCount!=mnSelectedPageCount)
     {
-        assert(nSelectionCount==mnSelectedPageCount);
+        // #120020# The former call to assert(..) internally calls
+        // SlideSorterModel::GetPageDescriptor which will crash in this situation
+        // (only in non-pro code). All what is wanted there is to assert it (the
+        // error is already detected), so do this directly.
+        OSL_ENSURE(false, "PageSelector: Consistency error (!)");
     }
 }
 
diff --git a/svl/inc/svl/undo.hxx b/svl/inc/svl/undo.hxx
index 68e0b72..d738f2b 100644
--- a/svl/inc/svl/undo.hxx
+++ b/svl/inc/svl/undo.hxx
@@ -51,17 +51,20 @@ public:
 };
 
 //====================================================================
+class SfxLinkUndoAction;
 
 class SVL_DLLPUBLIC SfxUndoAction
 {
-    sal_Bool bLinked;
+private:
+    SfxLinkUndoAction*      mpSfxLinkUndoAction;
+
 public:
                             TYPEINFO();
                             SfxUndoAction();
     virtual                 ~SfxUndoAction();
 
-    virtual sal_Bool            IsLinked();
-    virtual void            SetLinked( sal_Bool bIsLinked = sal_True );
+    virtual void SetLinkToSfxLinkUndoAction(SfxLinkUndoAction* pSfxLinkUndoAction);
+
     virtual void            Undo();
     virtual void            UndoWithContext( SfxUndoContext& i_context );
     virtual void            Redo();
@@ -448,6 +451,10 @@ class SVL_DLLPUBLIC SfxLinkUndoAction : public SfxUndoAction
 */
 
 {
+private:
+    friend class SfxUndoAction;
+    void LinkedSfxUndoActionDestructed(const SfxUndoAction& rCandidate);
+
 public:
                             TYPEINFO();
                             SfxLinkUndoAction(::svl::IUndoManager *pManager);
diff --git a/svl/source/undo/undo.cxx b/svl/source/undo/undo.cxx
index 8896926..09a60ae 100644
--- a/svl/source/undo/undo.cxx
+++ b/svl/source/undo/undo.cxx
@@ -63,16 +63,9 @@ SfxUndoContext::~SfxUndoContext()
 
 //------------------------------------------------------------------------
 
-sal_Bool SfxUndoAction::IsLinked()
+void SfxUndoAction::SetLinkToSfxLinkUndoAction(SfxLinkUndoAction* pSfxLinkUndoAction)
 {
-    return bLinked;
-}
-
-//------------------------------------------------------------------------
-
-void SfxUndoAction::SetLinked( sal_Bool bIsLinked )
-{
-    bLinked = bIsLinked;
+    mpSfxLinkUndoAction = pSfxLinkUndoAction;
 }
 
 //------------------------------------------------------------------------
@@ -80,14 +73,19 @@ void SfxUndoAction::SetLinked( sal_Bool bIsLinked )
 SfxUndoAction::~SfxUndoAction()
 {
     DBG_DTOR(SfxUndoAction, 0);
-    DBG_ASSERT( !IsLinked(), "Gelinkte Action geloescht" );
+
+    if(mpSfxLinkUndoAction)
+    {
+        mpSfxLinkUndoAction->LinkedSfxUndoActionDestructed(*this);
+        mpSfxLinkUndoAction = 0;
+    }
 }
 
 
 SfxUndoAction::SfxUndoAction()
+:   mpSfxLinkUndoAction(0)
 {
     DBG_CTOR(SfxUndoAction, 0);
-    SetLinked( sal_False );
 }
 
 //------------------------------------------------------------------------
@@ -455,24 +453,18 @@ void SfxUndoManager::SetMaxUndoActionCount( size_t nMaxUndoActionCount )
         if ( nPos > m_pData->pActUndoArray->nCurUndoAction )
         {
             SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[nPos-1].pAction;
-            if ( !pAction->IsLinked() )
-            {
-                aGuard.markForDeletion( pAction );
-                m_pData->pActUndoArray->aUndoActions.Remove( nPos-1 );
-                --nNumToDelete;
-            }
+            aGuard.markForDeletion( pAction );
+            m_pData->pActUndoArray->aUndoActions.Remove( nPos-1 );
+            --nNumToDelete;
         }
 
         if ( nNumToDelete > 0 && m_pData->pActUndoArray->nCurUndoAction > 0 )
         {
             SfxUndoAction* pAction = m_pData->pActUndoArray->aUndoActions[0].pAction;
-            if ( !pAction->IsLinked() )
-            {
-                aGuard.markForDeletion( pAction );
-                m_pData->pActUndoArray->aUndoActions.Remove(0);
-                --m_pData->pActUndoArray->nCurUndoAction;
-                --nNumToDelete;
-            }
+            aGuard.markForDeletion( pAction );
+            m_pData->pActUndoArray->aUndoActions.Remove(0);
+            --m_pData->pActUndoArray->nCurUndoAction;
+            --nNumToDelete;
         }
 
         if ( nPos == m_pData->pActUndoArray->aUndoActions.size() )
@@ -640,9 +632,7 @@ bool SfxUndoManager::ImplAddUndoAction_NoNotify( SfxUndoAction *pAction, bool bT
     // respect max number
     if( m_pData->pActUndoArray == m_pData->pUndoArray )
     {
-        while( m_pData->pActUndoArray->aUndoActions.size() >=
-               m_pData->pActUndoArray->nMaxUndoActions &&
-               !m_pData->pActUndoArray->aUndoActions[0].pAction->IsLinked() )
+        while(m_pData->pActUndoArray->aUndoActions.size() >= m_pData->pActUndoArray->nMaxUndoActions)
         {
             i_guard.markForDeletion( m_pData->pActUndoArray->aUndoActions[0].pAction );
             m_pData->pActUndoArray->aUndoActions.Remove(0);
@@ -1400,7 +1390,7 @@ SfxLinkUndoAction::SfxLinkUndoAction(::svl::IUndoManager *pManager)
     {
         size_t nPos = pManager->GetUndoActionCount()-1;
         pAction = pUndoManagerImplementation->m_pData->pActUndoArray->aUndoActions[nPos].pAction;
-        pAction->SetLinked();
+        pAction->SetLinkToSfxLinkUndoAction(this);
     }
     else
         pAction = 0;
@@ -1467,9 +1457,18 @@ XubString SfxLinkUndoAction::GetRepeatComment(SfxRepeatTarget&r) const
 SfxLinkUndoAction::~SfxLinkUndoAction()
 {
     if( pAction )
-        pAction->SetLinked( sal_False );
+        pAction->SetLinkToSfxLinkUndoAction(0);
 }
 
+//------------------------------------------------------------------------
+
+void SfxLinkUndoAction::LinkedSfxUndoActionDestructed(const SfxUndoAction& rCandidate)
+{
+    OSL_ENSURE(0 != pAction, "OOps, we have no linked SfxUndoAction (!)");
+    OSL_ENSURE(pAction == &rCandidate, "OOps, the destroyed and linked UndoActions differ (!)");
+    (void)rCandidate;
+    pAction = 0;
+}
 
 //------------------------------------------------------------------------
 


More information about the Libreoffice-commits mailing list