summaryrefslogtreecommitdiff
path: root/xmloff/qa/unit
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2022-12-02 14:59:08 -0500
committerMiklos Vajna <vmiklos@collabora.com>2022-12-21 07:57:08 +0000
commit7b279ffa22a5c2080e31e6cac534ccc048229e6e (patch)
tree02dbb25d51c1712dc6032c9cce80352b9ede5ab4 /xmloff/qa/unit
parent4c7a9650cc27ac3ac67dda108ffd74612f9cdb3c (diff)
sw content controls: enhance preserve id
Squashed commit including NFC cleanup docxattributeoutput: use existing function to clear fd14dd0e4c6a7ea0866a686f653db90301d664b6 Follow-up to 100c914d44ae8f362924fe567d7d41d0033ae8ad which added the initial id preservation for DOCX. adding DOCX block SDT grabbaging, ODF import/export [content controls can't exist in DOC format] The ID field is CRITICAL to preserve for VBA purposes. This patch adjusts BlockSDT to also round-trip the id instead of just creating a random one. m_nRunSdtPrToken <never equals> FSNS(XML_w, XML_id) since 2021 with 5f3af56b2c0ef6c628a7cfe5ce6e86f8e1765f5f, so I removed that part of the clause. I had thought about changing the ID to use a string instead of an int, but then the integer version was adopted to fix a regression in the commit mentioned earlier. I think it is AWFUL to have a number as the identifier when it will be used in StarBASIC. The VBA guys have to deal with it, but it would be nice to do something reasonable for LO native access to content controls. However, the concern would be if we allow VBA macro content created in LO to be exported to DOCX format - that would cause problems converting from a string ID to a number ID. VBA editing already is happening to some extent, and mmeeks seems interested in enabling it. So over-all it seems best to just stick with an integer ID. I used the commits for <w:alias> and <w:tag> to compose this patch. XML_ID already existed in include/xmloff/xmltoken.hxx and "id" already exists in xmloff/source/token/tokens.txt The ID can be used in VBA to select a specific control. The id (which is a positive or negative integer in DOCX) specifies a unique control - either by passing the number as a string (of the UNSIGNED value) or by passing as a float (specified with #). For example: msgbox ActiveDocument.ContentControls(2587720202#).ID msgbox ActiveDocument.ContentControls("2587720202").ID but not as an integer since that is used for index access. dim index as integer index = 1 msgbox ActiveDocument.ContentControls(index).ID make CppunitTest_writerfilter_dmapper CPPUNIT_TEST_NAME=testSdtRunRichText make CppunitTest_sw_ooxmlexport17 CPPUNIT_TEST_NAME=testDateContentControlExport make CppunitTest_sw_core_unocore CPPUNIT_TEST_NAME=testContentControlDate make CppunitTest_xmloff_text CPPUNIT_TEST_NAME=testAliasContentControlExport make CppunitTest_xmloff_text CPPUNIT_TEST_NAME=testAliasContentControlImport Change-Id: I5c4022dc932d941fad9da6d75ce899ee1ff66ff5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/142818 Tested-by: Jenkins Reviewed-by: Justin Luth <jluth@mail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144625 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'xmloff/qa/unit')
-rw-r--r--xmloff/qa/unit/data/content-control-alias.fodt2
-rw-r--r--xmloff/qa/unit/text.cxx5
2 files changed, 6 insertions, 1 deletions
diff --git a/xmloff/qa/unit/data/content-control-alias.fodt b/xmloff/qa/unit/data/content-control-alias.fodt
index 48fdc7b9436c..0742610ca63a 100644
--- a/xmloff/qa/unit/data/content-control-alias.fodt
+++ b/xmloff/qa/unit/data/content-control-alias.fodt
@@ -2,7 +2,7 @@
<office:document xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0" office:version="1.3" office:mimetype="application/vnd.oasis.opendocument.text">
<office:body>
<office:text>
- <text:p><loext:content-control loext:alias="my alias" loext:tag="my tag" loext:tab-index="4" loext:lock="sdtContentLocked">test</loext:content-control></text:p>
+ <text:p><loext:content-control loext:alias="my alias" loext:tag="my tag" loext:id="2147483647" loext:tab-index="4" loext:lock="sdtContentLocked">test</loext:content-control></text:p>
</office:text>
</office:body>
</office:document>
diff --git a/xmloff/qa/unit/text.cxx b/xmloff/qa/unit/text.cxx
index 9d6be54c5e70..c8dc35c28d00 100644
--- a/xmloff/qa/unit/text.cxx
+++ b/xmloff/qa/unit/text.cxx
@@ -849,6 +849,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testAliasContentControlExport)
uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
xContentControlProps->setPropertyValue("Alias", uno::Any(OUString("my alias")));
xContentControlProps->setPropertyValue("Tag", uno::Any(OUString("my tag")));
+ xContentControlProps->setPropertyValue("Id", uno::Any(static_cast<sal_Int32>(-2147483648)));
xContentControlProps->setPropertyValue("TabIndex", uno::Any(sal_uInt32(3)));
xContentControlProps->setPropertyValue("Lock", uno::Any(OUString("unlocked")));
xText->insertTextContent(xCursor, xContentControl, /*bAbsorb=*/true);
@@ -872,6 +873,7 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testAliasContentControlExport)
// i.e. alias was lost on export.
assertXPath(pXmlDoc, "//loext:content-control", "alias", "my alias");
assertXPath(pXmlDoc, "//loext:content-control", "tag", "my tag");
+ assertXPath(pXmlDoc, "//loext:content-control", "id", "-2147483648");
assertXPath(pXmlDoc, "//loext:content-control", "tab-index", "3");
assertXPath(pXmlDoc, "//loext:content-control", "lock", "unlocked");
}
@@ -939,6 +941,9 @@ CPPUNIT_TEST_FIXTURE(XmloffStyleTest, testAliasContentControlImport)
OUString aTag;
xContentControlProps->getPropertyValue("Tag") >>= aTag;
CPPUNIT_ASSERT_EQUAL(OUString("my tag"), aTag);
+ sal_Int32 nId = 0;
+ xContentControlProps->getPropertyValue("Id") >>= nId;
+ CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2147483647), nId);
sal_uInt32 nTabIndex;
xContentControlProps->getPropertyValue("TabIndex") >>= nTabIndex;
CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(4), nTabIndex);