sw/qa/core/crsr/crsr.cxx    |   24 ++++++++++++++++++++++++
 sw/source/core/crsr/pam.cxx |    7 +++++++
 2 files changed, 31 insertions(+)

New commits:
commit 7cb6be3e866bad39a37844802d49b1f5c7031910
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Wed Oct 12 11:44:49 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu Oct 13 11:05:18 2022 +0200

    tdf#151190 sw content controls: make them read-write in protected sections
    
    When the user picked a date in the date picker inside a protected
    section, then we blocked the deletion of the placeholder, but allowed
    insertion to the content control, which is inconsistent.
    
    The trouble was that SwPaM::HasReadonlySel() detected that the cursor is
    in a protected section, so deletion failed, leading to an ever growing
    value of the content control.
    
    Fix the problem by handling content controls similar to legacy form
    fields: if the cursor is inside a content control, then that value is
    editable, even if we're inside a protected section.
    
    This is meant to fix all content control types, not just date pickers.
    
    Change-Id: I9eca4c4f71dcfaa61d84414f7727adcd4496735c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141249
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141266
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/qa/core/crsr/crsr.cxx b/sw/qa/core/crsr/crsr.cxx
index 8f8d9963a285..3dc236c41f06 100644
--- a/sw/qa/core/crsr/crsr.cxx
+++ b/sw/qa/core/crsr/crsr.cxx
@@ -20,6 +20,7 @@
 #include <svl/srchitem.hxx>
 #include <vcl/scheduler.hxx>
 
+#include <formatcontentcontrol.hxx>
 #include <docsh.hxx>
 #include <unotxdoc.hxx>
 #include <wrtsh.hxx>
@@ -164,6 +165,29 @@ CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, 
testContentControlReadOnly)
     CPPUNIT_ASSERT(pWrtShell->HasReadonlySel());
 }
 
+CPPUNIT_TEST_FIXTURE(SwCoreCrsrTest, testContentControlProtectedSection)
+{
+    // Given a document with a date content control in a protected section:
+    SwDoc* pDoc = createSwDoc();
+    SwWrtShell* pWrtShell = pDoc->GetDocShell()->GetWrtShell();
+    pWrtShell->InsertContentControl(SwContentControlType::DATE);
+    pWrtShell->SelAll();
+    OUString aSectionName = pWrtShell->GetUniqueSectionName();
+    SwSectionData aSection(SectionType::Content, aSectionName);
+    aSection.SetProtectFlag(true);
+    pWrtShell->InsertSection(aSection);
+
+    // When entering the content control:
+    pWrtShell->SttEndDoc(/*bStt=*/true);
+    pWrtShell->Right(CRSR_SKIP_CHARS, /*bSelect=*/false, 1, 
/*bBasicCall=*/false);
+
+    // Then make sure that the cursor is read-only:
+    // Without the accompanying fix in place, this test would have failed, it 
was not possible to
+    // pick a date in a protected section (the new value was inserted, but the 
placeholder was not
+    // removed).
+    CPPUNIT_ASSERT(!pWrtShell->HasReadonlySel());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index f771e09f5739..6dc26d2ac074 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -761,6 +761,13 @@ bool SwPaM::HasReadonlySel( bool bFormView ) const
     {
         // Allow editing when the cursor/selection is fully inside of a legacy 
form field.
         bRet = !( pA != nullptr && !bAtStartA && !bAtStartB && pA == pB );
+
+        if (bRet && rDoc.GetEditShell()->CursorInsideContentControl())
+        {
+            // Also allow editing inside content controls in general, similar 
to form fields.
+            // Specific types will be disabled below.
+            bRet = false;
+        }
     }
 
     if (!bRet)

Reply via email to