tdf#126792: DOCX legacy drop-downs are only supposed to hold 25 items, DOCX
Truncate item list if the MSO limit is exceeded.
Reviewed-on: https://gerrit.libreoffice.org/77844
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
(cherry picked from commit 8d84f32d55df06c2944da78e2b779de2dba21d50)
Change-Id: I21fd63fd2b8d6c8fe76500e1cdd468d4692612c1
Reviewed-on: https://gerrit.libreoffice.org/77869
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/include/xmloff/odffields.hxx b/include/xmloff/odffields.hxx
index 27525fb..fd1b6b4 100644
--- a/include/xmloff/odffields.hxx
+++ b/include/xmloff/odffields.hxx
@@ -32,6 +32,7 @@
#define ODF_FORMDROPDOWN "vnd.oasis.opendocument.field.FORMDROPDOWN"
#define ODF_FORMDROPDOWN_LISTENTRY "Dropdown_ListEntry"
#define ODF_FORMDROPDOWN_RESULT "Dropdown_Selected"
#define ODF_FORMDROPDOWN_ENTRY_COUNT_LIMIT 25
#define ODF_TOC "vnd.oasis.opendocument.field.TOC"
diff --git a/sw/qa/extras/ooxmlexport/data/tdf126792.odt b/sw/qa/extras/ooxmlexport/data/tdf126792.odt
new file mode 100644
index 0000000..7eb43e7
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf126792.odt
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
index b5b6b60..1765a28 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlfieldexport.cxx
@@ -8,6 +8,9 @@
*/
#include <swmodeltestbase.hxx>
#include <xmloff/odffields.hxx>
#include <IDocumentMarkAccess.hxx>
#include <IMark.hxx>
class Test : public SwModelTestBase
{
@@ -664,6 +667,33 @@ DECLARE_OOXMLEXPORT_TEST( testTdf66401, "tdf66401.docx")
}
}
DECLARE_OOXMLEXPORT_TEST(testDropDownFieldEntryLimit, "tdf126792.odt" )
{
// In MSO, there is a limit of 25 for the items in a drop-down form field.
// So we truncate the list of items to not exceed this limit.
SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument *>(mxComponent.get());
CPPUNIT_ASSERT(pTextDoc);
SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), pMarkAccess->getAllMarksCount());
::sw::mark::IFieldmark* pFieldmark
= dynamic_cast<::sw::mark::IFieldmark*>(*pMarkAccess->getAllMarksBegin());
CPPUNIT_ASSERT(pFieldmark);
CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDROPDOWN), pFieldmark->GetFieldname());
const sw::mark::IFieldmark::parameter_map_t* const pParameters = pFieldmark->GetParameters();
auto pListEntries = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
CPPUNIT_ASSERT(bool(pListEntries != pParameters->end()));
css::uno::Sequence<OUString> vListEntries;
pListEntries->second >>= vListEntries;
if (!mbExported)
CPPUNIT_ASSERT_EQUAL(sal_Int32(26), vListEntries.getLength());
else
CPPUNIT_ASSERT_EQUAL(sal_Int32(25), vListEntries.getLength());
}
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 2bdbc30..ff208c9 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -1840,6 +1840,9 @@ void DocxAttributeOutput::WriteFFData( const FieldInfos& rInfos )
OUString sName, sSelected;
params.extractParam( ODF_FORMDROPDOWN_LISTENTRY, vListEntries );
if (vListEntries.getLength() > ODF_FORMDROPDOWN_ENTRY_COUNT_LIMIT)
vListEntries = uno::Sequence< OUString>(vListEntries.getArray(), ODF_FORMDROPDOWN_ENTRY_COUNT_LIMIT);
sName = params.getName();
sal_Int32 nSelectedIndex = 0;