diff options
-rw-r--r-- | sc/inc/charthelper.hxx | 3 | ||||
-rw-r--r-- | sc/source/core/data/documen9.cxx | 84 | ||||
-rw-r--r-- | sc/source/core/tool/charthelper.cxx | 87 | ||||
-rw-r--r-- | sc/source/ui/view/viewfun2.cxx | 5 |
4 files changed, 97 insertions, 82 deletions
diff --git a/sc/inc/charthelper.hxx b/sc/inc/charthelper.hxx index b4c677d7c3c6..4fad54851797 100644 --- a/sc/inc/charthelper.hxx +++ b/sc/inc/charthelper.hxx @@ -29,9 +29,11 @@ #define SC_CHARTHELPER_HXX #include <tools/solar.h> +#include "address.hxx" class ScDocument; class ScAddress; +class ScRangeList; /** Use this to handle charts in a calc document */ @@ -40,6 +42,7 @@ 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 ); }; #endif 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/tool/charthelper.cxx b/sc/source/core/tool/charthelper.cxx index 756493cc86e9..1fd7114f5954 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,52 @@ 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() ) + { + uno::Reference< chart2::XChartDocument > xChartDoc( pDestDoc->GetChartByName( aChartName ) ); + uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY ); + if( xChartDoc.is() && xReceiver.is() ) + { + if( !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(); + } + } +} 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 ); } } |