diff options
author | Bjoern Michaelsen <bjoern.michaelsen@libreoffice.org> | 2019-09-05 01:17:47 +0200 |
---|---|---|
committer | Björn Michaelsen <bjoern.michaelsen@libreoffice.org> | 2019-09-07 08:23:08 +0200 |
commit | 8ac6d2e7e7293e7c5f4bb79ab7b36a843b2c3175 (patch) | |
tree | a9e65bb0dc03367913a2c04428ba82110b5da81b | |
parent | 29bda20c915287bbd1cd0fc6c56574cfa74b5ce3 (diff) |
make page bookkeep the SwXShapes
- and remove SwClient/Modify between SwXShape and Page
Change-Id: I482f5357dbd361e957fef54b5cbc594351c70b96
Reviewed-on: https://gerrit.libreoffice.org/78734
Tested-by: Jenkins
Reviewed-by: Björn Michaelsen <bjoern.michaelsen@libreoffice.org>
-rw-r--r-- | sw/inc/unodraw.hxx | 21 | ||||
-rw-r--r-- | sw/source/core/unocore/unodraw.cxx | 83 | ||||
-rw-r--r-- | sw/source/uibase/uno/unotxvw.cxx | 3 |
3 files changed, 55 insertions, 52 deletions
diff --git a/sw/inc/unodraw.hxx b/sw/inc/unodraw.hxx index b3013e4da610..6bfa4839eba7 100644 --- a/sw/inc/unodraw.hxx +++ b/sw/inc/unodraw.hxx @@ -38,10 +38,12 @@ class SdrMarkList; class SdrView; class SwDoc; +class SwXShape; class SwFmDrawPage : public SvxFmDrawPage { SdrPageView* pPageView; + std::vector<SwXShape*> m_vShapes; public: SwFmDrawPage( SdrPage* pPage ); virtual ~SwFmDrawPage() throw () override; @@ -52,12 +54,19 @@ public: SdrView* GetDrawView() {return mpView.get();} SdrPageView* GetPageView(); void RemovePageView(); - static css::uno::Reference< css::uno::XInterface > GetInterface( SdrObject* pObj ); + static css::uno::Reference<css::drawing::XShape> GetShape(SdrObject* pObj); + static css::uno::Reference<css::drawing::XShapeGroup> GetShapeGroup(SdrObject* pObj); // The following method is called when a SvxShape-object is to be created. // Derived classes may obtain at this point a derivation or an object // that is aggregating a SvxShape. virtual css::uno::Reference< css::drawing::XShape > CreateShape( SdrObject *pObj ) const override; + void RemoveShape(const SwXShape* pShape) + { + auto ppShape = find(m_vShapes.begin(), m_vShapes.end(), pShape); + if(ppShape != m_vShapes.end()) + m_vShapes.erase(ppShape); + }; }; typedef cppu::WeakAggImplHelper4 @@ -121,12 +130,12 @@ cppu::WeakAggImplHelper6 css::drawing::XShape > SwXShapeBaseClass; -class SwXShape : public SwXShapeBaseClass, - public SwClient +class SwXShape : public SwXShapeBaseClass, public SwClient { friend class SwXGroupShape; friend class SwXDrawPage; friend class SwFmDrawPage; + const SwFmDrawPage* m_pPage; css::uno::Reference< css::uno::XAggregation > xShapeAgg; // reference to <XShape>, determined in the @@ -191,11 +200,9 @@ class SwXShape : public SwXShapeBaseClass, protected: virtual ~SwXShape() override; - //SwClient - virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override; - + void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override; public: - SwXShape(css::uno::Reference<css::uno::XInterface> & xShape, SwDoc const* pDoc); + SwXShape(css::uno::Reference<css::uno::XInterface> & xShape, SwDoc const*const pDoc); static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId(); virtual css::uno::Any SAL_CALL queryInterface( const css::uno::Type& aType ) override; diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index 69eefbb45a06..e91e4168c7fb 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -255,6 +255,8 @@ SwFmDrawPage::SwFmDrawPage( SdrPage* pPage ) : SwFmDrawPage::~SwFmDrawPage() throw () { + while (!m_vShapes.empty()) + m_vShapes.back()->dispose(); RemovePageView(); } @@ -284,37 +286,26 @@ void SwFmDrawPage::RemovePageView() pPageView = nullptr; } -uno::Reference< uno::XInterface > SwFmDrawPage::GetInterface( SdrObject* pObj ) +uno::Reference<drawing::XShape> SwFmDrawPage::GetShape(SdrObject* pObj) { - uno::Reference< XInterface > xShape; - if( pObj ) + if(!pObj) + return nullptr; + SwFrameFormat* pFormat = ::FindFrameFormat( pObj ); + SwFmDrawPage* pPage = dynamic_cast<SwFmDrawPage*>(pFormat); + if(!pPage || pPage->m_vShapes.empty()) + return uno::Reference<drawing::XShape>(pObj->getUnoShape(), uno::UNO_QUERY); + for(auto pShape : pPage->m_vShapes) { - SwFrameFormat* pFormat = ::FindFrameFormat( pObj ); - - SwIterator<SwXShape,SwFormat> aIter(*pFormat); - SwXShape* pxShape = aIter.First(); - if (pxShape) - { - //tdf#113615 when mapping from SdrObject to XShape via - //SwFrameFormat check all the SdrObjects belonging to this - //SwFrameFormat to find the right one. In the case of Grouped - //objects there can be both the group and the elements of the group - //registered here so the first one isn't necessarily the right one - while (SwXShape* pNext = aIter.Next()) - { - SvxShape* pSvxShape = pNext->GetSvxShape(); - if (pSvxShape && pSvxShape->GetSdrObject() == pObj) - { - pxShape = pNext; - break; - } - } - xShape = *static_cast<cppu::OWeakObject*>(pxShape); - } - else - xShape = pObj->getUnoShape(); + SvxShape* pSvxShape = pShape->GetSvxShape(); + if (pSvxShape && pSvxShape->GetSdrObject() == pObj) + return uno::Reference<drawing::XShape>(static_cast<::cppu::OWeakObject*>(pShape), uno::UNO_QUERY); } - return xShape; + return nullptr; +} + +uno::Reference<drawing::XShapeGroup> SwFmDrawPage::GetShapeGroup(SdrObject* pObj) +{ + return uno::Reference<drawing::XShapeGroup>(GetShape(pObj), uno::UNO_QUERY); } uno::Reference< drawing::XShape > SwFmDrawPage::CreateShape( SdrObject *pObj ) const @@ -375,13 +366,15 @@ uno::Reference< drawing::XShape > SwFmDrawPage::CreateShape( SdrObject *pObj ) c xShapeTunnel = nullptr; uno::Reference< uno::XInterface > xCreate(xRet, uno::UNO_QUERY); xRet = nullptr; - uno::Reference< beans::XPropertySet > xPrSet; if ( pObj->IsGroupObject() && (!pObj->Is3DObj() || (dynamic_cast<const E3dScene*>( pObj) != nullptr)) ) - xPrSet = new SwXGroupShape(xCreate, nullptr); + pShape = new SwXGroupShape(xCreate, nullptr); else - xPrSet = new SwXShape(xCreate, nullptr); + pShape = new SwXShape(xCreate, nullptr); + uno::Reference<beans::XPropertySet> xPrSet = pShape; xRet.set(xPrSet, uno::UNO_QUERY); } + const_cast<std::vector<SwXShape*>*>(&m_vShapes)->push_back(pShape); + pShape->m_pPage = this; } return xRet; } @@ -582,7 +575,7 @@ void SwXDrawPage::add(const uno::Reference< drawing::XShape > & xShape) static_cast< cppu::OWeakObject * > ( this ) ); // we're already registered in the model / SwXDrawPage::add() already called - if(pShape->GetRegisteredIn() || !pShape->m_bDescriptor ) + if(pShape->m_pPage || pShape->GetRegisteredIn() || !pShape->m_bDescriptor ) return; // we're inserted elsewhere already @@ -771,10 +764,7 @@ uno::Reference< drawing::XShapeGroup > SwXDrawPage::group(const uno::Reference< pPage->GetDrawView()->UnmarkAll(); if(pContact) - { - uno::Reference< uno::XInterface > xInt = SwFmDrawPage::GetInterface( pContact->GetMaster() ); - xRet.set(xInt, uno::UNO_QUERY); - } + xRet = SwFmDrawPage::GetShapeGroup( pContact->GetMaster() ); pDoc->GetIDocumentUndoRedo().EndUndo( SwUndoId::END, nullptr ); } pPage->RemovePageView(); @@ -877,13 +867,14 @@ namespace } } -SwXShape::SwXShape(uno::Reference<uno::XInterface> & xShape, - SwDoc const*const pDoc) - : - m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_SHAPE)), - m_pPropertyMapEntries(aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_TEXT_SHAPE)), - pImpl(new SwShapeDescriptor_Impl(pDoc)), - m_bDescriptor(true) +SwXShape::SwXShape( + uno::Reference<uno::XInterface> & xShape, + SwDoc const*const pDoc) + : m_pPage(nullptr) + , m_pPropSet(aSwMapProvider.GetPropertySet(PROPERTY_MAP_TEXT_SHAPE)) + , m_pPropertyMapEntries(aSwMapProvider.GetPropertyMapEntries(PROPERTY_MAP_TEXT_SHAPE)) + , pImpl(new SwShapeDescriptor_Impl(pDoc)) + , m_bDescriptor(true) { if(!xShape.is()) // default Ctor return; @@ -970,6 +961,9 @@ SwXShape::~SwXShape() } pImpl.reset(); EndListeningAll(); + if(m_pPage) + const_cast<SwFmDrawPage*>(m_pPage)->RemoveShape(this); + m_pPage = nullptr; } uno::Any SwXShape::queryInterface( const uno::Type& aType ) @@ -2124,6 +2118,9 @@ void SwXShape::dispose() if(xComp.is()) xComp->dispose(); } + if(m_pPage) + const_cast<SwFmDrawPage*>(m_pPage)->RemoveShape(this); + m_pPage = nullptr; } void SwXShape::addEventListener( diff --git a/sw/source/uibase/uno/unotxvw.cxx b/sw/source/uibase/uno/unotxvw.cxx index dd04e6f53a5f..1842b90cd497 100644 --- a/sw/source/uibase/uno/unotxvw.cxx +++ b/sw/source/uibase/uno/unotxvw.cxx @@ -416,8 +416,7 @@ uno::Any SwXTextView::getSelection() for(size_t i = 0; i < rMarkList.GetMarkCount(); ++i) { SdrObject* pObj = rMarkList.GetMark(i)->GetMarkedSdrObj(); - uno::Reference< uno::XInterface > xInt = SwFmDrawPage::GetInterface( pObj ); - uno::Reference< drawing::XShape > xShape(xInt, uno::UNO_QUERY); + uno::Reference<drawing::XShape> xShape = SwFmDrawPage::GetShape( pObj ); xShCol->add(xShape); } aRef.set(xShCol, uno::UNO_QUERY); |