diff --git a/sw/qa/extras/ooxmlimport/data/inheritFirstHeader.docx b/sw/qa/extras/ooxmlimport/data/inheritFirstHeader.docx new file mode 100644 index 000000000000..e3d7d20a2d23 Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/inheritFirstHeader.docx differ diff --git a/sw/qa/extras/ooxmlimport/data/n780843b.docx b/sw/qa/extras/ooxmlimport/data/n780843b.docx new file mode 100644 index 000000000000..2ba9ab2c6f0f Binary files /dev/null and b/sw/qa/extras/ooxmlimport/data/n780843b.docx differ diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx index 50f587faa8d2..4c099e178e80 100644 --- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx +++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx @@ -971,25 +971,8 @@ DECLARE_OOXMLIMPORT_TEST(testN780853, "n780853.docx") DECLARE_OOXMLIMPORT_TEST(testN780843, "n780843.docx") { - /* - * The problem was that wrong footer was picked. - * - * oParas = ThisComponent.Text.createEnumeration - * oPara = oParas.nextElement - * oPara = oParas.nextElement - * oPara = oParas.nextElement - * sStyle = oPara.PageStyleName - * oStyle = ThisComponent.StyleFamilies.PageStyles.getByName(sStyle) - * xray oStyle.FooterText.String ' was "hidden footer" - */ - uno::Reference< text::XTextRange > xPara = getParagraph(3); + uno::Reference< text::XTextRange > xPara = getParagraph(1); OUString aStyleName = getProperty(xPara, "PageStyleName"); - uno::Reference xPageStyle(getStyles("PageStyles")->getByName(aStyleName), uno::UNO_QUERY); - uno::Reference xFooter = getProperty< uno::Reference >(xPageStyle, "FooterText"); - CPPUNIT_ASSERT_EQUAL(OUString("shown footer"), xFooter->getString()); - - xPara = getParagraph(1); - aStyleName = getProperty(xPara, "PageStyleName"); CPPUNIT_ASSERT_EQUAL(OUString("First Page"), aStyleName); //tdf64372 this document should only have one page break (2 pages, not 3) @@ -1000,6 +983,39 @@ DECLARE_OOXMLIMPORT_TEST(testN780843, "n780843.docx") CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage()); } +DECLARE_OOXMLIMPORT_TEST(testN780843b, "n780843b.docx") +{ + // Same document as testN780843 except there is more text before the continuous break. Now the opposite footer results should happen. + uno::Reference< text::XTextRange > xPara = getParagraph(3); + OUString aStyleName = getProperty(xPara, "PageStyleName"); + uno::Reference xPageStyle(getStyles("PageStyles")->getByName(aStyleName), uno::UNO_QUERY); + uno::Reference xFooterText = getProperty< uno::Reference >(xPageStyle, "FooterText"); + CPPUNIT_ASSERT_EQUAL( OUString("hidden footer"), xFooterText->getString() ); +} + +DECLARE_OOXMLIMPORT_TEST(testInheritFirstHeader,"inheritFirstHeader.docx") +{ +// First page headers always link to last used first header, never to a follow header + uno::Reference xModel(mxComponent, uno::UNO_QUERY); + uno::Reference xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); + + xCursor->jumpToLastPage(); + OUString sPageStyleName = getProperty( xCursor, "PageStyleName" ); + uno::Reference xHeaderText = getProperty< uno::Reference >(getStyles("PageStyles")->getByName(sPageStyleName), "HeaderText"); + CPPUNIT_ASSERT_EQUAL( OUString("Last Header"), xHeaderText->getString() ); + + xCursor->jumpToPreviousPage(); + sPageStyleName = getProperty( xCursor, "PageStyleName" ); + xHeaderText = getProperty< uno::Reference >(getStyles("PageStyles")->getByName(sPageStyleName), "HeaderText"); + CPPUNIT_ASSERT_EQUAL( OUString("First Header"), xHeaderText->getString() ); + + xCursor->jumpToPreviousPage(); + sPageStyleName = getProperty( xCursor, "PageStyleName" ); + xHeaderText = getProperty< uno::Reference >(getStyles("PageStyles")->getByName(sPageStyleName), "HeaderText"); + CPPUNIT_ASSERT_EQUAL( OUString("Follow Header"), xHeaderText->getString() ); +} + DECLARE_OOXMLIMPORT_TEST(testShadow, "imgshadow.docx") { /* diff --git a/writerfilter/source/dmapper/PropertyMap.cxx b/writerfilter/source/dmapper/PropertyMap.cxx index 6a07e9d3c250..03198f349d4f 100644 --- a/writerfilter/source/dmapper/PropertyMap.cxx +++ b/writerfilter/source/dmapper/PropertyMap.cxx @@ -1114,19 +1114,19 @@ throw ( css::beans::UnknownPropertyException, ApplyProperties_( m_aFollowPageStyle ); } - if( pLastContext && m_sFirstPageStyleName.isEmpty() ) - m_sFirstPageStyleName = pLastContext->GetPageStyleName( /*bFirst=*/true ); + // FirstPageStyle may only be inherited if it will not be used or re-linked to a different follow + if( !m_bTitlePage && pLastContext && m_sFirstPageStyleName.isEmpty() ) + m_sFirstPageStyleName = pLastContext->GetPageStyleName( /*bFirst=*/true ); else { HandleMarginsHeaderFooter( /*bFirst=*/true, rDM_Impl ); GetPageStyle( xPageStyles, xTextFactory, /*bFirst=*/true ); if( rDM_Impl.IsNewDoc() && m_aFirstPageStyle.is() ) ApplyProperties_( m_aFirstPageStyle ); - } - GetPageStyle( xPageStyles, xTextFactory, /*bFirst=*/true ); - // Chain m_aFollowPageStyle to be after m_aFirstPageStyle - m_aFirstPageStyle->setPropertyValue( "FollowStyle", uno::makeAny(m_sFollowPageStyleName) ); + // Chain m_aFollowPageStyle to be after m_aFirstPageStyle + m_aFirstPageStyle->setPropertyValue( "FollowStyle", uno::makeAny(m_sFollowPageStyleName) ); + } } void SectionPropertyMap::CloseSectionGroup( DomainMapper_Impl& rDM_Impl )