diff options
author | Thomas Benisch <tbe@openoffice.org> | 2010-06-04 20:08:33 +0200 |
---|---|---|
committer | Thomas Benisch <tbe@openoffice.org> | 2010-06-04 20:08:33 +0200 |
commit | 577c42293f4b89ad84048314679b6a3c1e3cb434 (patch) | |
tree | f02c6c605f7b3dde99a27cce99592d3c2662cce3 /sc | |
parent | 83f4f8b725a029dab48fedc29fd28605b6e9dadc (diff) |
calc55: #i112084# All charts in a Calc document are loaded when saving the document
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/chartuno.hxx | 49 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlexprt.cxx | 81 | ||||
-rw-r--r-- | sc/source/ui/docshell/docsh.cxx | 43 | ||||
-rw-r--r-- | sc/source/ui/unoobj/chartuno.cxx | 138 |
4 files changed, 278 insertions, 33 deletions
diff --git a/sc/inc/chartuno.hxx b/sc/inc/chartuno.hxx index f5c2b758f..4545ad03f 100644 --- a/sc/inc/chartuno.hxx +++ b/sc/inc/chartuno.hxx @@ -31,7 +31,9 @@ #include "address.hxx" #include <svl/lstner.hxx> #include <tools/string.hxx> - +#include <comphelper/proparrhlp.hxx> +#include <comphelper/propertycontainer.hxx> + #include <com/sun/star/table/XTableChart.hpp> #include <com/sun/star/table/XTableCharts.hpp> #include <com/sun/star/document/XEmbeddedObjectSupplier.hpp> @@ -39,6 +41,7 @@ #include <com/sun/star/container/XEnumerationAccess.hpp> #include <com/sun/star/container/XIndexAccess.hpp> #include <com/sun/star/container/XNamed.hpp> +#include <cppuhelper/compbase4.hxx> #include <cppuhelper/implbase4.hxx> @@ -113,12 +116,20 @@ public: }; -class ScChartObj : public cppu::WeakImplHelper4< - com::sun::star::table::XTableChart, - com::sun::star::document::XEmbeddedObjectSupplier, - com::sun::star::container::XNamed, - com::sun::star::lang::XServiceInfo >, - public SfxListener +typedef ::cppu::WeakComponentImplHelper4< + ::com::sun::star::table::XTableChart, + ::com::sun::star::document::XEmbeddedObjectSupplier, + ::com::sun::star::container::XNamed, + ::com::sun::star::lang::XServiceInfo > ScChartObj_Base; + +typedef ::comphelper::OPropertyContainer ScChartObj_PBase; +typedef ::comphelper::OPropertyArrayUsageHelper< ScChartObj > ScChartObj_PABase; + +class ScChartObj : public ::comphelper::OBaseMutex + ,public ScChartObj_Base + ,public ScChartObj_PBase + ,public ScChartObj_PABase + ,public SfxListener { private: ScDocShell* pDocShell; @@ -128,12 +139,32 @@ private: void Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, bool bRowHeaders ); void GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& rRowHeaders ) const; +protected: + // ::comphelper::OPropertySetHelper + virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper(); + virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) + throw (::com::sun::star::uno::Exception); + using ::cppu::OPropertySetHelper::getFastPropertyValue; + virtual void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; + + // ::comphelper::OPropertyArrayUsageHelper + virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const; + public: ScChartObj(ScDocShell* pDocSh, SCTAB nT, const String& rN); virtual ~ScChartObj(); virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); + // XInterface + DECLARE_XINTERFACE() + + // XTypeProvider + DECLARE_XTYPEPROVIDER() + + // XComponent + virtual void SAL_CALL disposing(); + // XTableChart virtual sal_Bool SAL_CALL getHasColumnHeaders() throw(::com::sun::star::uno::RuntimeException); virtual void SAL_CALL setHasColumnHeaders( sal_Bool bHasColumnHeaders ) @@ -163,6 +194,10 @@ public: throw(::com::sun::star::uno::RuntimeException); virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw(::com::sun::star::uno::RuntimeException); + + // XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); }; #endif diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx index 1f16a6448..648a6a47e 100644 --- a/sc/source/filter/xml/xmlexprt.cxx +++ b/sc/source/filter/xml/xmlexprt.cxx @@ -3064,32 +3064,69 @@ void ScXMLExport::ExportShape(const uno::Reference < drawing::XShape >& xShape, if ( sCLSID.equalsIgnoreAsciiCase(GetChartExport()->getChartCLSID()) ) { // we have a chart - uno::Reference< frame::XModel > xChartModel; - if( ( xShapeProps->getPropertyValue( sPropModel ) >>= xChartModel ) && - xChartModel.is()) + ::rtl::OUString sRanges; + if ( pDoc ) { - uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY ); - uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartModel, uno::UNO_QUERY ); - if( xChartDoc.is() && xReceiver.is() && - ! xChartDoc->hasInternalDataProvider()) + ::rtl::OUString aChartName; + xShapeProps->getPropertyValue( sPersistName ) >>= aChartName; + ScRange aEmptyRange; + ScChartListener aSearcher( aChartName, pDoc, aEmptyRange ); + USHORT nIndex = 0; + ScChartListenerCollection* pCollection = pDoc->GetChartListenerCollection(); + if ( pCollection && pCollection->Search( &aSearcher, nIndex ) ) { - // we have a chart that gets its data from Calc - bIsChart = true; - uno::Sequence< ::rtl::OUString > aRepresentations( - xReceiver->getUsedRangeRepresentations()); - SvXMLAttributeList* pAttrList = 0; - if(aRepresentations.getLength()) + ScChartListener* pListener = static_cast< ScChartListener* >( pCollection->At( nIndex ) ); + if ( pListener ) { - // add the ranges used by the chart to the shape - // element to be able to start listening after - // load (when the chart is not yet loaded) - uno::Reference< chart2::data::XRangeXMLConversion > xRangeConverter( xChartDoc->getDataProvider(), uno::UNO_QUERY ); - ::rtl::OUString sRanges( lcl_RangeSequenceToString( aRepresentations, xRangeConverter )); - pAttrList = new SvXMLAttributeList(); - pAttrList->AddAttribute( - GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken(XML_NOTIFY_ON_UPDATE_OF_RANGES) ), sRanges ); + const ScRangeListRef& rRangeList = pListener->GetRangeList(); + if ( rRangeList.Is() ) + { + ScRangeStringConverter::GetStringFromRangeList( sRanges, rRangeList, pDoc, FormulaGrammar::CONV_OOO ); + if ( sRanges.getLength() > 0 ) + { + bIsChart = true; + SvXMLAttributeList* pAttrList = new SvXMLAttributeList(); + if ( pAttrList ) + { + pAttrList->AddAttribute( + GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken( XML_NOTIFY_ON_UPDATE_OF_RANGES ) ), sRanges ); + } + GetShapeExport()->exportShape( xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList ); + } + } + } + } + } + + if ( sRanges.getLength() == 0 ) + { + uno::Reference< frame::XModel > xChartModel; + if( ( xShapeProps->getPropertyValue( sPropModel ) >>= xChartModel ) && + xChartModel.is()) + { + uno::Reference< chart2::XChartDocument > xChartDoc( xChartModel, uno::UNO_QUERY ); + uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartModel, uno::UNO_QUERY ); + if( xChartDoc.is() && xReceiver.is() && + ! xChartDoc->hasInternalDataProvider()) + { + // we have a chart that gets its data from Calc + bIsChart = true; + uno::Sequence< ::rtl::OUString > aRepresentations( + xReceiver->getUsedRangeRepresentations()); + SvXMLAttributeList* pAttrList = 0; + if(aRepresentations.getLength()) + { + // add the ranges used by the chart to the shape + // element to be able to start listening after + // load (when the chart is not yet loaded) + uno::Reference< chart2::data::XRangeXMLConversion > xRangeConverter( xChartDoc->getDataProvider(), uno::UNO_QUERY ); + sRanges = lcl_RangeSequenceToString( aRepresentations, xRangeConverter ); + pAttrList = new SvXMLAttributeList(); + pAttrList->AddAttribute( + GetNamespaceMap().GetQNameByKey( XML_NAMESPACE_DRAW, GetXMLToken(XML_NOTIFY_ON_UPDATE_OF_RANGES) ), sRanges ); + } + GetShapeExport()->exportShape(xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList); } - GetShapeExport()->exportShape(xShape, SEF_EXPORT_NO_CHART_DATA | SEF_DEFAULT, pPoint, pAttrList); } } diff --git a/sc/source/ui/docshell/docsh.cxx b/sc/source/ui/docshell/docsh.cxx index 500a92ca6..15766f8d9 100644 --- a/sc/source/ui/docshell/docsh.cxx +++ b/sc/source/ui/docshell/docsh.cxx @@ -68,6 +68,9 @@ #include "chgviset.hxx" #include <sfx2/request.hxx> #include <com/sun/star/document/UpdateDocMode.hpp> +#include <com/sun/star/container/XContentEnumerationAccess.hpp> +#include <com/sun/star/sheet/XSpreadsheetView.hpp> +#include <com/sun/star/task/XJob.hpp> #include "scabstdlg.hxx" //CHINA001 @@ -581,6 +584,46 @@ void __EXPORT ScDocShell::Notify( SfxBroadcaster&, const SfxHint& rHint ) } } } + + try + { + uno::Reference< uno::XComponentContext > xContext; + uno::Reference< lang::XMultiServiceFactory > xServiceManager = ::comphelper::getProcessServiceFactory(); + uno::Reference< beans::XPropertySet > xProp( xServiceManager, uno::UNO_QUERY_THROW ); + xProp->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ) ) ) >>= xContext; + if ( xContext.is() ) + { + uno::Reference< container::XContentEnumerationAccess > xEnumAccess( xServiceManager, uno::UNO_QUERY_THROW ); + uno::Reference< container::XEnumeration> xEnum = xEnumAccess->createContentEnumeration( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocumentJob" ) ) ); + if ( xEnum.is() ) + { + while ( xEnum->hasMoreElements() ) + { + uno::Any aAny = xEnum->nextElement(); + uno::Reference< lang::XSingleComponentFactory > xFactory; + aAny >>= xFactory; + if ( xFactory.is() ) + { + uno::Reference< task::XJob > xJob( xFactory->createInstanceWithContext( xContext ), uno::UNO_QUERY_THROW ); + uno::Sequence< beans::NamedValue > aArgsForJob(1); + ScViewData* pViewData = GetViewData(); + SfxViewShell* pViewShell = ( pViewData ? pViewData->GetViewShell() : NULL ); + SfxViewFrame* pViewFrame = ( pViewShell ? pViewShell->GetViewFrame() : NULL ); + SfxFrame* pFrame = ( pViewFrame ? &pViewFrame->GetFrame() : NULL ); + uno::Reference< frame::XController > xController = ( pFrame ? pFrame->GetController() : 0 ); + uno::Reference< sheet::XSpreadsheetView > xSpreadsheetView( xController, uno::UNO_QUERY_THROW ); + aArgsForJob[0] = beans::NamedValue( ::rtl::OUString::createFromAscii( "SpreadsheetView" ), + uno::makeAny( xSpreadsheetView ) ); + xJob->execute( aArgsForJob ); + } + } + } + } + } + catch ( uno::Exception & ) + { + } } break; case SFX_EVENT_SAVEDOC: diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx index 6e0ecd21c..2fdbb04e4 100644 --- a/sc/source/ui/unoobj/chartuno.cxx +++ b/sc/source/ui/unoobj/chartuno.cxx @@ -31,10 +31,12 @@ #include <com/sun/star/embed/Aspects.hpp> #include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/chart2/data/XDataReceiver.hpp> #include <com/sun/star/chart/ChartDataRowSource.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/embed/Aspects.hpp> +#include <com/sun/star/table/CellRangeAddress.hpp> #include <svx/svditer.hxx> #include <svx/svdoole2.hxx> @@ -54,9 +56,12 @@ #include "chartlis.hxx" #include "unoguard.hxx" #include "chart2uno.hxx" +#include "convuno.hxx" using namespace com::sun::star; +#define PROP_HANDLE_RELATED_CELLRANGES 1 + //------------------------------------------------------------------------ SC_SIMPLE_SERVICE_INFO( ScChartObj, "ScChartObj", "com.sun.star.table.TableChart" ) @@ -451,12 +456,19 @@ sal_Bool SAL_CALL ScChartsObj::hasByName( const rtl::OUString& aName ) //------------------------------------------------------------------------ -ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, const String& rN) : - pDocShell( pDocSh ), - nTab( nT ), - aChartName( rN ) +ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, const String& rN) + :ScChartObj_Base( m_aMutex ) + ,ScChartObj_PBase( ScChartObj_Base::rBHelper ) + ,pDocShell( pDocSh ) + ,nTab( nT ) + ,aChartName( rN ) { pDocShell->GetDocument()->AddUnoObject(*this); + + uno::Sequence< table::CellRangeAddress > aInitialPropValue; + registerPropertyNoMember( ::rtl::OUString::createFromAscii( "RelatedCellRanges" ), + PROP_HANDLE_RELATED_CELLRANGES, beans::PropertyAttribute::MAYBEVOID, + ::getCppuType( &aInitialPropValue ), &aInitialPropValue ); } ScChartObj::~ScChartObj() @@ -552,6 +564,117 @@ void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, b } } +// ::comphelper::OPropertySetHelper + +::cppu::IPropertyArrayHelper& ScChartObj::getInfoHelper() +{ + return *ScChartObj_PABase::getArrayHelper(); +} + +void ScChartObj::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) throw (uno::Exception) +{ + switch ( nHandle ) + { + case PROP_HANDLE_RELATED_CELLRANGES: + { + uno::Sequence< table::CellRangeAddress > aCellRanges; + if ( rValue >>= aCellRanges ) + { + ScRangeListRef rRangeList = new ScRangeList(); + const table::CellRangeAddress* pCellRanges = aCellRanges.getArray(); + sal_Int32 nCount = aCellRanges.getLength(); + for ( sal_Int32 i = 0; i < nCount; ++i ) + { + table::CellRangeAddress aCellRange = pCellRanges[ i ]; + ScRange aRange; + ScUnoConversion::FillScRange( aRange, aCellRange ); + rRangeList->Append( aRange ); + } + ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL ); + ScChartListenerCollection* pCollection = ( pDoc ? pDoc->GetChartListenerCollection() : NULL ); + if ( pCollection ) + { + pCollection->ChangeListening( aChartName, rRangeList ); + } + } + } + break; + default: + { + } + break; + } +} + +void ScChartObj::getFastPropertyValue( uno::Any& rValue, sal_Int32 nHandle ) const +{ + switch ( nHandle ) + { + case PROP_HANDLE_RELATED_CELLRANGES: + { + ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL ); + if ( pDoc ) + { + ScRange aEmptyRange; + USHORT nIndex = 0; + ScChartListener aSearcher( aChartName, pDoc, aEmptyRange ); + ScChartListenerCollection* pCollection = pDoc->GetChartListenerCollection(); + if ( pCollection && pCollection->Search( &aSearcher, nIndex ) ) + { + ScChartListener* pListener = static_cast< ScChartListener* >( pCollection->At( nIndex ) ); + if ( pListener ) + { + const ScRangeListRef& rRangeList = pListener->GetRangeList(); + if ( rRangeList.Is() ) + { + ULONG nCount = rRangeList->Count(); + uno::Sequence< table::CellRangeAddress > aCellRanges( nCount ); + table::CellRangeAddress* pCellRanges = aCellRanges.getArray(); + for ( USHORT i = 0; i < nCount; ++i ) + { + ScRange aRange( *rRangeList->GetObject( i ) ); + table::CellRangeAddress aCellRange; + ScUnoConversion::FillApiRange( aCellRange, aRange ); + pCellRanges[ i ] = aCellRange; + } + rValue <<= aCellRanges; + } + } + } + } + } + break; + default: + { + } + break; + } +} + +// ::comphelper::OPropertyArrayUsageHelper + +::cppu::IPropertyArrayHelper* ScChartObj::createArrayHelper() const +{ + uno::Sequence< beans::Property > aProps; + describeProperties( aProps ); + return new ::cppu::OPropertyArrayHelper( aProps ); +} + +// XInterface + +IMPLEMENT_FORWARD_XINTERFACE2( ScChartObj, ScChartObj_Base, ScChartObj_PBase ) + +// XTypeProvider + +IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScChartObj, ScChartObj_Base, ScChartObj_PBase ) + +// XComponent + +void ScChartObj::disposing() +{ + ScChartObj_Base::disposing(); +} + // XTableChart sal_Bool SAL_CALL ScChartObj::getHasColumnHeaders() throw(uno::RuntimeException) @@ -681,6 +804,13 @@ void SAL_CALL ScChartObj::setName( const rtl::OUString& /* aName */ ) throw(uno: throw uno::RuntimeException(); // name cannot be changed } +// XPropertySet + +uno::Reference< beans::XPropertySetInfo > ScChartObj::getPropertySetInfo() throw (uno::RuntimeException) +{ + return createPropertySetInfo( getInfoHelper() ) ; +} + //------------------------------------------------------------------------ |