summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCzeber László Ádám <czeber.laszloadam@nisz.hu>2023-04-18 15:01:14 +0200
committerXisco Fauli <xiscofauli@libreoffice.org>2023-04-28 10:53:50 +0200
commit63e1a98e07b12edd967cea48f23e307cf47efea8 (patch)
treeb3c3477fbd3ff6fe34b415b0bf4d81359a36ac14
parentf2034af7eee1174481c4220decea51d00e8b8ab0 (diff)
tdf#138093 DOCX import: fix broken date selector control in table
In tables, first character of the text value of the date selector control left outside of the control during the import, resulting broken date selector, e.g. 2[023] instead of [2023]. (Clicking on the broken control, according to the year *023*, the selector listed the lowest possible value, year 1900, and selecting that, the result became 2[1900].) Note: the fix works well with nested tables, too, so likely the condition with tables is obsolete. Perhaps regression from commit b36ef83ea59eeaca239e58b95aa0b1acdcb99efc "tdf126701: MSForms: Fix import of date field at the end of the paragraph." and commit 68e1be4ccbb90ee9a788962219a88312c4ffbea2 "MSForms: Rework text-based date form field's representation". Change-Id: Ib217a3a06522bfe7b3b0fbc884f98504f628fc59 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150575 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/151053 Tested-by: Jenkins
-rw-r--r--sw/qa/extras/ooxmlexport/data/tdf138093.docxbin0 -> 39532 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport17.cxx56
-rw-r--r--writerfilter/source/dmapper/SdtHelper.cxx4
3 files changed, 59 insertions, 1 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/tdf138093.docx b/sw/qa/extras/ooxmlexport/data/tdf138093.docx
new file mode 100644
index 000000000000..097fbb1351cc
--- /dev/null
+++ b/sw/qa/extras/ooxmlexport/data/tdf138093.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index ebb5ae15a87e..2f412a7d85f1 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -23,6 +23,7 @@
#include <com/sun/star/drawing/XShapes.hpp>
#include <com/sun/star/util/XRefreshable.hpp>
#include <com/sun/star/text/XTextDocument.hpp>
+#include <com/sun/star/text/XTextTable.hpp>
#include <com/sun/star/frame/XStorable.hpp>
#include <com/sun/star/awt/FontSlant.hpp>
#include <com/sun/star/awt/FontWeight.hpp>
@@ -38,6 +39,7 @@
#include <wrtsh.hxx>
#include <IDocumentLayoutAccess.hxx>
#include <rootfrm.hxx>
+#include <xmloff/odffields.hxx>
class Test : public SwModelTestBase
{
@@ -88,6 +90,60 @@ DECLARE_OOXMLEXPORT_TEST(testTdf148380_createField, "tdf148380_createField.docx"
CPPUNIT_ASSERT_EQUAL(OUString("yesterday at noon"), xField->getPresentation(false));
}
+DECLARE_OOXMLEXPORT_TEST(testTdf138093, "tdf138093.docx")
+{
+ if (isExported())
+ {
+ xmlDocUniquePtr pXmlDoc = parseExport("word/document.xml");
+ assertXPath(pXmlDoc, "//w:sdt", 3);
+ uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
+ uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables(),
+ uno::UNO_QUERY);
+ uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
+ uno::Reference<table::XCell> xCell = xTable->getCellByName("B1");
+ uno::Reference<container::XEnumerationAccess> xParagraphsAccess(xCell, uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xParagraphs
+ = xParagraphsAccess->createEnumeration();
+ uno::Reference<container::XEnumerationAccess> xParagraph(xParagraphs->nextElement(),
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xPortions = xParagraph->createEnumeration();
+ uno::Reference<beans::XPropertySet> xTextPortion(xPortions->nextElement(), uno::UNO_QUERY);
+
+ OUString aPortionType;
+ xTextPortion->getPropertyValue("TextPortionType") >>= aPortionType;
+ CPPUNIT_ASSERT_EQUAL(OUString("ContentControl"), aPortionType);
+
+ uno::Reference<text::XTextContent> xContentControl;
+ xTextPortion->getPropertyValue("ContentControl") >>= xContentControl;
+ uno::Reference<beans::XPropertySet> xContentControlProps(xContentControl, uno::UNO_QUERY);
+ bool bDate{};
+ xContentControlProps->getPropertyValue("Date") >>= bDate;
+ CPPUNIT_ASSERT(bDate);
+ uno::Reference<container::XEnumerationAccess> xContentControlEnumAccess(xContentControl,
+ uno::UNO_QUERY);
+ uno::Reference<container::XEnumeration> xContentControlEnum
+ = xContentControlEnumAccess->createEnumeration();
+ uno::Reference<text::XTextRange> xTextPortionRange(xContentControlEnum->nextElement(),
+ uno::UNO_QUERY);
+ CPPUNIT_ASSERT_EQUAL(OUString("2017"), xTextPortionRange->getString());
+ }
+ else
+ {
+ SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+ CPPUNIT_ASSERT(pTextDoc);
+ SwDoc* pDoc = pTextDoc->GetDocShell()->GetDoc();
+ IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+ CPPUNIT_ASSERT_EQUAL(sal_Int32(2), pMarkAccess->getAllMarksCount());
+
+ ::sw::mark::IDateFieldmark* pFieldmark
+ = dynamic_cast<::sw::mark::IDateFieldmark*>(*pMarkAccess->getAllMarksBegin());
+ CPPUNIT_ASSERT(pFieldmark);
+ CPPUNIT_ASSERT_EQUAL(OUString(ODF_FORMDATE), pFieldmark->GetFieldname());
+ CPPUNIT_ASSERT_EQUAL(OUString("2017"), pFieldmark->GetContent());
+ }
+}
+
+
DECLARE_OOXMLEXPORT_TEST(testTdf148380_fldLocked, "tdf148380_fldLocked.docx")
{
getParagraph(2, "4/5/2022 4:29:00 PM");
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx b/writerfilter/source/dmapper/SdtHelper.cxx
index a6a6b6cb08f8..f71af1340884 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -380,8 +380,10 @@ void SdtHelper::createDateContentControl()
try
{
xCrsr->gotoRange(m_xDateFieldStartRange, false);
+ // tdf#138093: Date selector reset, if placed inside table
+ // Modified to XOR relationship
bool bIsInTable = (m_rDM_Impl.hasTableManager() && m_rDM_Impl.getTableManager().isInTable())
- || (m_rDM_Impl.m_nTableDepth > 0);
+ != (m_rDM_Impl.m_nTableDepth > 0);
if (bIsInTable)
xCrsr->goRight(1, false);
xCrsr->gotoEnd(true);