diff options
Diffstat (limited to 'chart2/source/model/main/ChartModel_Persistence.cxx')
-rw-r--r-- | chart2/source/model/main/ChartModel_Persistence.cxx | 142 |
1 files changed, 62 insertions, 80 deletions
diff --git a/chart2/source/model/main/ChartModel_Persistence.cxx b/chart2/source/model/main/ChartModel_Persistence.cxx index efb4d0b44c31..4fb17e9f1001 100644 --- a/chart2/source/model/main/ChartModel_Persistence.cxx +++ b/chart2/source/model/main/ChartModel_Persistence.cxx @@ -22,10 +22,15 @@ #include <MediaDescriptorHelper.hxx> #include <ChartViewHelper.hxx> #include <ChartModelHelper.hxx> +#include <ChartTypeManager.hxx> +#include <ChartTypeTemplate.hxx> #include <DataSourceHelper.hxx> #include <AxisHelper.hxx> #include <ThreeDHelper.hxx> -#include <DiagramHelper.hxx> +#include <Diagram.hxx> +#include <BaseCoordinateSystem.hxx> +#include <Legend.hxx> +#include <XMLFilter.hxx> #include <com/sun/star/chart2/LegendPosition.hpp> #include <com/sun/star/container/XNameAccess.hpp> @@ -41,8 +46,6 @@ #include <com/sun/star/io/IOException.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/uno/XComponentContext.hpp> -#include <com/sun/star/io/TempFile.hpp> -#include <com/sun/star/io/XSeekable.hpp> #include <com/sun/star/ucb/CommandFailedException.hpp> #include <com/sun/star/ucb/ContentCreationException.hpp> @@ -50,12 +53,14 @@ #include <ucbhelper/content.hxx> #include <unotools/ucbstreamhelper.hxx> +#include <unotools/tempfile.hxx> +#include <utility> #include <vcl/cvtgrf.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/storagehelper.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> #include <sal/log.hxx> #include <sfx2/objsh.hxx> @@ -71,8 +76,8 @@ namespace { struct lcl_PropNameEquals { - explicit lcl_PropNameEquals( const OUString & rStrToCompareWith ) : - m_aStr( rStrToCompareWith ) + explicit lcl_PropNameEquals( OUString aStrToCompareWith ) : + m_aStr(std::move( aStrToCompareWith )) {} bool operator() ( const beans::PropertyValue & rProp ) { @@ -104,7 +109,7 @@ void lcl_addStorageToMediaDescriptor( const Reference< embed::XStorage > & xStorage ) { rOutMD.realloc( rOutMD.getLength() + 1 ); - rOutMD[rOutMD.getLength() - 1] = beans::PropertyValue( + rOutMD.getArray()[rOutMD.getLength() - 1] = beans::PropertyValue( "Storage", -1, uno::Any( xStorage ), beans::PropertyState_DIRECT_VALUE ); } @@ -125,10 +130,9 @@ Reference< embed::XStorage > lcl_createStorage( uno::UNO_QUERY ); Reference< lang::XSingleServiceFactory > xStorageFact( embed::StorageFactory::create( xContext ) ); - Sequence< uno::Any > aStorageArgs( 3 ); - aStorageArgs[0] <<= xStream; - aStorageArgs[1] <<= embed::ElementModes::READWRITE; - aStorageArgs[2] <<= rMediaDescriptor; + Sequence< uno::Any > aStorageArgs{ uno::Any(xStream), + uno::Any(embed::ElementModes::READWRITE), + uno::Any(rMediaDescriptor) }; xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW ); } @@ -196,10 +200,7 @@ Reference< document::XFilter > ChartModel::impl_createFilter( if( ! xFilter.is()) { SAL_WARN("chart2", "No FilterName passed in MediaDescriptor" ); - xFilter.set( - m_xContext->getServiceManager()->createInstanceWithContext( - "com.sun.star.comp.chart2.XMLFilter", m_xContext ), - uno::UNO_QUERY_THROW ); + xFilter = new XMLFilter(m_xContext); } return xFilter; @@ -300,8 +301,7 @@ void SAL_CALL ChartModel::storeToURL( { if( m_xContext.is() && aMediaDescriptorHelper.ISSET_OutputStream ) { - Reference< io::XStream > xStream( - io::TempFile::create(m_xContext), uno::UNO_QUERY_THROW ); + rtl::Reference< utl::TempFileFastService > xStream = new utl::TempFileFastService; Reference< io::XInputStream > xInputStream( xStream->getInputStream()); Reference< embed::XStorage > xStorage( @@ -310,8 +310,7 @@ void SAL_CALL ChartModel::storeToURL( { impl_store( aReducedMediaDescriptor, xStorage ); - Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY_THROW ); - xSeekable->seek( 0 ); + xStream->seek( 0 ); ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, aMediaDescriptorHelper.OutputStream ); } } @@ -385,7 +384,7 @@ void ChartModel::insertDefaultChart() try { // create default chart - Reference< chart2::XChartTypeTemplate > xTemplate( impl_createDefaultChartTypeTemplate() ); + rtl::Reference< ::chart::ChartTypeTemplate > xTemplate( impl_createDefaultChartTypeTemplate() ); if( xTemplate.is()) { try @@ -396,12 +395,11 @@ void ChartModel::insertDefaultChart() bool bSupportsCategories = xTemplate->supportsCategories(); if( bSupportsCategories ) { - aParam.realloc( 1 ); - aParam[0] = beans::PropertyValue( "HasCategories", -1, uno::Any( true ), - beans::PropertyState_DIRECT_VALUE ); + aParam = { beans::PropertyValue( "HasCategories", -1, uno::Any( true ), + beans::PropertyState_DIRECT_VALUE ) }; } - Reference< chart2::XDiagram > xDiagram( xTemplate->createDiagramByDataSource( xDataSource, aParam ) ); + rtl::Reference< Diagram > xDiagram( xTemplate->createDiagramByDataSource2( xDataSource, aParam ) ); setFirstDiagram( xDiagram ); @@ -411,30 +409,23 @@ void ChartModel::insertDefaultChart() AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) ); // create and attach legend - Reference< chart2::XLegend > xLegend( - m_xContext->getServiceManager()->createInstanceWithContext( - "com.sun.star.chart2.Legend", m_xContext ), uno::UNO_QUERY_THROW ); - Reference< beans::XPropertySet > xLegendProperties( xLegend, uno::UNO_QUERY ); - if( xLegendProperties.is() ) - { - xLegendProperties->setPropertyValue( "FillStyle", uno::Any( drawing::FillStyle_NONE )); - xLegendProperties->setPropertyValue( "LineStyle", uno::Any( drawing::LineStyle_NONE )); - xLegendProperties->setPropertyValue( "LineColor", uno::Any( static_cast< sal_Int32 >( 0xb3b3b3 ) )); // gray30 - xLegendProperties->setPropertyValue( "FillColor", uno::Any( static_cast< sal_Int32 >( 0xe6e6e6 ) ) ); // gray10 + rtl::Reference< Legend > xLegend = new Legend(); + xLegend->setPropertyValue( "FillStyle", uno::Any( drawing::FillStyle_NONE )); + xLegend->setPropertyValue( "LineStyle", uno::Any( drawing::LineStyle_NONE )); + xLegend->setPropertyValue( "LineColor", uno::Any( static_cast< sal_Int32 >( 0xb3b3b3 ) )); // gray30 + xLegend->setPropertyValue( "FillColor", uno::Any( static_cast< sal_Int32 >( 0xe6e6e6 ) ) ); // gray10 - if( bIsRTL ) - xLegendProperties->setPropertyValue( "AnchorPosition", uno::Any( chart2::LegendPosition_LINE_START )); - } + if( bIsRTL ) + xLegend->setPropertyValue( "AnchorPosition", uno::Any( chart2::LegendPosition_LINE_START )); if(xDiagram.is()) xDiagram->setLegend( xLegend ); // set simple 3D look - Reference< beans::XPropertySet > xDiagramProperties( xDiagram, uno::UNO_QUERY ); - if( xDiagramProperties.is() ) + if( xDiagram.is() ) { - xDiagramProperties->setPropertyValue( "RightAngledAxes", uno::Any( true )); - xDiagramProperties->setPropertyValue( "D3DScenePerspective", uno::Any( drawing::ProjectionMode_PARALLEL )); - ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme::ThreeDLookScheme_Realistic ); + xDiagram->setPropertyValue( "RightAngledAxes", uno::Any( true )); + xDiagram->setPropertyValue( "D3DScenePerspective", uno::Any( drawing::ProjectionMode_PARALLEL )); + xDiagram->setScheme( ThreeDLookScheme::ThreeDLookScheme_Realistic ); } //set some new 'defaults' for wall and floor @@ -510,10 +501,9 @@ void SAL_CALL ChartModel::load( if( aMDHelper.ISSET_Stream ) { // convert XStream to XStorage via the storage factory - Sequence< uno::Any > aStorageArgs( 2 ); - aStorageArgs[0] <<= aMDHelper.Stream; - // todo: check if stream is read-only - aStorageArgs[1] <<= embed::ElementModes::READ; //WRITE | embed::ElementModes::NOCREATE); + Sequence< uno::Any > aStorageArgs{ uno::Any(aMDHelper.Stream), + // todo: check if stream is read-only + uno::Any(embed::ElementModes::READ) }; //WRITE | embed::ElementModes::NOCREATE); xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW ); @@ -522,9 +512,8 @@ void SAL_CALL ChartModel::load( { OSL_ASSERT( aMDHelper.ISSET_InputStream ); // convert XInputStream to XStorage via the storage factory - Sequence< uno::Any > aStorageArgs( 2 ); - aStorageArgs[0] <<= aMDHelper.InputStream; - aStorageArgs[1] <<= embed::ElementModes::READ; + Sequence< uno::Any > aStorageArgs{ uno::Any(aMDHelper.InputStream), + uno::Any(embed::ElementModes::READ) }; xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW ); @@ -646,16 +635,11 @@ void ChartModel::impl_notifyModifiedListeners() //always notify the view first! ChartViewHelper::setViewToDirtyState( this ); - ::comphelper::OInterfaceContainerHelper2* pIC = m_aLifeTimeManager.m_aListenerContainer - .getContainer( cppu::UnoType<util::XModifyListener>::get()); - if( pIC ) + std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex); + if( m_aLifeTimeManager.m_aModifyListeners.getLength(aGuard) ) { lang::EventObject aEvent( static_cast< lang::XComponent*>(this) ); - ::comphelper::OInterfaceIteratorHelper2 aIt( *pIC ); - while( aIt.hasMoreElements() ) - { - static_cast< util::XModifyListener* >( aIt.next() )->modified( aEvent ); - } + m_aLifeTimeManager.m_aModifyListeners.notifyEach(aGuard, &util::XModifyListener::modified, aEvent); } } @@ -684,7 +668,8 @@ void SAL_CALL ChartModel::setModified( sal_Bool bModified ) if( m_nControllerLockCount > 0 ) { - m_bUpdateNotificationsPending = true; + if (bModified) + m_bUpdateNotificationsPending = true; // Maybe !bModified should reset it? return;//don't call listeners if controllers are locked } aGuard.clear(); @@ -700,8 +685,8 @@ void SAL_CALL ChartModel::addModifyListener( if( m_aLifeTimeManager.impl_isDisposedOrClosed() ) return; //behave passive if already disposed or closed - m_aLifeTimeManager.m_aListenerContainer.addInterface( - cppu::UnoType<util::XModifyListener>::get(), xListener ); + std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex); + m_aLifeTimeManager.m_aModifyListeners.addInterface( aGuard, xListener ); } void SAL_CALL ChartModel::removeModifyListener( @@ -710,8 +695,8 @@ void SAL_CALL ChartModel::removeModifyListener( if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) ) return; //behave passive if already disposed or closed - m_aLifeTimeManager.m_aListenerContainer.removeInterface( - cppu::UnoType<util::XModifyListener>::get(), xListener ); + std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex); + m_aLifeTimeManager.m_aModifyListeners.removeInterface( aGuard, xListener ); } // util::XModifyListener @@ -728,12 +713,11 @@ void SAL_CALL ChartModel::modified( const lang::EventObject& rEvenObject) DataSourceHelper::createArguments("PivotChart", uno::Sequence<sal_Int32>(), true, true, true); Reference<chart2::data::XDataSource> xDataSource(xDataProvider->createDataSource(aArguments)); - Reference<lang::XMultiServiceFactory> xFactory(getChartTypeManager(), uno::UNO_QUERY); - Reference<chart2::XDiagram> xDiagram(getFirstDiagram()); + rtl::Reference< ::chart::ChartTypeManager > xChartTypeManager = getTypeManager(); + rtl::Reference<Diagram> xDiagram(getFirstChartDiagram()); - DiagramHelper::tTemplateWithServiceName aTemplateAndService = DiagramHelper::getTemplateForDiagram(xDiagram, xFactory); - css::uno::Reference<css::chart2::XChartTypeTemplate> xChartTypeTemplate(aTemplateAndService.first); - xChartTypeTemplate->changeDiagramData(xDiagram, xDataSource, aArguments); + Diagram::tTemplateWithServiceName aTemplateAndService = xDiagram->getTemplate(xChartTypeManager); + aTemplateAndService.xChartTypeTemplate->changeDiagramData(xDiagram, xDataSource, aArguments); } catch (const uno::Exception &) { @@ -781,16 +765,14 @@ Reference< embed::XStorage > SAL_CALL ChartModel::getDocumentStorage() void ChartModel::impl_notifyStorageChangeListeners() { - ::comphelper::OInterfaceContainerHelper2* pIC = m_aLifeTimeManager.m_aListenerContainer - .getContainer( cppu::UnoType<document::XStorageChangeListener>::get()); - if( pIC ) + std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex); + if( m_aLifeTimeManager.m_aStorageChangeListeners.getLength(aGuard) ) { - ::comphelper::OInterfaceIteratorHelper2 aIt( *pIC ); - while( aIt.hasMoreElements() ) - { - static_cast< document::XStorageChangeListener* >( aIt.next() ) - ->notifyStorageChange( static_cast< ::cppu::OWeakObject* >( this ), m_xStorage ); - } + m_aLifeTimeManager.m_aStorageChangeListeners.forEach(aGuard, + [this](const uno::Reference<document::XStorageChangeListener>& l) + { + l->notifyStorageChange( static_cast< ::cppu::OWeakObject* >( this ), m_xStorage ); + }); } } @@ -799,8 +781,8 @@ void SAL_CALL ChartModel::addStorageChangeListener( const Reference< document::X if( m_aLifeTimeManager.impl_isDisposedOrClosed() ) return; //behave passive if already disposed or closed - m_aLifeTimeManager.m_aListenerContainer.addInterface( - cppu::UnoType<document::XStorageChangeListener>::get(), xListener ); + std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex); + m_aLifeTimeManager.m_aStorageChangeListeners.addInterface( aGuard, xListener ); } void SAL_CALL ChartModel::removeStorageChangeListener( const Reference< document::XStorageChangeListener >& xListener ) @@ -808,8 +790,8 @@ void SAL_CALL ChartModel::removeStorageChangeListener( const Reference< document if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) ) return; //behave passive if already disposed or closed - m_aLifeTimeManager.m_aListenerContainer.removeInterface( - cppu::UnoType<document::XStorageChangeListener>::get(), xListener ); + std::unique_lock aGuard(m_aLifeTimeManager.m_aAccessMutex); + m_aLifeTimeManager.m_aStorageChangeListeners.removeInterface(aGuard, xListener ); } } // namespace chart |