summaryrefslogtreecommitdiff
path: root/xmloff/source
diff options
context:
space:
mode:
authorJustin Luth <justin.luth@collabora.com>2022-11-16 21:56:51 -0500
committerMiklos Vajna <vmiklos@collabora.com>2022-12-16 07:34:20 +0000
commit54599383a2f86b83c237a10f7d9fce492e798487 (patch)
tree551093fc1d2632db821128131871269d8bd8598d /xmloff/source
parent73e062be1ff10e2dd889d9ec9c2d07b692077f62 (diff)
sw content controls: enhance preserve id
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_ooxmlexport18 CPPUNIT_TEST_NAME=testTdf151912 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>
Diffstat (limited to 'xmloff/source')
-rw-r--r--xmloff/source/text/txtparae.cxx7
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.cxx13
-rw-r--r--xmloff/source/text/xmlcontentcontrolcontext.hxx1
3 files changed, 21 insertions, 0 deletions
diff --git a/xmloff/source/text/txtparae.cxx b/xmloff/source/text/txtparae.cxx
index 4ee5f3fd8a90..56e6c3737553 100644
--- a/xmloff/source/text/txtparae.cxx
+++ b/xmloff/source/text/txtparae.cxx
@@ -4067,6 +4067,13 @@ void XMLTextParagraphExport::ExportContentControl(
GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_TAG, aTag);
}
+ sal_Int32 nId = 0;
+ xPropertySet->getPropertyValue("Id") >>= nId;
+ if (nId)
+ {
+ GetExport().AddAttribute(XML_NAMESPACE_LO_EXT, XML_ID, OUString::number(nId));
+ }
+
sal_uInt32 nTabIndex;
xPropertySet->getPropertyValue("TabIndex") >>= nTabIndex;
if (nTabIndex)
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.cxx b/xmloff/source/text/xmlcontentcontrolcontext.cxx
index caf1af04b8d7..2a7ef5b2eebe 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.cxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.cxx
@@ -152,6 +152,14 @@ void XMLContentControlContext::startFastElement(
m_aTag = rIter.toString();
break;
}
+ case XML_ELEMENT(LO_EXT, XML_ID):
+ {
+ if (sax::Converter::convertNumber(nTmp, rIter.toView()))
+ {
+ m_nId = nTmp;
+ }
+ break;
+ }
case XML_ELEMENT(LO_EXT, XML_TAB_INDEX):
{
if (sax::Converter::convertNumber(nTmp, rIter.toView()))
@@ -276,6 +284,11 @@ void XMLContentControlContext::endFastElement(sal_Int32)
xPropertySet->setPropertyValue("Tag", uno::Any(m_aTag));
}
+ if (m_nId)
+ {
+ xPropertySet->setPropertyValue("Id", uno::Any(m_nId));
+ }
+
if (m_nTabIndex)
{
xPropertySet->setPropertyValue("TabIndex", uno::Any(m_nTabIndex));
diff --git a/xmloff/source/text/xmlcontentcontrolcontext.hxx b/xmloff/source/text/xmlcontentcontrolcontext.hxx
index 44abe71d6a08..13c1e50f23fa 100644
--- a/xmloff/source/text/xmlcontentcontrolcontext.hxx
+++ b/xmloff/source/text/xmlcontentcontrolcontext.hxx
@@ -53,6 +53,7 @@ class XMLContentControlContext : public SvXMLImportContext
bool m_bDropDown = false;
OUString m_aAlias;
OUString m_aTag;
+ sal_Int32 m_nId = 0;
sal_uInt32 m_nTabIndex = 0;
OUString m_aLock;