diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2024-03-22 16:47:23 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2024-03-22 19:35:40 +0100 |
commit | c900850742efd4e1fb7c79c13c1b9a17fcd4981d (patch) | |
tree | 982447918d299517ecede0dd5711bfc997499ac3 | |
parent | c469e786be9345fc76e5cc62fd23dd317db53c02 (diff) |
Relatted: tdf#160139 RTF paste: don't turn off headers/footers
Regression from commit d918beda2ab42668014b0dd42996b6ccc97e8c3a
(tdf#158814 DOCX import: fix unwanted header with type="first" & no
titlePg, 2024-02-05), pasting shape text into the body text of Writer
turned off the header, which was not intentional.
The original use-case was DOCX/RTF import, and the paste case was just
not considered.
Fix the problem by leaving the paste alone: we already omit a number of
actions in this case (e.g. not overwrite styles), don't turn off
headers, either.
Note that the original problem is wider: we would probably need to track
what page styles are created and only touch those, or something similar.
Change-Id: If08fa7956e98766d5807332c5c0baa25b46afe38
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/165191
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Tested-by: Jenkins
-rw-r--r-- | writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx | 40 | ||||
-rw-r--r-- | writerfilter/source/dmapper/PropertyMap.cxx | 2 |
2 files changed, 41 insertions, 1 deletions
diff --git a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx index dae6e387ee64..2952f1f93302 100644 --- a/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx +++ b/writerfilter/qa/cppunittests/dmapper/PropertyMap.cxx @@ -15,6 +15,12 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <com/sun/star/table/BorderLine2.hpp> +#include <com/sun/star/text/XTextDocument.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XImporter.hpp> + +#include <unotools/streamwrap.hxx> +#include <comphelper/propertyvalue.hxx> using namespace ::com::sun::star; @@ -135,6 +141,40 @@ CPPUNIT_TEST_FIXTURE(Test, testNegativePageBorderNoMargin) // i.e. the border negative distance was lost. CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1147), nTopBorderDistance); } + +CPPUNIT_TEST_FIXTURE(Test, testPasteHeaderDisable) +{ + // Given an empty document with a turned on header: + mxComponent = loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"); + uno::Reference<style::XStyleFamiliesSupplier> xStyleFamiliesSupplier(mxComponent, + uno::UNO_QUERY); + uno::Reference<container::XNameAccess> xStyleFamilies + = xStyleFamiliesSupplier->getStyleFamilies(); + uno::Reference<container::XNameAccess> xStyleFamily(xStyleFamilies->getByName("PageStyles"), + uno::UNO_QUERY); + uno::Reference<beans::XPropertySet> xStyle(xStyleFamily->getByName("Standard"), uno::UNO_QUERY); + xStyle->setPropertyValue("HeaderIsOn", uno::Any(true)); + + // 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("com.sun.star.comp.Writer.RtfFilter"), 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("InputStream", xStream), + comphelper::makePropertyValue("InsertMode", true), + comphelper::makePropertyValue("TextInsertModeRange", xBodyEnd) }; + CPPUNIT_ASSERT(xFilter->filter(aDescriptor)); + + // Then make sure the header stays on: + CPPUNIT_ASSERT(xStyle->getPropertyValue("HeaderIsOn").get<bool>()); +} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 2301bc24893a..3e836f831e63 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -574,7 +574,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) + if (bHasHeader && !bHadFirstHeader && !m_bHadLeftHeader && !m_bHadRightHeader && rDM_Impl.IsNewDoc()) { m_aPageStyle->setPropertyValue(sHeaderIsOn, uno::Any(false)); } |