summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <Michael.Stahl@cib.de>2020-03-06 13:10:48 +0100
committerMichael Stahl <michael.stahl@cib.de>2020-03-06 16:05:59 +0100
commit1f5af453b5994c9e8ccd0756882b98715c75114b (patch)
treea27bebf13b28d0306543dc7b587fa198e257de04
parentbdbb63abd40b55e696856a53a959b69215a56d54 (diff)
sw: DOCX export: fix bookmark inside sdtDropDown
Word refuses to open a document that has a w:bookmarkEnd inside w:sdtContent but with no text content following it. It turns out that the bookmark position is wrong anyway, it should end before the text according to Writer's model. It shouldn't make a difference whether the end is inside the sdtContent or preceding the SDT, so write the text content of the SDT from the EndField_Impl(). Another idea would be to move the writing of bookmarks in EndRun() before the StartField_Impl() but who knows what that would break. (regression from d55b26a093bdbced08985dbc7113190b52a8bc66) Change-Id: I476c0829814b061d80811cc6817923ee06013a26 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/90100 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.stahl@cib.de>
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport13.cxx1
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.cxx24
-rw-r--r--sw/source/filter/ww8/docxattributeoutput.hxx1
3 files changed, 24 insertions, 2 deletions
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
index ccb2c196ae58..67745700cc04 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport13.cxx
@@ -480,6 +480,7 @@ DECLARE_OOXMLEXPORT_TEST(testInputListExport, "tdf122186_input_list.odt")
CPPUNIT_ASSERT_EQUAL(OUString("1"), items[0]);
CPPUNIT_ASSERT_EQUAL(OUString("2"), items[1]);
CPPUNIT_ASSERT_EQUAL(OUString("3"), items[2]);
+ CPPUNIT_ASSERT_EQUAL(OUString("1"), getProperty<OUString>(xPropertySet, "DefaultText"));
}
}
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 3686dba83df7..6b8d1f9a1085 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1960,6 +1960,17 @@ void DocxAttributeOutput::WriteSdtDropDownStart(
m_pSerializer->endElementNS(XML_w, XML_sdtPr);
m_pSerializer->startElementNS(XML_w, XML_sdtContent);
+}
+
+void DocxAttributeOutput::WriteSdtDropDownEnd(OUString const& rSelected,
+ uno::Sequence<OUString> const& rListItems)
+{
+ // note: rSelected might be empty?
+ sal_Int32 nId = comphelper::findValue(rListItems, rSelected);
+ if (nId == -1)
+ {
+ nId = 0;
+ }
// the lastValue only identifies the entry in the list, also export
// currently selected item's displayText as run content (if one exists)
@@ -1971,6 +1982,8 @@ void DocxAttributeOutput::WriteSdtDropDownStart(
m_pSerializer->endElementNS(XML_w, XML_t);
m_pSerializer->endElementNS(XML_w, XML_r);
}
+
+ WriteSdtEnd();
}
void DocxAttributeOutput::StartField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos const & rInfos, bool bWriteRun )
@@ -2217,12 +2230,19 @@ void DocxAttributeOutput::DoWriteFieldRunProperties( const SwTextNode * pNode, s
void DocxAttributeOutput::EndField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos& rInfos )
{
- if (rInfos.eType == ww::eFORMDATE
- || (rInfos.eType == ww::eFORMDROPDOWN && rInfos.pField))
+ if (rInfos.eType == ww::eFORMDATE)
{
WriteSdtEnd();
return;
}
+ if (rInfos.eType == ww::eFORMDROPDOWN && rInfos.pField)
+ {
+ // write selected item from End not Start to ensure that any bookmarks
+ // precede it
+ SwDropDownField const& rField(*static_cast<SwDropDownField const*>(rInfos.pField.get()));
+ WriteSdtDropDownEnd(rField.GetSelectedItem(), rField.GetItemSequence());
+ return;
+ }
// The command has to be written before for the hyperlinks
if ( rInfos.pField )
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index 8b7b8ac3c8cf..dc77baf08c0b 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -719,6 +719,7 @@ private:
void WriteFormDateStart(const OUString& sFullDate, const OUString& sDateFormat, const OUString& sLang);
void WriteSdtDropDownStart(OUString const& rName, OUString const& rSelected, uno::Sequence<OUString> const& rListItems);
+ void WriteSdtDropDownEnd(OUString const& rSelected, uno::Sequence<OUString> const& rListItems);
void WriteSdtEnd();
void StartField_Impl( const SwTextNode* pNode, sal_Int32 nPos, FieldInfos const & rInfos, bool bWriteRun = false );