20#include <com/sun/star/util/XModifiable.hpp>
21#include <com/sun/star/chart/ChartDataRowSource.hpp>
22#include <com/sun/star/chart2/XChartDocument.hpp>
23#include <com/sun/star/chart2/data/XDataProvider.hpp>
24#include <com/sun/star/chart2/data/XDataReceiver.hpp>
25#include <com/sun/star/embed/XEmbeddedObject.hpp>
32#include <document.hxx>
41#include <charthelper.hxx>
46 OUString& rRanges, chart::ChartDataRowSource& rDataRowSource,
47 bool& rHasCategories,
bool& rFirstCellAsLabel )
49 rHasCategories = rFirstCellAsLabel =
false;
51 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
53 uno::Reference< chart2::data::XDataSource > xDataSource = xReceiver->getUsedData();
54 uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
56 if ( !xProvider.is() )
59 const uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xDataSource ) );
61 for (
const beans::PropertyValue& rProp : aArgs)
65 if (
aPropName ==
"CellRangeRepresentation" )
66 rProp.Value >>= rRanges;
71 else if (
aPropName ==
"FirstCellAsLabel" )
77 const OUString& rRanges, chart::ChartDataRowSource eDataRowSource,
78 bool bHasCategories,
bool bFirstCellAsLabel )
80 if ( !xReceiver.is() )
83 uno::Sequence< beans::PropertyValue > aArgs{
85 "CellRangeRepresentation", -1,
86 uno::Any( rRanges ), beans::PropertyState_DIRECT_VALUE ),
89 uno::Any( bHasCategories ), beans::PropertyState_DIRECT_VALUE ),
91 "FirstCellAsLabel", -1,
92 uno::Any( bFirstCellAsLabel ), beans::PropertyState_DIRECT_VALUE ),
95 uno::Any( eDataRowSource ), beans::PropertyState_DIRECT_VALUE )
97 xReceiver->setArguments( aArgs );
105 OSL_ENSURE(pPage,
"Page ?");
111 if (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 &&
112 pObject->GetCurrentBoundRect().Contains(rPos) )
131 const ScRange& rNewArea,
bool bColHeaders,
bool bRowHeaders,
140 uno::Reference< chart2::XChartDocument > xReturn;
146 for (sal_uInt16 nTab=0; nTab<
nCount && nTab < nSize; nTab++)
149 OSL_ENSURE(pPage,
"Page ?");
155 if (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 &&
170 rRangesVector.clear();
171 uno::Reference< chart2::XChartDocument > xChartDoc(
GetChartByName( rChartName ) );
172 if ( xChartDoc.is() )
174 std::vector< OUString > aRangeStrings;
176 for(
const OUString & aRangeString : aRangeStrings)
180 rRangesVector.push_back(aRanges);
187 uno::Reference< chart2::XChartDocument > xChartDoc(
GetChartByName( rChartName ) );
188 if ( !xChartDoc.is() )
191 sal_Int32
nCount =
static_cast<sal_Int32
>( rRangesVector.size() );
192 uno::Sequence< OUString > aRangeStrings(
nCount);
193 auto aRangeStringsRange = asNonConstRange(aRangeStrings);
194 for( sal_Int32 nN=0; nN<
nCount; nN++ )
199 aRangeStringsRange[nN]=sRangeStr;
205 ScRangeList& rRanges,
bool& rColHeaders,
bool& rRowHeaders )
213 for (sal_uInt16 nTab=0; nTab<nCount && nTab < static_cast<SCTAB>(
maTabs.size()); nTab++)
216 OSL_ENSURE(pPage,
"Page ?");
222 if (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 &&
226 if ( xChartDoc.is() )
228 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
229 bool bHasCategories =
false;
230 bool bFirstCellAsLabel =
false;
235 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
237 rRowHeaders = bHasCategories;
238 rColHeaders = bFirstCellAsLabel;
242 rColHeaders = bHasCategories;
243 rRowHeaders = bFirstCellAsLabel;
254 const ScRangeListRef& rNewList,
bool bColHeaders,
bool bRowHeaders,
260 for (
SCTAB nTab=0; nTab< static_cast<SCTAB>(
maTabs.size()) &&
maTabs[nTab]; nTab++)
263 OSL_ENSURE(pPage,
"Page ?");
269 if (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 &&
273 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
274 if ( xChartDoc.is() && xReceiver.is() )
277 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
278 bool bHasCategories =
false;
279 bool bFirstCellAsLabel =
false;
283 bool bInternalData = xChartDoc->hasInternalDataProvider();
285 if ( bAdd && !bInternalData )
291 aNewRanges->insert( aNewRanges->begin(), rNewList->begin(), rNewList->end() );
297 if ( eDataRowSource == chart::ChartDataRowSource_COLUMNS )
299 bHasCategories = bRowHeaders;
300 bFirstCellAsLabel = bColHeaders;
304 bHasCategories = bColHeaders;
305 bFirstCellAsLabel = bRowHeaders;
307 aNewRanges = rNewList;
310 if ( bInternalData &&
mpShell )
314 xReceiver->attachDataProvider( xDataProvider );
315 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier(
317 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
339 uno::Reference< chart2::XChartDocument > xChartDoc(
GetChartByName( rChartName ) );
344 uno::Reference< util::XModifiable > xModif( xChartDoc, uno::UNO_QUERY_THROW );
346 apTemporaryChartLock->AlsoLockThisChart( uno::Reference< frame::XModel >( xModif, uno::UNO_QUERY ) );
347 xModif->setModified(
true );
349 catch ( uno::Exception& )
375 uno::Reference< util::XCloseable > xComponent = xObject->getComponent();
376 uno::Reference< chart2::XChartDocument > xChartDoc( xComponent, uno::UNO_QUERY );
377 uno::Reference< chart2::data::XDataReceiver > xReceiver( xComponent, uno::UNO_QUERY );
378 if ( !xChartDoc.is() || !xReceiver.is() || xChartDoc->hasInternalDataProvider() )
381 const uno::Sequence<OUString> aRepresentations( xReceiver->getUsedRangeRepresentations() );
383 for (
const auto& rRepresentation : aRepresentations )
388 aRanges->push_back( aRange );
403 for (
auto const& it : rListeners)
408 bool bChanged =
false;
409 bool bDataChanged =
false;
410 for (
size_t i = 0, nListSize = aRLR->size();
i < nListSize; ++
i )
420 this, eUpdateRefMode,
421 nCol1,nRow1,nTab1, nCol2,nRow2,nTab2,
423 theCol1,theRow1,theTab1,
424 theCol2,theRow2,theTab2 );
429 theCol1, theRow1, theTab1,
430 theCol2, theRow2, theTab2 ));
435 != theCol2 - theCol1)
437 != theRow2 - theRow1)
439 != theTab2 - theTab1))) )
445 aNewRLR->push_back( rRange );
453 uno::Reference<embed::XEmbeddedObject> xIPObj =
461 bool bInternalDataProvider =
false;
466 uno::Reference< chart2::XChartDocument > xChartDoc( xIPObj->getComponent(), uno::UNO_QUERY_THROW );
467 bInternalDataProvider = xChartDoc->hasInternalDataProvider();
469 catch ( uno::Exception& )
473 if ( bInternalDataProvider )
493 for (
SCTAB nTab=0; nTab< static_cast<SCTAB>(
maTabs.size()) &&
maTabs[nTab]; nTab++)
496 OSL_ENSURE(pPage,
"Page ?");
502 if (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 &&
506 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
507 if ( xChartDoc.is() && xReceiver.is() )
509 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
510 bool bHasCategories =
false;
511 bool bFirstCellAsLabel =
false;
532 return pTable->HasData(nCol, nRow);
536uno::Reference< embed::XEmbeddedObject >
540 return uno::Reference< embed::XEmbeddedObject >();
546 for (sal_uInt16 nTab=0; nTab<
nCount; nTab++)
549 OSL_ENSURE(pPage,
"Page ?");
555 if (
pObject->GetObjIdentifier() == SdrObjKind::OLE2 )
568 return uno::Reference< embed::XEmbeddedObject >();
579 for (
SCTAB nTab=0; nTab< static_cast<SCTAB>(
maTabs.size()); nTab++)
585 OSL_ENSURE(pPage,
"Page ?");
596 if (
pObject->GetObjIdentifier() != SdrObjKind::OLE2 )
604 else if (rNonOleObjects.count(aObjName) > 0)
610 uno::Reference< embed::XEmbeddedObject > xIPObj =
static_cast<SdrOle2Obj*
>(
pObject)->GetObjRef();
611 OSL_ENSURE( xIPObj.is(),
"No embedded object is given!");
612 uno::Reference< css::chart2::data::XDataReceiver > xReceiver;
614 xReceiver.set( xIPObj->getComponent(), uno::UNO_QUERY );
617 if( xReceiver.is() &&
638 rNonOleObjects.insert(aObjName);
652 rNonOleObjects.insert(rName);
static void GetChartRanges(const css::uno::Reference< css::chart2::XChartDocument > &xChartDoc, std::vector< OUString > &rRanges)
static void SetChartRanges(const css::uno::Reference< css::chart2::XChartDocument > &xChartDoc, const css::uno::Sequence< OUString > &rRanges)
static css::uno::Reference< css::chart2::XChartDocument > GetChartFromSdrObject(const SdrObject *pObject)
std::unordered_set< OUString > StringSetType
std::map< OUString, std::unique_ptr< ScChartListener > > ListenersType
void ChangeListening(const ScRangeListRef &rRangeListRef, bool bDirty)
const OUString & GetName() const
ScRangeListRef GetRangeList() const
css::uno::Reference< css::chart2::XChartDocument > GetChartByName(std::u16string_view rChartName)
void AddOLEObjectToCollection(const OUString &rName)
SC_DLLPUBLIC ScTable * FetchTable(SCTAB nTab)
SC_DLLPUBLIC void UpdateChartListenerCollection()
bool bChartListenerCollectionNeedsUpdate
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
SC_DLLPUBLIC void GetChartRanges(std::u16string_view rChartName, std::vector< ScRangeList > &rRanges, const ScDocument &rSheetNameDoc)
SC_DLLPUBLIC bool HasData(SCCOL nCol, SCROW nRow, SCTAB nTab)
bool PastingDrawFromOtherDoc() const
static bool IsChart(const SdrObject *pObject)
void UpdateChartArea(const OUString &rChartName, const ScRange &rNewArea, bool bColHeaders, bool bRowHeaders, bool bAdd)
std::unique_ptr< ScTemporaryChartLock > apTemporaryChartLock
void UpdateChart(const OUString &rName)
void UpdateChartRef(UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCCOL nDx, SCROW nDy, SCTAB nDz)
css::uno::Reference< css::embed::XEmbeddedObject > FindOleObjectByName(std::u16string_view rName)
void GetOldChartParameters(std::u16string_view rName, ScRangeList &rRanges, bool &rColHeaders, bool &rRowHeaders)
void SetChartRanges(std::u16string_view rChartName, const std::vector< ScRangeList > &rRanges)
std::unique_ptr< ScDrawLayer > mpDrawLayer
bool HasChartAtPoint(SCTAB nTab, const Point &rPos, OUString &rName)
void SetChartRangeList(std::u16string_view rChartName, const ScRangeListRef &rNewRangeListRef)
only assigns the new RangeList, no ChartListener or the like
void RestoreChartListener(const OUString &rName)
std::unique_ptr< ScChartListenerCollection > pChartListenerCollection
void Format(OUString &, ScRefFlags nFlags, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, sal_Unicode cDelimiter=0, bool bFullAddressNotation=false) const
ScRefFlags Parse(std::u16string_view, const ScDocument &, formula::FormulaGrammar::AddressConvention eConv=formula::FormulaGrammar::CONV_OOO, SCTAB nDefaultTab=0, sal_Unicode cDelimiter=0)
ScRefFlags ParseAny(const OUString &, const ScDocument &, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1)
static ScRefUpdateRes Update(const ScDocument *pDoc, UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCCOL nDx, SCROW nDy, SCTAB nDz, SCCOL &theCol1, SCROW &theRow1, SCTAB &theTab1, SCCOL &theCol2, SCROW &theRow2, SCTAB &theTab2)
SCCOL GetAllocatedColumnsCount() const
static sal_Int32 GetEnumFromAny(const css::uno::Any &aAny)
static bool GetBoolFromAny(const css::uno::Any &aAny)
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
const OUString & GetPersistName() const
bool IsEnableSetModified() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
static void lcl_GetChartParameters(const uno::Reference< chart2::XChartDocument > &xChartDoc, OUString &rRanges, chart::ChartDataRowSource &rDataRowSource, bool &rHasCategories, bool &rFirstCellAsLabel)
static void lcl_SetChartParameters(const uno::Reference< chart2::data::XDataReceiver > &xReceiver, const OUString &rRanges, chart::ChartDataRowSource eDataRowSource, bool bHasCategories, bool bFirstCellAsLabel)
EmbeddedObjectRef * pObject
@ UR_INVALID
Some part of the reference became invalid.
@ UR_NOTHING
Reference not affected, no change at all.