sw/qa/extras/ooxmlexport/data/tdf138093.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport19.cxx   |   55 +++++++++++++++++++++++++++
 writerfilter/source/dmapper/SdtHelper.cxx    |    4 +
 3 files changed, 58 insertions(+), 1 deletion(-)

New commits:
commit e898f95bfab16ddd9b04e516293cb6eb7e0a3847
Author:     Czeber László Ádám <czeber.laszloa...@nisz.hu>
AuthorDate: Tue Apr 18 15:01:14 2023 +0200
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Apr 26 10:55:29 2023 +0200

    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 <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>

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
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/tdf138093.docx differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
index 9e01ca72ca17..729fd09724a9 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport19.cxx
@@ -33,6 +33,8 @@
 #include <flyfrms.hxx>
 #include <sortedobjs.hxx>
 #include <txtfrm.hxx>
+#include <IDocumentMarkAccess.hxx>
+#include <xmloff/odffields.hxx>
 
 class Test : public SwModelTestBase
 {
@@ -894,6 +896,59 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf133363)
                 "0");
 }
 
+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());
+    }
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/SdtHelper.cxx 
b/writerfilter/source/dmapper/SdtHelper.cxx
index ce2cb3e9b136..f9cedcbf19eb 100644
--- a/writerfilter/source/dmapper/SdtHelper.cxx
+++ b/writerfilter/source/dmapper/SdtHelper.cxx
@@ -381,8 +381,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);

Reply via email to