sw/qa/writerfilter/dmapper/PropertyMap.cxx | 37 +++++++++++++++++++++++++ sw/source/writerfilter/dmapper/PropertyMap.cxx | 5 ++- 2 files changed, 40 insertions(+), 2 deletions(-)
New commits: commit aaf93cd9629acd476284a4933a656ddd188a80aa Author: Justin Luth <[email protected]> AuthorDate: Wed Jul 10 19:26:20 2024 -0400 Commit: Tomaž Vajngerl <[email protected]> CommitDate: Thu Jul 11 12:33:07 2024 +0200 tdf#160139 sw RTF paste: don't empty headers/footers Regression from quikee's 24.2 commit 4b0fa253a4540f5461397815d290586f9ddabe61 tdf#136472 adjust ooxml import to handle first header/footer RTF paste is particularly nasty because it calls CloseSectionGroup, which is rather strange for just pasting some characters... Fix the problem by leaving the paste alone: we already omit a number of actions in this case, and was similarly done initially by quikee in copyHeaderFooter. setHeaderFooterProperties() was newly added by quikee, so relatively safe to start avoiding on paste. make CppunitTest_sw_writerfilter_dmapper \ CPPUNIT_TEST_NAME=testPasteHeaderEmptied Change-Id: Iad997481a75bb971f9e71373175134cbec9aa7d9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170328 Reviewed-by: Tomaž Vajngerl <[email protected]> Tested-by: Jenkins diff --git a/sw/qa/writerfilter/dmapper/PropertyMap.cxx b/sw/qa/writerfilter/dmapper/PropertyMap.cxx index 3a564d886f1f..83a3b660c3c9 100644 --- a/sw/qa/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/qa/writerfilter/dmapper/PropertyMap.cxx @@ -181,6 +181,43 @@ CPPUNIT_TEST_FIXTURE(Test, testPasteHeaderDisable) // Then make sure the header stays on: CPPUNIT_ASSERT(xStyle->getPropertyValue(u"HeaderIsOn"_ustr).get<bool>()); } + +CPPUNIT_TEST_FIXTURE(Test, testPasteHeaderEmptied) +{ + // Given an empty document with a turned on footer with content: + loadFromFile(u"page-break-footer-table.docx"); + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference<container::XNameAccess> xStyleFamily( + xStyleFamilies->getByName(u"PageStyles"_ustr), uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName(u"Standard"_ustr), + uno::UNO_QUERY); + + // When pasting RTF content: + uno::Reference<text::XTextDocument> xTextDocument(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextRange> xText = xTextDocument->getText(); + uno::Reference<text::XTextRange> xBodyEnd = xText->getEnd(); + uno::Reference<document::XFilter> xFilter( + m_xSFactory->createInstance(u"com.sun.star.comp.Writer.RtfFilter"_ustr), uno::UNO_QUERY); + uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY); + xImporter->setTargetDocument(mxComponent); + std::unique_ptr<SvStream> pStream(new SvMemoryStream); + pStream->WriteOString("{\rtf1 paste}"); + pStream->Seek(0); + uno::Reference<io::XStream> xStream(new utl::OStreamWrapper(std::move(pStream))); + uno::Sequence aDescriptor{ comphelper::makePropertyValue(u"InputStream"_ustr, xStream), + comphelper::makePropertyValue(u"InsertMode"_ustr, true), + comphelper::makePropertyValue(u"TextInsertModeRange"_ustr, + xBodyEnd) }; + CPPUNIT_ASSERT(xFilter->filter(aDescriptor)); + + // Then make sure the header retains its contents: + uno::Reference<text::XTextRange> xFooterText(xStyle->getPropertyValue(u"FooterText"_ustr), + uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(u"Odd page footer"_ustr, xFooterText->getString()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/writerfilter/dmapper/PropertyMap.cxx b/sw/source/writerfilter/dmapper/PropertyMap.cxx index c4754c6095ee..76e195eeb486 100644 --- a/sw/source/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/source/writerfilter/dmapper/PropertyMap.cxx @@ -530,7 +530,8 @@ void SectionPropertyMap::removeXTextContent(uno::Reference<text::XText> const& r */ void SectionPropertyMap::setHeaderFooterProperties(DomainMapper_Impl& rDM_Impl) { - if (!m_aPageStyle.is()) + // do not alter header/footer during copy/paste + if (!m_aPageStyle.is() || !rDM_Impl.IsNewDoc()) return; bool bHasHeader = false; @@ -593,7 +594,7 @@ void SectionPropertyMap::setHeaderFooterProperties(DomainMapper_Impl& rDM_Impl) m_aPageStyle->setPropertyValue(sFirstIsShared, uno::Any(!m_bTitlePage)); bool bHadFirstHeader = m_bHadFirstHeader && m_bTitlePage; - if (bHasHeader && !bHadFirstHeader && !m_bHadLeftHeader && !m_bHadRightHeader && rDM_Impl.IsNewDoc()) + if (bHasHeader && !bHadFirstHeader && !m_bHadLeftHeader && !m_bHadRightHeader) { m_aPageStyle->setPropertyValue(sHeaderIsOn, uno::Any(false)); }
