diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-11-20 16:44:21 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2014-11-20 16:57:49 +0100 |
commit | 01fc08c0b5c57fef8ad3755672f4266d85e849a5 (patch) | |
tree | 9f1a7f71281feae7e9be344a94371495f1a77338 | |
parent | 3d601cfa4b63580b5a0d18044b5792894d54089f (diff) |
fdo#85554 SwXShape: fix getting ZOrder property when doc contains TextBoxes
Change-Id: I9b6b83f0f6d627bb14a880a19769ee70564cf52b
-rw-r--r-- | sw/inc/textboxhelper.hxx | 3 | ||||
-rw-r--r-- | sw/qa/extras/uiwriter/data/fdo85554.odt | bin | 0 -> 10091 bytes | |||
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter.cxx | 25 | ||||
-rw-r--r-- | sw/source/core/doc/textboxhelper.cxx | 19 | ||||
-rw-r--r-- | sw/source/core/unocore/unodraw.cxx | 13 |
5 files changed, 60 insertions, 0 deletions
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 <swdllapi.h> class SdrPage; +class SdrObject; class SfxItemSet; class SwFrmFmt; class SwFrmFmts; @@ -82,6 +83,8 @@ public: static sal_Int32 getCount(SdrPage* pPage, std::set<const SwFrmFmt*>& rTextBoxes); /// Get a shape by index, excluding TextBoxes. static css::uno::Any getByIndex(SdrPage* pPage, sal_Int32 nIndex, std::set<const SwFrmFmt*>& rTextBoxes) throw(css::lang::IndexOutOfBoundsException); + /// Get the order of the shape, excluding TextBoxes. + static sal_Int32 getOrdNum(const SdrObject* pObject, std::set<const SwFrmFmt*>& rTextBoxes); /// Saves the current shape -> textbox links in a map, so they can be restored later. static void saveLinks(const SwFrmFmts& rFormats, std::map<const SwFrmFmt*, const SwFrmFmt*>& rLinks); diff --git a/sw/qa/extras/uiwriter/data/fdo85554.odt b/sw/qa/extras/uiwriter/data/fdo85554.odt Binary files differnew file mode 100644 index 000000000000..9c30b8d0fe08 --- /dev/null +++ b/sw/qa/extras/uiwriter/data/fdo85554.odt 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<css::lang::XMultiServiceFactory> xFactory(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XShape> 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<drawing::XDrawPageSupplier> xDrawPageSupplier(mxComponent, uno::UNO_QUERY); + uno::Reference<drawing::XDrawPage> 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<sal_Int32>(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<drawing::XShape>(pRet->getUnoShape(), uno::UNO_QUERY)) : uno::Any(); } +sal_Int32 SwTextBoxHelper::getOrdNum(const SdrObject* pObject, std::set<const SwFrmFmt*>& 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<drawing::XShape> xShape) { SwXShape* pShape = dynamic_cast<SwXShape*>(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<const SwFrmFmt*> aTextBoxes = SwTextBoxHelper::findTextBoxes(pFmt->GetDoc()); + aRet <<= SwTextBoxHelper::getOrdNum(pObj, aTextBoxes); + } + } + } } } return aRet; |