sw/qa/writerfilter/dmapper/PropertyMap.cxx | 37 +++++++++++++++++++++++++ sw/source/writerfilter/dmapper/PropertyMap.cxx | 5 ++- 2 files changed, 40 insertions(+), 2 deletions(-)
New commits: commit 54410768676b247c2524aae229574527c67dc1d5 Author: Justin Luth <[email protected]> AuthorDate: Wed Jul 10 19:26:20 2024 -0400 Commit: Xisco Fauli <[email protected]> CommitDate: Thu Jul 11 18:06:27 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 (cherry picked from commit aaf93cd9629acd476284a4933a656ddd188a80aa) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170349 Reviewed-by: Xisco Fauli <[email protected]> diff --git a/sw/qa/writerfilter/dmapper/PropertyMap.cxx b/sw/qa/writerfilter/dmapper/PropertyMap.cxx index d0e8533e1acb..2952506c8647 100644 --- a/sw/qa/writerfilter/dmapper/PropertyMap.cxx +++ b/sw/qa/writerfilter/dmapper/PropertyMap.cxx @@ -175,6 +175,43 @@ CPPUNIT_TEST_FIXTURE(Test, testPasteHeaderDisable) // Then make sure the header stays on: CPPUNIT_ASSERT(xStyle->getPropertyValue("HeaderIsOn").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 6c169b610d4b..b0cefec30ad4 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; @@ -581,7 +582,7 @@ void SectionPropertyMap::setHeaderFooterProperties(DomainMapper_Impl& rDM_Impl) m_aPageStyle->setPropertyValue(getPropertyName(PROP_FIRST_IS_SHARED), 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)); }
