sw/qa/extras/ooxmlexport/data/dropdown-in-cell.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 17 +++++++++++++++++ writerfilter/source/dmapper/DomainMapper.cxx | 13 ++++++++++--- writerfilter/source/ooxml/model.xml | 5 ++++- 4 files changed, 31 insertions(+), 4 deletions(-)
New commits: commit 419054c0f19acb323a0e51c7ef49a1a2d9f42ac8 Author: Miklos Vajna <vmik...@collabora.co.uk> Date: Thu Sep 18 15:47:59 2014 +0200 DOCX import: fix handling of dropdown SDT around cell There were two problems here: 1) The CT_SdtContentCell handlers didn't emit the usual NS_ooxml::LN_CT_SdtBlock_sdtContent / NS_ooxml::LN_CT_SdtBlock_sdtEndContent tokens, so the dropdown control was not created (and then was created with the wrong anchor). 2) In case the SDT was around the cell, the newline character was also added to the text of the currently selected entry, resulting in an invalid argument of SwXText::convertToTable(), so no table was created. Change-Id: I4806626181f40c6d26ff7b25f5dbb863967d8077 diff --git a/sw/qa/extras/ooxmlexport/data/dropdown-in-cell.docx b/sw/qa/extras/ooxmlexport/data/dropdown-in-cell.docx new file mode 100644 index 0000000..8abe25f Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/dropdown-in-cell.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index 4dd7dfc..92965f0 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -25,6 +25,7 @@ #include <com/sun/star/text/XTextFramesSupplier.hpp> #include <com/sun/star/text/XTextViewCursorSupplier.hpp> #include <com/sun/star/text/XTextSection.hpp> +#include <com/sun/star/text/XTextRangeCompare.hpp> #include <com/sun/star/style/CaseMap.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <com/sun/star/style/LineSpacing.hpp> @@ -253,6 +254,22 @@ DECLARE_OOXMLEXPORT_TEST(testEmptyAnnotationMark, "empty-annotation-mark.docx") } } +DECLARE_OOXMLEXPORT_TEST(testDropdownInCell, "dropdown-in-cell.docx") +{ + // First problem: table was missing from the document, this was 0. + uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xTables->getCount()); + + // Second problem: dropdown shape wasn't anchored inside the B1 cell. + uno::Reference<text::XTextContent> xShape(getShape(1), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xAnchor = xShape->getAnchor(); + uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY); + uno::Reference<text::XTextRange> xCell(xTable->getCellByName("B1"), uno::UNO_QUERY); + uno::Reference<text::XTextRangeCompare> xTextRangeCompare(xCell, uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(sal_Int16(0), xTextRangeCompare->compareRegionStarts(xAnchor, xCell)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx index 7c4fe8a..5fd818c 100644 --- a/writerfilter/source/dmapper/DomainMapper.cxx +++ b/writerfilter/source/dmapper/DomainMapper.cxx @@ -2949,10 +2949,17 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len) m_pImpl->setSdtEndDeferred(false); } + bool bNewLine = len == 1 && (sText[0] == 0x0d || sText[0] == 0x07); if (!m_pImpl->m_pSdtHelper->getDropDownItems().empty()) { - m_pImpl->m_pSdtHelper->getSdtTexts().append(sText); - return; + if (bNewLine) + // Dropdown control has single-line texts, so in case of newline, create the control. + m_pImpl->m_pSdtHelper->createDropDownControl(); + else + { + m_pImpl->m_pSdtHelper->getSdtTexts().append(sText); + return; + } } // Form controls are not allowed in headers / footers; see sw::DocumentContentOperationsManager::InsertDrawObj() else if (!m_pImpl->m_pSdtHelper->getDateFormat().isEmpty() && !IsInHeaderFooter()) @@ -3005,7 +3012,7 @@ void DomainMapper::lcl_utext(const sal_uInt8 * data_, size_t len) { m_pImpl->getTableManager().utext(data_, len); - if(len == 1 && (sText[0] == 0x0d || sText[0] == 0x07)) + if (bNewLine) { if (m_pImpl->m_bIgnoreNextPara) { diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml index 0ae1df8..f194a13 100644 --- a/writerfilter/source/ooxml/model.xml +++ b/writerfilter/source/ooxml/model.xml @@ -18030,7 +18030,10 @@ <resource name="CT_SdtContentRun" resource="Stream"/> <resource name="CT_SdtContentBlock" resource="Stream"/> <resource name="CT_SdtContentRow" resource="Stream"/> - <resource name="CT_SdtContentCell" resource="Stream"/> + <resource name="CT_SdtContentCell" resource="Stream"> + <action name="start" action="startSdt"/> + <action name="end" action="endSdt"/> + </resource> <resource name="CT_SdtBlock" resource="Stream"> <element name="sdtPr" tokenid="ooxml:CT_SdtBlock_sdtPr"/> <element name="sdtEndPr" tokenid="ooxml:CT_SdtBlock_sdtEndPr"/> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits