Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / unoobj / chartuno.cxx
blob31ef9da291fd4418e25af51a3750c9c8f0aa1eea
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/awt/Size.hpp>
22 #include <com/sun/star/beans/PropertyAttribute.hpp>
23 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
24 #include <com/sun/star/chart/ChartDataRowSource.hpp>
25 #include <com/sun/star/chart2/XChartDocument.hpp>
26 #include <com/sun/star/table/CellRangeAddress.hpp>
28 #include <svx/svditer.hxx>
29 #include <svx/svdoole2.hxx>
30 #include <svx/svdpage.hxx>
31 #include <svx/svdundo.hxx>
32 #include <sfx2/app.hxx>
33 #include <unotools/moduleoptions.hxx>
34 #include <comphelper/classids.hxx>
35 #include <toolkit/helper/vclunohelper.hxx>
36 #include <svx/charthelper.hxx>
38 #include "chartuno.hxx"
39 #include "miscuno.hxx"
40 #include "docsh.hxx"
41 #include "drwlayer.hxx"
42 #include "undodat.hxx"
43 #include "chartarr.hxx"
44 #include "chartlis.hxx"
45 #include "chart2uno.hxx"
46 #include "convuno.hxx"
48 using namespace com::sun::star;
50 #define PROP_HANDLE_RELATED_CELLRANGES 1
52 //------------------------------------------------------------------------
54 SC_SIMPLE_SERVICE_INFO( ScChartObj, "ScChartObj", "com.sun.star.table.TableChart" )
55 SC_SIMPLE_SERVICE_INFO( ScChartsObj, "ScChartsObj", "com.sun.star.table.TableCharts" )
57 //------------------------------------------------------------------------
59 static SdrOle2Obj* lcl_FindChartObj( ScDocShell* pDocShell, SCTAB nTab, const OUString& rName )
61 if (pDocShell)
63 ScDocument* pDoc = pDocShell->GetDocument();
64 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
65 if (pDrawLayer)
67 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
68 OSL_ENSURE(pPage, "Page nicht gefunden");
69 if (pPage)
71 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
72 SdrObject* pObject = aIter.Next();
73 while (pObject)
75 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
77 uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
78 if ( xObj.is() )
80 OUString aObjName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
81 if ( aObjName == rName )
82 return (SdrOle2Obj*)pObject;
85 pObject = aIter.Next();
90 return NULL;
93 //------------------------------------------------------------------------
95 ScChartsObj::ScChartsObj(ScDocShell* pDocSh, SCTAB nT) :
96 pDocShell( pDocSh ),
97 nTab( nT )
99 pDocShell->GetDocument()->AddUnoObject(*this);
102 ScChartsObj::~ScChartsObj()
104 if (pDocShell)
105 pDocShell->GetDocument()->RemoveUnoObject(*this);
108 void ScChartsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
110 //! Referenz-Update
112 if ( rHint.ISA( SfxSimpleHint ) &&
113 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
115 pDocShell = NULL; // ungueltig geworden
119 ScChartObj* ScChartsObj::GetObjectByIndex_Impl(long nIndex) const
121 OUString aName;
122 if ( pDocShell )
124 ScDocument* pDoc = pDocShell->GetDocument();
125 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
126 if (pDrawLayer)
128 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
129 OSL_ENSURE(pPage, "Page nicht gefunden");
130 if (pPage)
132 long nPos = 0;
133 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
134 SdrObject* pObject = aIter.Next();
135 while (pObject)
137 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
139 if ( nPos == nIndex )
141 uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
142 if ( xObj.is() )
143 aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
144 break; // nicht weitersuchen
146 ++nPos;
148 pObject = aIter.Next();
154 if (!aName.isEmpty())
155 return new ScChartObj( pDocShell, nTab, aName );
156 return NULL;
159 ScChartObj* ScChartsObj::GetObjectByName_Impl(const OUString& aName) const
161 if ( lcl_FindChartObj( pDocShell, nTab, aName ) )
162 return new ScChartObj( pDocShell, nTab, aName );
163 return NULL;
166 // XTableCharts
168 void SAL_CALL ScChartsObj::addNewByName( const OUString& rName,
169 const awt::Rectangle& aRect,
170 const uno::Sequence<table::CellRangeAddress>& aRanges,
171 sal_Bool bColumnHeaders, sal_Bool bRowHeaders )
172 throw(::com::sun::star::uno::RuntimeException)
174 SolarMutexGuard aGuard;
175 if (!pDocShell)
176 return;
178 ScDocument* pDoc = pDocShell->GetDocument();
179 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
180 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab));
181 OSL_ENSURE(pPage,"addChart: keine Page");
182 if (!pPage || !pDoc)
183 return;
185 // chart can't be inserted if any ole object with that name exists on any table
186 // (empty string: generate valid name)
188 OUString aName = rName;
189 SCTAB nDummy;
190 if ( !aName.isEmpty() && pModel->GetNamedObject( aName, OBJ_OLE2, nDummy ) )
192 // object exists - only RuntimeException is specified
193 throw uno::RuntimeException();
196 ScRangeList* pList = new ScRangeList;
197 sal_Int32 nRangeCount = aRanges.getLength();
198 if (nRangeCount)
200 const table::CellRangeAddress* pAry = aRanges.getConstArray();
201 for (sal_Int32 i=0; i<nRangeCount; i++)
203 ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
204 static_cast<SCCOL>(pAry[i].EndColumn), pAry[i].EndRow, pAry[i].Sheet );
205 pList->Append( aRange );
208 ScRangeListRef xNewRanges( pList );
210 uno::Reference < embed::XEmbeddedObject > xObj;
211 if ( SvtModuleOptions().IsChart() )
212 xObj = pDocShell->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aName );
213 if ( xObj.is() )
215 // Rechteck anpassen
216 //! Fehler/Exception, wenn leer/ungueltig ???
217 Point aRectPos( aRect.X, aRect.Y );
218 bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
219 if ( ( aRectPos.X() < 0 && !bLayoutRTL ) || ( aRectPos.X() > 0 && bLayoutRTL ) )
220 aRectPos.X() = 0;
222 if (aRectPos.Y() < 0)
223 aRectPos.Y() = 0;
225 Size aRectSize( aRect.Width, aRect.Height );
226 if (aRectSize.Width() <= 0)
227 aRectSize.Width() = 5000; // Default-Groesse
229 if (aRectSize.Height() <= 0)
230 aRectSize.Height() = 5000;
231 Rectangle aInsRect( aRectPos, aRectSize );
233 sal_Int64 nAspect(embed::Aspects::MSOLE_CONTENT);
234 MapUnit aMapUnit(VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ));
235 Size aSize(aInsRect.GetSize());
236 aSize = Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) );
237 awt::Size aSz;
238 aSz.Width = aSize.Width();
239 aSz.Height = aSize.Height();
241 // Calc -> DataProvider
242 uno::Reference< chart2::data::XDataProvider > xDataProvider = new
243 ScChart2DataProvider( pDoc );
244 // Chart -> DataReceiver
245 uno::Reference< chart2::data::XDataReceiver > xReceiver;
246 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
247 if( xCompSupp.is())
248 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
249 if( xReceiver.is())
251 OUString sRangeStr;
252 xNewRanges->Format(sRangeStr, SCR_ABS_3D, pDoc);
254 // connect
255 if( !sRangeStr.isEmpty() )
256 xReceiver->attachDataProvider( xDataProvider );
257 else
258 sRangeStr = "all";
260 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
261 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
263 // set arguments
264 uno::Sequence< beans::PropertyValue > aArgs( 4 );
265 aArgs[0] = beans::PropertyValue(
266 OUString("CellRangeRepresentation"), -1,
267 uno::makeAny( OUString( sRangeStr )), beans::PropertyState_DIRECT_VALUE );
268 aArgs[1] = beans::PropertyValue(
269 OUString("HasCategories"), -1,
270 uno::makeAny( bRowHeaders ), beans::PropertyState_DIRECT_VALUE );
271 aArgs[2] = beans::PropertyValue(
272 OUString("FirstCellAsLabel"), -1,
273 uno::makeAny( bColumnHeaders ), beans::PropertyState_DIRECT_VALUE );
274 aArgs[3] = beans::PropertyValue(
275 OUString("DataRowSource"), -1,
276 uno::makeAny( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE );
277 xReceiver->setArguments( aArgs );
280 ScChartListener* pChartListener =
281 new ScChartListener( aName, pDoc, xNewRanges );
282 pDoc->GetChartListenerCollection()->insert( pChartListener );
283 pChartListener->StartListeningTo();
285 SdrOle2Obj* pObj = new SdrOle2Obj( ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ), aName, aInsRect );
287 // set VisArea
288 if( xObj.is())
289 xObj->setVisualAreaSize( nAspect, aSz );
291 // #i121334# This call will change the chart's default background fill from white to transparent.
292 // Add here again if this is wanted (see task description for details)
293 // ChartHelper::AdaptDefaultsForChart( xObj );
295 pPage->InsertObject( pObj );
296 pModel->AddUndo( new SdrUndoInsertObj( *pObj ) );
300 void SAL_CALL ScChartsObj::removeByName( const OUString& aName )
301 throw(uno::RuntimeException)
303 SolarMutexGuard aGuard;
304 SdrOle2Obj* pObj = lcl_FindChartObj( pDocShell, nTab, aName );
305 if (pObj)
307 ScDocument* pDoc = pDocShell->GetDocument();
308 pDoc->GetChartListenerCollection()->removeByName(aName);
309 ScDrawLayer* pModel = pDoc->GetDrawLayer(); // ist nicht 0
310 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab)); // ist nicht 0
312 pModel->AddUndo( new SdrUndoDelObj( *pObj ) );
313 pPage->RemoveObject( pObj->GetOrdNum() );
315 //! Notify etc.???
319 // XEnumerationAccess
321 uno::Reference<container::XEnumeration> SAL_CALL ScChartsObj::createEnumeration()
322 throw(uno::RuntimeException)
324 SolarMutexGuard aGuard;
325 return new ScIndexEnumeration(this, OUString("com.sun.star.table.TableChartsEnumeration"));
328 // XIndexAccess
330 sal_Int32 SAL_CALL ScChartsObj::getCount() throw(uno::RuntimeException)
332 SolarMutexGuard aGuard;
333 sal_Int32 nCount = 0;
334 if ( pDocShell )
336 ScDocument* pDoc = pDocShell->GetDocument();
337 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
338 if (pDrawLayer)
340 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
341 OSL_ENSURE(pPage, "Page nicht gefunden");
342 if (pPage)
344 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
345 SdrObject* pObject = aIter.Next();
346 while (pObject)
348 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
349 ++nCount;
350 pObject = aIter.Next();
355 return nCount;
358 uno::Any SAL_CALL ScChartsObj::getByIndex( sal_Int32 nIndex )
359 throw(lang::IndexOutOfBoundsException,
360 lang::WrappedTargetException, uno::RuntimeException)
362 SolarMutexGuard aGuard;
363 uno::Reference<table::XTableChart> xChart(GetObjectByIndex_Impl(nIndex));
364 if (xChart.is())
365 return uno::makeAny(xChart);
366 else
367 throw lang::IndexOutOfBoundsException();
370 uno::Type SAL_CALL ScChartsObj::getElementType() throw(uno::RuntimeException)
372 SolarMutexGuard aGuard;
373 return getCppuType((uno::Reference<table::XTableChart>*)0);
376 sal_Bool SAL_CALL ScChartsObj::hasElements() throw(uno::RuntimeException)
378 SolarMutexGuard aGuard;
379 return getCount() != 0;
382 uno::Any SAL_CALL ScChartsObj::getByName( const OUString& aName )
383 throw(container::NoSuchElementException,
384 lang::WrappedTargetException, uno::RuntimeException)
386 SolarMutexGuard aGuard;
387 uno::Reference<table::XTableChart> xChart(GetObjectByName_Impl(aName));
388 if (xChart.is())
389 return uno::makeAny(xChart);
390 else
391 throw container::NoSuchElementException();
394 uno::Sequence<OUString> SAL_CALL ScChartsObj::getElementNames() throw(uno::RuntimeException)
396 SolarMutexGuard aGuard;
397 if (pDocShell)
399 ScDocument* pDoc = pDocShell->GetDocument();
401 long nCount = getCount();
402 uno::Sequence<OUString> aSeq(nCount);
403 OUString* pAry = aSeq.getArray();
405 long nPos = 0;
406 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
407 if (pDrawLayer)
409 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
410 OSL_ENSURE(pPage, "Page nicht gefunden");
411 if (pPage)
413 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
414 SdrObject* pObject = aIter.Next();
415 while (pObject)
417 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
419 OUString aName;
420 uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
421 if ( xObj.is() )
422 aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
424 OSL_ENSURE(nPos<nCount, "huch, verzaehlt?");
425 pAry[nPos++] = aName;
427 pObject = aIter.Next();
431 OSL_ENSURE(nPos==nCount, "nanu, verzaehlt?");
433 return aSeq;
435 return uno::Sequence<OUString>(0);
438 sal_Bool SAL_CALL ScChartsObj::hasByName( const OUString& aName )
439 throw(uno::RuntimeException)
441 SolarMutexGuard aGuard;
442 return ( lcl_FindChartObj( pDocShell, nTab, aName ) != NULL );
445 //------------------------------------------------------------------------
447 ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, const OUString& rN)
448 :ScChartObj_Base( m_aMutex )
449 ,ScChartObj_PBase( ScChartObj_Base::rBHelper )
450 ,pDocShell( pDocSh )
451 ,nTab( nT )
452 ,aChartName( rN )
454 pDocShell->GetDocument()->AddUnoObject(*this);
456 uno::Sequence< table::CellRangeAddress > aInitialPropValue;
457 registerPropertyNoMember( OUString( "RelatedCellRanges" ),
458 PROP_HANDLE_RELATED_CELLRANGES, beans::PropertyAttribute::MAYBEVOID,
459 ::getCppuType( &aInitialPropValue ), &aInitialPropValue );
462 ScChartObj::~ScChartObj()
464 if (pDocShell)
465 pDocShell->GetDocument()->RemoveUnoObject(*this);
468 void ScChartObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
470 //! Referenz-Update
472 if ( rHint.ISA( SfxSimpleHint ) &&
473 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
475 pDocShell = NULL; // ungueltig geworden
479 void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& rRowHeaders ) const
481 bool bFound = false;
482 ScDocument* pDoc = (pDocShell? pDocShell->GetDocument(): 0);
484 if( pDoc )
486 uno::Reference< chart2::XChartDocument > xChartDoc( pDoc->GetChartByName( aChartName ) );
487 if( xChartDoc.is() )
489 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
490 uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
491 if( xReceiver.is() && xProvider.is() )
493 uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xReceiver->getUsedData() ) );
495 OUString aRanges;
496 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
497 bool bHasCategories=false;
498 bool bFirstCellAsLabel=false;
499 const beans::PropertyValue* pPropArray = aArgs.getConstArray();
500 long nPropCount = aArgs.getLength();
501 for (long i = 0; i < nPropCount; i++)
503 const beans::PropertyValue& rProp = pPropArray[i];
504 OUString aPropName(rProp.Name);
506 if (aPropName.equalsAscii( "CellRangeRepresentation" ))
507 rProp.Value >>= aRanges;
508 else if (aPropName.equalsAscii( "DataRowSource" ))
509 eDataRowSource = (chart::ChartDataRowSource)ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
510 else if (aPropName.equalsAscii( "HasCategories" ))
511 bHasCategories = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
512 else if (aPropName.equalsAscii( "FirstCellAsLabel" ))
513 bFirstCellAsLabel = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
516 if( chart::ChartDataRowSource_COLUMNS == eDataRowSource )
518 rColHeaders=bFirstCellAsLabel;
519 rRowHeaders=bHasCategories;
521 else
523 rColHeaders=bHasCategories;
524 rRowHeaders=bFirstCellAsLabel;
526 rRanges->Parse( aRanges, pDoc);
528 bFound = true;
531 if( !bFound )
533 rRanges = 0;
534 rColHeaders = false;
535 rRowHeaders = false;
539 void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, bool bRowHeaders )
541 if (pDocShell)
543 ScDocument* pDoc = pDocShell->GetDocument();
544 sal_Bool bUndo(pDoc->IsUndoEnabled());
546 if (bUndo)
548 pDocShell->GetUndoManager()->AddUndoAction(
549 new ScUndoChartData( pDocShell, aChartName, rRanges, bColHeaders, bRowHeaders, false ) );
551 pDoc->UpdateChartArea( aChartName, rRanges, bColHeaders, bRowHeaders, false );
555 // ::comphelper::OPropertySetHelper
557 ::cppu::IPropertyArrayHelper& ScChartObj::getInfoHelper()
559 return *ScChartObj_PABase::getArrayHelper();
562 void ScChartObj::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) throw (uno::Exception)
564 switch ( nHandle )
566 case PROP_HANDLE_RELATED_CELLRANGES:
568 uno::Sequence< table::CellRangeAddress > aCellRanges;
569 if ( rValue >>= aCellRanges )
571 ScRangeListRef rRangeList = new ScRangeList();
572 const table::CellRangeAddress* pCellRanges = aCellRanges.getArray();
573 sal_Int32 nCount = aCellRanges.getLength();
574 for ( sal_Int32 i = 0; i < nCount; ++i )
576 table::CellRangeAddress aCellRange = pCellRanges[ i ];
577 ScRange aRange;
578 ScUnoConversion::FillScRange( aRange, aCellRange );
579 rRangeList->Append( aRange );
581 ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL );
582 ScChartListenerCollection* pCollection = ( pDoc ? pDoc->GetChartListenerCollection() : NULL );
583 if ( pCollection )
585 pCollection->ChangeListening( aChartName, rRangeList );
589 break;
590 default:
591 break;
595 void ScChartObj::getFastPropertyValue( uno::Any& rValue, sal_Int32 nHandle ) const
597 switch ( nHandle )
599 case PROP_HANDLE_RELATED_CELLRANGES:
601 ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL );
602 if (!pDoc)
603 break;
605 ScChartListenerCollection* pCollection = pDoc->GetChartListenerCollection();
606 if (!pCollection)
607 break;
609 ScChartListener* pListener = pCollection->findByName(aChartName);
610 if (!pListener)
611 break;
613 const ScRangeListRef& rRangeList = pListener->GetRangeList();
614 if (!rRangeList.Is())
615 break;
617 size_t nCount = rRangeList->size();
618 uno::Sequence<table::CellRangeAddress> aCellRanges(nCount);
619 table::CellRangeAddress* pCellRanges = aCellRanges.getArray();
620 for (size_t i = 0; i < nCount; ++i)
622 ScRange aRange(*(*rRangeList)[i]);
623 table::CellRangeAddress aCellRange;
624 ScUnoConversion::FillApiRange(aCellRange, aRange);
625 pCellRanges[i] = aCellRange;
627 rValue <<= aCellRanges;
629 break;
630 default:
635 // ::comphelper::OPropertyArrayUsageHelper
637 ::cppu::IPropertyArrayHelper* ScChartObj::createArrayHelper() const
639 uno::Sequence< beans::Property > aProps;
640 describeProperties( aProps );
641 return new ::cppu::OPropertyArrayHelper( aProps );
644 // XInterface
646 IMPLEMENT_FORWARD_XINTERFACE2( ScChartObj, ScChartObj_Base, ScChartObj_PBase )
648 // XTypeProvider
650 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScChartObj, ScChartObj_Base, ScChartObj_PBase )
652 // XComponent
654 void ScChartObj::disposing()
656 ScChartObj_Base::disposing();
659 // XTableChart
661 sal_Bool SAL_CALL ScChartObj::getHasColumnHeaders() throw(uno::RuntimeException)
663 SolarMutexGuard aGuard;
664 ScRangeListRef xRanges = new ScRangeList;
665 bool bColHeaders, bRowHeaders;
666 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
667 return bColHeaders;
670 void SAL_CALL ScChartObj::setHasColumnHeaders( sal_Bool bHasColumnHeaders )
671 throw(uno::RuntimeException)
673 SolarMutexGuard aGuard;
674 ScRangeListRef xRanges = new ScRangeList;
675 bool bOldColHeaders, bOldRowHeaders;
676 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
677 if ( bOldColHeaders != (bHasColumnHeaders != false) )
678 Update_Impl( xRanges, bHasColumnHeaders, bOldRowHeaders );
681 sal_Bool SAL_CALL ScChartObj::getHasRowHeaders() throw(uno::RuntimeException)
683 SolarMutexGuard aGuard;
684 ScRangeListRef xRanges = new ScRangeList;
685 bool bColHeaders, bRowHeaders;
686 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
687 return bRowHeaders;
690 void SAL_CALL ScChartObj::setHasRowHeaders( sal_Bool bHasRowHeaders )
691 throw(uno::RuntimeException)
693 SolarMutexGuard aGuard;
694 ScRangeListRef xRanges = new ScRangeList;
695 bool bOldColHeaders, bOldRowHeaders;
696 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
697 if ( bOldRowHeaders != (bHasRowHeaders != false) )
698 Update_Impl( xRanges, bOldColHeaders, bHasRowHeaders );
701 uno::Sequence<table::CellRangeAddress> SAL_CALL ScChartObj::getRanges() throw(uno::RuntimeException)
703 SolarMutexGuard aGuard;
704 ScRangeListRef xRanges = new ScRangeList;
705 bool bColHeaders, bRowHeaders;
706 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
707 if ( xRanges.Is() )
709 size_t nCount = xRanges->size();
711 table::CellRangeAddress aRangeAddress;
712 uno::Sequence<table::CellRangeAddress> aSeq(nCount);
713 table::CellRangeAddress* pAry = aSeq.getArray();
714 for (size_t i = 0; i < nCount; i++)
716 ScRange aRange( *(*xRanges)[i] );
718 aRangeAddress.Sheet = aRange.aStart.Tab();
719 aRangeAddress.StartColumn = aRange.aStart.Col();
720 aRangeAddress.StartRow = aRange.aStart.Row();
721 aRangeAddress.EndColumn = aRange.aEnd.Col();
722 aRangeAddress.EndRow = aRange.aEnd.Row();
724 pAry[i] = aRangeAddress;
726 return aSeq;
729 OSL_FAIL("ScChartObj::getRanges: keine Ranges");
730 return uno::Sequence<table::CellRangeAddress>();
733 void SAL_CALL ScChartObj::setRanges( const uno::Sequence<table::CellRangeAddress>& aRanges )
734 throw(uno::RuntimeException)
736 SolarMutexGuard aGuard;
737 ScRangeListRef xOldRanges = new ScRangeList;
738 bool bColHeaders, bRowHeaders;
739 GetData_Impl( xOldRanges, bColHeaders, bRowHeaders );
741 ScRangeList* pList = new ScRangeList;
742 sal_uInt16 nRangeCount = (sal_uInt16)aRanges.getLength();
743 if (nRangeCount)
745 const table::CellRangeAddress* pAry = aRanges.getConstArray();
746 for (sal_uInt16 i=0; i<nRangeCount; i++)
748 ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
749 static_cast<SCCOL>(pAry[i].EndColumn), pAry[i].EndRow, pAry[i].Sheet );
750 pList->Append( aRange );
753 ScRangeListRef xNewRanges( pList );
755 if ( !xOldRanges.Is() || *xOldRanges != *xNewRanges )
756 Update_Impl( xNewRanges, bColHeaders, bRowHeaders );
759 // XEmbeddedObjectSupplier
761 uno::Reference<lang::XComponent> SAL_CALL ScChartObj::getEmbeddedObject() throw(uno::RuntimeException)
763 SolarMutexGuard aGuard;
764 SdrOle2Obj* pObject = lcl_FindChartObj( pDocShell, nTab, aChartName );
765 if ( pObject && svt::EmbeddedObjectRef::TryRunningState( pObject->GetObjRef() ) )
767 //TODO/LATER: is it OK that something is returned for *all* objects, not only own objects?
768 return uno::Reference < lang::XComponent > ( pObject->GetObjRef()->getComponent(), uno::UNO_QUERY );
771 return NULL;
774 // XNamed
776 OUString SAL_CALL ScChartObj::getName() throw(uno::RuntimeException)
778 SolarMutexGuard aGuard;
779 return aChartName;
782 void SAL_CALL ScChartObj::setName( const OUString& /* aName */ ) throw(uno::RuntimeException)
784 SolarMutexGuard aGuard;
785 throw uno::RuntimeException(); // name cannot be changed
788 // XPropertySet
790 uno::Reference< beans::XPropertySetInfo > ScChartObj::getPropertySetInfo() throw (uno::RuntimeException)
792 return createPropertySetInfo( getInfoHelper() ) ;
795 //------------------------------------------------------------------------
799 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */