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@numbertext.org>
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index 49ce72a..e678f52 100644
--- a/sw/inc/IDocumentMarkAccess.hxx
+++ b/sw/inc/IDocumentMarkAccess.hxx
@@ -341,8 +341,13 @@
        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 82579d0..438c294 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 @@
            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 @@
            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 d4d5cce..1eed6d7 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -1346,8 +1346,8 @@
        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 @@
                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 c616376..18dd7cc 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 @@
                        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 4e1547f..97e93677 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -117,6 +117,12 @@

            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: