sw/inc/textcontentcontrol.hxx                 |    2 ++
 sw/qa/core/data/docm/testModernVBA.docm       |binary
 sw/source/core/txtnode/attrcontentcontrol.cxx |   14 ++++++++++++++
 sw/source/ui/vba/vbacontentcontrol.cxx        |    5 ++---
 4 files changed, 18 insertions(+), 3 deletions(-)

New commits:
commit 982f9ec1e07364e317fbcd25f1ef06f984cc0ce8
Author:     Justin Luth <justin.l...@collabora.com>
AuthorDate: Wed Nov 23 18:12:20 2022 -0500
Commit:     Justin Luth <jl...@mail.com>
CommitDate: Thu Dec 1 21:32:05 2022 +0100

    tdf#151548 ContentControls: Add Delete()
    
    Needed a function to delete a control,
    so it seemed to make sense to include it here.
    
    [I saw a nice bExact flag, but it doesn't work because
     RES_TXTATTR_CONTENTCONTROLS is outside of a certain
     range. Oh well.]
    
    make CppunitTest_sw_macros_test CPPUNIT_TEST_NAME=testVba
    
    Change-Id: If7da3d4d614d9dfd20f539f651477cbd18d25e20
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143195
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>

diff --git a/sw/inc/textcontentcontrol.hxx b/sw/inc/textcontentcontrol.hxx
index a9bc4e4a1054..3fb7ea124b99 100644
--- a/sw/inc/textcontentcontrol.hxx
+++ b/sw/inc/textcontentcontrol.hxx
@@ -41,6 +41,8 @@ public:
 
     void ChgTextNode(SwTextNode* pNode);
 
+    void Delete(bool bSaveContents);
+
     SwTextNode* GetTextNode() const;
     /// Get the current (potentially invalid) string from the doc
     OUString ToString() const;
diff --git a/sw/qa/core/data/docm/testModernVBA.docm 
b/sw/qa/core/data/docm/testModernVBA.docm
index dd96686659ca..be7d99a24b84 100644
Binary files a/sw/qa/core/data/docm/testModernVBA.docm and 
b/sw/qa/core/data/docm/testModernVBA.docm differ
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx 
b/sw/source/core/txtnode/attrcontentcontrol.cxx
index e3d0c2237b3b..890bf20c1376 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -675,6 +675,20 @@ void SwTextContentControl::ChgTextNode(SwTextNode* pNode)
     }
 }
 
+void SwTextContentControl::Delete(bool bSaveContents)
+{
+    if (!GetTextNode())
+        return;
+
+    if (bSaveContents)
+        GetTextNode()->RstTextAttr(GetStart(), *End() - GetStart(), 
RES_TXTATR_CONTENTCONTROL);
+    else
+    {
+        SwPaM aPaM(*GetTextNode(), GetStart(), *GetTextNode(), *End());
+        
GetTextNode()->GetDoc().getIDocumentContentOperations().DeleteAndJoin(aPaM);
+    }
+}
+
 SwTextNode* SwTextContentControl::GetTextNode() const
 {
     auto& rFormatContentControl = static_cast<const 
SwFormatContentControl&>(GetAttr());
diff --git a/sw/source/ui/vba/vbacontentcontrol.cxx 
b/sw/source/ui/vba/vbacontentcontrol.cxx
index d75ce84d7f4a..da3f3ec6f4ee 100644
--- a/sw/source/ui/vba/vbacontentcontrol.cxx
+++ b/sw/source/ui/vba/vbacontentcontrol.cxx
@@ -676,15 +676,14 @@ void SwVbaContentControl::Cut()
     SAL_INFO("sw.vba",
              "SwVbaContentControl::Cut[" << getID() << "], but missing sending 
to clipboard");
 
-    Delete(uno::Any(false));
+    m_rCC.Delete(/*bSaveContents=*/false);
 }
 
 void SwVbaContentControl::Delete(const uno::Any& DeleteContents)
 {
     bool bDeleteContents = false;
     DeleteContents >>= bDeleteContents;
-    SAL_INFO("sw.vba", "SwVbaContentControl::Delete[" << DeleteContents << "] 
stub");
-    //m_rCC.ChgTextNode(nullptr); // works, but crashes on UI touch - probably 
requires invalidation
+    m_rCC.Delete(!bDeleteContents);
 }
 
 void SwVbaContentControl::SetCheckedSymbol(sal_Int32 Character, const 
uno::Any& Font)

Reply via email to