diff options
author | Michael Stahl <mstahl@redhat.com> | 2014-09-30 17:59:08 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-10-01 07:25:52 +0000 |
commit | 902de8a1cbdb86c1eb1a05c8307b109fd75f493c (patch) | |
tree | 17bb4c2488b9b93d529b6d68b7d444fe93dcf0a3 | |
parent | 5aceca0f5bf25d535c33a726d698777322b378d7 (diff) |
fdo#79269: fix ODF import of style:footer-first
The implementation of SwXStyle's FirstIsShared property is busted, and
that causes xmloff to write the footer-first content into the master
footer.
This is a re-implementation of 0f21f932081471b2a5eda820fa1a194fbf3ab85c
because unostyle.cxx is very different on master...
Change-Id: I485d8089c1fb5ba3ca369fbfe8f3115bf700ba13
Reviewed-on: https://gerrit.libreoffice.org/11722
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
-rw-r--r-- | sw/qa/extras/odfimport/data/fdo79269.odt | bin | 0 -> 8496 bytes | |||
-rw-r--r-- | sw/qa/extras/odfimport/data/fdo79269_header.odt | bin | 0 -> 8528 bytes | |||
-rw-r--r-- | sw/qa/extras/odfimport/odfimport.cxx | 35 | ||||
-rw-r--r-- | sw/source/core/unocore/unostyle.cxx | 35 |
4 files changed, 55 insertions, 15 deletions
diff --git a/sw/qa/extras/odfimport/data/fdo79269.odt b/sw/qa/extras/odfimport/data/fdo79269.odt Binary files differnew file mode 100644 index 000000000000..2e3bf1e80985 --- /dev/null +++ b/sw/qa/extras/odfimport/data/fdo79269.odt diff --git a/sw/qa/extras/odfimport/data/fdo79269_header.odt b/sw/qa/extras/odfimport/data/fdo79269_header.odt Binary files differnew file mode 100644 index 000000000000..6f1a839ecb89 --- /dev/null +++ b/sw/qa/extras/odfimport/data/fdo79269_header.odt diff --git a/sw/qa/extras/odfimport/odfimport.cxx b/sw/qa/extras/odfimport/odfimport.cxx index 8cd4b09b1064..36aa4374639e 100644 --- a/sw/qa/extras/odfimport/odfimport.cxx +++ b/sw/qa/extras/odfimport/odfimport.cxx @@ -272,6 +272,41 @@ DECLARE_ODFIMPORT_TEST(testFdo60842, "fdo60842.odt") getCell(xTable, "E1", "01/04/2012"); } +DECLARE_ODFIMPORT_TEST(testFdo79269, "fdo79269.odt") +{ + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); + xCursor->jumpToLastPage(); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage()); + + // The problem was that the first-footer was shared. + uno::Reference<beans::XPropertySet> xPropSet(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xPropSet, "FirstIsShared")); + + uno::Reference<text::XTextRange> xFooter1 = getProperty< uno::Reference<text::XTextRange> >(xPropSet, "FooterTextFirst"); + CPPUNIT_ASSERT_EQUAL(OUString("forst"), xFooter1->getString()); + uno::Reference<text::XTextRange> xFooter = getProperty< uno::Reference<text::XTextRange> >(xPropSet, "FooterText"); + CPPUNIT_ASSERT_EQUAL(OUString("second"), xFooter->getString()); +} + +DECLARE_ODFIMPORT_TEST(testFdo79269_header, "fdo79269_header.odt") +{ + uno::Reference<frame::XModel> xModel(mxComponent, uno::UNO_QUERY); + uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(xModel->getCurrentController(), uno::UNO_QUERY); + uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(), uno::UNO_QUERY); + xCursor->jumpToLastPage(); + CPPUNIT_ASSERT_EQUAL(sal_Int16(2), xCursor->getPage()); + + uno::Reference<beans::XPropertySet> xPropSet(getStyles("PageStyles")->getByName(DEFAULT_STYLE), uno::UNO_QUERY); + CPPUNIT_ASSERT_EQUAL(false, getProperty<bool>(xPropSet, "FirstIsShared")); + + uno::Reference<text::XTextRange> xFooter1 = getProperty< uno::Reference<text::XTextRange> >(xPropSet, "HeaderTextFirst"); + CPPUNIT_ASSERT_EQUAL(OUString("forst"), xFooter1->getString()); + uno::Reference<text::XTextRange> xFooter = getProperty< uno::Reference<text::XTextRange> >(xPropSet, "HeaderText"); + CPPUNIT_ASSERT_EQUAL(OUString("second"), xFooter->getString()); +} + DECLARE_ODFIMPORT_TEST(testFdo56272, "fdo56272.odt") { uno::Reference<drawing::XShape> xShape = getShape(1); diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx index 5c24b91886c8..4ed26e01d460 100644 --- a/sw/source/core/unocore/unostyle.cxx +++ b/sw/source/core/unocore/unostyle.cxx @@ -462,6 +462,24 @@ SwXStyleFamily::~SwXStyleFamily() } +static bool lcl_GetHeaderFooterItem( + SfxItemSet const& rSet, OUString const& rPropName, bool const bFooter, + SvxSetItem const*& o_rpItem) +{ + SfxItemState eState = rSet.GetItemState( + (bFooter) ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, + false, reinterpret_cast<const SfxPoolItem**>(&o_rpItem)); + if (SFX_ITEM_SET != eState && + rPropName == UNO_NAME_FIRST_IS_SHARED) + { // fdo#79269 header may not exist, check footer then + eState = rSet.GetItemState( + (!bFooter) ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, + false, reinterpret_cast<const SfxPoolItem**>(&o_rpItem)); + } + return SFX_ITEM_SET == eState; +} + + static sal_Int32 lcl_GetCountOrName(const SwDoc &rDoc, SfxStyleFamily eFamily, OUString *pString, sal_uInt16 nIndex = USHRT_MAX) { @@ -3093,20 +3111,9 @@ void SAL_CALL SwXPageStyle::SetPropertyValues_Impl( break; } const SvxSetItem* pSetItem; - if(SFX_ITEM_SET == aBaseImpl.GetItemSet().GetItemState( - bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, - false, (const SfxPoolItem**)&pSetItem)) + if (lcl_GetHeaderFooterItem(aBaseImpl.GetItemSet(), pNames[nProp], bFooter, pSetItem)) { lcl_putItemToSet(pSetItem, nRes, nItemType, pValues[nProp], pEntry->nMemberId, aBaseImpl); - - if (nRes == SID_ATTR_PAGE_SHARED_FIRST) - { - // Need to add this to the other as well - if (SFX_ITEM_SET == aBaseImpl.GetItemSet().GetItemState( - bFooter ? SID_ATTR_PAGE_HEADERSET : SID_ATTR_PAGE_FOOTERSET, - false, (const SfxPoolItem**)&pSetItem)) - lcl_putItemToSet(pSetItem, nRes, nItemType, pValues[nProp], pEntry->nMemberId, aBaseImpl); - } } else if(SID_ATTR_PAGE_ON == nRes ) { @@ -3350,9 +3357,7 @@ uno::Sequence< uno::Any > SAL_CALL SwXPageStyle::GetPropertyValues_Impl( break; } const SvxSetItem* pSetItem; - if(SFX_ITEM_SET == rSet.GetItemState( - bFooter ? SID_ATTR_PAGE_FOOTERSET : SID_ATTR_PAGE_HEADERSET, - false, (const SfxPoolItem**)&pSetItem)) + if (lcl_GetHeaderFooterItem(rSet, pNames[nProp], bFooter, pSetItem)) { const SfxItemSet& rTmpSet = pSetItem->GetItemSet(); const SfxPoolItem* pItem = 0; |