diff options
author | Vladimir Glazunov <vg@openoffice.org> | 2010-03-24 13:26:00 +0100 |
---|---|---|
committer | Vladimir Glazunov <vg@openoffice.org> | 2010-03-24 13:26:00 +0100 |
commit | 56357e8ac33235cd467715901b2ee7830871e3af (patch) | |
tree | b5f1bd289d1334a159f5bcad704f2d2bf6307682 /sc | |
parent | 8a0f23349d4acee6fadb9b628d1080ee219a7ffe (diff) | |
parent | 8195643ff81f7a60e46522767c6b6483713f4af1 (diff) |
CWS-TOOLING: integrate CWS chart43
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/charthelper.hxx | 13 | ||||
-rw-r--r-- | sc/source/core/data/documen5.cxx | 414 | ||||
-rw-r--r-- | sc/source/core/data/documen9.cxx | 84 | ||||
-rwxr-xr-x[-rw-r--r--] | sc/source/core/data/drwlayer.cxx | 186 | ||||
-rw-r--r-- | sc/source/core/tool/charthelper.cxx | 195 | ||||
-rw-r--r-- | sc/source/core/tool/makefile.mk | 1 | ||||
-rw-r--r-- | sc/source/ui/unoobj/chartuno.cxx | 15 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 5 |
8 files changed, 426 insertions, 487 deletions
diff --git a/sc/inc/charthelper.hxx b/sc/inc/charthelper.hxx index b4c677d7c3c6..50b8586bdace 100644 --- a/sc/inc/charthelper.hxx +++ b/sc/inc/charthelper.hxx @@ -29,9 +29,12 @@ #define SC_CHARTHELPER_HXX #include <tools/solar.h> +#include "address.hxx" +#include "global.hxx" -class ScDocument; -class ScAddress; +#include <com/sun/star/chart2/XChartDocument.hpp> + +class SdrObject; /** Use this to handle charts in a calc document */ @@ -40,6 +43,12 @@ class ScChartHelper public: static USHORT DoUpdateAllCharts( ScDocument* pDoc ); static USHORT DoUpdateCharts( const ScAddress& rPos, ScDocument* pDoc ); //use this to replace ScDBFunc::DoUpdateCharts in future + static void AdjustRangesOfChartsOnDestinationPage( ScDocument* pSrcDoc, ScDocument* pDestDoc, const SCTAB nSrcTab, const SCTAB nDestTab ); + static ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument > GetChartFromSdrObject( SdrObject* pObject ); + static void GetChartRanges( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDoc, + ::com::sun::star::uno::Sequence< rtl::OUString >& rRanges ); + static void SetChartRanges( const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartDocument >& xChartDoc, + const ::com::sun::star::uno::Sequence< rtl::OUString >& rRanges ); }; #endif diff --git a/sc/source/core/data/documen5.cxx b/sc/source/core/data/documen5.cxx index 14a88abd32ca..d6653402c46a 100644 --- a/sc/source/core/data/documen5.cxx +++ b/sc/source/core/data/documen5.cxx @@ -64,107 +64,12 @@ #include "miscuno.hxx" #include "chart2uno.hxx" +#include "charthelper.hxx" using namespace ::com::sun::star; // ----------------------------------------------------------------------- -void lcl_GetChartRanges( const uno::Reference< chart2::XChartDocument >& xChartDoc, - uno::Sequence< rtl::OUString >& rRanges ) -{ - rRanges.realloc(0); - uno::Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY ); - if( !xDataSource.is() ) - return; - //uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider(); - - uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledDataSequences( xDataSource->getDataSequences() ); - rRanges.realloc(2*aLabeledDataSequences.getLength()); - sal_Int32 nRealCount=0; - for( sal_Int32 nN=0;nN<aLabeledDataSequences.getLength();nN++) - { - uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aLabeledDataSequences[nN] ); - if(!xLabeledSequence.is()) - continue; - uno::Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel()); - uno::Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues()); - - if( xLabel.is()) - rRanges[nRealCount++] = xLabel->getSourceRangeRepresentation(); - if( xValues.is()) - rRanges[nRealCount++] = xValues->getSourceRangeRepresentation(); - } - rRanges.realloc(nRealCount); -} - -void lcl_SetChartRanges( const uno::Reference< chart2::XChartDocument >& xChartDoc, - const uno::Sequence< rtl::OUString >& rRanges ) -{ - uno::Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY ); - if( !xDataSource.is() ) - return; - uno::Reference< chart2::data::XDataProvider > xDataProvider = xChartDoc->getDataProvider(); - if( !xDataProvider.is() ) - return; - - uno::Reference< frame::XModel > xModel( xChartDoc, uno::UNO_QUERY ); - if( xModel.is() ) - xModel->lockControllers(); - - try - { - rtl::OUString aPropertyNameRole( ::rtl::OUString::createFromAscii("Role") ); - - uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledDataSequences( xDataSource->getDataSequences() ); - sal_Int32 nRange=0; - for( sal_Int32 nN=0; (nN<aLabeledDataSequences.getLength()) && (nRange<rRanges.getLength()); nN++ ) - { - uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aLabeledDataSequences[nN] ); - if(!xLabeledSequence.is()) - continue; - uno::Reference< beans::XPropertySet > xLabel( xLabeledSequence->getLabel(), uno::UNO_QUERY ); - uno::Reference< beans::XPropertySet > xValues( xLabeledSequence->getValues(), uno::UNO_QUERY ); - - if( xLabel.is()) - { - // the range string must be in Calc A1 format. - uno::Reference< chart2::data::XDataSequence > xNewSeq( - xDataProvider->createDataSequenceByRangeRepresentation( rRanges[nRange++] )); - - uno::Reference< beans::XPropertySet > xNewProps( xNewSeq, uno::UNO_QUERY ); - if( xNewProps.is() ) - xNewProps->setPropertyValue( aPropertyNameRole, xLabel->getPropertyValue( aPropertyNameRole ) ); - - xLabeledSequence->setLabel( xNewSeq ); - } - - if( !(nRange<rRanges.getLength()) ) - break; - - if( xValues.is()) - { - // the range string must be in Calc A1 format. - uno::Reference< chart2::data::XDataSequence > xNewSeq( - xDataProvider->createDataSequenceByRangeRepresentation( rRanges[nRange++] )); - - uno::Reference< beans::XPropertySet > xNewProps( xNewSeq, uno::UNO_QUERY ); - if( xNewProps.is() ) - xNewProps->setPropertyValue( aPropertyNameRole, xValues->getPropertyValue( aPropertyNameRole ) ); - - xLabeledSequence->setValues( xNewSeq ); - } - } - } - catch ( uno::Exception& ex ) - { - (void)ex; - DBG_ERROR("Exception in lcl_SetChartRanges - invalid range string?"); - } - - if( xModel.is() ) - xModel->unlockControllers(); -} - void lcl_GetChartParameters( const uno::Reference< chart2::XChartDocument >& xChartDoc, rtl::OUString& rRanges, chart::ChartDataRowSource& rDataRowSource, bool& rHasCategories, bool& rFirstCellAsLabel ) @@ -363,14 +268,7 @@ uno::Reference< chart2::XChartDocument > ScDocument::GetChartByName( const Strin if ( pObject->GetObjIdentifier() == OBJ_OLE2 && ((SdrOle2Obj*)pObject)->GetPersistName() == rChartName ) { - uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); - if ( xIPObj.is() ) - { - svt::EmbeddedObjectRef::TryRunningState( xIPObj ); - - uno::Reference< util::XCloseable > xComponent = xIPObj->getComponent(); - xReturn.set( uno::Reference< chart2::XChartDocument >( xComponent, uno::UNO_QUERY ) ); - } + xReturn.set( ScChartHelper::GetChartFromSdrObject( pObject ) ); return xReturn; } pObject = aIter.Next(); @@ -386,7 +284,7 @@ void ScDocument::GetChartRanges( const String& rChartName, ::std::vector< ScRang if ( xChartDoc.is() ) { uno::Sequence< rtl::OUString > aRangeStrings; - lcl_GetChartRanges( xChartDoc, aRangeStrings ); + ScChartHelper::GetChartRanges( xChartDoc, aRangeStrings ); for( sal_Int32 nN=0; nN<aRangeStrings.getLength(); nN++ ) { ScRangeList aRanges; @@ -410,7 +308,7 @@ void ScDocument::SetChartRanges( const String& rChartName, const ::std::vector< aScRangeList.Format( sRangeStr, SCR_ABS_3D, this ); aRangeStrings[nN]=sRangeStr; } - lcl_SetChartRanges( xChartDoc, aRangeStrings ); + ScChartHelper::SetChartRanges( xChartDoc, aRangeStrings ); } } @@ -435,32 +333,25 @@ void ScDocument::GetOldChartParameters( const String& rName, if ( pObject->GetObjIdentifier() == OBJ_OLE2 && ((SdrOle2Obj*)pObject)->GetPersistName() == rName ) { - uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); - if ( xIPObj.is() ) + uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) ); + if ( xChartDoc.is() ) { - svt::EmbeddedObjectRef::TryRunningState( xIPObj ); - - uno::Reference< util::XCloseable > xComponent = xIPObj->getComponent(); - uno::Reference< chart2::XChartDocument > xChartDoc( xComponent, uno::UNO_QUERY ); - if ( xChartDoc.is() ) + chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS; + bool bHasCategories = false; + bool bFirstCellAsLabel = false; + rtl::OUString aRangesStr; + lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); + + rRanges.Parse( aRangesStr, this ); + if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS ) { - chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS; - bool bHasCategories = false; - bool bFirstCellAsLabel = false; - rtl::OUString aRangesStr; - lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); - - rRanges.Parse( aRangesStr, this ); - if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS ) - { - rRowHeaders = bHasCategories; - rColHeaders = bFirstCellAsLabel; - } - else - { - rColHeaders = bHasCategories; - rRowHeaders = bFirstCellAsLabel; - } + rRowHeaders = bHasCategories; + rColHeaders = bFirstCellAsLabel; + } + else + { + rColHeaders = bHasCategories; + rRowHeaders = bFirstCellAsLabel; } } return; @@ -489,75 +380,68 @@ void ScDocument::UpdateChartArea( const String& rChartName, if ( pObject->GetObjIdentifier() == OBJ_OLE2 && ((SdrOle2Obj*)pObject)->GetPersistName() == rChartName ) { - uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); - if ( xIPObj.is() ) + uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) ); + uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY ); + if ( xChartDoc.is() && xReceiver.is() ) { - svt::EmbeddedObjectRef::TryRunningState( xIPObj ); + ScRangeListRef aNewRanges; + chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS; + bool bHasCategories = false; + bool bFirstCellAsLabel = false; + rtl::OUString aRangesStr; + lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); - uno::Reference< util::XCloseable > xComponent = xIPObj->getComponent(); - uno::Reference< chart2::XChartDocument > xChartDoc( xComponent, uno::UNO_QUERY ); - uno::Reference< chart2::data::XDataReceiver > xReceiver( xComponent, uno::UNO_QUERY ); - if ( xChartDoc.is() && xReceiver.is() ) - { - ScRangeListRef aNewRanges; - chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS; - bool bHasCategories = false; - bool bFirstCellAsLabel = false; - rtl::OUString aRangesStr; - lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); + sal_Bool bInternalData = xChartDoc->hasInternalDataProvider(); - sal_Bool bInternalData = xChartDoc->hasInternalDataProvider(); + if ( bAdd && !bInternalData ) + { + // append to old ranges, keep other settings - if ( bAdd && !bInternalData ) - { - // append to old ranges, keep other settings + aNewRanges = new ScRangeList; + aNewRanges->Parse( aRangesStr, this ); - aNewRanges = new ScRangeList; - aNewRanges->Parse( aRangesStr, this ); + ULONG nAddCount = rNewList->Count(); + for ( ULONG nAdd=0; nAdd<nAddCount; nAdd++ ) + aNewRanges->Append( *rNewList->GetObject(nAdd) ); + } + else + { + // directly use new ranges (only eDataRowSource is used from old settings) - ULONG nAddCount = rNewList->Count(); - for ( ULONG nAdd=0; nAdd<nAddCount; nAdd++ ) - aNewRanges->Append( *rNewList->GetObject(nAdd) ); + if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS ) + { + bHasCategories = bRowHeaders; + bFirstCellAsLabel = bColHeaders; } else { - // directly use new ranges (only eDataRowSource is used from old settings) - - if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS ) - { - bHasCategories = bRowHeaders; - bFirstCellAsLabel = bColHeaders; - } - else - { - bHasCategories = bColHeaders; - bFirstCellAsLabel = bRowHeaders; - } - aNewRanges = rNewList; + bHasCategories = bColHeaders; + bFirstCellAsLabel = bRowHeaders; } + aNewRanges = rNewList; + } - if ( bInternalData && pShell ) - { - // Calc -> DataProvider - uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( this ); - xReceiver->attachDataProvider( xDataProvider ); - uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( - pShell->GetModel(), uno::UNO_QUERY ); - xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier ); - } + if ( bInternalData && pShell ) + { + // Calc -> DataProvider + uno::Reference< chart2::data::XDataProvider > xDataProvider = new ScChart2DataProvider( this ); + xReceiver->attachDataProvider( xDataProvider ); + uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( + pShell->GetModel(), uno::UNO_QUERY ); + xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier ); + } - String sRangeStr; - aNewRanges->Format( sRangeStr, SCR_ABS_3D, this, GetAddressConvention() ); + String sRangeStr; + aNewRanges->Format( sRangeStr, SCR_ABS_3D, this, GetAddressConvention() ); - lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); + lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); - pChartListenerCollection->ChangeListening( rChartName, aNewRanges ); + pChartListenerCollection->ChangeListening( rChartName, aNewRanges ); - // ((SdrOle2Obj*)pObject)->GetNewReplacement(); - // pObject->ActionChanged(); + // ((SdrOle2Obj*)pObject)->GetNewReplacement(); + // pObject->ActionChanged(); - return; // nicht weitersuchen - } + return; // nicht weitersuchen } } pObject = aIter.Next(); @@ -569,124 +453,25 @@ void ScDocument::UpdateChart( const String& rChartName ) { if (!pDrawLayer || bInDtorClear) return; - - for (SCTAB nTab=0; nTab<=MAXTAB && pTab[nTab]; nTab++) + uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( rChartName ) ); + if( xChartDoc.is() ) { - SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab)); - DBG_ASSERT(pPage,"Page ?"); - - SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS ); - SdrObject* pObject = aIter.Next(); - while (pObject) + try + { + uno::Reference< util::XModifiable > xModif( xChartDoc, uno::UNO_QUERY_THROW ); + if( apTemporaryChartLock.get() ) + apTemporaryChartLock->AlsoLockThisChart( uno::Reference< frame::XModel >( xModif, uno::UNO_QUERY ) ); + xModif->setModified( sal_True ); + } + catch ( uno::Exception& ) { - if ( pObject->GetObjIdentifier() == OBJ_OLE2 && - ((SdrOle2Obj*)pObject)->GetPersistName() == rChartName ) - { - //@todo?: maybe we need a notification - //from the calc to the chart in future - //that calc content has changed - // ((SdrOle2Obj*)pObject)->GetNewReplacement(); - - // Load the object and set modified - - uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); - if ( xIPObj.is() ) - { - svt::EmbeddedObjectRef::TryRunningState( xIPObj ); - - try - { - uno::Reference< util::XModifiable > xModif( xIPObj->getComponent(), uno::UNO_QUERY_THROW ); - if( apTemporaryChartLock.get() ) - apTemporaryChartLock->AlsoLockThisChart( uno::Reference< frame::XModel >( xModif, uno::UNO_QUERY ) ); - xModif->setModified( sal_True ); - } - catch ( uno::Exception& ) - { - } - } - - // repaint - - pObject->ActionChanged(); - - // After the update, chart keeps track of its own data source ranges, - // the listener doesn't need to listen anymore. - - pChartListenerCollection->ChangeListening( rChartName, new ScRangeList ); - - return; - - /* old chart: - uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); - if ( xIPObj.is() ) - { - const SchMemChart* pChartData = SchDLL::GetChartData(xIPObj); - if ( pChartData ) - { - ScChartArray aArray( this, *pChartData ); - - SchMemChart* pMemChart = aArray.CreateMemChart(); - ScChartArray::CopySettings( *pMemChart, *pChartData ); - - // #57655# Chart-Update ohne geaenderte Einstellungen (MemChart) - // soll das Dokument nicht auf modified setzen (z.B. in frisch - // geladenem Dokument durch initiales Recalc) - - // #72576# disable SetModified for readonly documents only - - sal_Bool bEnabled = ( (pShell && pShell->IsReadOnly()) || IsImportingXML() ); - sal_Bool bModified = sal_False; - uno::Reference< util::XModifiable > xModif; - - if ( bEnabled ) - { - try - { - xModif = - uno::Reference< util::XModifiable >( xIPObj->getComponent(), uno::UNO_QUERY_THROW ); - bModified = xModif->isModified(); - } - catch( uno::Exception& ) - { - bEnabled = sal_False; - } - } - - SchDLL::Update( xIPObj, pMemChart, pWindow ); - ((SdrOle2Obj*)pObject)->GetNewReplacement(); - delete pMemChart; - - // Dies veranlaesst Chart zum sofortigen Update - //SvData aEmpty; - //aIPObj->SendDataChanged( aEmpty ); - - // the method below did nothing in SO7 -//REMOVE aIPObj->SendViewChanged(); - - // redraw only - pObject->ActionChanged(); - // pObject->SendRepaintBroadcast(); - - if ( bEnabled && xModif.is() ) - { - try - { - if ( xModif->isModified() != bModified ) - xModif->setModified( bModified ); - } - catch ( uno::Exception& ) - {} - } - - return; // nicht weitersuchen - } - } - */ - } - pObject = aIter.Next(); } } + + // After the update, chart keeps track of its own data source ranges, + // the listener doesn't need to listen anymore. + if(pChartListenerCollection) + pChartListenerCollection->ChangeListening( rChartName, new ScRangeList ); } void ScDocument::RestoreChartListener( const String& rName ) @@ -823,31 +608,24 @@ void ScDocument::SetChartRangeList( const String& rChartName, if ( pObject->GetObjIdentifier() == OBJ_OLE2 && ((SdrOle2Obj*)pObject)->GetPersistName() == rChartName ) { - uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); - if ( xIPObj.is() ) + uno::Reference< chart2::XChartDocument > xChartDoc( ScChartHelper::GetChartFromSdrObject( pObject ) ); + uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY ); + if ( xChartDoc.is() && xReceiver.is() ) { - svt::EmbeddedObjectRef::TryRunningState( xIPObj ); - - uno::Reference< util::XCloseable > xComponent = xIPObj->getComponent(); - uno::Reference< chart2::XChartDocument > xChartDoc( xComponent, uno::UNO_QUERY ); - uno::Reference< chart2::data::XDataReceiver > xReceiver( xComponent, uno::UNO_QUERY ); - if ( xChartDoc.is() && xReceiver.is() ) - { - ScRangeListRef aNewRanges; - chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS; - bool bHasCategories = false; - bool bFirstCellAsLabel = false; - rtl::OUString aRangesStr; - lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); + ScRangeListRef aNewRanges; + chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS; + bool bHasCategories = false; + bool bFirstCellAsLabel = false; + rtl::OUString aRangesStr; + lcl_GetChartParameters( xChartDoc, aRangesStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); - String sRangeStr; - rNewRangeListRef->Format( sRangeStr, SCR_ABS_3D, this, GetAddressConvention() ); + String sRangeStr; + rNewRangeListRef->Format( sRangeStr, SCR_ABS_3D, this, GetAddressConvention() ); - lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); + lcl_SetChartParameters( xReceiver, sRangeStr, eDataRowSource, bHasCategories, bFirstCellAsLabel ); - // don't modify pChartListenerCollection here, called from there - return; - } + // don't modify pChartListenerCollection here, called from there + return; } } pObject = aIter.Next(); diff --git a/sc/source/core/data/documen9.cxx b/sc/source/core/data/documen9.cxx index b9abe0839279..ec6bba8cc33d 100644 --- a/sc/source/core/data/documen9.cxx +++ b/sc/source/core/data/documen9.cxx @@ -28,10 +28,6 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sc.hxx" -#include <com/sun/star/embed/XEmbeddedObject.hpp> -#include <com/sun/star/embed/XClassifiedObject.hpp> -#include <com/sun/star/chart2/data/XDataReceiver.hpp> - // INCLUDE --------------------------------------------------------------- #include "scitems.hxx" @@ -65,10 +61,10 @@ #include "rechead.hxx" #include "poolhelp.hxx" #include "docpool.hxx" -#include "chartarr.hxx" #include "detfunc.hxx" // for UpdateAllComments #include "editutil.hxx" #include "postit.hxx" +#include "charthelper.hxx" using namespace ::com::sun::star; @@ -102,37 +98,6 @@ XColorTable* ScDocument::GetColorTable() } } -BOOL lcl_AdjustRanges( ScRangeList& rRanges, SCTAB nSource, SCTAB nDest, SCTAB nTabCount ) -{ - //! if multiple sheets are copied, update references into the other copied sheets? - - BOOL bChanged = FALSE; - - ULONG nCount = rRanges.Count(); - for (ULONG i=0; i<nCount; i++) - { - ScRange* pRange = rRanges.GetObject(i); - if ( pRange->aStart.Tab() == nSource && pRange->aEnd.Tab() == nSource ) - { - pRange->aStart.SetTab( nDest ); - pRange->aEnd.SetTab( nDest ); - bChanged = TRUE; - } - if ( pRange->aStart.Tab() >= nTabCount ) - { - pRange->aStart.SetTab( nTabCount > 0 ? ( nTabCount - 1 ) : 0 ); - bChanged = TRUE; - } - if ( pRange->aEnd.Tab() >= nTabCount ) - { - pRange->aEnd.SetTab( nTabCount > 0 ? ( nTabCount - 1 ) : 0 ); - bChanged = TRUE; - } - } - - return bChanged; -} - void ScDocument::TransferDrawPage(ScDocument* pSrcDoc, SCTAB nSrcPos, SCTAB nDestPos) { if (pDrawLayer && pSrcDoc->pDrawLayer) @@ -158,53 +123,14 @@ void ScDocument::TransferDrawPage(ScDocument* pSrcDoc, SCTAB nSrcPos, SCTAB nDes if (pDrawLayer->IsRecording()) pDrawLayer->AddCalcUndo( new SdrUndoInsertObj( *pNewObject ) ); - // #71726# if it's a chart, make sure the data references are valid - // (this must be after InsertObject!) - - if ( pNewObject->GetObjIdentifier() == OBJ_OLE2 ) - { - uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pNewObject)->GetObjRef(); - uno::Reference< embed::XClassifiedObject > xClassified( xIPObj, uno::UNO_QUERY ); - SvGlobalName aObjectClassName; - if ( xClassified.is() ) - { - try { - aObjectClassName = SvGlobalName( xClassified->getClassID() ); - } catch( uno::Exception& ) - { - // TODO: handle error? - } - } - - if ( xIPObj.is() && SotExchange::IsChart( aObjectClassName ) ) - { - String aChartName = ((SdrOle2Obj*)pNewObject)->GetPersistName(); - - uno::Reference< chart2::XChartDocument > xChartDoc( GetChartByName( aChartName ) ); - uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY ); - if( xChartDoc.is() && xReceiver.is() ) - { - if( !xChartDoc->hasInternalDataProvider() ) - { - ::std::vector< ScRangeList > aRangesVector; - GetChartRanges( aChartName, aRangesVector, pSrcDoc ); - - ::std::vector< ScRangeList >::iterator aIt( aRangesVector.begin() ); - for( ; aIt!=aRangesVector.end(); aIt++ ) - { - ScRangeList& rScRangeList( *aIt ); - lcl_AdjustRanges( rScRangeList, nSrcPos, nDestPos, GetTableCount() ); - } - SetChartRanges( aChartName, aRangesVector ); - } - } - } - } - pOldObject = aIter.Next(); } } } + + // #71726# make sure the data references of charts are adapted + // (this must be after InsertObject!) + ScChartHelper::AdjustRangesOfChartsOnDestinationPage( pSrcDoc, this, nSrcPos, nDestPos ); } void ScDocument::InitDrawLayer( SfxObjectShell* pDocShell ) diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx index 4e9de6179809..69dee934ce66 100644..100755 --- a/sc/source/core/data/drwlayer.cxx +++ b/sc/source/core/data/drwlayer.cxx @@ -28,6 +28,7 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sc.hxx" #include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/chart/XChartDocument.hpp> #include <com/sun/star/embed/XEmbeddedObject.hpp> #include <com/sun/star/embed/XVisualObject.hpp> #include <com/sun/star/embed/XClassifiedObject.hpp> @@ -79,6 +80,7 @@ #include "chartarr.hxx" #include "postit.hxx" #include "attrib.hxx" +#include "charthelper.hxx" #define DET_ARROW_OFFSET 1000 @@ -1386,7 +1388,9 @@ void ScDrawLayer::CopyToClip( ScDocument* pClipDoc, SCTAB nTab, const Rectangle& pNewObject->SetModel(pDestModel); pNewObject->SetPage(pDestPage); - pNewObject->NbcMove(Size(0,0)); + uno::Reference< chart2::XChartDocument > xOldChart( ScChartHelper::GetChartFromSdrObject( pOldObject ) ); + if(!xOldChart.is())//#i110034# do not move charts as they loose all their data references otherwise + pNewObject->NbcMove(Size(0,0)); pDestPage->InsertObject( pNewObject ); // no undo needed in clipboard document @@ -1399,38 +1403,48 @@ void ScDrawLayer::CopyToClip( ScDocument* pClipDoc, SCTAB nTab, const Rectangle& } } -BOOL lcl_IsAllInRange( const ScRangeList& rRanges, const ScRange& rClipRange ) +BOOL lcl_IsAllInRange( const ::std::vector< ScRangeList >& rRangesVector, const ScRange& rClipRange ) { - // check if every range of rRanges is completely in rClipRange + // check if every range of rRangesVector is completely in rClipRange - ULONG nCount = rRanges.Count(); - for (ULONG i=0; i<nCount; i++) + ::std::vector< ScRangeList >::const_iterator aIt = rRangesVector.begin(); + for( ;aIt!=rRangesVector.end(); ++aIt ) { - ScRange aRange = *rRanges.GetObject(i); - if ( !rClipRange.In( aRange ) ) + const ScRangeList& rRanges = *aIt; + ULONG nCount = rRanges.Count(); + for (ULONG i=0; i<nCount; i++) { - return FALSE; // at least one range is not valid + ScRange aRange = *rRanges.GetObject(i); + if ( !rClipRange.In( aRange ) ) + { + return FALSE; // at least one range is not valid + } } } return TRUE; // everything is fine } -BOOL lcl_MoveRanges( ScRangeList& rRanges, const ScRange& rSourceRange, const ScAddress& rDestPos ) +BOOL lcl_MoveRanges( ::std::vector< ScRangeList >& rRangesVector, const ScRange& rSourceRange, const ScAddress& rDestPos ) { BOOL bChanged = FALSE; - ULONG nCount = rRanges.Count(); - for (ULONG i=0; i<nCount; i++) + ::std::vector< ScRangeList >::iterator aIt = rRangesVector.begin(); + for( ;aIt!=rRangesVector.end(); ++aIt ) { - ScRange* pRange = rRanges.GetObject(i); - if ( rSourceRange.In( *pRange ) ) + ScRangeList& rRanges = *aIt; + ULONG nCount = rRanges.Count(); + for (ULONG i=0; i<nCount; i++) { - SCsCOL nDiffX = rDestPos.Col() - (SCsCOL)rSourceRange.aStart.Col(); - SCsROW nDiffY = rDestPos.Row() - (SCsROW)rSourceRange.aStart.Row(); - SCsTAB nDiffZ = rDestPos.Tab() - (SCsTAB)rSourceRange.aStart.Tab(); - pRange->Move( nDiffX, nDiffY, nDiffZ ); - bChanged = TRUE; + ScRange* pRange = rRanges.GetObject(i); + if ( rSourceRange.In( *pRange ) ) + { + SCsCOL nDiffX = rDestPos.Col() - (SCsCOL)rSourceRange.aStart.Col(); + SCsROW nDiffY = rDestPos.Row() - (SCsROW)rSourceRange.aStart.Row(); + SCsTAB nDiffZ = rDestPos.Tab() - (SCsTAB)rSourceRange.aStart.Tab(); + pRange->Move( nDiffX, nDiffY, nDiffZ ); + bChanged = TRUE; + } } } @@ -1469,6 +1483,37 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const if ( !pSrcPage || !pDestPage ) return; + SdrObjListIter aIter( *pSrcPage, IM_FLAT ); + SdrObject* pOldObject = aIter.Next(); + + ScDocument* pClipDoc = pClipModel->GetDocument(); + // a clipboard document and its source share the same document item pool, + // so the pointers can be compared to see if this is copy&paste within + // the same document + BOOL bSameDoc = pDoc && pClipDoc && pDoc->GetPool() == pClipDoc->GetPool(); + BOOL bDestClip = pDoc && pDoc->IsClipboard(); + + //#i110034# charts need correct sheet names for xml range conversion during load + //so the target sheet name is temporarily renamed (if we have any SdrObjects) + String aDestTabName; + BOOL bRestoreDestTabName = FALSE; + if( pOldObject && !bSameDoc && !bDestClip ) + { + if( pDoc && pClipDoc ) + { + String aSourceTabName; + if( pClipDoc->GetName( nSourceTab, aSourceTabName ) + && pDoc->GetName( nDestTab, aDestTabName ) ) + { + if( !(aSourceTabName==aDestTabName) && + pDoc->ValidNewTabName(aSourceTabName) ) + { + bRestoreDestTabName = pDoc->RenameTab( nDestTab, aSourceTabName ); //BOOL bUpdateRef = TRUE, BOOL bExternalDocument = FALSE + } + } + } + } + // first mirror, then move Size aMove( rDestRange.Left() - aMirroredSource.Left(), rDestRange.Top() - aMirroredSource.Top() ); @@ -1497,8 +1542,6 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const } Point aRefPos = rDestRange.TopLeft(); // for resizing (after moving) - SdrObjListIter aIter( *pSrcPage, IM_FLAT ); - SdrObject* pOldObject = aIter.Next(); while (pOldObject) { Rectangle aObjRect = pOldObject->GetCurrentBoundRect(); @@ -1522,7 +1565,7 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const if (bRecording) AddCalcUndo( new SdrUndoInsertObj( *pNewObject ) ); - // handle chart data references (after InsertObject) + //#i110034# handle chart data references (after InsertObject) if ( pNewObject->GetObjIdentifier() == OBJ_OLE2 ) { @@ -1541,73 +1584,63 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const if ( xIPObj.is() && SotExchange::IsChart( aObjectClassName ) ) { - String aNewName = ((SdrOle2Obj*)pNewObject)->GetPersistName(); - - //! need to set new DataProvider, or does Chart handle this itself? - - ScRangeListRef xRanges( new ScRangeList ); - BOOL bColHeaders = FALSE; - BOOL bRowHeaders = FALSE; - pDoc->GetOldChartParameters( aNewName, *xRanges, bColHeaders, bRowHeaders ); - - if ( xRanges->Count() > 0 ) + uno::Reference< chart2::XChartDocument > xNewChart( ScChartHelper::GetChartFromSdrObject( pNewObject ) ); + if( xNewChart.is() && !xNewChart->hasInternalDataProvider() ) { - ScDocument* pClipDoc = pClipModel->GetDocument(); - - // a clipboard document and its source share the same document item pool, - // so the pointers can be compared to see if this is copy&paste within - // the same document - BOOL bSameDoc = pDoc && pClipDoc && pDoc->GetPool() == pClipDoc->GetPool(); - - BOOL bDestClip = pDoc && pDoc->IsClipboard(); - - BOOL bInSourceRange = FALSE; - ScRange aClipRange; - if ( pClipDoc ) + String aChartName = ((SdrOle2Obj*)pNewObject)->GetPersistName(); + ::std::vector< ScRangeList > aRangesVector; + pDoc->GetChartRanges( aChartName, aRangesVector, pDoc ); + if( !aRangesVector.empty() ) { - SCCOL nClipStartX; - SCROW nClipStartY; - SCCOL nClipEndX; - SCROW nClipEndY; - pClipDoc->GetClipStart( nClipStartX, nClipStartY ); - pClipDoc->GetClipArea( nClipEndX, nClipEndY, TRUE ); - nClipEndX = nClipEndX + nClipStartX; - nClipEndY += nClipStartY; // GetClipArea returns the difference - - aClipRange = ScRange( nClipStartX, nClipStartY, nSourceTab, - nClipEndX, nClipEndY, nSourceTab ); - - bInSourceRange = lcl_IsAllInRange( *xRanges, aClipRange ); - } + BOOL bInSourceRange = FALSE; + ScRange aClipRange; + if ( pClipDoc ) + { + SCCOL nClipStartX; + SCROW nClipStartY; + SCCOL nClipEndX; + SCROW nClipEndY; + pClipDoc->GetClipStart( nClipStartX, nClipStartY ); + pClipDoc->GetClipArea( nClipEndX, nClipEndY, TRUE ); + nClipEndX = nClipEndX + nClipStartX; + nClipEndY += nClipStartY; // GetClipArea returns the difference + + SCTAB nClipTab = bRestoreDestTabName ? nDestTab : nSourceTab; + aClipRange = ScRange( nClipStartX, nClipStartY, nClipTab, + nClipEndX, nClipEndY, nClipTab ); + + bInSourceRange = lcl_IsAllInRange( aRangesVector, aClipRange ); + } - // always lose references when pasting into a clipboard document (transpose) - if ( ( bInSourceRange || bSameDoc ) && !bDestClip ) - { - if ( bInSourceRange ) + // always lose references when pasting into a clipboard document (transpose) + if ( ( bInSourceRange || bSameDoc ) && !bDestClip ) { - if ( rDestPos != aClipRange.aStart ) + if ( bInSourceRange ) { - // update the data ranges to the new (copied) position - ScRangeListRef xNewRanges = new ScRangeList( *xRanges ); - if ( lcl_MoveRanges( *xNewRanges, aClipRange, rDestPos ) ) + if ( rDestPos != aClipRange.aStart ) { - pDoc->UpdateChartArea( aNewName, xNewRanges, bColHeaders, bRowHeaders, FALSE ); + // update the data ranges to the new (copied) position + if ( lcl_MoveRanges( aRangesVector, aClipRange, rDestPos ) ) + pDoc->SetChartRanges( aChartName, aRangesVector ); } } + else + { + // leave the ranges unchanged + } } else { - // leave the ranges unchanged - } - } - else - { - // pasting into a new document without the complete source data - // -> break connection to source data + // pasting into a new document without the complete source data + // -> break connection to source data and switch to own data - // (see ScDocument::UpdateChartListenerCollection, PastingDrawFromOtherDoc) + uno::Reference< chart::XChartDocument > xOldChartDoc( ScChartHelper::GetChartFromSdrObject( pOldObject ), uno::UNO_QUERY ); + uno::Reference< chart::XChartDocument > xNewChartDoc( xNewChart, uno::UNO_QUERY ); + if( xOldChartDoc.is() && xNewChartDoc.is() ) + xNewChartDoc->attachData( xOldChartDoc->getData() ); - //! need chart interface to switch to own data + // (see ScDocument::UpdateChartListenerCollection, PastingDrawFromOtherDoc) + } } } } @@ -1616,6 +1649,9 @@ void ScDrawLayer::CopyFromClip( ScDrawLayer* pClipModel, SCTAB nSourceTab, const pOldObject = aIter.Next(); } + + if( bRestoreDestTabName ) + pDoc->RenameTab( nDestTab, aDestTabName ); } void ScDrawLayer::MirrorRTL( SdrObject* pObj ) diff --git a/sc/source/core/tool/charthelper.cxx b/sc/source/core/tool/charthelper.cxx index 756493cc86e9..1b2cde3d4a6d 100644 --- a/sc/source/core/tool/charthelper.cxx +++ b/sc/source/core/tool/charthelper.cxx @@ -31,17 +31,18 @@ #include "charthelper.hxx" #include "document.hxx" #include "drwlayer.hxx" +#include "rangelst.hxx" +#include "chartlis.hxx" //#include <vcl/svapp.hxx> #include <svx/svditer.hxx> #include <svx/svdoole2.hxx> #include <svx/svdpage.hxx> -/* +#include <com/sun/star/chart2/data/XDataReceiver.hpp> + using namespace com::sun::star; using ::com::sun::star::uno::Reference; -using ::com::sun::star::uno::WeakReference; -*/ // ==================================================================== @@ -92,6 +93,37 @@ USHORT lcl_DoUpdateCharts( const ScAddress& rPos, ScDocument* pDoc, BOOL bAllCha return nFound; } +BOOL lcl_AdjustRanges( ScRangeList& rRanges, SCTAB nSourceTab, SCTAB nDestTab, SCTAB nTabCount ) +{ + //! if multiple sheets are copied, update references into the other copied sheets? + + BOOL bChanged = FALSE; + + ULONG nCount = rRanges.Count(); + for (ULONG i=0; i<nCount; i++) + { + ScRange* pRange = rRanges.GetObject(i); + if ( pRange->aStart.Tab() == nSourceTab && pRange->aEnd.Tab() == nSourceTab ) + { + pRange->aStart.SetTab( nDestTab ); + pRange->aEnd.SetTab( nDestTab ); + bChanged = TRUE; + } + if ( pRange->aStart.Tab() >= nTabCount ) + { + pRange->aStart.SetTab( nTabCount > 0 ? ( nTabCount - 1 ) : 0 ); + bChanged = TRUE; + } + if ( pRange->aEnd.Tab() >= nTabCount ) + { + pRange->aEnd.SetTab( nTabCount > 0 ? ( nTabCount - 1 ) : 0 ); + bChanged = TRUE; + } + } + + return bChanged; +} + }//end anonymous namespace // === ScChartHelper ====================================== @@ -107,3 +139,160 @@ USHORT ScChartHelper::DoUpdateAllCharts( ScDocument* pDoc ) { return lcl_DoUpdateCharts( ScAddress(), pDoc, TRUE ); } + +//static +void ScChartHelper::AdjustRangesOfChartsOnDestinationPage( ScDocument* pSrcDoc, ScDocument* pDestDoc, const SCTAB nSrcTab, const SCTAB nDestTab ) +{ + if( !pSrcDoc || !pDestDoc ) + return; + ScDrawLayer* pDrawLayer = pDestDoc->GetDrawLayer(); + if( !pDrawLayer ) + return; + + SdrPage* pDestPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nDestTab)); + if( pDestPage ) + { + SdrObjListIter aIter( *pDestPage, IM_FLAT ); + SdrObject* pObject = aIter.Next(); + while( pObject ) + { + if( pObject->GetObjIdentifier() == OBJ_OLE2 && ((SdrOle2Obj*)pObject)->IsChart() ) + { + String aChartName = ((SdrOle2Obj*)pObject)->GetPersistName(); + + Reference< chart2::XChartDocument > xChartDoc( pDestDoc->GetChartByName( aChartName ) ); + Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY ); + if( xChartDoc.is() && xReceiver.is() && !xChartDoc->hasInternalDataProvider() ) + { + ::std::vector< ScRangeList > aRangesVector; + pDestDoc->GetChartRanges( aChartName, aRangesVector, pSrcDoc ); + + ::std::vector< ScRangeList >::iterator aIt( aRangesVector.begin() ); + for( ; aIt!=aRangesVector.end(); aIt++ ) + { + ScRangeList& rScRangeList( *aIt ); + lcl_AdjustRanges( rScRangeList, nSrcTab, nDestTab, pDestDoc->GetTableCount() ); + } + pDestDoc->SetChartRanges( aChartName, aRangesVector ); + } + } + pObject = aIter.Next(); + } + } +} + +//static +uno::Reference< chart2::XChartDocument > ScChartHelper::GetChartFromSdrObject( SdrObject* pObject ) +{ + uno::Reference< chart2::XChartDocument > xReturn; + if( pObject ) + { + if( pObject->GetObjIdentifier() == OBJ_OLE2 && ((SdrOle2Obj*)pObject)->IsChart() ) + { + uno::Reference< embed::XEmbeddedObject > xIPObj = ((SdrOle2Obj*)pObject)->GetObjRef(); + if( xIPObj.is() ) + { + svt::EmbeddedObjectRef::TryRunningState( xIPObj ); + uno::Reference< util::XCloseable > xComponent = xIPObj->getComponent(); + xReturn.set( uno::Reference< chart2::XChartDocument >( xComponent, uno::UNO_QUERY ) ); + } + } + } + return xReturn; +} + +void ScChartHelper::GetChartRanges( const uno::Reference< chart2::XChartDocument >& xChartDoc, + uno::Sequence< rtl::OUString >& rRanges ) +{ + rRanges.realloc(0); + uno::Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY ); + if( !xDataSource.is() ) + return; + //uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider(); + + uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledDataSequences( xDataSource->getDataSequences() ); + rRanges.realloc(2*aLabeledDataSequences.getLength()); + sal_Int32 nRealCount=0; + for( sal_Int32 nN=0;nN<aLabeledDataSequences.getLength();nN++) + { + uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aLabeledDataSequences[nN] ); + if(!xLabeledSequence.is()) + continue; + uno::Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel()); + uno::Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues()); + + if( xLabel.is()) + rRanges[nRealCount++] = xLabel->getSourceRangeRepresentation(); + if( xValues.is()) + rRanges[nRealCount++] = xValues->getSourceRangeRepresentation(); + } + rRanges.realloc(nRealCount); +} + +void ScChartHelper::SetChartRanges( const uno::Reference< chart2::XChartDocument >& xChartDoc, + const uno::Sequence< rtl::OUString >& rRanges ) +{ + uno::Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY ); + if( !xDataSource.is() ) + return; + uno::Reference< chart2::data::XDataProvider > xDataProvider = xChartDoc->getDataProvider(); + if( !xDataProvider.is() ) + return; + + uno::Reference< frame::XModel > xModel( xChartDoc, uno::UNO_QUERY ); + if( xModel.is() ) + xModel->lockControllers(); + + try + { + rtl::OUString aPropertyNameRole( ::rtl::OUString::createFromAscii("Role") ); + + uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledDataSequences( xDataSource->getDataSequences() ); + sal_Int32 nRange=0; + for( sal_Int32 nN=0; (nN<aLabeledDataSequences.getLength()) && (nRange<rRanges.getLength()); nN++ ) + { + uno::Reference< chart2::data::XLabeledDataSequence > xLabeledSequence( aLabeledDataSequences[nN] ); + if(!xLabeledSequence.is()) + continue; + uno::Reference< beans::XPropertySet > xLabel( xLabeledSequence->getLabel(), uno::UNO_QUERY ); + uno::Reference< beans::XPropertySet > xValues( xLabeledSequence->getValues(), uno::UNO_QUERY ); + + if( xLabel.is()) + { + // the range string must be in Calc A1 format. + uno::Reference< chart2::data::XDataSequence > xNewSeq( + xDataProvider->createDataSequenceByRangeRepresentation( rRanges[nRange++] )); + + uno::Reference< beans::XPropertySet > xNewProps( xNewSeq, uno::UNO_QUERY ); + if( xNewProps.is() ) + xNewProps->setPropertyValue( aPropertyNameRole, xLabel->getPropertyValue( aPropertyNameRole ) ); + + xLabeledSequence->setLabel( xNewSeq ); + } + + if( !(nRange<rRanges.getLength()) ) + break; + + if( xValues.is()) + { + // the range string must be in Calc A1 format. + uno::Reference< chart2::data::XDataSequence > xNewSeq( + xDataProvider->createDataSequenceByRangeRepresentation( rRanges[nRange++] )); + + uno::Reference< beans::XPropertySet > xNewProps( xNewSeq, uno::UNO_QUERY ); + if( xNewProps.is() ) + xNewProps->setPropertyValue( aPropertyNameRole, xValues->getPropertyValue( aPropertyNameRole ) ); + + xLabeledSequence->setValues( xNewSeq ); + } + } + } + catch ( uno::Exception& ex ) + { + (void)ex; + DBG_ERROR("Exception in ScChartHelper::SetChartRanges - invalid range string?"); + } + + if( xModel.is() ) + xModel->unlockControllers(); +} diff --git a/sc/source/core/tool/makefile.mk b/sc/source/core/tool/makefile.mk index 54f40c55a681..6c730f3a1743 100644 --- a/sc/source/core/tool/makefile.mk +++ b/sc/source/core/tool/makefile.mk @@ -116,6 +116,7 @@ SLOFILES = \ EXCEPTIONSFILES= \ $(SLO)$/addincol.obj \ $(SLO)$/cellkeytranslator.obj \ + $(SLO)$/charthelper.obj \ $(SLO)$/chartarr.obj \ $(SLO)$/chartlis.obj \ $(SLO)$/chartlock.obj \ diff --git a/sc/source/ui/unoobj/chartuno.cxx b/sc/source/ui/unoobj/chartuno.cxx index 5feabe72207d..201c411ea45c 100644 --- a/sc/source/ui/unoobj/chartuno.cxx +++ b/sc/source/ui/unoobj/chartuno.cxx @@ -480,20 +480,15 @@ void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& { bool bFound = false; ScDocument* pDoc = (pDocShell? pDocShell->GetDocument(): 0); - uno::Reference< embed::XEmbeddedObject > xIPObj; + if( pDoc ) - xIPObj.set( pDoc->FindOleObjectByName( aChartName ), uno::UNO_QUERY ); - if( xIPObj.is()) { - //make sure that the chart is loaded - svt::EmbeddedObjectRef::TryRunningState( xIPObj ); - - uno::Reference< chart2::XChartDocument > xChartDoc( xIPObj->getComponent(), uno::UNO_QUERY ); - uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY ); - if( xReceiver.is() ) + uno::Reference< chart2::XChartDocument > xChartDoc( pDoc->GetChartByName( aChartName ) ); + if( xChartDoc.is() ) { + uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY ); uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider(); - if( xProvider.is() ) + if( xReceiver.is() && xProvider.is() ) { uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xReceiver->getUsedData() ) ); diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 627f214c4ec6..5fcd094acffc 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -85,6 +85,7 @@ #include "inputwin.hxx" #include "funcdesc.hxx" #include "docuno.hxx" +#include "charthelper.hxx" // STATIC DATA --------------------------------------------------------------- @@ -2800,6 +2801,10 @@ void ScViewFunc::MoveTable( USHORT nDestDocNo, SCTAB nDestTab, BOOL bCopy ) nNewTab--; SetTabNo( nNewTab, TRUE ); + + //#i29848# adjust references to data on the copied sheet + if( bCopy ) + ScChartHelper::AdjustRangesOfChartsOnDestinationPage( pDoc, pDestDoc, nTab, nNewTab ); } } |