oox/qa/unit/export.cxx            |   42 ++++++++++++++++++++++++++++++++++++++
 sw/source/uibase/wrtsh/wrtsh1.cxx |    5 ++++
 2 files changed, 47 insertions(+)

New commits:
commit d30e4ada63bb05489174d2bf0b3a30d0ded86a77
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Wed Jan 31 05:53:56 2024 -0500
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Feb 9 08:11:32 2024 +0100

    sw: do not redline ContentControl items
    
    When we redline the ContentControl item
    itself, we break docx XML. Instead, we
    only need to redline the placeholder,
    which we already do.
    
    This simply disables redlining when
    inserting the ContentControl item
    while leaving it otherwise enabled
    while inserting the placeholder.
    
    Before:
    
    <w:body>
        <w:p>
            <w:pPr>
                <w:pStyle w:val="Normal"/>
                <w:rPr></w:rPr>
            </w:pPr>
    ==>     <w:ins w:id="-1" w:author="Unknown Author" 
w:date="2024-01-24T19:43:08Z">
            <w:sdt>
                <w:sdtPr>
                    <w12:checkbox>
                        <w12:checked w14:val="0"/>
                        <w12:checkedState w14:val="2612"/>
                        <w12:uncheckedState w14:val="2610"/>
                    </w12:checkbox>
                </w:sdtPr>
                <w:sdtContent>
                    <w:r>
                        <w:rPr></w:rPr>
                    </w:r>
    ==>         </w:ins>
    ==>         <w:ins w:id="0" w:author="Unknown Author" 
w:date="2024-01-24T19:43:08Z">
                    <w:r>
                        <w:rPr></w:rPr>
                        <w:t>☐</w:t>
                    </w:r>
    ==>         </w:ins>
                    <w:r>
                        <w:rPr></w:rPr>
                    </w:r>
                </w:sdtContent>
            </w:sdt>
        </w:p>
    </w:body>
    
    The first <w:ins> and its closing tag
    is not seen in the reference docx
    file, and we can see that it's invalid
    XML here.
    
    After:
    <w:body>
        <w:p>
            <w:pPr>
                <w:pStyle w:val="Normal"/>
                <w:rPr></w:rPr>
            </w:pPr>
            <w:sdt>
                <w:sdtPr>
                    <w12:checkbox>
                        <w12:checked w14:val="0"/>
                        <w12:checkedState w14:val="2612"/>
                        <w12:uncheckedState w14:val="2610"/>
                    </w12:checkbox>
                </w:sdtPr>
                <w:sdtContent>
                    <w:r>
                        <w:rPr></w:rPr>
                    </w:r>
    ==>         <w:ins w:id="0" w:author="Unknown Author" 
w:date="2024-01-24T19:43:08Z">
                    <w:r>
                        <w:rPr></w:rPr>
                        <w:t>☐</w:t>
                    </w:r>
    ==>         </w:ins>
                    <w:r>
                        <w:rPr></w:rPr>
                    </w:r>
                </w:sdtContent>
            </w:sdt>
        </w:p>
    </w:body>
    
    Only the valid <w:ins> around the
    placeholder exists.
    
    Signed-off-by: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
    Change-Id: I1404e41aec3b5efdc2e4115236102ffa2733b15c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162802
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit 7a3e9c66baff8554d1267bc98c9c69e763bc8bdc)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163050
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/oox/qa/unit/export.cxx b/oox/qa/unit/export.cxx
index 6ad32c2981e3..d8be16ba8000 100644
--- a/oox/qa/unit/export.cxx
+++ b/oox/qa/unit/export.cxx
@@ -77,6 +77,48 @@ CPPUNIT_TEST_FIXTURE(Test, testRotatedShapePosition)
     assertXPath(pXmlDoc, "//wpg:wgp/wps:wsp[1]/wps:spPr/a:xfrm/a:off", "y", 
"469440");
 }
 
+CPPUNIT_TEST_FIXTURE(Test, testInsertCheckboxContentControlOdt)
+{
+    loadFromURL(u"tdf141786_RotatedShapeInGroup.odt");
+
+    dispatchCommand(mxComponent, ".uno:TrackChanges", {});
+    dispatchCommand(mxComponent, ".uno:InsertCheckboxContentControl", {});
+
+    // FIXME: validation error in OOXML export: Errors: 3
+    skipValidation();
+
+    save("Office Open XML Text");
+}
+
+CPPUNIT_TEST_FIXTURE(Test, testInsertCheckboxContentControlDocx)
+{
+    {
+        loadFromURL(u"dml-groupshape-polygon.docx");
+
+        // Without TrackChanges, inserting the Checkbox works just fine
+        // when exporting to docx.
+        dispatchCommand(mxComponent, ".uno:InsertCheckboxContentControl", {});
+
+        // FIXME: validation error in OOXML export: Errors: 9
+        skipValidation();
+
+        save("Office Open XML Text");
+    }
+
+    {
+        loadFromURL(u"dml-groupshape-polygon.docx");
+
+        // With TrackChanges, the Checkbox causes an assertion in the sax 
serializer,
+        // in void 
sax_fastparser::FastSaxSerializer::endFastElement(sal_Int32).
+        // Element == maMarkStack.top()->m_DebugStartedElements.back()
+        // sax/source/tools/fastserializer.cxx#402
+        dispatchCommand(mxComponent, ".uno:TrackChanges", {});
+        dispatchCommand(mxComponent, ".uno:InsertCheckboxContentControl", {});
+
+        save("Office Open XML Text");
+    }
+}
+
 CPPUNIT_TEST_FIXTURE(Test, testDmlGroupshapePolygon)
 {
     // Given a document with a group shape, containing a single polygon child 
shape:
diff --git a/sw/source/uibase/wrtsh/wrtsh1.cxx 
b/sw/source/uibase/wrtsh/wrtsh1.cxx
index 5fc8c7948480..61fbce892540 100644
--- a/sw/source/uibase/wrtsh/wrtsh1.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh1.cxx
@@ -112,6 +112,7 @@
 #include <frmtool.hxx>
 #include <viewopt.hxx>
 
+#include <IDocumentRedlineAccess.hxx>
 #include <IDocumentUndoRedo.hxx>
 #include <UndoInsert.hxx>
 #include <UndoCore.hxx>
@@ -1164,8 +1165,12 @@ void 
SwWrtShell::InsertContentControl(SwContentControlType eType)
         Left(SwCursorSkipMode::Chars, /*bSelect=*/true, 
aPlaceholder.getLength(),
                 /*bBasicCall=*/false);
     }
+
+    const RedlineFlags oldRedlineFlags = 
getIDocumentRedlineAccess().GetRedlineFlags();
+    getIDocumentRedlineAccess().SetRedlineFlags(RedlineFlags::Ignore);
     SwFormatContentControl aContentControl(pContentControl, 
RES_TXTATR_CONTENTCONTROL);
     SetAttrItem(aContentControl);
+    getIDocumentRedlineAccess().SetRedlineFlags(oldRedlineFlags);
 }
 
 // Insert footnote

Reply via email to