diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-27 10:27:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-29 13:44:02 +0200 |
commit | 8611f6e259b807b4f19c8dc0eab86ca648891ce3 (patch) | |
tree | fa2b0e463aafb51df754768f916ca9104969a557 /chart2 | |
parent | 25a997c15d39fb30676a375df8ea4ce1ed2e1acd (diff) |
ref-count SdrObject
Which means we can get rid of the majestic hack of ScCaptionPtr
Previously, SdrObject was manually managed, and the ownership
passed around in very complicated fashion.
Notes:
(*) SvxShape has a strong reference to SdrObject, where
previously it had a weak reference. It is now strong
since otherwise the SdrObject will go away very eagerly.
(*) SdrObject still has a weak reference to SvxShape
(*) In the existing places that an SdrObject is being
deleted, we now just clear the reference
(*) instead of SwVirtFlyDrawObj removing itself from the
page that contains inside it's destructor, make the call site
do the removing from the page.
(*) Needed to take the SolarMutex in UndoManagerHelper_Impl::impl_clear
because this can be called from UNO (e.g. sfx2_complex JUnit test)
and the SdrObjects need the SolarMutex when destructing.
(*) handle a tricky situation with SwDrawVirtObj in the SwDrawModel
destructor because the existing code wants mpDrawObj in
SwAnchoredObject to be sometimes owning, sometimes not, which
results in a cycle with the new code.
Change-Id: I4d79df1660e386388e5d51030653755bca02a163
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138837
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'chart2')
7 files changed, 25 insertions, 20 deletions
diff --git a/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx b/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx index 4459219965d8..7cb38e9e8b48 100644 --- a/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx +++ b/chart2/source/controller/dialogs/tp_3D_SceneIllumination.cxx @@ -30,6 +30,7 @@ #include <svx/svx3ditems.hxx> #include <svx/svddef.hxx> #include <utility> +#include <svx/obj3d.hxx> #include <vcl/svapp.hxx> #include <comphelper/diagnose_ex.hxx> diff --git a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx index 1f0ef08578d3..0b3df1aa22ad 100644 --- a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx +++ b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx @@ -139,7 +139,7 @@ Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, co nStandardSymbol*=-1; if( o3tl::make_unsigned(nStandardSymbol) >= pSymbolList->GetObjCount() ) nStandardSymbol %= pSymbolList->GetObjCount(); - SdrObject* pObj = pSymbolList->GetObj(nStandardSymbol); + rtl::Reference<SdrObject> pObj = pSymbolList->GetObj(nStandardSymbol); ScopedVclPtrInstance< VirtualDevice > pVDev; pVDev->SetMapMode(MapMode(MapUnit::Map100thMM)); @@ -158,8 +158,8 @@ Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, co // directly clone to target SdrModel pObj = pObj->CloneSdrObject(*pModel); - pPage->NbcInsertObject(pObj); - aView.MarkObj(pObj,pPageView); + pPage->NbcInsertObject(pObj.get()); + aView.MarkObj(pObj.get(),pPageView); if( pSymbolShapeProperties ) pObj->SetMergedItemSet(*pSymbolShapeProperties); @@ -172,7 +172,9 @@ Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, co aView.UnmarkAll(); pObj=pPage->RemoveObject(0); - SdrObject::Free( pObj ); + // these need to die before the associated SdrModel + pObj.clear(); + pPage.clear(); return aGraph; } diff --git a/chart2/source/controller/main/ChartController_Tools.cxx b/chart2/source/controller/main/ChartController_Tools.cxx index 18771a553eaa..085f31e8b574 100644 --- a/chart2/source/controller/main/ChartController_Tools.cxx +++ b/chart2/source/controller/main/ChartController_Tools.cxx @@ -418,7 +418,9 @@ void ChartController::impl_PasteShapes( SdrModel* pModel ) { SdrObject* pObj(aIter.Next()); // Clone to new SdrModel - SdrObject* pNewObj(pObj ? pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel()) : nullptr); + rtl::Reference<SdrObject> pNewObj; + if (pObj) + pNewObj = pObj->CloneSdrObject(pDrawModelWrapper->getSdrModel()); if ( pNewObj ) { @@ -429,7 +431,7 @@ void ChartController::impl_PasteShapes( SdrModel* pModel ) xShape->setPosition( awt::Point( 0, 0 ) ); } - pDestPage->InsertObject( pNewObj ); + pDestPage->InsertObject( pNewObj.get() ); m_pDrawViewWrapper->AddUndo( std::make_unique<SdrUndoInsertObj>( *pNewObj ) ); xSelShape = xShape; } diff --git a/chart2/source/controller/main/DrawCommandDispatch.cxx b/chart2/source/controller/main/DrawCommandDispatch.cxx index c5cea4c5b6cd..9d896b75425e 100644 --- a/chart2/source/controller/main/DrawCommandDispatch.cxx +++ b/chart2/source/controller/main/DrawCommandDispatch.cxx @@ -362,11 +362,11 @@ void DrawCommandDispatch::execute( const OUString& rCommand, const Sequence< bea if ( eDrawMode != CHARTDRAW_INSERT ) return; - SdrObject* pObj = createDefaultObject( nFeatureId ); + rtl::Reference<SdrObject> pObj = createDefaultObject( nFeatureId ); if ( pObj ) { SdrPageView* pPageView = pDrawViewWrapper->GetSdrPageView(); - if (pDrawViewWrapper->InsertObjectAtView(pObj, *pPageView)) + if (pDrawViewWrapper->InsertObjectAtView(pObj.get(), *pPageView)) m_pChartController->SetAndApplySelection(Reference<drawing::XShape>(pObj->getUnoShape(), uno::UNO_QUERY)); if ( nFeatureId == COMMAND_ID_DRAW_TEXT ) { @@ -402,9 +402,9 @@ void DrawCommandDispatch::setInsertObj(SdrObjKind eObj) } } -SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID ) +rtl::Reference<SdrObject> DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID ) { - SdrObject* pObj = nullptr; + rtl::Reference<SdrObject> pObj; DrawViewWrapper* pDrawViewWrapper = ( m_pChartController ? m_pChartController->GetDrawViewWrapper() : nullptr ); DrawModelWrapper* pDrawModelWrapper = ( m_pChartController ? m_pChartController->GetDrawModelWrapper() : nullptr ); @@ -435,7 +435,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID ) case COMMAND_ID_DRAW_LINE: case COMMAND_ID_LINE_ARROW_END: { - if ( auto const pathObj = dynamic_cast<SdrPathObj*>( pObj) ) + if ( auto const pathObj = dynamic_cast<SdrPathObj*>( pObj.get()) ) { Point aStart = aRect.TopLeft(); Point aEnd = aRect.BottomRight(); @@ -452,7 +452,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID ) break; case COMMAND_ID_DRAW_FREELINE_NOFILL: { - if ( auto const pathObj = dynamic_cast<SdrPathObj*>( pObj) ) + if ( auto const pathObj = dynamic_cast<SdrPathObj*>( pObj.get()) ) { basegfx::B2DPolygon aInnerPoly; aInnerPoly.append( basegfx::B2DPoint( aRect.Left(), aRect.Bottom() ) ); @@ -473,7 +473,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID ) case COMMAND_ID_DRAW_TEXT: case COMMAND_ID_DRAW_TEXT_VERTICAL: { - if ( SdrTextObj* pTextObj = dynamic_cast<SdrTextObj*>( pObj) ) + if ( SdrTextObj* pTextObj = dynamic_cast<SdrTextObj*>( pObj.get()) ) { pTextObj->SetLogicRect( aRect ); bool bVertical = ( nID == COMMAND_ID_DRAW_TEXT_VERTICAL ); @@ -493,7 +493,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID ) case COMMAND_ID_DRAW_CAPTION: case COMMAND_ID_DRAW_CAPTION_VERTICAL: { - if ( SdrCaptionObj* pCaptionObj = dynamic_cast<SdrCaptionObj*>( pObj) ) + if ( SdrCaptionObj* pCaptionObj = dynamic_cast<SdrCaptionObj*>( pObj.get()) ) { bool bIsVertical( nID == COMMAND_ID_DRAW_CAPTION_VERTICAL ); pCaptionObj->SetVerticalWriting( bIsVertical ); @@ -514,7 +514,7 @@ SdrObject* DrawCommandDispatch::createDefaultObject( const sal_uInt16 nID ) { pObj->SetLogicRect( aRect ); SfxItemSet aSet( pDrawModelWrapper->GetItemPool() ); - setAttributes( pObj ); + setAttributes( pObj.get() ); pObj->SetMergedItemSet( aSet ); } break; diff --git a/chart2/source/controller/main/DrawCommandDispatch.hxx b/chart2/source/controller/main/DrawCommandDispatch.hxx index febfa8338d40..6e707b102e68 100644 --- a/chart2/source/controller/main/DrawCommandDispatch.hxx +++ b/chart2/source/controller/main/DrawCommandDispatch.hxx @@ -20,6 +20,7 @@ #include <svx/svdobjkind.hxx> #include "FeatureCommandDispatchBase.hxx" +#include <rtl/ref.hxx> class SfxItemSet; class SdrObject; @@ -60,7 +61,7 @@ protected: private: void setInsertObj(SdrObjKind eObj); - SdrObject* createDefaultObject( const sal_uInt16 nID ); + rtl::Reference<SdrObject> createDefaultObject( const sal_uInt16 nID ); bool parseCommandURL( const OUString& rCommandURL, sal_uInt16* pnFeatureId, OUString* pBaseCommand, OUString* pCustomShapeType ); diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index 8faa295d2492..584dfdb5ea72 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -1310,8 +1310,7 @@ void lcl_removeEmptyGroupShapes( const SdrObject& rParent ) if (pChildObjList->GetObjCount() == 0) { //remove empty group shape - SdrObject* pRemoved = pObjList->NbcRemoveObject(nIdx); - SdrObject::Free( pRemoved ); + pObjList->NbcRemoveObject(nIdx); } else lcl_removeEmptyGroupShapes(*pChildSdrObject); diff --git a/chart2/source/view/main/ShapeFactory.cxx b/chart2/source/view/main/ShapeFactory.cxx index 4a3d207a1edb..d1f73636c546 100644 --- a/chart2/source/view/main/ShapeFactory.cxx +++ b/chart2/source/view/main/ShapeFactory.cxx @@ -1115,8 +1115,8 @@ rtl::Reference<SvxShapePolyPolygon> return nullptr; //create shape - SdrPathObj* pPath = new SdrPathObj(xTarget->GetSdrObject()->getSdrModelFromSdrObject(), SdrObjKind::Polygon); - xTarget->GetSdrObject()->GetSubList()->InsertObject(pPath); + rtl::Reference<SdrPathObj> pPath = new SdrPathObj(xTarget->GetSdrObject()->getSdrModelFromSdrObject(), SdrObjKind::Polygon); + xTarget->GetSdrObject()->GetSubList()->InsertObject(pPath.get()); //set properties try |