20#include <com/sun/star/embed/Aspects.hpp>
21#include <com/sun/star/embed/XEmbeddedObject.hpp>
22#include <com/sun/star/awt/Size.hpp>
23#include <com/sun/star/beans/PropertyAttribute.hpp>
24#include <com/sun/star/chart2/data/XDataReceiver.hpp>
25#include <com/sun/star/chart/ChartDataRowSource.hpp>
26#include <com/sun/star/chart2/XChartDocument.hpp>
27#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
28#include <com/sun/star/table/CellRangeAddress.hpp>
30#include <osl/diagnose.h>
55#define PROP_HANDLE_RELATED_CELLRANGES 1
64 pDocShell->GetDocument().AddUnoObject(*
this);
79 if ( rHint.
GetId() == SfxHintId::Dying )
96 OSL_ENSURE(pPage,
"Page not found");
108 uno::Reference < embed::XEmbeddedObject > xObj =
static_cast<SdrOle2Obj*
>(
pObject)->GetObjRef();
120 if (!
aName.isEmpty())
139 const awt::Rectangle& aRect,
140 const uno::Sequence<table::CellRangeAddress>& aRanges,
150 OSL_ENSURE(pPage,
"addChart: no Page");
157 OUString
aName = rName;
162 throw uno::RuntimeException();
166 for (
const table::CellRangeAddress& rRange : aRanges)
168 ScRange aRange(
static_cast<SCCOL>(rRange.StartColumn), rRange.StartRow, rRange.Sheet,
169 static_cast<SCCOL>(rRange.EndColumn), rRange.EndRow, rRange.Sheet );
174 uno::Reference < embed::XEmbeddedObject > xObj;
182 Point aRectPos( aRect.X, aRect.Y );
184 if ( ( aRectPos.
X() < 0 && !bLayoutRTL ) || ( aRectPos.
X() > 0 && bLayoutRTL ) )
187 if (aRectPos.
Y() < 0)
190 Size aRectSize( aRect.Width, aRect.Height );
191 if (aRectSize.
Width() <= 0)
194 if (aRectSize.
Height() <= 0)
198 sal_Int64 nAspect(embed::Aspects::MSOLE_CONTENT);
203 aSz.Width = aSize.
Width();
204 aSz.Height = aSize.
Height();
207 uno::Reference< chart2::data::XDataProvider > xDataProvider =
new
210 uno::Reference< chart2::data::XDataReceiver > xReceiver;
212 xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
220 if( !sRangeStr.isEmpty() )
221 xReceiver->attachDataProvider( xDataProvider );
225 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( cppu::getXWeak(
pDocShell->
GetModel()), uno::UNO_QUERY );
226 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
229 uno::Sequence< beans::PropertyValue > aArgs{
230 beans::PropertyValue(
231 "CellRangeRepresentation", -1,
232 uno::Any( sRangeStr ), beans::PropertyState_DIRECT_VALUE ),
233 beans::PropertyValue(
235 uno::Any( bRowHeaders ), beans::PropertyState_DIRECT_VALUE ),
236 beans::PropertyValue(
237 "FirstCellAsLabel", -1,
238 uno::Any( bColumnHeaders ), beans::PropertyState_DIRECT_VALUE ),
239 beans::PropertyValue(
241 uno::Any( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE )
243 xReceiver->setArguments( aArgs );
259 xObj->setVisualAreaSize( nAspect, aSz );
266 pModel->
AddUndo( std::make_unique<SdrUndoInsertObj>( *pObj ) );
280 pModel->
AddUndo( std::make_unique<SdrUndoDelObj>( *pObj ) );
308 OSL_ENSURE(pPage,
"Page not found");
330 throw lang::IndexOutOfBoundsException();
351 throw container::NoSuchElementException();
365 OUString* pAry =
aSeq.getArray();
372 OSL_ENSURE(pPage,
"Page not found");
382 uno::Reference < embed::XEmbeddedObject > xObj =
static_cast<SdrOle2Obj*
>(
pObject)->GetObjRef();
405 return aOle2Obj !=
nullptr;
413 ,aChartName(
std::move( aN ))
419 cppu::UnoType<uno::Sequence<table::CellRangeAddress>>::get(),
420 css::uno::Any(uno::Sequence<table::CellRangeAddress>()) );
435 if ( rHint.
GetId() == SfxHintId::Dying )
451 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
452 uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
453 if( xReceiver.is() && xProvider.is() )
455 const uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xReceiver->getUsedData() ) );
458 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
459 bool bHasCategories=
false;
460 bool bFirstCellAsLabel=
false;
461 for (
const beans::PropertyValue& rProp : aArgs)
465 if (
aPropName ==
"CellRangeRepresentation")
466 rProp.Value >>= aRanges;
471 else if (
aPropName ==
"FirstCellAsLabel")
475 if( chart::ChartDataRowSource_COLUMNS == eDataRowSource )
477 rColHeaders=bFirstCellAsLabel;
478 rRowHeaders=bHasCategories;
482 rColHeaders=bHasCategories;
483 rRowHeaders=bFirstCellAsLabel;
509 std::make_unique<ScUndoChartData>(
pDocShell,
aChartName, rRanges, bColHeaders, bRowHeaders,
false ) );
528 uno::Sequence< table::CellRangeAddress > aCellRanges;
529 if ( rValue >>= aCellRanges )
532 for ( table::CellRangeAddress
const & aCellRange : std::as_const(aCellRanges) )
536 rRangeList->push_back( aRange );
573 if (!rRangeList.
is())
576 size_t nCount = rRangeList->size();
577 uno::Sequence<table::CellRangeAddress> aCellRanges(
nCount);
578 table::CellRangeAddress* pCellRanges = aCellRanges.getArray();
581 ScRange const & rRange = (*rRangeList)[
i];
582 table::CellRangeAddress aCellRange;
584 pCellRanges[
i] = aCellRange;
586 rValue <<= aCellRanges;
598 uno::Sequence< beans::Property > aProps;
600 return new ::cppu::OPropertyArrayHelper( aProps );
617 bool bColHeaders, bRowHeaders;
618 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
626 bool bOldColHeaders, bOldRowHeaders;
627 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
628 if ( bOldColHeaders !=
bool(bHasColumnHeaders) )
629 Update_Impl( xRanges, bHasColumnHeaders, bOldRowHeaders );
636 bool bColHeaders, bRowHeaders;
645 bool bOldColHeaders, bOldRowHeaders;
646 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
647 if ( bOldRowHeaders !=
bool(bHasRowHeaders) )
648 Update_Impl( xRanges, bOldColHeaders, bHasRowHeaders );
655 bool bColHeaders, bRowHeaders;
659 size_t nCount = xRanges->size();
661 table::CellRangeAddress aRangeAddress;
662 uno::Sequence<table::CellRangeAddress>
aSeq(
nCount);
663 table::CellRangeAddress* pAry =
aSeq.getArray();
666 ScRange const & rRange = (*xRanges)[
i];
668 aRangeAddress.Sheet = rRange.
aStart.
Tab();
669 aRangeAddress.StartColumn = rRange.
aStart.
Col();
670 aRangeAddress.StartRow = rRange.
aStart.
Row();
671 aRangeAddress.EndColumn = rRange.
aEnd.
Col();
672 aRangeAddress.EndRow = rRange.
aEnd.
Row();
674 pAry[
i] = aRangeAddress;
679 OSL_FAIL(
"ScChartObj::getRanges: no Ranges");
680 return uno::Sequence<table::CellRangeAddress>();
687 bool bColHeaders, bRowHeaders;
691 for (
const table::CellRangeAddress& rRange : aRanges)
693 ScRange aRange(
static_cast<SCCOL>(rRange.StartColumn), rRange.StartRow, rRange.Sheet,
694 static_cast<SCCOL>(rRange.EndColumn), rRange.EndRow, rRange.Sheet );
699 if ( !xOldRanges.
is() || *xOldRanges != *xNewRanges )
700 Update_Impl( xNewRanges, bColHeaders, bRowHeaders );
713 return uno::Reference < lang::XComponent > (
pObject->GetObjRef()->getComponent(), uno::UNO_QUERY );
729 throw uno::RuntimeException();
#define PROP_HANDLE_RELATED_CELLRANGES
::cppu::WeakComponentImplHelper< css::table::XTableChart, css::document::XEmbeddedObjectSupplier, css::container::XNamed, css::lang::XServiceInfo > ScChartObj_Base
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
ScChartListener * findByName(const OUString &rName)
bool insert(ScChartListener *pListener)
void removeByName(const OUString &rName)
void ChangeListening(const OUString &rName, const ScRangeListRef &rRangeListRef)
ScRangeListRef GetRangeList() const
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
void GetData_Impl(ScRangeListRef &rRanges, bool &rColHeaders, bool &rRowHeaders) const
virtual void SAL_CALL setHasRowHeaders(sal_Bool bHasRowHeaders) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual css::uno::Sequence< css::table::CellRangeAddress > SAL_CALL getRanges() override
virtual void SAL_CALL setName(const OUString &aName) override
void Update_Impl(const ScRangeListRef &rRanges, bool bColHeaders, bool bRowHeaders)
virtual css::uno::Reference< css::lang::XComponent > SAL_CALL getEmbeddedObject() override
ScChartObj(ScDocShell *pDocSh, SCTAB nT, OUString aN)
virtual sal_Bool SAL_CALL getHasRowHeaders() override
virtual OUString SAL_CALL getName() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
virtual void SAL_CALL setRanges(const css::uno::Sequence< css::table::CellRangeAddress > &aRanges) override
virtual ~ScChartObj() override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual void SAL_CALL setHasColumnHeaders(sal_Bool bHasColumnHeaders) override
rtl::Reference< ScChartObj > GetObjectByName_Impl(const OUString &aName) const
virtual void SAL_CALL removeByName(const OUString &aName) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
rtl::Reference< ScChartObj > GetObjectByIndex_Impl(tools::Long nIndex) const
virtual sal_Bool SAL_CALL hasElements() override
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual void SAL_CALL addNewByName(const OUString &aName, const css::awt::Rectangle &aRect, const css::uno::Sequence< css::table::CellRangeAddress > &aRanges, sal_Bool bColumnHeaders, sal_Bool bRowHeaders) override
virtual ~ScChartsObj() override
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
virtual sal_Int32 SAL_CALL getCount() override
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual css::uno::Type SAL_CALL getElementType() override
const ScDocument & GetDocument() const
ScDrawLayer * MakeDrawLayer()
ScModelObj * GetModel() const
virtual SfxUndoManager * GetUndoManager() override
css::uno::Reference< css::chart2::XChartDocument > GetChartByName(std::u16string_view rChartName)
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
SC_DLLPUBLIC ScChartListenerCollection * GetChartListenerCollection() const
void AddUnoObject(SfxListener &rObject)
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
static bool IsChart(const SdrObject *pObject)
void UpdateChartArea(const OUString &rChartName, const ScRange &rNewArea, bool bColHeaders, bool bRowHeaders, bool bAdd)
void RemoveUnoObject(SfxListener &rObject)
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
bool IsUndoEnabled() const
SdrObject * GetNamedObject(std::u16string_view rName, SdrObjKind nId, SCTAB &rFoundTab) const
void push_back(const ScRange &rRange)
static void FillScRange(ScRange &rScRange, const css::table::CellRangeAddress &rApiRange)
static void FillApiRange(css::table::CellRangeAddress &rApiRange, const ScRange &rScRange)
static sal_Int32 GetEnumFromAny(const css::uno::Any &aAny)
static bool GetBoolFromAny(const css::uno::Any &aAny)
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
const SdrPage * GetPage(sal_uInt16 nPgNum) const
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
virtual rtl::Reference< SdrObject > RemoveObject(size_t nObjNum)
sal_uInt32 GetOrdNum() const
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
virtual void AddUndoAction(std::unique_ptr< SfxUndoAction > pAction, bool bTryMerg=false)
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
static MapUnit UnoEmbed2VCLMapUnit(sal_Int32 nUnoEmbedMapUnit)
OUString GetEmbeddedObjectName(const css::uno::Reference< css::embed::XEmbeddedObject > &) const
css::uno::Reference< css::embed::XEmbeddedObject > CreateEmbeddedObject(const css::uno::Sequence< sal_Int8 > &, OUString &, OUString const *pBaseURL=nullptr)
::cppu::IPropertyArrayHelper * getArrayHelper()
void registerPropertyNoMember(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, const css::uno::Type &_rType, css::uno::Any const &_pInitialValue)
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
css::uno::Type const & get()
static bool TryRunningState(const css::uno::Reference< css::embed::XEmbeddedObject > &)
EmbeddedObjectRef * pObject
Sequence< sal_Int8 > aSeq
#define SC_SIMPLE_SERVICE_INFO(ClassName, ClassNameAscii, ServiceAscii)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)