tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / unoobj / chartuno.cxx
blobc0d88b03178959817dcad5cecb8027fdf7052a5b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
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>
31 #include <svx/svditer.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <svx/svdpage.hxx>
34 #include <svx/svdundo.hxx>
35 #include <unotools/moduleoptions.hxx>
36 #include <comphelper/classids.hxx>
37 #include <toolkit/helper/vclunohelper.hxx>
38 #include <tools/globname.hxx>
39 #include <svtools/embedhlp.hxx>
40 #include <utility>
41 #include <vcl/svapp.hxx>
43 #include <ChartTools.hxx>
44 #include <chartuno.hxx>
45 #include <miscuno.hxx>
46 #include <docsh.hxx>
47 #include <drwlayer.hxx>
48 #include <undodat.hxx>
49 #include <chartlis.hxx>
50 #include <chart2uno.hxx>
51 #include <convuno.hxx>
53 using namespace css;
55 #define PROP_HANDLE_RELATED_CELLRANGES 1
57 SC_SIMPLE_SERVICE_INFO( ScChartObj, u"ScChartObj"_ustr, u"com.sun.star.table.TableChart"_ustr )
58 SC_SIMPLE_SERVICE_INFO( ScChartsObj, u"ScChartsObj"_ustr, u"com.sun.star.table.TableCharts"_ustr )
60 ScChartsObj::ScChartsObj(ScDocShell* pDocSh, SCTAB nT) :
61 pDocShell( pDocSh ),
62 nTab( nT )
64 pDocShell->GetDocument().AddUnoObject(*this);
67 ScChartsObj::~ScChartsObj()
69 SolarMutexGuard g;
71 if (pDocShell)
72 pDocShell->GetDocument().RemoveUnoObject(*this);
75 void ScChartsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
77 //! update reference
79 if ( rHint.GetId() == SfxHintId::Dying )
81 pDocShell = nullptr;
85 rtl::Reference<ScChartObj> ScChartsObj::GetObjectByIndex_Impl(tools::Long nIndex) const
87 if ( pDocShell )
89 OUString aName;
91 ScDocument& rDoc = pDocShell->GetDocument();
92 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
93 if (pDrawLayer)
95 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
96 OSL_ENSURE(pPage, "Page not found");
97 if (pPage)
99 tools::Long nPos = 0;
100 SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
101 SdrObject* pObject = aIter.Next();
102 while (pObject)
104 if ( pObject->GetObjIdentifier() == SdrObjKind::OLE2 && ScDocument::IsChart(pObject) )
106 if ( nPos == nIndex )
108 uno::Reference < embed::XEmbeddedObject > xObj = static_cast<SdrOle2Obj*>(pObject)->GetObjRef();
109 if ( xObj.is() )
110 aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
111 break; // stop searching
113 ++nPos;
115 pObject = aIter.Next();
120 if (!aName.isEmpty())
121 return new ScChartObj( pDocShell, nTab, aName );
124 return nullptr;
127 rtl::Reference<ScChartObj> ScChartsObj::GetObjectByName_Impl(const OUString& aName) const
129 if (sc::tools::findChartsByName(pDocShell, nTab, aName, sc::tools::ChartSourceType::CELL_RANGE))
130 return new ScChartObj( pDocShell, nTab, aName );
131 if (sc::tools::findChartsByName(pDocShell, nTab, aName, sc::tools::ChartSourceType::PIVOT_TABLE))
132 return new ScChartObj( pDocShell, nTab, aName );
133 return nullptr;
136 // XTableCharts
138 void SAL_CALL ScChartsObj::addNewByName( const OUString& rName,
139 const awt::Rectangle& aRect,
140 const uno::Sequence<table::CellRangeAddress>& aRanges,
141 sal_Bool bColumnHeaders, sal_Bool bRowHeaders )
143 SolarMutexGuard aGuard;
144 if (!pDocShell)
145 return;
147 ScDocument& rDoc = pDocShell->GetDocument();
148 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
149 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab));
150 OSL_ENSURE(pPage,"addChart: no Page");
151 if (!pPage)
152 return;
154 // chart can't be inserted if any ole object with that name exists on any table
155 // (empty string: generate valid name)
157 OUString aName = rName;
158 SCTAB nDummy;
159 if ( !aName.isEmpty() && pModel->GetNamedObject( aName, SdrObjKind::OLE2, nDummy ) )
161 // object exists - only RuntimeException is specified
162 throw uno::RuntimeException();
165 ScRangeList* pList = new ScRangeList;
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 );
170 pList->push_back( aRange );
172 ScRangeListRef xNewRanges( pList );
174 uno::Reference < embed::XEmbeddedObject > xObj;
175 if ( SvtModuleOptions().IsChartInstalled() )
176 xObj = pDocShell->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aName );
177 if ( !xObj.is() )
178 return;
180 // adjust rectangle
181 //! error/exception, if empty/invalid ???
182 Point aRectPos( aRect.X, aRect.Y );
183 bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
184 if ( ( aRectPos.X() < 0 && !bLayoutRTL ) || ( aRectPos.X() > 0 && bLayoutRTL ) )
185 aRectPos.setX( 0 );
187 if (aRectPos.Y() < 0)
188 aRectPos.setY( 0 );
190 Size aRectSize( aRect.Width, aRect.Height );
191 if (aRectSize.Width() <= 0)
192 aRectSize.setWidth( 5000 ); // default size
194 if (aRectSize.Height() <= 0)
195 aRectSize.setHeight( 5000 );
196 tools::Rectangle aInsRect( aRectPos, aRectSize );
198 sal_Int64 nAspect(embed::Aspects::MSOLE_CONTENT);
199 MapUnit aMapUnit(VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ));
200 Size aSize(aInsRect.GetSize());
201 aSize = OutputDevice::LogicToLogic( aSize, MapMode( MapUnit::Map100thMM ), MapMode( aMapUnit ) );
202 awt::Size aSz;
203 aSz.Width = aSize.Width();
204 aSz.Height = aSize.Height();
206 // Calc -> DataProvider
207 uno::Reference< chart2::data::XDataProvider > xDataProvider = new
208 ScChart2DataProvider( &rDoc );
209 // Chart -> DataReceiver
210 uno::Reference< chart2::data::XDataReceiver > xReceiver;
211 if( xObj.is())
212 xReceiver.set( xObj->getComponent(), uno::UNO_QUERY );
213 if( xReceiver.is())
215 // Range in UI representation.
216 OUString sRangeStr;
217 xNewRanges->Format(sRangeStr, ScRefFlags::RANGE_ABS_3D, rDoc, rDoc.GetAddressConvention());
219 // connect
220 if( !sRangeStr.isEmpty() )
221 xReceiver->attachDataProvider( xDataProvider );
222 else
223 sRangeStr = "all";
225 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( cppu::getXWeak(pDocShell->GetModel()), uno::UNO_QUERY );
226 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
228 // set arguments
229 uno::Sequence< beans::PropertyValue > aArgs{
230 beans::PropertyValue(
231 u"CellRangeRepresentation"_ustr, -1,
232 uno::Any( sRangeStr ), beans::PropertyState_DIRECT_VALUE ),
233 beans::PropertyValue(
234 u"HasCategories"_ustr, -1,
235 uno::Any( bRowHeaders ), beans::PropertyState_DIRECT_VALUE ),
236 beans::PropertyValue(
237 u"FirstCellAsLabel"_ustr, -1,
238 uno::Any( bColumnHeaders ), beans::PropertyState_DIRECT_VALUE ),
239 beans::PropertyValue(
240 u"DataRowSource"_ustr, -1,
241 uno::Any( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE )
243 xReceiver->setArguments( aArgs );
246 ScChartListener* pChartListener =
247 new ScChartListener( aName, rDoc, xNewRanges );
248 rDoc.GetChartListenerCollection()->insert( pChartListener );
249 pChartListener->StartListeningTo();
251 rtl::Reference<SdrOle2Obj> pObj = new SdrOle2Obj(
252 *pModel,
253 ::svt::EmbeddedObjectRef(xObj, embed::Aspects::MSOLE_CONTENT),
254 aName,
255 aInsRect);
257 // set VisArea
258 if( xObj.is())
259 xObj->setVisualAreaSize( nAspect, aSz );
261 // #i121334# This call will change the chart's default background fill from white to transparent.
262 // Add here again if this is wanted (see task description for details)
263 // ChartHelper::AdaptDefaultsForChart( xObj );
265 pPage->InsertObject( pObj.get() );
266 pModel->AddUndo( std::make_unique<SdrUndoInsertObj>( *pObj ) );
269 void SAL_CALL ScChartsObj::removeByName( const OUString& aName )
271 SolarMutexGuard aGuard;
272 SdrOle2Obj* pObj = sc::tools::findChartsByName(pDocShell, nTab, aName, sc::tools::ChartSourceType::CELL_RANGE);
273 if (pObj)
275 ScDocument& rDoc = pDocShell->GetDocument();
276 rDoc.GetChartListenerCollection()->removeByName(aName);
277 ScDrawLayer* pModel = rDoc.GetDrawLayer(); // is not zero
278 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab)); // is not zero
280 pModel->AddUndo( std::make_unique<SdrUndoDelObj>( *pObj ) );
281 pPage->RemoveObject( pObj->GetOrdNum() );
283 //! Notify etc.???
287 // XEnumerationAccess
289 uno::Reference<container::XEnumeration> SAL_CALL ScChartsObj::createEnumeration()
291 SolarMutexGuard aGuard;
292 return new ScIndexEnumeration(this, u"com.sun.star.table.TableChartsEnumeration"_ustr);
295 // XIndexAccess
297 sal_Int32 SAL_CALL ScChartsObj::getCount()
299 SolarMutexGuard aGuard;
300 sal_Int32 nCount = 0;
301 if ( pDocShell )
303 ScDocument& rDoc = pDocShell->GetDocument();
304 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
305 if (pDrawLayer)
307 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
308 OSL_ENSURE(pPage, "Page not found");
309 if (pPage)
311 SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
312 SdrObject* pObject = aIter.Next();
313 while (pObject)
315 if ( pObject->GetObjIdentifier() == SdrObjKind::OLE2 && ScDocument::IsChart(pObject) )
316 ++nCount;
317 pObject = aIter.Next();
322 return nCount;
325 uno::Any SAL_CALL ScChartsObj::getByIndex( sal_Int32 nIndex )
327 SolarMutexGuard aGuard;
328 uno::Reference<table::XTableChart> xChart(GetObjectByIndex_Impl(nIndex));
329 if (!xChart.is())
330 throw lang::IndexOutOfBoundsException();
332 return uno::Any(xChart);
335 uno::Type SAL_CALL ScChartsObj::getElementType()
337 return cppu::UnoType<table::XTableChart>::get();
340 sal_Bool SAL_CALL ScChartsObj::hasElements()
342 SolarMutexGuard aGuard;
343 return getCount() != 0;
346 uno::Any SAL_CALL ScChartsObj::getByName( const OUString& aName )
348 SolarMutexGuard aGuard;
349 uno::Reference<table::XTableChart> xChart(GetObjectByName_Impl(aName));
350 if (!xChart.is())
351 throw container::NoSuchElementException();
353 return uno::Any(xChart);
356 uno::Sequence<OUString> SAL_CALL ScChartsObj::getElementNames()
358 SolarMutexGuard aGuard;
359 if (pDocShell)
361 ScDocument& rDoc = pDocShell->GetDocument();
363 tools::Long nCount = getCount();
364 uno::Sequence<OUString> aSeq(nCount);
365 OUString* pAry = aSeq.getArray();
367 tools::Long nPos = 0;
368 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
369 if (pDrawLayer)
371 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
372 OSL_ENSURE(pPage, "Page not found");
373 if (pPage)
375 SdrObjListIter aIter( pPage, SdrIterMode::DeepNoGroups );
376 SdrObject* pObject = aIter.Next();
377 while (pObject)
379 if ( pObject->GetObjIdentifier() == SdrObjKind::OLE2 && ScDocument::IsChart(pObject) )
381 OUString aName;
382 uno::Reference < embed::XEmbeddedObject > xObj = static_cast<SdrOle2Obj*>(pObject)->GetObjRef();
383 if ( xObj.is() )
384 aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
386 OSL_ENSURE(nPos<nCount, "oops, miscounted?");
387 pAry[nPos++] = aName;
389 pObject = aIter.Next();
393 OSL_ENSURE(nPos==nCount, "hey, miscounted?");
395 return aSeq;
397 return {};
400 sal_Bool SAL_CALL ScChartsObj::hasByName( const OUString& aName )
402 SolarMutexGuard aGuard;
403 SdrOle2Obj* aOle2Obj = sc::tools::findChartsByName(pDocShell, nTab, aName,
404 sc::tools::ChartSourceType::CELL_RANGE);
405 return aOle2Obj != nullptr;
408 ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, OUString aN)
409 :pDocShell( pDocSh )
410 ,nTab( nT )
411 ,aChartName(std::move( aN ))
413 pDocShell->GetDocument().AddUnoObject(*this);
415 registerPropertyNoMember( u"RelatedCellRanges"_ustr,
416 PROP_HANDLE_RELATED_CELLRANGES, beans::PropertyAttribute::MAYBEVOID,
417 cppu::UnoType<uno::Sequence<table::CellRangeAddress>>::get(),
418 css::uno::Any(uno::Sequence<table::CellRangeAddress>()) );
421 ScChartObj::~ScChartObj()
423 SolarMutexGuard g;
425 if (pDocShell)
426 pDocShell->GetDocument().RemoveUnoObject(*this);
429 void ScChartObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
431 //! update reference
433 if ( rHint.GetId() == SfxHintId::Dying )
435 pDocShell = nullptr;
439 void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& rRowHeaders ) const
441 bool bFound = false;
443 if( pDocShell )
445 ScDocument& rDoc = pDocShell->GetDocument();
446 uno::Reference< chart2::XChartDocument > xChartDoc( rDoc.GetChartByName( aChartName ) );
447 if( xChartDoc.is() )
449 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
450 uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
451 if( xReceiver.is() && xProvider.is() )
453 const uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xReceiver->getUsedData() ) );
455 OUString aRanges;
456 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
457 bool bHasCategories=false;
458 bool bFirstCellAsLabel=false;
459 for (const beans::PropertyValue& rProp : aArgs)
461 OUString aPropName(rProp.Name);
463 if (aPropName == "CellRangeRepresentation")
464 rProp.Value >>= aRanges;
465 else if (aPropName == "DataRowSource")
466 eDataRowSource = static_cast<chart::ChartDataRowSource>(ScUnoHelpFunctions::GetEnumFromAny( rProp.Value ));
467 else if (aPropName == "HasCategories")
468 bHasCategories = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
469 else if (aPropName == "FirstCellAsLabel")
470 bFirstCellAsLabel = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
473 if( chart::ChartDataRowSource_COLUMNS == eDataRowSource )
475 rColHeaders=bFirstCellAsLabel;
476 rRowHeaders=bHasCategories;
478 else
480 rColHeaders=bHasCategories;
481 rRowHeaders=bFirstCellAsLabel;
483 // Range in UI representation.
484 rRanges->Parse( aRanges, rDoc, rDoc.GetAddressConvention());
486 bFound = true;
489 if( !bFound )
491 rRanges = nullptr;
492 rColHeaders = false;
493 rRowHeaders = false;
497 void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, bool bRowHeaders )
499 if (pDocShell)
501 ScDocument& rDoc = pDocShell->GetDocument();
502 bool bUndo(rDoc.IsUndoEnabled());
504 if (bUndo)
506 pDocShell->GetUndoManager()->AddUndoAction(
507 std::make_unique<ScUndoChartData>( pDocShell, aChartName, rRanges, bColHeaders, bRowHeaders, false ) );
509 rDoc.UpdateChartArea( aChartName, rRanges, bColHeaders, bRowHeaders, false );
513 // ::comphelper::OPropertySetHelper
515 ::cppu::IPropertyArrayHelper& ScChartObj::getInfoHelper()
517 return *ScChartObj_PABase::getArrayHelper();
520 void ScChartObj::setFastPropertyValue_NoBroadcast( std::unique_lock<std::mutex>& /*rGuard*/, sal_Int32 nHandle, const uno::Any& rValue )
522 switch ( nHandle )
524 case PROP_HANDLE_RELATED_CELLRANGES:
526 uno::Sequence< table::CellRangeAddress > aCellRanges;
527 if ( rValue >>= aCellRanges )
529 ScRangeListRef rRangeList = new ScRangeList();
530 for (table::CellRangeAddress const& aCellRange : aCellRanges)
532 ScRange aRange;
533 ScUnoConversion::FillScRange( aRange, aCellRange );
534 rRangeList->push_back( aRange );
536 if ( pDocShell )
538 ScChartListenerCollection* pCollection = pDocShell->GetDocument().GetChartListenerCollection();
539 if ( pCollection )
541 pCollection->ChangeListening( aChartName, rRangeList );
546 break;
547 default:
548 break;
552 void ScChartObj::getFastPropertyValue( std::unique_lock<std::mutex>& /*rGuard*/, uno::Any& rValue, sal_Int32 nHandle ) const
554 switch ( nHandle )
556 case PROP_HANDLE_RELATED_CELLRANGES:
558 if (!pDocShell)
559 break;
560 ScDocument& rDoc = pDocShell->GetDocument();
562 ScChartListenerCollection* pCollection = rDoc.GetChartListenerCollection();
563 if (!pCollection)
564 break;
566 ScChartListener* pListener = pCollection->findByName(aChartName);
567 if (!pListener)
568 break;
570 const ScRangeListRef xRangeList = pListener->GetRangeList();
571 if (!xRangeList.is())
572 break;
574 size_t nCount = xRangeList->size();
575 uno::Sequence<table::CellRangeAddress> aCellRanges(nCount);
576 table::CellRangeAddress* pCellRanges = aCellRanges.getArray();
577 for (size_t i = 0; i < nCount; ++i)
579 ScRange const & rRange = (*xRangeList)[i];
580 table::CellRangeAddress aCellRange;
581 ScUnoConversion::FillApiRange(aCellRange, rRange);
582 pCellRanges[i] = aCellRange;
584 rValue <<= aCellRanges;
586 break;
587 default:
592 // ::comphelper::OPropertyArrayUsageHelper
594 ::cppu::IPropertyArrayHelper* ScChartObj::createArrayHelper() const
596 uno::Sequence< beans::Property > aProps;
597 describeProperties( aProps );
598 return new ::cppu::OPropertyArrayHelper( aProps );
601 // XInterface
603 IMPLEMENT_FORWARD_XINTERFACE2( ScChartObj, ScChartObj_Base, ScChartObj_PBase )
605 // XTypeProvider
607 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScChartObj, ScChartObj_Base, ScChartObj_PBase )
609 // XTableChart
611 sal_Bool SAL_CALL ScChartObj::getHasColumnHeaders()
613 SolarMutexGuard aGuard;
614 ScRangeListRef xRanges = new ScRangeList;
615 bool bColHeaders, bRowHeaders;
616 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
617 return bColHeaders;
620 void SAL_CALL ScChartObj::setHasColumnHeaders( sal_Bool bHasColumnHeaders )
622 SolarMutexGuard aGuard;
623 ScRangeListRef xRanges = new ScRangeList;
624 bool bOldColHeaders, bOldRowHeaders;
625 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
626 if ( bOldColHeaders != bool(bHasColumnHeaders) )
627 Update_Impl( xRanges, bHasColumnHeaders, bOldRowHeaders );
630 sal_Bool SAL_CALL ScChartObj::getHasRowHeaders()
632 SolarMutexGuard aGuard;
633 ScRangeListRef xRanges = new ScRangeList;
634 bool bColHeaders, bRowHeaders;
635 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
636 return bRowHeaders;
639 void SAL_CALL ScChartObj::setHasRowHeaders( sal_Bool bHasRowHeaders )
641 SolarMutexGuard aGuard;
642 ScRangeListRef xRanges = new ScRangeList;
643 bool bOldColHeaders, bOldRowHeaders;
644 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
645 if ( bOldRowHeaders != bool(bHasRowHeaders) )
646 Update_Impl( xRanges, bOldColHeaders, bHasRowHeaders );
649 uno::Sequence<table::CellRangeAddress> SAL_CALL ScChartObj::getRanges()
651 SolarMutexGuard aGuard;
652 ScRangeListRef xRanges = new ScRangeList;
653 bool bColHeaders, bRowHeaders;
654 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
655 if ( xRanges.is() )
657 size_t nCount = xRanges->size();
659 table::CellRangeAddress aRangeAddress;
660 uno::Sequence<table::CellRangeAddress> aSeq(nCount);
661 table::CellRangeAddress* pAry = aSeq.getArray();
662 for (size_t i = 0; i < nCount; i++)
664 ScRange const & rRange = (*xRanges)[i];
666 aRangeAddress.Sheet = rRange.aStart.Tab();
667 aRangeAddress.StartColumn = rRange.aStart.Col();
668 aRangeAddress.StartRow = rRange.aStart.Row();
669 aRangeAddress.EndColumn = rRange.aEnd.Col();
670 aRangeAddress.EndRow = rRange.aEnd.Row();
672 pAry[i] = aRangeAddress;
674 return aSeq;
677 OSL_FAIL("ScChartObj::getRanges: no Ranges");
678 return uno::Sequence<table::CellRangeAddress>();
681 void SAL_CALL ScChartObj::setRanges( const uno::Sequence<table::CellRangeAddress>& aRanges )
683 SolarMutexGuard aGuard;
684 ScRangeListRef xOldRanges = new ScRangeList;
685 bool bColHeaders, bRowHeaders;
686 GetData_Impl( xOldRanges, bColHeaders, bRowHeaders );
688 ScRangeList* pList = new ScRangeList;
689 for (const table::CellRangeAddress& rRange : aRanges)
691 ScRange aRange( static_cast<SCCOL>(rRange.StartColumn), rRange.StartRow, rRange.Sheet,
692 static_cast<SCCOL>(rRange.EndColumn), rRange.EndRow, rRange.Sheet );
693 pList->push_back( aRange );
695 ScRangeListRef xNewRanges( pList );
697 if ( !xOldRanges.is() || *xOldRanges != *xNewRanges )
698 Update_Impl( xNewRanges, bColHeaders, bRowHeaders );
701 // XEmbeddedObjectSupplier
703 uno::Reference<lang::XComponent> SAL_CALL ScChartObj::getEmbeddedObject()
705 SolarMutexGuard aGuard;
706 SdrOle2Obj* pObject = sc::tools::findChartsByName(pDocShell, nTab, aChartName,
707 sc::tools::ChartSourceType::CELL_RANGE);
708 if ( pObject && svt::EmbeddedObjectRef::TryRunningState( pObject->GetObjRef() ) )
710 //TODO/LATER: is it OK that something is returned for *all* objects, not only own objects?
711 return uno::Reference < lang::XComponent > ( pObject->GetObjRef()->getComponent(), uno::UNO_QUERY );
714 return nullptr;
717 // XNamed
719 OUString SAL_CALL ScChartObj::getName()
721 SolarMutexGuard aGuard;
722 return aChartName;
725 void SAL_CALL ScChartObj::setName( const OUString& /* aName */ )
727 throw uno::RuntimeException(); // name cannot be changed
730 // XPropertySet
732 uno::Reference< beans::XPropertySetInfo > ScChartObj::getPropertySetInfo()
734 return createPropertySetInfo( getInfoHelper() ) ;
737 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */