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

László Németh (via logerrit) logerrit at kemper.freedesktop.org
Thu Mar 18 15:33:33 UTC 2021


 sw/inc/IDocumentMarkAccess.hxx         |    7 ++++++-
 sw/source/core/doc/docbm.cxx           |   24 ++++++++++++++++++++++--
 sw/source/core/doc/docredln.cxx        |    8 ++++----
 sw/source/core/fields/postithelper.cxx |   17 ++++++++++++++++-
 sw/source/core/inc/MarkManager.hxx     |    6 ++++++
 5 files changed, 54 insertions(+), 8 deletions(-)

New commits:
commit 31442054520cf0a263cc17e157cfa102cff8ef6a
Author:     László Németh <nemeth at numbertext.org>
AuthorDate: Thu Mar 18 13:41:46 2021 +0100
Commit:     László Németh <nemeth at numbertext.org>
CommitDate: Thu Mar 18 16:32:46 2021 +0100

    tdf#140980 sw: fix bad strikethrough of annotations
    
    Not deleted annotation windows got a bad strikethrough
    in ChangesInMargin mode, if they annotate tracked
    deletions.
    
    Also clean-up commit a001a66ba27e2fe9a485388869d53f001f2b09af
    (tdf#140982 sw ChangesInMargin: fix annotation ranges).
    
    Change-Id: I06cb88113bf038c09702b6ef33e46c94c963730d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112672
    Tested-by: Jenkins
    Reviewed-by: László Németh <nemeth at numbertext.org>

diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index 49ce72ad28b4..e678f52605ff 100644
--- a/sw/inc/IDocumentMarkAccess.hxx
+++ b/sw/inc/IDocumentMarkAccess.hxx
@@ -341,8 +341,13 @@ class IDocumentMarkAccess
         virtual sal_Int32 getAnnotationMarksCount() const = 0;
         virtual const_iterator_t findAnnotationMark( const OUString& rName ) const = 0;
         virtual sw::mark::IMark* getAnnotationMarkFor(const SwPosition& rPosition) const = 0;
-        // restore text ranges of annotations of tracked deletions
+        // handle and restore text ranges of annotations of tracked deletions
         // based on the helper bookmarks (which can survive I/O and hiding redlines)
+        virtual ::sw::mark::IMark* makeAnnotationBookmark(const SwPaM& rPaM,
+            const OUString& rProposedName,
+            MarkType eMark, ::sw::mark::InsertMode eMode,
+            SwPosition const* pSepPos = nullptr) = 0;
+        virtual const_iterator_t findAnnotationBookmark( const OUString& rName ) const = 0;
         virtual void restoreAnnotationMarks(bool bDelete = true) = 0;
         /** Finds the first mark that is starting after.
 
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 82579d079445..438c294c5ecd 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -49,6 +49,8 @@
 #include <libxml/xmlwriter.h>
 #include <comphelper/lok.hxx>
 
+#define S_ANNOTATION_BOOKMARK u"____"
+
 using namespace ::sw::mark;
 
 std::vector<::sw::mark::MarkBase*>::const_iterator const&
@@ -1641,7 +1643,25 @@ namespace sw::mark
             CompareIMarkStartsAfter());
     }
 
-    // restore text ranges of annotations of tracked deletions
+    // create helper bookmark for annotations on tracked deletions
+    ::sw::mark::IMark* MarkManager::makeAnnotationBookmark(const SwPaM& rPaM,
+        const OUString& rName,
+        const IDocumentMarkAccess::MarkType eType,
+        sw::mark::InsertMode const eMode,
+        SwPosition const*const pSepPos)
+    {
+        OUString sAnnotationBookmarkName(rName + S_ANNOTATION_BOOKMARK);
+        return makeMark( rPaM, sAnnotationBookmarkName, eType, eMode, pSepPos);
+    }
+
+    // find helper bookmark of annotations on tracked deletions
+    IDocumentMarkAccess::const_iterator_t MarkManager::findAnnotationBookmark(const OUString& rName) const
+    {
+        OUString sAnnotationBookmarkName(rName + S_ANNOTATION_BOOKMARK);
+        return findBookmark(sAnnotationBookmarkName);
+    }
+
+    // restore text ranges of annotations on tracked deletions
     // based on the helper bookmarks (which can survive I/O and hiding redlines)
     void MarkManager::restoreAnnotationMarks(bool bDelete)
     {
@@ -1651,7 +1671,7 @@ namespace sw::mark
             const OUString & rBookmarkName = (**iter).GetName();
             sal_Int32 nPos;
             if ( rBookmarkName.startsWith("__Annotation__") &&
-                  (nPos = rBookmarkName.indexOf("____")) > -1 )
+                  (nPos = rBookmarkName.indexOf(S_ANNOTATION_BOOKMARK)) > -1 )
             {
                 ::sw::UndoGuard const undoGuard(m_rDoc.GetIDocumentUndoRedo());
                 IDocumentMarkAccess::const_iterator_t pMark = findAnnotationMark(rBookmarkName.copy(0, nPos));
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index d4d5cce88483..1eed6d70ce2e 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -1346,8 +1346,8 @@ static void lcl_storeAnnotationMarks(SwDoc& rDoc, const SwPosition* pStt, const
         SwPosition const& rStartPos((**iter).GetMarkStart());
         if ( *pStt <= rStartPos && rStartPos < *pEnd )
         {
-            OUString sBookmarkName((**iter).GetName() + "____");
-            IDocumentMarkAccess::const_iterator_t pOldMark = rDMA.findBookmark(sBookmarkName);
+            IDocumentMarkAccess::const_iterator_t pOldMark =
+                    rDMA.findAnnotationBookmark((**iter).GetName());
             if ( pOldMark == rDMA.getBookmarksEnd() )
             {
                 // at start of redlines use a 1-character length bookmark range
@@ -1355,9 +1355,9 @@ static void lcl_storeAnnotationMarks(SwDoc& rDoc, const SwPosition* pStt, const
                 sal_Int32 nLen = (*pStt == rStartPos) ? 1 : 0;
                 SwPaM aPam( rStartPos.nNode, rStartPos.nContent.GetIndex(),
                                 rStartPos.nNode, rStartPos.nContent.GetIndex() + nLen);
-                ::sw::mark::IMark* pMark = rDMA.makeMark(
+                ::sw::mark::IMark* pMark = rDMA.makeAnnotationBookmark(
                     aPam,
-                    sBookmarkName,
+                    (**iter).GetName(),
                     IDocumentMarkAccess::MarkType::BOOKMARK, sw::mark::InsertMode::New);
                 ::sw::mark::IBookmark* pBookmark = dynamic_cast< ::sw::mark::IBookmark* >(pMark);
                 if (pBookmark)
diff --git a/sw/source/core/fields/postithelper.cxx b/sw/source/core/fields/postithelper.cxx
index c61637601ad2..18dd7cc10c71 100644
--- a/sw/source/core/fields/postithelper.cxx
+++ b/sw/source/core/fields/postithelper.cxx
@@ -29,6 +29,7 @@
 #include <txtfrm.hxx>
 #include <IDocumentRedlineAccess.hxx>
 #include <IDocumentFieldsAccess.hxx>
+#include <IDocumentMarkAccess.hxx>
 #include <redline.hxx>
 #include <scriptinfo.hxx>
 #include <calbck.hxx>
@@ -193,7 +194,21 @@ SwPostItHelper::SwLayoutStatus SwPostItHelper::getLayoutInfos(
                         if( RedlineType::Insert == pRedline->GetType() )
                             aRet = INSERTED;
                         else if( RedlineType::Delete == pRedline->GetType() )
-                            aRet = DELETED;
+                        {
+                            bool bDeleted = pAnnotationMark == nullptr;
+                            if( !bDeleted )
+                            {
+                                IDocumentMarkAccess& rDMA(*pTextNode->GetDoc().getIDocumentMarkAccess());
+                                IDocumentMarkAccess::const_iterator_t pAnnotationBookmark =
+                                    rDMA.findAnnotationBookmark(pAnnotationMark->GetName());
+                                // tdf#140980 only really deleted, if there is no helper bookmark
+                                // in ChangesInMargin mode
+                                if ( pAnnotationBookmark == rDMA.getBookmarksEnd() )
+                                    bDeleted = true;
+                            }
+                            if ( bDeleted )
+                                aRet = DELETED;
+                        }
                         o_rInfo.mRedlineAuthor = pRedline->GetAuthor();
                     }
                 }
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index 4e1547f00731..97e936771ad1 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -117,6 +117,12 @@ namespace sw::mark {
 
             typedef std::vector<sw::mark::MarkBase*> container_t;
 
+            // helper bookmark to store annotation range of redlines
+            virtual ::sw::mark::IMark* makeAnnotationBookmark(const SwPaM& rPaM,
+                const OUString& rName, IDocumentMarkAccess::MarkType eMark,
+                sw::mark::InsertMode eMode,
+                SwPosition const* pSepPos = nullptr) override;
+            virtual const_iterator_t findAnnotationBookmark( const OUString& rName ) const override;
             virtual void restoreAnnotationMarks(bool bDelete = true) override;
 
         private:


More information about the Libreoffice-commits mailing list