summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJaume Pujantell <jaume.pujantell@collabora.com>2023-09-13 08:58:21 +0200
committerJaume Pujantell <jaume.pujantell@collabora.com>2023-10-11 15:19:58 +0200
commit5082d50d24c3fec4487c724a15eb0d54a82ecd0d (patch)
tree8cae9bc61647c7ba87b53c28d8d4e11269c0fe2c /sw
parentaf9c3ed6f748781f2a77e676ffe740992788969b (diff)
writerfilter: use content controls for text in block SDTs
Text inside block SDTs was shown as Text Fields wich ignored properties such as alias and formatting. Now those texts are imported as content controls like in the case of run SDTs. Added the ability for content controls to remember and export the "multiline" property of block SDT text. Some existing tests have been changed due to some different export results. Change-Id: Ice1eb4ca6dd53c99d5abb239371f8ac896c3b6e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/156867 Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Tested-by: Jenkins
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/formatcontentcontrol.hxx9
-rw-r--r--sw/inc/unoprnms.hxx1
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport17.cxx30
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport19.cxx5
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport3.cxx3
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx2
-rw-r--r--sw/source/core/txtnode/attrcontentcontrol.cxx3
-rw-r--r--sw/source/core/unocore/unocontentcontrol.cxx28
-rw-r--r--sw/source/core/unocore/unomap1.cxx1
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx6
10 files changed, 59 insertions, 29 deletions
diff --git a/sw/inc/formatcontentcontrol.hxx b/sw/inc/formatcontentcontrol.hxx
index 190d0bd540fe..cffe326d0703 100644
--- a/sw/inc/formatcontentcontrol.hxx
+++ b/sw/inc/formatcontentcontrol.hxx
@@ -173,7 +173,7 @@ class SW_DLLPUBLIC SwContentControl final : public sw::BroadcastingModify
/// The appearance: just remembered.
OUString m_aAppearance;
- /// The alias: just remembered.
+ /// The alias.
OUString m_aAlias;
/// The tag: just remembered.
@@ -188,6 +188,9 @@ class SW_DLLPUBLIC SwContentControl final : public sw::BroadcastingModify
/// The control and content locks: mostly just remembered.
OUString m_aLock;
+ /// The multiline property: just remembered.
+ OUString m_aMultiLine;
+
/// Stores a list item index, in case the doc model is not yet updated.
// i.e. temporarily store the selected item until the text is inserted by GotoContentControl.
std::optional<size_t> m_oSelectedListItem;
@@ -389,6 +392,10 @@ public:
// At the implementation level, define whether the user can directly modify the contents.
bool GetReadWrite() const { return m_bReadWrite; }
+ void SetMultiLine(const OUString& rMultiline) { m_aMultiLine = rMultiline; }
+
+ const OUString& GetMultiLine() const { return m_aMultiLine; }
+
SwContentControlType GetType() const;
};
diff --git a/sw/inc/unoprnms.hxx b/sw/inc/unoprnms.hxx
index 6553153b459d..630028f0e7a6 100644
--- a/sw/inc/unoprnms.hxx
+++ b/sw/inc/unoprnms.hxx
@@ -941,6 +941,7 @@ inline constexpr OUStringLiteral UNO_NAME_TAG = u"Tag";
inline constexpr OUStringLiteral UNO_NAME_ID = u"Id";
inline constexpr OUStringLiteral UNO_NAME_TAB_INDEX = u"TabIndex";
inline constexpr OUStringLiteral UNO_NAME_LOCK = u"Lock";
+inline constexpr OUStringLiteral UNO_NAME_MULTILINE = u"MultiLine";
inline constexpr OUStringLiteral UNO_NAME_DATE_STRING = u"DateString";
inline constexpr OUStringLiteral UNO_NAME_PARA_ID = u"ParaId";
inline constexpr OUStringLiteral UNO_NAME_PARA_ID_PARENT = u"ParaIdParent";
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 90c3c750c53c..6d3d0452740a 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -683,28 +683,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf123642_BookmarkAtDocEnd, "tdf123642.docx")
DECLARE_OOXMLEXPORT_TEST(testTdf148361, "tdf148361.docx")
{
- if (isExported())
- {
- // Block SDT is turned into run SDT on export, so the next import will have this as content
- // control, not as a field.
- OUString aActual = getParagraph(1)->getString();
- // This was "itadmin".
- CPPUNIT_ASSERT_EQUAL(OUString("itadmin"), aActual);
- }
- else
- {
- // Refresh fields and ensure cross-reference to numbered para is okay
- uno::Reference<text::XTextFieldsSupplier> xTextFieldsSupplier(mxComponent, uno::UNO_QUERY);
- uno::Reference<container::XEnumerationAccess> xFieldsAccess(xTextFieldsSupplier->getTextFields());
-
- uno::Reference<container::XEnumeration> xFields(xFieldsAccess->createEnumeration());
- CPPUNIT_ASSERT(xFields->hasMoreElements());
-
- uno::Reference<text::XTextField> xTextField1(xFields->nextElement(), uno::UNO_QUERY);
- CPPUNIT_ASSERT_EQUAL(OUString("itadmin"), xTextField1->getPresentation(false));
- }
+ // Plain text Block SDT is imported as content control
+ OUString aActual = getParagraph(1)->getString();
+ // This was "itadmin".
+ CPPUNIT_ASSERT_EQUAL(OUString("itadmin"), aActual);
- OUString aActual = getParagraph(2)->getString();
+ aActual = getParagraph(2)->getString();
// This was "itadmin".
CPPUNIT_ASSERT_EQUAL(OUString("[Type text]"), aActual);
}
@@ -936,9 +920,7 @@ DECLARE_OOXMLEXPORT_TEST(testTdf81507, "tdf81507.docx")
// Ensure that we have <w:text/>
assertXPath(pXmlDoc, "/w:document/w:body/w:p[3]/w:sdt/w:sdtPr/w:text");
-
- // Ensure that we have no <w:text/> (not quite correct case, but to ensure import/export are okay)
- assertXPath(pXmlDoc, "/w:document/w:body/w:p[4]/w:sdt/w:sdtPr/w:text", 0);
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p[4]/w:sdt/w:sdtPr/w:text");
}
DECLARE_OOXMLEXPORT_TEST(testTdf139948, "tdf139948.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
index 275891d4f58b..fbd3bdb4aaaf 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
@@ -1108,7 +1108,10 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf157136)
{
// 1st paragraph - block content control
auto xRun = getRun(getParagraph(1), 1);
- CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text.\r"), xRun->getString());
+ auto xContentControl
+ = getProperty<css::uno::Reference<css::text::XTextRange>>(xRun, "ContentControl");
+ CPPUNIT_ASSERT_EQUAL(OUString("Click or tap here to enter text."),
+ xContentControl->getString());
// Without the fix in place, this would fail with
// - Expected: Placeholder Text
// - Actual :
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
index ae1aa909d5fe..24b2ee333e49 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport3.cxx
@@ -1003,7 +1003,8 @@ CPPUNIT_TEST_FIXTURE(Test, testGlossaryWithEmail)
// preserve the ShowingPlaceholder setting on both block SDTs.
pXmlDoc = parseExport("word/document.xml");
- assertXPath(pXmlDoc,"/w:document/w:body/w:p/w:sdt/w:sdtPr/w:showingPlcHdr", 2);
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:sdt/w:sdtPr/w:showingPlcHdr", 1);
+ assertXPath(pXmlDoc, "/w:document/w:body/w:p/w:hyperlink/w:sdt/w:sdtPr/w:showingPlcHdr", 1);
}
DECLARE_OOXMLEXPORT_TEST(testFdo71785, "fdo71785.docx")
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index c0578ad31a16..a7ffaa2ae7f5 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -636,7 +636,7 @@ CPPUNIT_TEST_FIXTURE(Test, testSdtCompanyMultipara)
// Here is just a simple text node, so there should be either one or zero paragraph
// (in this case sdt element is inside paragraph)
assertXPath(pXmlDoc, "//w:sdtContent/w:p", 0);
- assertXPath(pXmlDoc, "//w:sdtContent/w:r", 1);
+ assertXPath(pXmlDoc, "//w:sdtContent/w:r", 2);
}
DECLARE_OOXMLEXPORT_TEST(testFixedDateFields, "fixed-date-field.docx")
diff --git a/sw/source/core/txtnode/attrcontentcontrol.cxx b/sw/source/core/txtnode/attrcontentcontrol.cxx
index bc62606f2d97..2dd007f480b3 100644
--- a/sw/source/core/txtnode/attrcontentcontrol.cxx
+++ b/sw/source/core/txtnode/attrcontentcontrol.cxx
@@ -220,6 +220,7 @@ SwContentControl::SwContentControl(SwFormatContentControl* pFormat)
SetId(pOther->m_nId);
SetTabIndex(pOther->m_nTabIndex);
SetLock(pOther->m_aLock);
+ SetMultiLine(pOther->m_aMultiLine);
}
SwContentControl::~SwContentControl() {}
@@ -605,6 +606,8 @@ void SwContentControl::dumpAsXml(xmlTextWriterPtr pWriter) const
BAD_CAST(OString::number(m_nTabIndex).getStr()));
(void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("lock"),
BAD_CAST(m_aLock.toUtf8().getStr()));
+ (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("multiline"),
+ BAD_CAST(m_aMultiLine.toUtf8().getStr()));
if (!m_aListItems.empty())
{
diff --git a/sw/source/core/unocore/unocontentcontrol.cxx b/sw/source/core/unocore/unocontentcontrol.cxx
index 541fc46699b3..8492e0fc94f7 100644
--- a/sw/source/core/unocore/unocontentcontrol.cxx
+++ b/sw/source/core/unocore/unocontentcontrol.cxx
@@ -176,6 +176,7 @@ public:
sal_Int32 m_nId;
sal_uInt32 m_nTabIndex;
OUString m_aLock;
+ OUString m_aMultiLine;
Impl(SwXContentControl& rThis, SwDoc& rDoc, SwContentControl* pContentControl,
css::uno::Reference<SwXText> xParentText, std::unique_ptr<const TextRangeList_t> pPortions)
@@ -475,6 +476,7 @@ void SwXContentControl::AttachImpl(const uno::Reference<text::XTextRange>& xText
pContentControl->SetId(m_pImpl->m_nId);
pContentControl->SetTabIndex(m_pImpl->m_nTabIndex);
pContentControl->SetLock(m_pImpl->m_aLock);
+ pContentControl->SetMultiLine(m_pImpl->m_aMultiLine);
SwFormatContentControl aContentControl(pContentControl, nWhich);
bool bSuccess
@@ -1010,6 +1012,21 @@ void SAL_CALL SwXContentControl::setPropertyValue(const OUString& rPropertyName,
}
}
}
+ else if (rPropertyName == UNO_NAME_MULTILINE)
+ {
+ OUString aValue;
+ if (rValue >>= aValue)
+ {
+ if (m_pImpl->m_bIsDescriptor)
+ {
+ m_pImpl->m_aMultiLine = aValue;
+ }
+ else
+ {
+ m_pImpl->m_pContentControl->SetMultiLine(aValue);
+ }
+ }
+ }
else
{
throw beans::UnknownPropertyException();
@@ -1305,6 +1322,17 @@ uno::Any SAL_CALL SwXContentControl::getPropertyValue(const OUString& rPropertyN
aRet <<= m_pImpl->m_pContentControl->GetLock();
}
}
+ else if (rPropertyName == UNO_NAME_MULTILINE)
+ {
+ if (m_pImpl->m_bIsDescriptor)
+ {
+ aRet <<= m_pImpl->m_aMultiLine;
+ }
+ else
+ {
+ aRet <<= m_pImpl->m_pContentControl->GetMultiLine();
+ }
+ }
else
{
throw beans::UnknownPropertyException();
diff --git a/sw/source/core/unocore/unomap1.cxx b/sw/source/core/unocore/unomap1.cxx
index aae854fc24e0..ba165289c177 100644
--- a/sw/source/core/unocore/unomap1.cxx
+++ b/sw/source/core/unocore/unomap1.cxx
@@ -1053,6 +1053,7 @@ o3tl::span<const SfxItemPropertyMapEntry> SwUnoPropertyMapProvider::GetContentCo
{ UNO_NAME_ID, 0, cppu::UnoType<sal_Int32>::get(), PROPERTY_NONE, 0 },
{ UNO_NAME_TAB_INDEX, 0, cppu::UnoType<sal_uInt32>::get(), PROPERTY_NONE, 0 },
{ UNO_NAME_LOCK, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
+ { UNO_NAME_MULTILINE, 0, cppu::UnoType<OUString>::get(), PROPERTY_NONE, 0 },
{ UNO_NAME_DATE_STRING, 0, cppu::UnoType<OUString>::get(), PropertyAttribute::READONLY, 0 },
};
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 9c67855acbdd..4a4d440abc44 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -2739,7 +2739,11 @@ void DocxAttributeOutput::WriteContentControlStart()
m_pSerializer->endElementNS(XML_w, XML_date);
}
- if (m_pContentControl->GetPlainText())
+ if (!m_pContentControl->GetMultiLine().isEmpty())
+ {
+ m_pSerializer->singleElementNS(XML_w, XML_text, FSNS(XML_w, XML_multiLine), m_pContentControl->GetMultiLine());
+ }
+ else if (m_pContentControl->GetPlainText())
{
m_pSerializer->singleElementNS(XML_w, XML_text);
}