diff options
Diffstat (limited to 'chart2/source/view/main/DrawModelWrapper.cxx')
-rw-r--r-- | chart2/source/view/main/DrawModelWrapper.cxx | 110 |
1 files changed, 49 insertions, 61 deletions
diff --git a/chart2/source/view/main/DrawModelWrapper.cxx b/chart2/source/view/main/DrawModelWrapper.cxx index c581b3871300..71cd8d699cf7 100644 --- a/chart2/source/view/main/DrawModelWrapper.cxx +++ b/chart2/source/view/main/DrawModelWrapper.cxx @@ -23,19 +23,16 @@ #include <ObjectIdentifier.hxx> #include <svx/unomodel.hxx> #include <svl/itempool.hxx> -#include <svl/eitem.hxx> -#include <editeng/eeitem.hxx> -#include <svx/svx3ditems.hxx> #include <svx/objfac3d.hxx> #include <svx/svdpage.hxx> +#include <svx/svx3ditems.hxx> #include <svx/xtable.hxx> #include <svx/svdoutl.hxx> #include <editeng/unolingu.hxx> #include <vcl/svapp.hxx> #include <vcl/virdev.hxx> #include <libxml/xmlwriter.h> - -#include <com/sun/star/container/XChild.hpp> +#include <osl/diagnose.h> namespace com::sun::star::linguistic2 { class XHyphenator; } namespace com::sun::star::linguistic2 { class XSpellChecker1; } @@ -48,31 +45,18 @@ namespace chart DrawModelWrapper::DrawModelWrapper() : SdrModel() - , m_pChartItemPool(nullptr) { - m_pChartItemPool = ChartItemPool::CreateChartItemPool(); + m_xChartItemPool = ChartItemPool::CreateChartItemPool(); - SetScaleUnit(MapUnit::Map100thMM); - SetScaleFraction(Fraction(1, 1)); SetDefaultFontHeight(423); // 12pt SfxItemPool* pMasterPool = &GetItemPool(); pMasterPool->SetDefaultMetric(MapUnit::Map100thMM); - pMasterPool->SetPoolDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) ); - pMasterPool->SetPoolDefaultItem(makeSvx3DPercentDiagonalItem (5)); + pMasterPool->SetUserDefaultItem(SfxBoolItem(EE_PARA_HYPHENATE, true) ); + pMasterPool->SetUserDefaultItem(makeSvx3DPercentDiagonalItem (5)); - SfxItemPool* pPool = pMasterPool; // append chart pool to end of pool chain - for (;;) - { - SfxItemPool* pSecondary = pPool->GetSecondaryPool(); - if (!pSecondary) - break; - - pPool = pSecondary; - } - pPool->SetSecondaryPool(m_pChartItemPool); - pMasterPool->FreezeIdRanges(); + pMasterPool->GetLastPoolInChain()->SetSecondaryPool(m_xChartItemPool.get()); SetTextDefaults(); //this factory needs to be created before first use of 3D scenes once upon an office runtime @@ -116,35 +100,36 @@ DrawModelWrapper::DrawModelWrapper() DrawModelWrapper::~DrawModelWrapper() { + // normally call from ~SdrModel, but do it here explicitly before we clear m_xChartItemPool + implDtorClearModel(); + //remove m_pChartItemPool from pool chain - if(m_pChartItemPool) + if (m_xChartItemPool) { SfxItemPool* pPool = &GetItemPool(); for (;;) { SfxItemPool* pSecondary = pPool->GetSecondaryPool(); - if(pSecondary == m_pChartItemPool) + if(pSecondary == m_xChartItemPool.get()) { pPool->SetSecondaryPool (nullptr); break; } pPool = pSecondary; } - SfxItemPool::Free(m_pChartItemPool); + m_xChartItemPool.clear(); } m_pRefDevice.disposeAndClear(); } -uno::Reference< uno::XInterface > DrawModelWrapper::createUnoModel() +uno::Reference< frame::XModel > DrawModelWrapper::createUnoModel() { - uno::Reference< lang::XComponent > xComponent = new SvxUnoDrawingModel( this ); //tell Andreas Schluens if SvxUnoDrawingModel is not needed anymore -> remove export from svx to avoid link problems in writer - return uno::Reference< uno::XInterface >::query( xComponent ); + return new SvxUnoDrawingModel( this ); //tell Andreas Schluens if SvxUnoDrawingModel is not needed anymore -> remove export from svx to avoid link problems in writer } uno::Reference< frame::XModel > DrawModelWrapper::getUnoModel() { - uno::Reference< uno::XInterface > xI = SdrModel::getUnoModel(); - return uno::Reference<frame::XModel>::query( xI ); + return SdrModel::getUnoModel(); } SdrModel& DrawModelWrapper::getSdrModel() @@ -158,7 +143,7 @@ uno::Reference< lang::XMultiServiceFactory > DrawModelWrapper::getShapeFactory() return xShapeFactory; } -uno::Reference< drawing::XDrawPage > const & DrawModelWrapper::getMainDrawPage() +const rtl::Reference<SvxDrawPage> & DrawModelWrapper::getMainDrawPage() { if (m_xMainDrawPage.is()) return m_xMainDrawPage; @@ -173,12 +158,16 @@ uno::Reference< drawing::XDrawPage > const & DrawModelWrapper::getMainDrawPage() { // Take the first page in case of multiple pages. uno::Any aPage = xDrawPages->getByIndex(0); - aPage >>= m_xMainDrawPage; + uno::Reference<drawing::XDrawPage> xTmp; + aPage >>= xTmp; + m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xTmp.get()); + assert(m_xMainDrawPage); } if (!m_xMainDrawPage.is()) { - m_xMainDrawPage = xDrawPages->insertNewByIndex(0); + m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex(0).get()); + assert(m_xMainDrawPage); } //ensure that additional shapes are in front of the chart objects so create the chart root before @@ -187,7 +176,8 @@ uno::Reference< drawing::XDrawPage > const & DrawModelWrapper::getMainDrawPage() // ShapeFactory::getOrCreateShapeFactory(getShapeFactory())->getOrCreateChartRootShape( m_xMainDrawPage ); return m_xMainDrawPage; } -uno::Reference< drawing::XDrawPage > const & DrawModelWrapper::getHiddenDrawPage() + +const rtl::Reference<SvxDrawPage> & DrawModelWrapper::getHiddenDrawPage() { if( !m_xHiddenDrawPage.is() ) { @@ -198,14 +188,21 @@ uno::Reference< drawing::XDrawPage > const & DrawModelWrapper::getHiddenDrawPage if( xDrawPages->getCount()>1 ) { uno::Any aPage = xDrawPages->getByIndex( 1 ) ; - aPage >>= m_xHiddenDrawPage; + uno::Reference<drawing::XDrawPage> xTmp; + aPage >>= xTmp; + m_xHiddenDrawPage = dynamic_cast<SvxDrawPage*>(xTmp.get()); + assert(m_xHiddenDrawPage); } if(!m_xHiddenDrawPage.is()) { if( xDrawPages->getCount()==0 ) - m_xMainDrawPage = xDrawPages->insertNewByIndex( 0 ); - m_xHiddenDrawPage = xDrawPages->insertNewByIndex( 1 ); + { + m_xMainDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex( 0 ).get()); + assert(m_xMainDrawPage); + } + m_xHiddenDrawPage = dynamic_cast<SvxDrawPage*>(xDrawPages->insertNewByIndex( 1 ).get()); + assert(m_xHiddenDrawPage); } } } @@ -214,7 +211,7 @@ uno::Reference< drawing::XDrawPage > const & DrawModelWrapper::getHiddenDrawPage void DrawModelWrapper::clearMainDrawPage() { //uno::Reference<drawing::XShapes> xChartRoot( m_xMainDrawPage, uno::UNO_QUERY ); - uno::Reference<drawing::XShapes> xChartRoot( ShapeFactory::getChartRootShape( m_xMainDrawPage ) ); + rtl::Reference<SvxShapeGroupAnyD> xChartRoot( ShapeFactory::getChartRootShape( m_xMainDrawPage ) ); if( xChartRoot.is() ) { sal_Int32 nSubCount = xChartRoot->getCount(); @@ -227,8 +224,7 @@ void DrawModelWrapper::clearMainDrawPage() } } -uno::Reference< drawing::XShapes > DrawModelWrapper::getChartRootShape( - const uno::Reference< drawing::XDrawPage>& xDrawPage ) +rtl::Reference<SvxShapeGroupAnyD> DrawModelWrapper::getChartRootShape( const rtl::Reference<SvxDrawPage>& xDrawPage ) { return ShapeFactory::getChartRootShape( xDrawPage ); } @@ -296,44 +292,36 @@ SdrObject* DrawModelWrapper::getNamedSdrObject( const OUString& rObjectCID, SdrO { if(!pSearchList || rObjectCID.isEmpty()) return nullptr; - const size_t nCount = pSearchList->GetObjCount(); - for( size_t nN=0; nN<nCount; ++nN ) + for (const rtl::Reference<SdrObject>& pObj : *pSearchList) { - SdrObject* pObj = pSearchList->GetObj(nN); - if(!pObj) - continue; if( ObjectIdentifier::areIdenticalObjects( rObjectCID, pObj->GetName() ) ) - return pObj; - pObj = DrawModelWrapper::getNamedSdrObject( rObjectCID, pObj->GetSubList() ); - if(pObj) - return pObj; + return pObj.get(); + SdrObject* pNamedObj = DrawModelWrapper::getNamedSdrObject( rObjectCID, pObj->GetSubList() ); + if(pNamedObj) + return pNamedObj; } return nullptr; } -bool DrawModelWrapper::removeShape( const uno::Reference< drawing::XShape >& xShape ) +bool DrawModelWrapper::removeShape( const rtl::Reference<SvxShape>& xShape ) { - uno::Reference< container::XChild > xChild( xShape, uno::UNO_QUERY ); - if( xChild.is() ) + uno::Reference<drawing::XShapes> xShapes( xShape->getParent(), uno::UNO_QUERY ); + if( xShapes.is() ) { - uno::Reference<drawing::XShapes> xShapes( xChild->getParent(), uno::UNO_QUERY ); - if( xShapes.is() ) - { - xShapes->remove(xShape); - return true; - } + xShapes->remove(xShape); + return true; } return false; } void DrawModelWrapper::dumpAsXml(xmlTextWriterPtr pWriter) const { - xmlTextWriterStartElement(pWriter, BAD_CAST("DrawModelWrapper")); - xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); + (void)xmlTextWriterStartElement(pWriter, BAD_CAST("DrawModelWrapper")); + (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this); SdrModel::dumpAsXml(pWriter); - xmlTextWriterEndElement(pWriter); + (void)xmlTextWriterEndElement(pWriter); } } //namespace chart |