sw/inc/IDocumentMarkAccess.hxx                |    3 
 sw/inc/IDocumentSettingAccess.hxx             |    2 
 sw/source/core/crsr/pam.cxx                   |   41 +++++++
 sw/source/core/doc/DocumentSettingManager.cxx |   12 +-
 sw/source/core/doc/docbm.cxx                  |  149 +++++++++++++++++---------
 sw/source/core/inc/DocumentSettingManager.hxx |    2 
 sw/source/core/inc/MarkManager.hxx            |    1 
 sw/source/ui/misc/bookmark.cxx                |   15 +-
 sw/source/uibase/inc/bookmark.hxx             |    1 
 sw/source/uibase/shells/textsh1.cxx           |    2 
 sw/source/uibase/uno/SwXDocumentSettings.cxx  |   36 ++++++
 sw/source/uibase/utlui/content.cxx            |   26 ++--
 sw/source/uibase/wrtsh/delete.cxx             |   12 ++
 13 files changed, 235 insertions(+), 67 deletions(-)

New commits:
commit c322064eac9a7d562f1a4501df7bb1ddd3ab843f
Author:     Katarina Behrens <katarina.behr...@cib.de>
AuthorDate: Fri Jan 24 18:40:24 2020 +0100
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Wed Mar 25 20:50:17 2020 +0100

    sw: Optionally disable bookmark manipulation GUIs
    
    If the ProtectBookmarks bit is set, don't allow bookmark
    changes, neither via the bookmark dialog nor the navigator.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87361
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    (cherry picked from commit cb5d18871b46ef4f7bc47eb4d71df5374d712575)
    
    Omit new strings for backport to 6.1 branch, was only shown as
    disabled context menu item anyway.
    
    Change-Id: I035faaf3871c7107dd1aac38c4e6867291827346

diff --git a/sw/source/ui/misc/bookmark.cxx b/sw/source/ui/misc/bookmark.cxx
index 309892627b47..3372dd3eb375 100644
--- a/sw/source/ui/misc/bookmark.cxx
+++ b/sw/source/ui/misc/bookmark.cxx
@@ -36,6 +36,7 @@
 #include <docsh.hxx>
 #include <globals.hrc>
 #include <strings.hrc>
+#include <IDocumentSettingAccess.hxx>
 
 using namespace ::com::sun::star;
 
@@ -84,12 +85,12 @@ IMPL_LINK_NOARG(SwInsertBookmarkDlg, ModifyHdl, Edit&, void)
     }
 
     // allow to add new bookmark only if one name provided and it's not taken
-    m_pInsertBtn->Enable(nEntries == 1 && nSelectedEntries == 0);
+    m_pInsertBtn->Enable(nEntries == 1 && nSelectedEntries == 0 && 
!m_bAreProtected);
 
     // allow to delete only if all bookmarks are recognized
-    m_pDeleteBtn->Enable(nEntries > 0 && nSelectedEntries == nEntries);
+    m_pDeleteBtn->Enable(nEntries > 0 && nSelectedEntries == nEntries && 
!m_bAreProtected);
     m_pGotoBtn->Enable(nEntries == 1 && nSelectedEntries == 1);
-    m_pRenameBtn->Enable(nEntries == 1 && nSelectedEntries == 1);
+    m_pRenameBtn->Enable(nEntries == 1 && nSelectedEntries == 1 && 
!m_bAreProtected);
 }
 
 // callback to delete a text mark
@@ -161,13 +162,13 @@ IMPL_LINK_NOARG(SwInsertBookmarkDlg, SelectionChangedHdl, 
SvTreeListBox*, void)
     {
         m_pInsertBtn->Disable();
         m_pGotoBtn->Enable(m_pBookmarksBox->GetSelectionCount() == 1);
-        m_pRenameBtn->Enable(m_pBookmarksBox->GetSelectionCount() == 1);
-        m_pDeleteBtn->Enable();
+        m_pRenameBtn->Enable(m_pBookmarksBox->GetSelectionCount() == 1 && 
!m_bAreProtected);
+        m_pDeleteBtn->Enable(!m_bAreProtected);
         m_pEditBox->SetText(sEditBoxText);
     }
     else
     {
-        m_pInsertBtn->Enable();
+        m_pInsertBtn->Enable(!m_bAreProtected);
         m_pGotoBtn->Disable();
         m_pRenameBtn->Disable();
         m_pDeleteBtn->Disable();
@@ -327,6 +328,8 @@ SwInsertBookmarkDlg::SwInsertBookmarkDlg(vcl::Window* 
pParent, SwWrtShell& rS, S
     m_pEditBox->SetCursorAtLast();
 
     sRemoveWarning = SwResId(STR_REMOVE_WARNING);
+
+    m_bAreProtected = 
rSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS);
 }
 
 SwInsertBookmarkDlg::~SwInsertBookmarkDlg()
diff --git a/sw/source/uibase/inc/bookmark.hxx 
b/sw/source/uibase/inc/bookmark.hxx
index e8554052b9aa..5f94efd7bb01 100644
--- a/sw/source/uibase/inc/bookmark.hxx
+++ b/sw/source/uibase/inc/bookmark.hxx
@@ -60,6 +60,7 @@ class SwInsertBookmarkDlg: public SvxStandardDialog
     SfxRequest&                         rReq;
     std::vector<std::pair<sw::mark::IMark*, OUString>> aTableBookmarks;
     sal_Int32                           m_nLastBookmarksCount;
+    bool m_bAreProtected;
 
     DECL_LINK(ModifyHdl, Edit&, void);
     DECL_LINK(InsertHdl, Button*, void);
diff --git a/sw/source/uibase/shells/textsh1.cxx 
b/sw/source/uibase/shells/textsh1.cxx
index 503f52b502fc..f19ff11b9af8 100644
--- a/sw/source/uibase/shells/textsh1.cxx
+++ b/sw/source/uibase/shells/textsh1.cxx
@@ -715,7 +715,7 @@ void SwTextShell::Execute(SfxRequest &rReq)
         }
         case FN_DELETE_BOOKMARK:
         {
-            if ( pItem )
+            if (pItem && 
!rWrtSh.getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS))
             {
                 IDocumentMarkAccess* const pMarkAccess = 
rWrtSh.getIDocumentMarkAccess();
                 pMarkAccess->deleteMark( 
pMarkAccess->findMark(static_cast<const SfxStringItem*>(pItem)->GetValue()) );
diff --git a/sw/source/uibase/utlui/content.cxx 
b/sw/source/uibase/utlui/content.cxx
index 9c6c26c1e47b..2784bb0da14a 100644
--- a/sw/source/uibase/utlui/content.cxx
+++ b/sw/source/uibase/utlui/content.cxx
@@ -51,6 +51,7 @@
 #include <navicfg.hxx>
 #include <edtwin.hxx>
 #include <doc.hxx>
+#include <IDocumentSettingAccess.hxx>
 #include <IDocumentDrawModelAccess.hxx>
 #include <IDocumentOutlineNodes.hxx>
 #include <unotools.hxx>
@@ -317,7 +318,9 @@ void SwContentType::Init(bool* pbInvalidateWindow)
                 pMarkAccess->getBookmarksEnd(),
                 &lcl_IsUiVisibleBookmark);
             sTypeToken.clear();
-            bEdit = true;
+            const bool bProtectedBM = 
pWrtShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS);
+            bEdit = !bProtectedBM;
+            bDelete = !bProtectedBM;
         }
         break;
         case ContentTypeId::REGION :
@@ -1217,19 +1220,21 @@ VclPtr<PopupMenu> SwContentTree::CreateContextMenu()
         
assert(dynamic_cast<SwContent*>(static_cast<SwTypeNumber*>(pEntry->GetUserData())));
         const SwContentType* pContType = 
static_cast<SwContent*>(pEntry->GetUserData())->GetParent();
         const ContentTypeId nContentType = pContType->GetType();
-        bool bReadonly = m_pActiveShell->GetView().GetDocShell()->IsReadOnly();
-        bool bVisible = 
!static_cast<SwContent*>(pEntry->GetUserData())->IsInvisible();
-        bool bProtected = 
static_cast<SwContent*>(pEntry->GetUserData())->IsProtect();
-        bool bEditable = pContType->IsEditable() &&
-            ((bVisible && !bProtected) ||ContentTypeId::REGION == 
nContentType);
-        bool bDeletable = pContType->IsDeletable() &&
-            ((bVisible && !bProtected) ||ContentTypeId::REGION == 
nContentType);
-        bool bRenamable = bEditable && !bReadonly &&
+        const bool bReadonly = 
m_pActiveShell->GetView().GetDocShell()->IsReadOnly();
+        const bool bVisible = 
!static_cast<SwContent*>(pEntry->GetUserData())->IsInvisible();
+        const bool bProtected = 
static_cast<SwContent*>(pEntry->GetUserData())->IsProtect();
+        const bool bProtectBM = (ContentTypeId::BOOKMARK == nContentType)
+            && 
m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS);
+        const bool bEditable = pContType->IsEditable() &&
+            ((bVisible && !bProtected && !bProtectBM) || ContentTypeId::REGION 
== nContentType);
+        const bool bDeletable = pContType->IsDeletable() &&
+            ((bVisible && !bProtected && !bProtectBM) || ContentTypeId::REGION 
== nContentType);
+        const bool bRenamable = bEditable && !bReadonly &&
             (ContentTypeId::TABLE == nContentType ||
                 ContentTypeId::FRAME == nContentType ||
                 ContentTypeId::GRAPHIC == nContentType ||
                 ContentTypeId::OLE == nContentType ||
-                ContentTypeId::BOOKMARK == nContentType ||
+                (ContentTypeId::BOOKMARK == nContentType && !bProtectBM) ||
                 ContentTypeId::REGION == nContentType||
                 ContentTypeId::INDEX == nContentType);
 
@@ -3276,6 +3281,7 @@ void SwContentTree::EditEntry(SvTreeListEntry const * 
pEntry, EditEntryMode nMod
                 nSlot = FN_FORMAT_FRAME_DLG;
         break;
         case ContentTypeId::BOOKMARK  :
+            
assert(!m_pActiveShell->getIDocumentSettingAccess().get(DocumentSettingId::PROTECT_BOOKMARKS));
             if(nMode == EditEntryMode::DELETE)
             {
                 IDocumentMarkAccess* const pMarkAccess = 
m_pActiveShell->getIDocumentMarkAccess();
commit 603e4d11a25b30b4b0c9d455420cc5f9b365a5e9
Author:     Michael Stahl <michael.st...@cib.de>
AuthorDate: Wed Feb 5 18:31:29 2020 +0100
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Wed Mar 25 20:46:53 2020 +0100

    sw: read-only/protected content dialog was missing on Delete/Backspace
    
    If SwWrtShell::DelRight()/DelLeft() are called without an active
    selection, they select 1 character to the right/left, but then they
    don't check if the selection is read-only, so then SwEditShell::Delete()
    calls HasReadonlySel() and silently returns.
    
    Pop up the dialog in this case too, for consistency.
    
    Change-Id: I3d72f136f4d132de3f8a6f3cc2aab493ced95a28
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88055
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    (cherry picked from commit 0788ab19869aa2ae5f7fbef9e3c13ceb641f80ee)

diff --git a/sw/source/uibase/wrtsh/delete.cxx 
b/sw/source/uibase/wrtsh/delete.cxx
index 59436decddf1..75deb845a988 100644
--- a/sw/source/uibase/wrtsh/delete.cxx
+++ b/sw/source/uibase/wrtsh/delete.cxx
@@ -285,6 +285,12 @@ bool SwWrtShell::DelLeft()
     if( !bRet && bSwap )
         SwCursorShell::SwapPam();
     CloseMark( bRet );
+    if (!bRet)
+    {   // false indicates HasReadonlySel failed
+        std::unique_ptr<weld::Builder> 
xBuilder(Application::CreateBuilder(GetView().GetFrameWeld(), 
"modules/swriter/ui/inforeadonlydialog.ui"));
+        std::unique_ptr<weld::MessageDialog> 
xInfo(xBuilder->weld_message_dialog("InfoReadonlyDialog"));
+        xInfo->run();
+    }
     return bRet;
 }
 
@@ -397,6 +403,12 @@ bool SwWrtShell::DelRight()
         SwCursorShell::Right(1, CRSR_SKIP_CELLS);
         bRet = Delete();
         CloseMark( bRet );
+        if (!bRet)
+        {   // false indicates HasReadonlySel failed
+            std::unique_ptr<weld::Builder> 
xBuilder(Application::CreateBuilder(GetView().GetFrameWeld(), 
"modules/swriter/ui/inforeadonlydialog.ui"));
+            std::unique_ptr<weld::MessageDialog> 
xInfo(xBuilder->weld_message_dialog("InfoReadonlyDialog"));
+            xInfo->run();
+        }
         break;
 
     case SelectionType::Frame:
commit 0d35a22cad9ab65465cd6f506c8a3873e54eaa9a
Author:     Michael Stahl <michael.st...@cib.de>
AuthorDate: Fri Jan 31 12:05:43 2020 +0100
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Wed Mar 25 20:46:53 2020 +0100

    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.st...@cib.de>
    (cherry picked from commit 9e7b5c74b484fcfd3317db56745b26b10897047d)
    
    Change-Id: Id87999198a03ba847ef0eff5651fef3bd2517fae

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;
commit 79cb138c393f94dfe8fe42887a5cfc5e20fe61e3
Author:     Michael Stahl <michael.st...@cib.de>
AuthorDate: Fri Jan 31 17:11:09 2020 +0100
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Wed Mar 25 20:46:52 2020 +0100

    sw: split into 2 settings ProtectBookmarks and ProtectFields
    
    On second thought, let's have 2 settings because there might be some
    use-case for protecting one but not the other.
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87777
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    (cherry picked from commit 249b10c22f4a35672a7388d34b2ded1b76054dac)
    
    Change-Id: If8442b64adeeed80b25c8b69f607f2d4993786e4

diff --git a/sw/inc/IDocumentSettingAccess.hxx 
b/sw/inc/IDocumentSettingAccess.hxx
index b2da919d29a3..903cd725745d 100644
--- a/sw/inc/IDocumentSettingAccess.hxx
+++ b/sw/inc/IDocumentSettingAccess.hxx
@@ -98,7 +98,8 @@ enum class DocumentSettingId
     EMBED_FONTS,
     EMBED_SYSTEM_FONTS,
     APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING,
-    PROTECT_BOOKMARKS_AND_FIELDS,
+    PROTECT_BOOKMARKS,
+    PROTECT_FIELDS,
 };
 
  /** Provides access to settings of a document
diff --git a/sw/source/core/doc/DocumentSettingManager.cxx 
b/sw/source/core/doc/DocumentSettingManager.cxx
index be39e0c3b8a9..38e4694c84d5 100644
--- a/sw/source/core/doc/DocumentSettingManager.cxx
+++ b/sw/source/core/doc/DocumentSettingManager.cxx
@@ -89,7 +89,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc 
&rDoc)
     mApplyParagraphMarkFormatToNumbering(false),
     mbLastBrowseMode( false ),
     mbDisableOffPagePositioning ( false ),
-    mbProtectBookmarksAndFields( false )
+    mbProtectBookmarks(false),
+    mbProtectFields(false)
 
     // COMPATIBILITY FLAGS END
 {
@@ -209,7 +210,8 @@ bool sw::DocumentSettingManager::get(/*[in]*/ 
DocumentSettingId id) const
         case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: 
return mApplyParagraphMarkFormatToNumbering;
         case DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING: return 
mbDisableOffPagePositioning;
         case DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA: return 
mbEmptyDbFieldHidesPara;
-        case DocumentSettingId::PROTECT_BOOKMARKS_AND_FIELDS: return 
mbProtectBookmarksAndFields;
+        case DocumentSettingId::PROTECT_BOOKMARKS: return mbProtectBookmarks;
+        case DocumentSettingId::PROTECT_FIELDS: return mbProtectFields;
         default:
             OSL_FAIL("Invalid setting id");
     }
@@ -430,8 +432,11 @@ void sw::DocumentSettingManager::set(/*[in]*/ 
DocumentSettingId id, /*[in]*/ boo
         case DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA:
             mbEmptyDbFieldHidesPara = value;
             break;
-        case DocumentSettingId::PROTECT_BOOKMARKS_AND_FIELDS:
-            mbProtectBookmarksAndFields = value;
+        case DocumentSettingId::PROTECT_BOOKMARKS:
+            mbProtectBookmarks = value;
+            break;
+        case DocumentSettingId::PROTECT_FIELDS:
+            mbProtectFields = value;
             break;
         default:
             OSL_FAIL("Invalid setting id");
diff --git a/sw/source/core/inc/DocumentSettingManager.hxx 
b/sw/source/core/inc/DocumentSettingManager.hxx
index f93d540165a9..351bd20c437a 100644
--- a/sw/source/core/inc/DocumentSettingManager.hxx
+++ b/sw/source/core/inc/DocumentSettingManager.hxx
@@ -156,7 +156,8 @@ class DocumentSettingManager :
     bool mbLastBrowseMode                           : 1;
     bool mbDisableOffPagePositioning; // tdf#112443
     bool mbEmptyDbFieldHidesPara;
-    bool mbProtectBookmarksAndFields;
+    bool mbProtectBookmarks;
+    bool mbProtectFields;
 
 public:
 
diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx 
b/sw/source/uibase/uno/SwXDocumentSettings.cxx
index f84c7535aa46..84522152d2fe 100644
--- a/sw/source/uibase/uno/SwXDocumentSettings.cxx
+++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx
@@ -137,7 +137,8 @@ enum SwDocumentSettingsPropertyHandles
     HANDLE_SUBTRACT_FLYS,
     HANDLE_DISABLE_OFF_PAGE_POSITIONING,
     HANDLE_EMPTY_DB_FIELD_HIDES_PARA,
-    HANDLE_PROTECT_BOOKMARKS_AND_FIELDS,
+    HANDLE_PROTECT_BOOKMARKS,
+    HANDLE_PROTECT_FIELDS,
 };
 
 static MasterPropertySetInfo * lcl_createSettingsInfo()
@@ -217,7 +218,8 @@ static MasterPropertySetInfo * lcl_createSettingsInfo()
         { OUString("SubtractFlysAnchoredAtFlys"),       HANDLE_SUBTRACT_FLYS,  
       cppu::UnoType<bool>::get(),           0},
         { OUString("DisableOffPagePositioning"),       
HANDLE_DISABLE_OFF_PAGE_POSITIONING,         cppu::UnoType<bool>::get(),        
   0},
         { OUString("EmptyDbFieldHidesPara"), HANDLE_EMPTY_DB_FIELD_HIDES_PARA, 
cppu::UnoType<bool>::get(), 0 },
-        { OUString("ProtectBookmarksAndFields"), 
HANDLE_PROTECT_BOOKMARKS_AND_FIELDS, cppu::UnoType<bool>::get(), 0 },
+        { OUString("ProtectBookmarks"), HANDLE_PROTECT_BOOKMARKS, 
cppu::UnoType<bool>::get(), 0 },
+        { OUString("ProtectFields"), HANDLE_PROTECT_FIELDS, 
cppu::UnoType<bool>::get(), 0 },
 /*
  * As OS said, we don't have a view when we need to set this, so I have to
  * find another solution before adding them to this property set - MTG
@@ -892,12 +894,22 @@ void SwXDocumentSettings::_setSingleValue( const 
comphelper::PropertyInfo & rInf
             }
         }
         break;
-        case HANDLE_PROTECT_BOOKMARKS_AND_FIELDS:
+        case HANDLE_PROTECT_BOOKMARKS:
         {
             bool bTmp;
             if (rValue >>= bTmp)
             {
-                
mpDoc->getIDocumentSettingAccess().set(DocumentSettingId::PROTECT_BOOKMARKS_AND_FIELDS,
+                
mpDoc->getIDocumentSettingAccess().set(DocumentSettingId::PROTECT_BOOKMARKS,
+                                                       bTmp);
+            }
+        }
+        break;
+        case HANDLE_PROTECT_FIELDS:
+        {
+            bool bTmp;
+            if (rValue >>= bTmp)
+            {
+                
mpDoc->getIDocumentSettingAccess().set(DocumentSettingId::PROTECT_FIELDS,
                                                        bTmp);
             }
         }
@@ -1334,10 +1346,16 @@ void SwXDocumentSettings::_getSingleValue( const 
comphelper::PropertyInfo & rInf
                 DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA);
         }
         break;
-        case HANDLE_PROTECT_BOOKMARKS_AND_FIELDS:
+        case HANDLE_PROTECT_BOOKMARKS:
+        {
+            rValue <<= mpDoc->getIDocumentSettingAccess().get(
+                DocumentSettingId::PROTECT_BOOKMARKS);
+        }
+        break;
+        case HANDLE_PROTECT_FIELDS:
         {
             rValue <<= mpDoc->getIDocumentSettingAccess().get(
-                DocumentSettingId::PROTECT_BOOKMARKS_AND_FIELDS);
+                DocumentSettingId::PROTECT_FIELDS);
         }
         break;
         default:
commit 8085c78902dd31133f1285740ef5fadde2834e27
Author:     Katarina Behrens <katarina.behr...@cib.de>
AuthorDate: Fri Jan 24 17:05:53 2020 +0100
Commit:     Michael Stahl <michael.st...@cib.de>
CommitDate: Wed Mar 25 20:46:52 2020 +0100

    Add ProtectBookmarksAndFields per-document option
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87360
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@cib.de>
    (cherry picked from commit a5cd4d39f09c3658c2b7cfff4ab6a74449d4f0c0)
    
    Change-Id: I8dac403ddea59026b5f52c132c8accc1bd0ada92

diff --git a/sw/inc/IDocumentSettingAccess.hxx 
b/sw/inc/IDocumentSettingAccess.hxx
index a66f2367c22f..b2da919d29a3 100644
--- a/sw/inc/IDocumentSettingAccess.hxx
+++ b/sw/inc/IDocumentSettingAccess.hxx
@@ -98,6 +98,7 @@ enum class DocumentSettingId
     EMBED_FONTS,
     EMBED_SYSTEM_FONTS,
     APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING,
+    PROTECT_BOOKMARKS_AND_FIELDS,
 };
 
  /** Provides access to settings of a document
diff --git a/sw/source/core/doc/DocumentSettingManager.cxx 
b/sw/source/core/doc/DocumentSettingManager.cxx
index c900a985dee2..be39e0c3b8a9 100644
--- a/sw/source/core/doc/DocumentSettingManager.cxx
+++ b/sw/source/core/doc/DocumentSettingManager.cxx
@@ -88,7 +88,8 @@ sw::DocumentSettingManager::DocumentSettingManager(SwDoc 
&rDoc)
     mbSubtractFlys(false),
     mApplyParagraphMarkFormatToNumbering(false),
     mbLastBrowseMode( false ),
-    mbDisableOffPagePositioning ( false )
+    mbDisableOffPagePositioning ( false ),
+    mbProtectBookmarksAndFields( false )
 
     // COMPATIBILITY FLAGS END
 {
@@ -208,6 +209,7 @@ bool sw::DocumentSettingManager::get(/*[in]*/ 
DocumentSettingId id) const
         case DocumentSettingId::APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING: 
return mApplyParagraphMarkFormatToNumbering;
         case DocumentSettingId::DISABLE_OFF_PAGE_POSITIONING: return 
mbDisableOffPagePositioning;
         case DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA: return 
mbEmptyDbFieldHidesPara;
+        case DocumentSettingId::PROTECT_BOOKMARKS_AND_FIELDS: return 
mbProtectBookmarksAndFields;
         default:
             OSL_FAIL("Invalid setting id");
     }
@@ -428,6 +430,9 @@ void sw::DocumentSettingManager::set(/*[in]*/ 
DocumentSettingId id, /*[in]*/ boo
         case DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA:
             mbEmptyDbFieldHidesPara = value;
             break;
+        case DocumentSettingId::PROTECT_BOOKMARKS_AND_FIELDS:
+            mbProtectBookmarksAndFields = value;
+            break;
         default:
             OSL_FAIL("Invalid setting id");
     }
diff --git a/sw/source/core/inc/DocumentSettingManager.hxx 
b/sw/source/core/inc/DocumentSettingManager.hxx
index 1cf9a9d9fea9..f93d540165a9 100644
--- a/sw/source/core/inc/DocumentSettingManager.hxx
+++ b/sw/source/core/inc/DocumentSettingManager.hxx
@@ -156,6 +156,7 @@ class DocumentSettingManager :
     bool mbLastBrowseMode                           : 1;
     bool mbDisableOffPagePositioning; // tdf#112443
     bool mbEmptyDbFieldHidesPara;
+    bool mbProtectBookmarksAndFields;
 
 public:
 
diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx 
b/sw/source/uibase/uno/SwXDocumentSettings.cxx
index 281bee24a542..f84c7535aa46 100644
--- a/sw/source/uibase/uno/SwXDocumentSettings.cxx
+++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx
@@ -137,6 +137,7 @@ enum SwDocumentSettingsPropertyHandles
     HANDLE_SUBTRACT_FLYS,
     HANDLE_DISABLE_OFF_PAGE_POSITIONING,
     HANDLE_EMPTY_DB_FIELD_HIDES_PARA,
+    HANDLE_PROTECT_BOOKMARKS_AND_FIELDS,
 };
 
 static MasterPropertySetInfo * lcl_createSettingsInfo()
@@ -216,6 +217,7 @@ static MasterPropertySetInfo * lcl_createSettingsInfo()
         { OUString("SubtractFlysAnchoredAtFlys"),       HANDLE_SUBTRACT_FLYS,  
       cppu::UnoType<bool>::get(),           0},
         { OUString("DisableOffPagePositioning"),       
HANDLE_DISABLE_OFF_PAGE_POSITIONING,         cppu::UnoType<bool>::get(),        
   0},
         { OUString("EmptyDbFieldHidesPara"), HANDLE_EMPTY_DB_FIELD_HIDES_PARA, 
cppu::UnoType<bool>::get(), 0 },
+        { OUString("ProtectBookmarksAndFields"), 
HANDLE_PROTECT_BOOKMARKS_AND_FIELDS, cppu::UnoType<bool>::get(), 0 },
 /*
  * As OS said, we don't have a view when we need to set this, so I have to
  * find another solution before adding them to this property set - MTG
@@ -890,6 +892,16 @@ void SwXDocumentSettings::_setSingleValue( const 
comphelper::PropertyInfo & rInf
             }
         }
         break;
+        case HANDLE_PROTECT_BOOKMARKS_AND_FIELDS:
+        {
+            bool bTmp;
+            if (rValue >>= bTmp)
+            {
+                
mpDoc->getIDocumentSettingAccess().set(DocumentSettingId::PROTECT_BOOKMARKS_AND_FIELDS,
+                                                       bTmp);
+            }
+        }
+        break;
         default:
             throw UnknownPropertyException();
     }
@@ -1322,6 +1334,12 @@ void SwXDocumentSettings::_getSingleValue( const 
comphelper::PropertyInfo & rInf
                 DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA);
         }
         break;
+        case HANDLE_PROTECT_BOOKMARKS_AND_FIELDS:
+        {
+            rValue <<= mpDoc->getIDocumentSettingAccess().get(
+                DocumentSettingId::PROTECT_BOOKMARKS_AND_FIELDS);
+        }
+        break;
         default:
             throw UnknownPropertyException();
     }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to