20#include <charthelper.hxx>
21#include <document.hxx>
34#include <com/sun/star/chart2/XChartDocument.hpp>
35#include <com/sun/star/chart2/data/XDataReceiver.hpp>
36#include <com/sun/star/embed/XEmbeddedObject.hpp>
37#include <com/sun/star/util/XModifiable.hpp>
40using ::com::sun::star::uno::Reference;
45sal_uInt16 lcl_DoUpdateCharts(
ScDocument& rDoc )
51 sal_uInt16 nFound = 0;
54 for (sal_uInt16 nPageNo=0; nPageNo<nPageCount; nPageNo++)
57 OSL_ENSURE(pPage,
"Page ?");
79 bool bChanged =
false;
81 for (
size_t i=0, nCount = rRanges.
size(); i < nCount; i++ )
92 rRange.
aStart.
SetTab( nTabCount > 0 ? ( nTabCount - 1 ) : 0 );
95 if ( rRange.
aEnd.
Tab() >= nTabCount )
97 rRange.
aEnd.
SetTab( nTabCount > 0 ? ( nTabCount - 1 ) : 0 );
111 return lcl_DoUpdateCharts( rDoc );
120 SdrPage* pDestPage = pDrawLayer->
GetPage(
static_cast<sal_uInt16
>(nDestTab));
132 Reference< chart2::XChartDocument > xChartDoc( rDestDoc.
GetChartByName( aChartName ) );
133 Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
134 if( xChartDoc.is() && xReceiver.is() && !xChartDoc->hasInternalDataProvider() )
136 ::std::vector< ScRangeList > aRangesVector;
141 lcl_AdjustRanges( rScRangeList, nSrcTab, nDestTab, rDestDoc.
GetTableCount() );
156 SdrPage* pDestPage = pDrawLayer->
GetPage(
static_cast<sal_uInt16
>(nDestTab));
167 Reference< chart2::XChartDocument > xChartDoc( rDestDoc.
GetChartByName( aChartName ) );
168 Reference< util::XModifiable > xModif(xChartDoc, uno::UNO_QUERY_THROW);
169 xModif->setModified(
true);
177 uno::Reference< chart2::XChartDocument > xReturn;
182 uno::Reference< embed::XEmbeddedObject > xIPObj =
static_cast<const SdrOle2Obj*
>(
pObject)->GetObjRef();
186 uno::Reference< util::XCloseable > xComponent = xIPObj->getComponent();
187 xReturn.set( uno::Reference< chart2::XChartDocument >( xComponent, uno::UNO_QUERY ) );
195 std::vector< OUString >& rRanges )
198 uno::Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY );
199 if( !xDataSource.is() )
202 const uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledDataSequences( xDataSource->getDataSequences() );
203 rRanges.reserve(2*aLabeledDataSequences.getLength());
204 for(
const uno::Reference<chart2::data::XLabeledDataSequence>& xLabeledSequence : aLabeledDataSequences)
206 if(!xLabeledSequence.is())
208 uno::Reference< chart2::data::XDataSequence > xLabel( xLabeledSequence->getLabel());
209 uno::Reference< chart2::data::XDataSequence > xValues( xLabeledSequence->getValues());
212 rRanges.push_back( xLabel->getSourceRangeRepresentation() );
214 rRanges.push_back( xValues->getSourceRangeRepresentation() );
219 const uno::Sequence< OUString >& rRanges )
221 uno::Reference< chart2::data::XDataSource > xDataSource( xChartDoc, uno::UNO_QUERY );
222 if( !xDataSource.is() )
224 uno::Reference< chart2::data::XDataProvider > xDataProvider = xChartDoc->getDataProvider();
225 if( !xDataProvider.is() )
228 xChartDoc->lockControllers();
232 OUString aPropertyNameRole(
"Role" );
234 uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > aLabeledDataSequences( xDataSource->getDataSequences() );
236 for( uno::Reference<chart2::data::XLabeledDataSequence>& xLabeledSequence : asNonConstRange(aLabeledDataSequences) )
238 if( nRange >= rRanges.getLength() )
241 if(!xLabeledSequence.is())
243 uno::Reference< beans::XPropertySet > xLabel( xLabeledSequence->getLabel(), uno::UNO_QUERY );
244 uno::Reference< beans::XPropertySet > xValues( xLabeledSequence->getValues(), uno::UNO_QUERY );
248 uno::Reference< chart2::data::XDataSequence > xNewSeq(
249 xDataProvider->createDataSequenceByRangeRepresentation( rRanges[nRange++] ));
251 uno::Reference< beans::XPropertySet > xNewProps( xNewSeq, uno::UNO_QUERY );
253 xNewProps->setPropertyValue( aPropertyNameRole, xLabel->getPropertyValue( aPropertyNameRole ) );
255 xLabeledSequence->setLabel( xNewSeq );
258 if( nRange >= rRanges.getLength() )
263 uno::Reference< chart2::data::XDataSequence > xNewSeq(
264 xDataProvider->createDataSequenceByRangeRepresentation( rRanges[nRange++] ));
266 uno::Reference< beans::XPropertySet > xNewProps( xNewSeq, uno::UNO_QUERY );
268 xNewProps->setPropertyValue( aPropertyNameRole, xValues->getPropertyValue( aPropertyNameRole ) );
270 xLabeledSequence->setValues( xNewSeq );
274 catch (
const uno::Exception&)
276 TOOLS_WARN_EXCEPTION(
"sc",
"Exception in ScChartHelper::SetChartRanges - invalid range string?");
279 xChartDoc->unlockControllers();
284 if ( !(
pObject && (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 )) )
288 if ( !(pSdrOle2Obj && pSdrOle2Obj->
IsChart()) )
291 const uno::Reference< embed::XEmbeddedObject >& xEmbeddedObj = pSdrOle2Obj->
GetObjRef();
292 if ( !xEmbeddedObj.is() )
295 bool bDisableDataTableDialog =
false;
296 sal_Int32 nOldState = xEmbeddedObj->getCurrentState();
298 uno::Reference< beans::XPropertySet > xProps( xEmbeddedObj->getComponent(), uno::UNO_QUERY );
300 ( xProps->getPropertyValue(
"DisableDataTableDialog") >>= bDisableDataTableDialog ) &&
301 bDisableDataTableDialog )
311 if ( rRangeList.
is() )
313 rRangesVector.push_back( *rRangeList );
318 if ( xEmbeddedObj->getCurrentState() != nOldState )
320 xEmbeddedObj->changeState( nOldState );
347 if (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 )
350 if ( pSdrOle2Obj && pSdrOle2Obj->
IsChart() )
360 const ScRangeListVector& rRangesVector, const ::std::vector< OUString >& rExcludedChartNames,
bool bSameDoc )
362 if ( !(pPage && pModelObj) )
365 size_t nRangeListCount = rRangesVector.size();
366 size_t nRangeList = 0;
371 if (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 )
374 if ( pSdrOle2Obj && pSdrOle2Obj->
IsChart() )
377 ::std::vector< OUString >::const_iterator aEnd = rExcludedChartNames.end();
378 ::std::vector< OUString >::const_iterator aFound = ::std::find( rExcludedChartNames.begin(), aEnd, aChartName );
379 if ( aFound == aEnd )
381 const uno::Reference< embed::XEmbeddedObject >& xEmbeddedObj = pSdrOle2Obj->
GetObjRef();
382 if ( xEmbeddedObj.is() && ( nRangeList < nRangeListCount ) )
384 bool bDisableDataTableDialog =
false;
386 uno::Reference< beans::XPropertySet > xProps( xEmbeddedObj->getComponent(), uno::UNO_QUERY );
388 ( xProps->getPropertyValue(
"DisableDataTableDialog") >>= bDisableDataTableDialog ) &&
389 bDisableDataTableDialog )
394 if (pCollection && !pCollection->
findByName(aChartName))
396 ScRangeList aRangeList( rRangesVector[ nRangeList++ ] );
399 pCollection->
insert( pChartListener );
405 xProps->setPropertyValue(
"DisableDataTableDialog",
407 xProps->setPropertyValue(
"DisableComplexChartTypes",
PropertiesInfo aProperties
::std::vector< ScRangeList > ScRangeListVector
static void GetChartRanges(const css::uno::Reference< css::chart2::XChartDocument > &xChartDoc, std::vector< OUString > &rRanges)
static void CreateProtectedChartListenersAndNotify(ScDocument &rDoc, const SdrPage *pPage, ScModelObj *pModelObj, SCTAB nTab, const ScRangeListVector &rRangesVector, const ::std::vector< OUString > &rExcludedChartNames, bool bSameDoc=true)
static void UpdateChartsOnDestinationPage(ScDocument &rDestDoc, const SCTAB nDestTab)
static sal_uInt16 DoUpdateAllCharts(ScDocument &rDoc)
static void SetChartRanges(const css::uno::Reference< css::chart2::XChartDocument > &xChartDoc, const css::uno::Sequence< OUString > &rRanges)
static void GetChartNames(::std::vector< OUString > &rChartNames, const SdrPage *pPage)
static void FillProtectedChartRangesVector(ScRangeListVector &rRangesVector, const ScDocument &rDocument, const SdrPage *pPage)
static void AddRangesIfProtectedChart(ScRangeListVector &rRangesVector, const ScDocument &rDocument, SdrObject *pObject)
static void AdjustRangesOfChartsOnDestinationPage(const ScDocument &rSrcDoc, ScDocument &rDestDoc, const SCTAB nSrcTab, const SCTAB nDestTab)
static css::uno::Reference< css::chart2::XChartDocument > GetChartFromSdrObject(const SdrObject *pObject)
ScChartListener * findByName(const OUString &rName)
bool insert(ScChartListener *pListener)
ScRangeListRef GetRangeList() const
css::uno::Reference< css::chart2::XChartDocument > GetChartByName(std::u16string_view rChartName)
SC_DLLPUBLIC ScRange GetRange(SCTAB nTab, const tools::Rectangle &rMMRect, bool bHiddenAsZero=true) const
SC_DLLPUBLIC void GetChartRanges(std::u16string_view rChartName, std::vector< ScRangeList > &rRanges, const ScDocument &rSheetNameDoc)
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
static bool IsChart(const SdrObject *pObject)
void UpdateChart(const OUString &rName)
void SetChartRanges(std::u16string_view rChartName, const std::vector< ScRangeList > &rRanges)
SC_DLLPUBLIC SCTAB GetTableCount() const
bool HasChangesListeners() const
void NotifyChanges(const OUString &rOperation, const ScRangeList &rRanges, const css::uno::Sequence< css::beans::PropertyValue > &rProperties)
virtual const tools::Rectangle & GetSnapRect() const override
const SdrPage * GetPage(sal_uInt16 nPgNum) const
sal_uInt16 GetPageCount() const
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
const OUString & GetPersistName() const
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
#define TOOLS_WARN_EXCEPTION(area, stream)
EmbeddedObjectRef * pObject
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)