sw/source/core/crsr/bookmrk.cxx |   45 ++++++++++++++++++++++++++++++++++++++++
 sw/source/core/doc/docbm.cxx    |   16 ++++++++++++++
 sw/source/core/inc/bookmrk.hxx  |   10 +++++---
 3 files changed, 67 insertions(+), 4 deletions(-)

New commits:
commit e210e9b67cd46de98ee94dfdc54952c99f58be17
Author:     Michael Stahl <michael.st...@cib.de>
AuthorDate: Tue Jan 21 13:15:50 2020 +0100
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Aug 24 11:02:19 2021 +0200

    tdf#45589 sw: invalidate on bookmark insertion/deletion
    
    Invalidate the text frames when a bookmark is inserted or deleted; also
    when MarkManager::repositionMark() changes the positions.
    
    The other calls of SetMarkPos()/SetOtherMarkPos() look like they're all
    from code that corrects positions after text insertions or deletions so
    no additional invalidate should be necessary there.
    
    It turns out that one WW8 document in sw_filters_test wants to insert
    a bookmark on a SwGrfNode; check for that in makeMark().
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87157
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    (cherry picked from commit ef8427d12a63127a2eb867637699343d630545dd)
    
    crashtesting: null dereference of reexporting abi12570.odt to odt
    
    FLY_AT_FLY shape is anchored on SwStartNode of fly section.
    
    (regression from ef8427d12a63127a2eb867637699343d630545dd)
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91336
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    (cherry picked from commit 71ed878556422068041025668876fb3300c128df)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/96318
    Tested-by: Thorsten Behrens <thorsten.behr...@cib.de>
    (cherry picked from commit 79bc162d86c62506614a19bf7c92c72237804f5e)
    
    Change-Id: I293e6da9042bea5992cb27091b9cff77e5c7961d
    4fe70237c060cc810af82657bc5791e7024db8f5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120869
    Tested-by: Michael Stahl <michael.st...@allotropia.de>
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/core/crsr/bookmrk.cxx b/sw/source/core/crsr/bookmrk.cxx
index a16713dc295d..fad65a238147 100644
--- a/sw/source/core/crsr/bookmrk.cxx
+++ b/sw/source/core/crsr/bookmrk.cxx
@@ -25,6 +25,7 @@
 #include <doc.hxx>
 #include <ndtxt.hxx>
 #include <pam.hxx>
+#include <hints.hxx>
 #include <swserv.hxx>
 #include <sfx2/linkmgr.hxx>
 #include <UndoBookmark.hxx>
@@ -238,6 +239,12 @@ namespace
 
         io_pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::UI_REPLACE, nullptr);
     };
+
+    auto InvalidatePosition(SwPosition const& rPos) -> void
+    {
+        SwUpdateAttr const hint(rPos.nContent.GetIndex(), 
rPos.nContent.GetIndex(), 0);
+        rPos.nNode.GetNode().GetTextNode()->NotifyClients(nullptr, &hint);
+    }
 }
 
 namespace sw { namespace mark
@@ -337,6 +344,11 @@ namespace sw { namespace mark
     }
 
     // TODO: everything else uses MarkBase::GenerateNewName ?
+
+    auto MarkBase::InvalidateFrames() -> void
+    {
+    }
+
     NavigatorReminder::NavigatorReminder(const SwPaM& rPaM)
         : MarkBase(rPaM, "__NavigatorReminder__")
     { }
@@ -393,6 +405,7 @@ namespace sw { namespace mark
                     std::make_unique<SwUndoInsBookmark>(*this));
         }
         io_pDoc->getIDocumentState().SetModified();
+        InvalidateFrames();
     }
 
     void Bookmark::DeregisterFromDoc(SwDoc* const io_pDoc)
@@ -405,6 +418,36 @@ namespace sw { namespace mark
                     std::make_unique<SwUndoDeleteBookmark>(*this));
         }
         io_pDoc->getIDocumentState().SetModified();
+        InvalidateFrames();
+    }
+
+    // invalidate text frames in case it's hidden or Formatting Marks enabled
+    auto Bookmark::InvalidateFrames() -> void
+    {
+        InvalidatePosition(GetMarkPos());
+        if (IsExpanded())
+        {
+            InvalidatePosition(GetOtherMarkPos());
+        }
+    }
+
+    void Bookmark::Hide(bool const isHide)
+    {
+        if (isHide != m_bHidden)
+        {
+            m_bHidden = isHide;
+            InvalidateFrames();
+        }
+    }
+
+    void Bookmark::SetHideCondition(OUString const& rHideCondition)
+    {
+        if (m_sHideCondition != rHideCondition)
+        {
+            m_sHideCondition = rHideCondition;
+            // don't eval condition here yet - probably only needed for
+            // UI editing condition and that doesn't exist yet
+        }
     }
 
     ::sfx2::IXmlIdRegistry& Bookmark::GetRegistry()
@@ -513,6 +556,8 @@ namespace sw { namespace mark
         if (eMode == sw::mark::InsertMode::New)
         {
             lcl_SetFieldMarks(this, io_pDoc, CH_TXT_ATR_FIELDSTART, 
CH_TXT_ATR_FIELDEND, pSepPos);
+            // no need to invalidate text frames here, the insertion of the
+            // CH_TXT_ATR already invalidates
         }
         else
         {
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index a9eed445a21c..e061dbf0a310 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -561,6 +561,18 @@ namespace sw { namespace mark
                 pPos2->nContent.GetIndex());
         }
 #endif
+        if (   (!rPaM.GetPoint()->nNode.GetNode().IsTextNode()
+                && (eType != MarkType::UNO_BOOKMARK
+                // SwXTextRange can be on table node or plain start node 
(FLY_AT_FLY)
+                    || !rPaM.GetPoint()->nNode.GetNode().IsStartNode()))
+            || (!rPaM.GetMark()->nNode.GetNode().IsTextNode()
+                && (eType != MarkType::UNO_BOOKMARK
+                    || !rPaM.GetMark()->nNode.GetNode().IsStartNode())))
+        {
+            SAL_WARN("sw.core", "MarkManager::makeMark(..)"
+                " - refusing to create mark on non-textnode");
+            return nullptr;
+        }
         // There should only be one CrossRefBookmark per Textnode per Type
         if ((eType == MarkType::CROSSREF_NUMITEM_BOOKMARK || eType == 
MarkType::CROSSREF_HEADING_BOOKMARK)
             && (lcl_FindMarkAtPos(m_vBookmarks, *rPaM.Start(), eType) != 
m_vBookmarks.end()))
@@ -809,6 +821,8 @@ namespace sw { namespace mark
         if (!pMarkBase)
             return;
 
+        pMarkBase->InvalidateFrames();
+
         pMarkBase->SetMarkPos(*(rPaM.GetPoint()));
         if(rPaM.HasMark())
             pMarkBase->SetOtherMarkPos(*(rPaM.GetMark()));
@@ -818,6 +832,8 @@ namespace sw { namespace mark
         if(pMarkBase->GetMarkPos() != pMarkBase->GetMarkStart())
             pMarkBase->Swap();
 
+        pMarkBase->InvalidateFrames();
+
         sortMarks();
     }
 
diff --git a/sw/source/core/inc/bookmrk.hxx b/sw/source/core/inc/bookmrk.hxx
index 3960ca4b3d8b..fe5bff942568 100644
--- a/sw/source/core/inc/bookmrk.hxx
+++ b/sw/source/core/inc/bookmrk.hxx
@@ -90,6 +90,8 @@ namespace sw {
             virtual void ClearOtherMarkPos()
                 { m_pPos2.reset(); }
 
+            virtual auto InvalidateFrames() -> void;
+
             virtual OUString ToString( ) const override;
             virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
 
@@ -170,6 +172,8 @@ namespace sw {
 
             virtual void DeregisterFromDoc(SwDoc* const io_pDoc) override;
 
+            virtual auto InvalidateFrames() -> void override;
+
             virtual const OUString& GetShortName() const override
                 { return m_sShortName; }
             virtual const vcl::KeyCode& GetKeyCode() const override
@@ -182,10 +186,8 @@ namespace sw {
                 { return m_bHidden; }
             virtual const OUString& GetHideCondition() const override
                 { return m_sHideCondition; }
-            virtual void Hide(bool rHide) override
-                { m_bHidden = rHide; }
-            virtual void SetHideCondition(const OUString& rHideCondition) 
override
-                { m_sHideCondition = rHideCondition; }
+            virtual void Hide(bool rHide) override;
+            virtual void SetHideCondition(const OUString& rHideCondition) 
override;
 
             // ::sfx2::Metadatable
             virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;

Reply via email to