summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-01-31 12:05:43 +0100
committerMichael Stahl <Michael.Stahl@cib.de>2020-03-25 20:46:53 +0100
commit0d35a22cad9ab65465cd6f506c8a3873e54eaa9a (patch)
tree3ad8fb262c21d30130661c91755d83515d63b7a7 /sw
parent79cb138c393f94dfe8fe42887a5cfc5e20fe61e3 (diff)
sw: implement protection of bookmarks and fields
SwPaM::HasReadonlySel() checks PROTECT_BOOKMARKS / PROTECT_FIELDS setting and checks if bookmarks or fields are selected for deletion. This should already be called by the UI code in all the right places, for the other content protection features, and cause a dialog to pop up. What's not ideal about this is that it's impossible to delete a character immediately before or after a point bookmark because that would delete the point bookmark too. The bookmark check is done by extracting a function out of MarkManager::deleteMarks() so both will use the same logic. The problem of DelContentIndex() duplicating that logic remains... Apparently the status bar at the bottom already displays "read-only" for such a selection. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87778 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de> (cherry picked from commit 9e7b5c74b484fcfd3317db56745b26b10897047d) Change-Id: Id87999198a03ba847ef0eff5651fef3bd2517fae
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/IDocumentMarkAccess.hxx3
-rw-r--r--sw/source/core/crsr/pam.cxx41
-rw-r--r--sw/source/core/doc/docbm.cxx149
-rw-r--r--sw/source/core/inc/MarkManager.hxx1
4 files changed, 145 insertions, 49 deletions
diff --git a/sw/inc/IDocumentMarkAccess.hxx b/sw/inc/IDocumentMarkAccess.hxx
index 3fb7090e5067..64c1ad3fcf17 100644
--- a/sw/inc/IDocumentMarkAccess.hxx
+++ b/sw/inc/IDocumentMarkAccess.hxx
@@ -224,6 +224,9 @@ class IDocumentMarkAccess
// interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK )
+ /** check if the selection would delete a BOOKMARK */
+ virtual bool isBookmarkDeleted(SwPaM const& rPaM) const =0;
+
/** returns a STL-like random access iterator to the begin of the sequence the IBookmarks.
*/
virtual const_iterator_t getBookmarksBegin() const =0;
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 4e762bfcf218..f0d88a26a4d5 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -41,6 +41,7 @@
#include <IMark.hxx>
#include <DocumentSettingManager.hxx>
#include <hints.hxx>
+#include <txatbase.hxx>
#include <xmloff/odffields.hxx>
#include <editsh.hxx>
@@ -720,6 +721,46 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
bRet = pDoc->GetEditShell()->IsCursorInParagraphMetadataField();
}
+ if (!bRet &&
+ pDoc->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
+ {
+ if (pDoc->getIDocumentMarkAccess()->isBookmarkDeleted(*this))
+ {
+ return true;
+ }
+ }
+ if (!bRet &&
+ pDoc->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_FIELDS))
+ {
+ SwPosition const& rStart(*Start());
+ SwPosition const& rEnd(*End());
+ for (SwNodeIndex n = rStart.nNode; n <= rEnd.nNode; ++n)
+ {
+ if (SwTextNode const*const pNode = n.GetNode().GetTextNode())
+ {
+ if (SwpHints const*const pHints = pNode->GetpSwpHints())
+ {
+ for (size_t i = 0; i < pHints->Count(); ++i)
+ {
+ SwTextAttr const*const pHint(pHints->Get(i));
+ if (n == rStart.nNode && pHint->GetStart() < rStart.nContent.GetIndex())
+ {
+ continue; // before selection
+ }
+ if (n == rEnd.nNode && rEnd.nContent.GetIndex() <= pHint->GetStart())
+ {
+ break; // after selection
+ }
+ if (pHint->Which() == RES_TXTATR_FIELD)
+ {
+ return true;
+ }
+ }
+ }
+ }
+ }
+ }
+
return bRet;
}
diff --git a/sw/source/core/doc/docbm.cxx b/sw/source/core/doc/docbm.cxx
index 65ae2df1c182..77dfdd976c1b 100644
--- a/sw/source/core/doc/docbm.cxx
+++ b/sw/source/core/doc/docbm.cxx
@@ -686,6 +686,103 @@ namespace sw { namespace mark
lcl_DebugMarks(m_vAllMarks);
}
+ static bool isDeleteMark(
+ ::sw::mark::MarkBase const*const pMark,
+ SwNodeIndex const& rStt,
+ SwNodeIndex const& rEnd,
+ SwIndex const*const pSttIdx,
+ SwIndex const*const pEndIdx,
+ bool & rbIsPosInRange,
+ bool & rbIsOtherPosInRange)
+ {
+ assert(pMark);
+ // navigator marks should not be moved
+ // TODO: Check if this might make them invalid
+ if (IDocumentMarkAccess::GetType(*pMark) == IDocumentMarkAccess::MarkType::NAVIGATOR_REMINDER)
+ {
+ return false;
+ }
+
+ // on position ??
+ rbIsPosInRange = lcl_GreaterThan(pMark->GetMarkPos(), rStt, pSttIdx)
+ && lcl_Lower(pMark->GetMarkPos(), rEnd, pEndIdx);
+ rbIsOtherPosInRange = pMark->IsExpanded()
+ && lcl_GreaterThan(pMark->GetOtherMarkPos(), rStt, pSttIdx)
+ && lcl_Lower(pMark->GetOtherMarkPos(), rEnd, pEndIdx);
+ // special case: completely in range, touching the end?
+ if ( pEndIdx != nullptr
+ && ( ( rbIsOtherPosInRange
+ && pMark->GetMarkPos().nNode == rEnd
+ && pMark->GetMarkPos().nContent == *pEndIdx )
+ || ( rbIsPosInRange
+ && pMark->IsExpanded()
+ && pMark->GetOtherMarkPos().nNode == rEnd
+ && pMark->GetOtherMarkPos().nContent == *pEndIdx ) ) )
+ {
+ rbIsPosInRange = true;
+ rbIsOtherPosInRange = true;
+ }
+
+ if (rbIsPosInRange
+ && (rbIsOtherPosInRange
+ || !pMark->IsExpanded()))
+ {
+ // completely in range
+
+ bool bDeleteMark = true;
+ {
+ switch ( IDocumentMarkAccess::GetType( *pMark ) )
+ {
+ case IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK:
+ case IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK:
+ // no delete of cross-reference bookmarks, if range is inside one paragraph
+ bDeleteMark = rStt != rEnd;
+ break;
+ case IDocumentMarkAccess::MarkType::UNO_BOOKMARK:
+ // no delete of UNO mark, if it is not expanded and only touches the start of the range
+ bDeleteMark = rbIsOtherPosInRange
+ || pMark->IsExpanded()
+ || pSttIdx == nullptr
+ || !( pMark->GetMarkPos().nNode == rStt
+ && pMark->GetMarkPos().nContent == *pSttIdx );
+ break;
+ default:
+ bDeleteMark = true;
+ break;
+ }
+ }
+ return bDeleteMark;
+ }
+ return false;
+ }
+
+ bool MarkManager::isBookmarkDeleted(SwPaM const& rPaM) const
+ {
+ SwPosition const& rStart(*rPaM.Start());
+ SwPosition const& rEnd(*rPaM.End());
+ for (auto ppMark = m_vBookmarks.begin();
+ ppMark != m_vBookmarks.end();
+ ++ppMark)
+ {
+ ::sw::mark::MarkBase const*const pMark = dynamic_cast< ::sw::mark::MarkBase* >(ppMark->get());
+
+ if (!pMark)
+ continue;
+
+ bool bIsPosInRange(false);
+ bool bIsOtherPosInRange(false);
+ bool const bDeleteMark = isDeleteMark(pMark,
+ rStart.nNode, rEnd.nNode, &rStart.nContent, &rEnd.nContent,
+ bIsPosInRange, bIsOtherPosInRange);
+ if (bDeleteMark
+ && IDocumentMarkAccess::GetType(*pMark) == MarkType::BOOKMARK)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
void MarkManager::deleteMarks(
const SwNodeIndex& rStt,
const SwNodeIndex& rEnd,
@@ -707,65 +804,19 @@ namespace sw { namespace mark
ppMark != m_vAllMarks.end();
++ppMark)
{
- // navigator marks should not be moved
- // TODO: Check if this might make them invalid
- if(IDocumentMarkAccess::GetType(**ppMark) == MarkType::NAVIGATOR_REMINDER)
- continue;
-
::sw::mark::MarkBase* pMark = dynamic_cast< ::sw::mark::MarkBase* >(ppMark->get());
if (!pMark)
continue;
- // on position ??
- bool bIsPosInRange = lcl_GreaterThan(pMark->GetMarkPos(), rStt, pSttIdx)
- && lcl_Lower(pMark->GetMarkPos(), rEnd, pEndIdx);
- bool bIsOtherPosInRange = pMark->IsExpanded()
- && lcl_GreaterThan(pMark->GetOtherMarkPos(), rStt, pSttIdx)
- && lcl_Lower(pMark->GetOtherMarkPos(), rEnd, pEndIdx);
- // special case: completely in range, touching the end?
- if ( pEndIdx != nullptr
- && ( ( bIsOtherPosInRange
- && pMark->GetMarkPos().nNode == rEnd
- && pMark->GetMarkPos().nContent == *pEndIdx )
- || ( bIsPosInRange
- && pMark->IsExpanded()
- && pMark->GetOtherMarkPos().nNode == rEnd
- && pMark->GetOtherMarkPos().nContent == *pEndIdx ) ) )
- {
- bIsPosInRange = true;
- bIsOtherPosInRange = true;
- }
+ bool bIsPosInRange(false);
+ bool bIsOtherPosInRange(false);
+ bool const bDeleteMark = isDeleteMark(pMark, rStt, rEnd, pSttIdx, pEndIdx, bIsPosInRange, bIsOtherPosInRange);
if ( bIsPosInRange
&& ( bIsOtherPosInRange
|| !pMark->IsExpanded() ) )
{
- // completely in range
-
- bool bDeleteMark = true;
- {
- switch ( IDocumentMarkAccess::GetType( *pMark ) )
- {
- case IDocumentMarkAccess::MarkType::CROSSREF_HEADING_BOOKMARK:
- case IDocumentMarkAccess::MarkType::CROSSREF_NUMITEM_BOOKMARK:
- // no delete of cross-reference bookmarks, if range is inside one paragraph
- bDeleteMark = rStt != rEnd;
- break;
- case IDocumentMarkAccess::MarkType::UNO_BOOKMARK:
- // no delete of UNO mark, if it is not expanded and only touches the start of the range
- bDeleteMark = bIsOtherPosInRange
- || pMark->IsExpanded()
- || pSttIdx == nullptr
- || !( pMark->GetMarkPos().nNode == rStt
- && pMark->GetMarkPos().nContent == *pSttIdx );
- break;
- default:
- bDeleteMark = true;
- break;
- }
- }
-
if ( bDeleteMark )
{
if ( pSaveBkmk )
diff --git a/sw/source/core/inc/MarkManager.hxx b/sw/source/core/inc/MarkManager.hxx
index a12657ef2469..2d972ed7696f 100644
--- a/sw/source/core/inc/MarkManager.hxx
+++ b/sw/source/core/inc/MarkManager.hxx
@@ -72,6 +72,7 @@ namespace sw {
virtual const_iterator_t findMark(const OUString& rName) const override;
// bookmarks
+ virtual bool isBookmarkDeleted(SwPaM const& rPaM) const override;
virtual const_iterator_t getBookmarksBegin() const override;
virtual const_iterator_t getBookmarksEnd() const override;
virtual sal_Int32 getBookmarksCount() const override;