From 01fc08c0b5c57fef8ad3755672f4266d85e849a5 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 20 Nov 2014 16:44:21 +0100 Subject: fdo#85554 SwXShape: fix getting ZOrder property when doc contains TextBoxes Change-Id: I9b6b83f0f6d627bb14a880a19769ee70564cf52b --- sw/inc/textboxhelper.hxx | 3 +++ sw/qa/extras/uiwriter/data/fdo85554.odt | Bin 0 -> 10091 bytes sw/qa/extras/uiwriter/uiwriter.cxx | 25 +++++++++++++++++++++++++ sw/source/core/doc/textboxhelper.cxx | 19 +++++++++++++++++++ sw/source/core/unocore/unodraw.cxx | 13 +++++++++++++ 5 files changed, 60 insertions(+) create mode 100644 sw/qa/extras/uiwriter/data/fdo85554.odt diff --git a/sw/inc/textboxhelper.hxx b/sw/inc/textboxhelper.hxx index 5473979d59a9..55c0ac8e3a0e 100644 --- a/sw/inc/textboxhelper.hxx +++ b/sw/inc/textboxhelper.hxx @@ -22,6 +22,7 @@ #include class SdrPage; +class SdrObject; class SfxItemSet; class SwFrmFmt; class SwFrmFmts; @@ -82,6 +83,8 @@ public: static sal_Int32 getCount(SdrPage* pPage, std::set& rTextBoxes); /// Get a shape by index, excluding TextBoxes. static css::uno::Any getByIndex(SdrPage* pPage, sal_Int32 nIndex, std::set& rTextBoxes) throw(css::lang::IndexOutOfBoundsException); + /// Get the order of the shape, excluding TextBoxes. + static sal_Int32 getOrdNum(const SdrObject* pObject, std::set& rTextBoxes); /// Saves the current shape -> textbox links in a map, so they can be restored later. static void saveLinks(const SwFrmFmts& rFormats, std::map& rLinks); diff --git a/sw/qa/extras/uiwriter/data/fdo85554.odt b/sw/qa/extras/uiwriter/data/fdo85554.odt new file mode 100644 index 000000000000..9c30b8d0fe08 Binary files /dev/null and b/sw/qa/extras/uiwriter/data/fdo85554.odt differ diff --git a/sw/qa/extras/uiwriter/uiwriter.cxx b/sw/qa/extras/uiwriter/uiwriter.cxx index d79b6b352d25..2ed5298f6aa0 100644 --- a/sw/qa/extras/uiwriter/uiwriter.cxx +++ b/sw/qa/extras/uiwriter/uiwriter.cxx @@ -56,6 +56,7 @@ public: void testChineseConversionNonChineseText(); void testChineseConversionTraditionalToSimplified(); void testChineseConversionSimplifiedToTraditional(); + void testFdo85554(); CPPUNIT_TEST_SUITE(SwUiWriterTest); CPPUNIT_TEST(testReplaceForward); @@ -78,6 +79,7 @@ public: CPPUNIT_TEST(testChineseConversionNonChineseText); CPPUNIT_TEST(testChineseConversionTraditionalToSimplified); CPPUNIT_TEST(testChineseConversionSimplifiedToTraditional); + CPPUNIT_TEST(testFdo85554); CPPUNIT_TEST_SUITE_END(); @@ -561,6 +563,29 @@ void SwUiWriterTest::testChineseConversionSimplifiedToTraditional() } +void SwUiWriterTest::testFdo85554() +{ + // Load the document, it contains one shape with a textbox. + load("/sw/qa/extras/uiwriter/data/", "fdo85554.odt"); + + // Add a second shape to the document. + uno::Reference xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference xShape(xFactory->createInstance("com.sun.star.drawing.RectangleShape"), uno::UNO_QUERY); + xShape->setSize(awt::Size(10000, 10000)); + xShape->setPosition(awt::Point(1000, 1000)); + uno::Reference xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference xDrawPage = xDrawPageSupplier->getDrawPage(); + xDrawPage->add(xShape); + + // Save it and load it back. + reload("writer8", "fdo85554.odt"); + + xDrawPageSupplier.set(mxComponent, uno::UNO_QUERY); + xDrawPage = xDrawPageSupplier->getDrawPage(); + // This was 1, we lost a shape on export. + CPPUNIT_ASSERT_EQUAL(static_cast(2), xDrawPage->getCount()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/core/doc/textboxhelper.cxx b/sw/source/core/doc/textboxhelper.cxx index e48160f7363d..0c8ede9d2ffd 100644 --- a/sw/source/core/doc/textboxhelper.cxx +++ b/sw/source/core/doc/textboxhelper.cxx @@ -215,6 +215,25 @@ uno::Any SwTextBoxHelper::getByIndex(SdrPage* pPage, sal_Int32 nIndex, std::set< return pRet ? uno::makeAny(uno::Reference(pRet->getUnoShape(), uno::UNO_QUERY)) : uno::Any(); } +sal_Int32 SwTextBoxHelper::getOrdNum(const SdrObject* pObject, std::set& rTextBoxes) +{ + if (const SdrPage* pPage = pObject->GetPage()) + { + sal_Int32 nOrder = 0; // Current logical order. + for (size_t i = 0; i < pPage->GetObjCount(); ++i) + { + if (lcl_isTextBox(pPage->GetObj(i), rTextBoxes)) + continue; + if (pPage->GetObj(i) == pObject) + return nOrder; + ++nOrder; + } + } + + SAL_WARN("sw.core", "SwTextBoxHelper::getOrdNum: no page or page doesn't contain the object"); + return pObject->GetOrdNum(); +} + SwFrmFmt* SwTextBoxHelper::findTextBox(uno::Reference xShape) { SwXShape* pShape = dynamic_cast(xShape.get()); diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index d8b463274a77..b4e0b0bbb68f 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -1756,6 +1756,19 @@ uno::Any SwXShape::getPropertyValue(const OUString& rPropertyName) aRet >>= aPath; aRet <<= _ConvertPolyPolygonBezierToLayoutDir( aPath ); } + else if (rPropertyName == "ZOrder") + { + // Convert the real draw page position to the logical one that ignores textboxes. + if (pFmt) + { + const SdrObject* pObj = pFmt->FindRealSdrObject(); + if (pObj) + { + std::set aTextBoxes = SwTextBoxHelper::findTextBoxes(pFmt->GetDoc()); + aRet <<= SwTextBoxHelper::getOrdNum(pObj, aTextBoxes); + } + } + } } } return aRet; -- cgit v1.2.3