update dev300-m58
[ooovba.git] / sc / source / ui / unoobj / chartuno.cxx
blobeb737d0ccc3ab6d7dfbd623e7ab2073554401a4f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chartuno.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 #include <com/sun/star/embed/Aspects.hpp>
36 #include <com/sun/star/awt/Size.hpp>
37 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
38 #include <com/sun/star/chart/ChartDataRowSource.hpp>
39 #include <com/sun/star/chart2/XChartDocument.hpp>
40 #include <com/sun/star/embed/Aspects.hpp>
42 #include <svx/svditer.hxx>
43 #include <svx/svdoole2.hxx>
44 #include <svx/svdpage.hxx>
45 #include <svx/svdundo.hxx>
46 #include <sfx2/app.hxx>
47 #include <svtools/moduleoptions.hxx>
48 #include <sot/clsids.hxx>
49 #include <toolkit/helper/vclunohelper.hxx>
51 #include "chartuno.hxx"
52 #include "miscuno.hxx"
53 #include "docsh.hxx"
54 #include "drwlayer.hxx"
55 #include "undodat.hxx"
56 #include "chartarr.hxx"
57 #include "chartlis.hxx"
58 #include "unoguard.hxx"
59 #include "chart2uno.hxx"
61 using namespace com::sun::star;
63 //------------------------------------------------------------------------
65 SC_SIMPLE_SERVICE_INFO( ScChartObj, "ScChartObj", "com.sun.star.table.TableChart" )
66 SC_SIMPLE_SERVICE_INFO( ScChartsObj, "ScChartsObj", "com.sun.star.table.TableCharts" )
68 //------------------------------------------------------------------------
70 SdrOle2Obj* lcl_FindChartObj( ScDocShell* pDocShell, SCTAB nTab, const String& rName )
72 if (pDocShell)
74 ScDocument* pDoc = pDocShell->GetDocument();
75 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
76 if (pDrawLayer)
78 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
79 DBG_ASSERT(pPage, "Page nicht gefunden");
80 if (pPage)
82 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
83 SdrObject* pObject = aIter.Next();
84 while (pObject)
86 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
88 uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
89 if ( xObj.is() )
91 String aObjName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
92 if ( aObjName == rName )
93 return (SdrOle2Obj*)pObject;
96 pObject = aIter.Next();
101 return NULL;
104 //------------------------------------------------------------------------
106 ScChartsObj::ScChartsObj(ScDocShell* pDocSh, SCTAB nT) :
107 pDocShell( pDocSh ),
108 nTab( nT )
110 pDocShell->GetDocument()->AddUnoObject(*this);
113 ScChartsObj::~ScChartsObj()
115 if (pDocShell)
116 pDocShell->GetDocument()->RemoveUnoObject(*this);
119 void ScChartsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
121 //! Referenz-Update
123 if ( rHint.ISA( SfxSimpleHint ) &&
124 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
126 pDocShell = NULL; // ungueltig geworden
130 ScChartObj* ScChartsObj::GetObjectByIndex_Impl(long nIndex) const
132 String aName;
133 if ( pDocShell )
135 ScDocument* pDoc = pDocShell->GetDocument();
136 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
137 if (pDrawLayer)
139 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
140 DBG_ASSERT(pPage, "Page nicht gefunden");
141 if (pPage)
143 long nPos = 0;
144 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
145 SdrObject* pObject = aIter.Next();
146 while (pObject)
148 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
150 if ( nPos == nIndex )
152 uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
153 if ( xObj.is() )
154 aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
155 break; // nicht weitersuchen
157 ++nPos;
159 pObject = aIter.Next();
165 if (aName.Len())
166 return new ScChartObj( pDocShell, nTab, aName );
167 return NULL;
170 ScChartObj* ScChartsObj::GetObjectByName_Impl(const rtl::OUString& aName) const
172 String aNameString(aName);
173 if ( lcl_FindChartObj( pDocShell, nTab, aNameString ) )
174 return new ScChartObj( pDocShell, nTab, aNameString );
175 return NULL;
178 // XTableCharts
180 void SAL_CALL ScChartsObj::addNewByName( const rtl::OUString& aName,
181 const awt::Rectangle& aRect,
182 const uno::Sequence<table::CellRangeAddress>& aRanges,
183 sal_Bool bColumnHeaders, sal_Bool bRowHeaders )
184 throw(::com::sun::star::uno::RuntimeException)
186 ScUnoGuard aGuard;
187 if (!pDocShell)
188 return;
190 ScDocument* pDoc = pDocShell->GetDocument();
191 ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
192 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab));
193 DBG_ASSERT(pPage,"addChart: keine Page");
194 if (!pPage || !pDoc)
195 return;
197 // chart can't be inserted if any ole object with that name exists on any table
198 // (empty string: generate valid name)
200 String aNameString(aName);
201 SCTAB nDummy;
202 if ( aNameString.Len() && pModel->GetNamedObject( aNameString, OBJ_OLE2, nDummy ) )
204 // object exists - only RuntimeException is specified
205 throw uno::RuntimeException();
208 ScRangeList* pList = new ScRangeList;
209 USHORT nRangeCount = (USHORT)aRanges.getLength();
210 if (nRangeCount)
212 const table::CellRangeAddress* pAry = aRanges.getConstArray();
213 for (USHORT i=0; i<nRangeCount; i++)
215 ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
216 static_cast<SCCOL>(pAry[i].EndColumn), pAry[i].EndRow, pAry[i].Sheet );
217 pList->Append( aRange );
220 ScRangeListRef xNewRanges( pList );
222 uno::Reference < embed::XEmbeddedObject > xObj;
223 ::rtl::OUString aTmp( aNameString );
224 if ( SvtModuleOptions().IsChart() )
225 xObj = pDocShell->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aTmp );
226 if ( xObj.is() )
228 String aObjName = aNameString; // wirklich eingefuegter Name...
230 // Rechteck anpassen
231 //! Fehler/Exception, wenn leer/ungueltig ???
232 Point aRectPos( aRect.X, aRect.Y );
233 if (aRectPos.X() < 0) aRectPos.X() = 0;
234 if (aRectPos.Y() < 0) aRectPos.Y() = 0;
235 Size aRectSize( aRect.Width, aRect.Height );
236 if (aRectSize.Width() <= 0) aRectSize.Width() = 5000; // Default-Groesse
237 if (aRectSize.Height() <= 0) aRectSize.Height() = 5000;
238 Rectangle aInsRect( aRectPos, aRectSize );
240 sal_Int64 nAspect(embed::Aspects::MSOLE_CONTENT);
241 MapUnit aMapUnit(VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ));
242 Size aSize(aInsRect.GetSize());
243 aSize = Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) );
244 awt::Size aSz;
245 aSz.Width = aSize.Width();
246 aSz.Height = aSize.Height();
248 // Calc -> DataProvider
249 uno::Reference< chart2::data::XDataProvider > xDataProvider = new
250 ScChart2DataProvider( pDoc );
251 // Chart -> DataReceiver
252 uno::Reference< chart2::data::XDataReceiver > xReceiver;
253 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
254 if( xCompSupp.is())
255 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
256 if( xReceiver.is())
258 // connect
259 xReceiver->attachDataProvider( xDataProvider );
260 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
261 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
263 // set arguments
264 String sRangeStr;
265 xNewRanges->Format(sRangeStr, SCR_ABS_3D, pDoc);
266 uno::Sequence< beans::PropertyValue > aArgs( 4 );
267 aArgs[0] = beans::PropertyValue(
268 ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1,
269 uno::makeAny( ::rtl::OUString( sRangeStr )), beans::PropertyState_DIRECT_VALUE );
270 aArgs[1] = beans::PropertyValue(
271 ::rtl::OUString::createFromAscii("HasCategories"), -1,
272 uno::makeAny( bRowHeaders ), beans::PropertyState_DIRECT_VALUE );
273 aArgs[2] = beans::PropertyValue(
274 ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1,
275 uno::makeAny( bColumnHeaders ), beans::PropertyState_DIRECT_VALUE );
276 aArgs[3] = beans::PropertyValue(
277 ::rtl::OUString::createFromAscii("DataRowSource"), -1,
278 uno::makeAny( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE );
279 xReceiver->setArguments( aArgs );
282 ScChartListener* pChartListener =
283 new ScChartListener( aObjName, pDoc, xNewRanges );
284 pDoc->GetChartListenerCollection()->Insert( pChartListener );
285 pChartListener->StartListeningTo();
287 SdrOle2Obj* pObj = new SdrOle2Obj( ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ), aObjName, aInsRect );
289 // set VisArea
290 if( xObj.is())
291 xObj->setVisualAreaSize( nAspect, aSz );
293 pPage->InsertObject( pObj );
294 pModel->AddUndo( new SdrUndoInsertObj( *pObj ) ); //! Undo-Kommentar?
296 // Dies veranlaesst Chart zum sofortigen Update
297 //SvData aEmpty;
298 //aIPObj->SendDataChanged( aEmpty );
302 void SAL_CALL ScChartsObj::removeByName( const rtl::OUString& aName )
303 throw(uno::RuntimeException)
305 ScUnoGuard aGuard;
306 String aNameString(aName);
307 SdrOle2Obj* pObj = lcl_FindChartObj( pDocShell, nTab, aNameString );
308 if (pObj)
310 ScDocument* pDoc = pDocShell->GetDocument();
311 ScDrawLayer* pModel = pDoc->GetDrawLayer(); // ist nicht 0
312 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab)); // ist nicht 0
314 pModel->AddUndo( new SdrUndoRemoveObj( *pObj ) ); //! Undo-Kommentar?
315 pPage->RemoveObject( pObj->GetOrdNum() );
317 //! Notify etc.???
321 // XEnumerationAccess
323 uno::Reference<container::XEnumeration> SAL_CALL ScChartsObj::createEnumeration()
324 throw(uno::RuntimeException)
326 ScUnoGuard aGuard;
327 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableChartsEnumeration")));
330 // XIndexAccess
332 sal_Int32 SAL_CALL ScChartsObj::getCount() throw(uno::RuntimeException)
334 ScUnoGuard aGuard;
335 INT32 nCount = 0;
336 if ( pDocShell )
338 ScDocument* pDoc = pDocShell->GetDocument();
339 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
340 if (pDrawLayer)
342 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
343 DBG_ASSERT(pPage, "Page nicht gefunden");
344 if (pPage)
346 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
347 SdrObject* pObject = aIter.Next();
348 while (pObject)
350 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
351 ++nCount;
352 pObject = aIter.Next();
357 return nCount;
360 uno::Any SAL_CALL ScChartsObj::getByIndex( sal_Int32 nIndex )
361 throw(lang::IndexOutOfBoundsException,
362 lang::WrappedTargetException, uno::RuntimeException)
364 ScUnoGuard aGuard;
365 uno::Reference<table::XTableChart> xChart(GetObjectByIndex_Impl(nIndex));
366 if (xChart.is())
367 return uno::makeAny(xChart);
368 else
369 throw lang::IndexOutOfBoundsException();
370 // return uno::Any();
373 uno::Type SAL_CALL ScChartsObj::getElementType() throw(uno::RuntimeException)
375 ScUnoGuard aGuard;
376 return getCppuType((uno::Reference<table::XTableChart>*)0);
379 sal_Bool SAL_CALL ScChartsObj::hasElements() throw(uno::RuntimeException)
381 ScUnoGuard aGuard;
382 return getCount() != 0;
385 uno::Any SAL_CALL ScChartsObj::getByName( const rtl::OUString& aName )
386 throw(container::NoSuchElementException,
387 lang::WrappedTargetException, uno::RuntimeException)
389 ScUnoGuard aGuard;
390 uno::Reference<table::XTableChart> xChart(GetObjectByName_Impl(aName));
391 if (xChart.is())
392 return uno::makeAny(xChart);
393 else
394 throw container::NoSuchElementException();
395 // return uno::Any();
398 uno::Sequence<rtl::OUString> SAL_CALL ScChartsObj::getElementNames() throw(uno::RuntimeException)
400 ScUnoGuard aGuard;
401 if (pDocShell)
403 ScDocument* pDoc = pDocShell->GetDocument();
405 long nCount = getCount();
406 uno::Sequence<rtl::OUString> aSeq(nCount);
407 rtl::OUString* pAry = aSeq.getArray();
409 long nPos = 0;
410 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
411 if (pDrawLayer)
413 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
414 DBG_ASSERT(pPage, "Page nicht gefunden");
415 if (pPage)
417 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
418 SdrObject* pObject = aIter.Next();
419 while (pObject)
421 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
423 String aName;
424 uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
425 if ( xObj.is() )
426 aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
428 DBG_ASSERT(nPos<nCount, "huch, verzaehlt?");
429 pAry[nPos++] = aName;
431 pObject = aIter.Next();
435 DBG_ASSERT(nPos==nCount, "nanu, verzaehlt?");
437 return aSeq;
439 return uno::Sequence<rtl::OUString>(0);
442 sal_Bool SAL_CALL ScChartsObj::hasByName( const rtl::OUString& aName )
443 throw(uno::RuntimeException)
445 ScUnoGuard aGuard;
446 String aNameString(aName);
447 return ( lcl_FindChartObj( pDocShell, nTab, aNameString ) != NULL );
450 //------------------------------------------------------------------------
452 ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, const String& rN) :
453 pDocShell( pDocSh ),
454 nTab( nT ),
455 aChartName( rN )
457 pDocShell->GetDocument()->AddUnoObject(*this);
460 ScChartObj::~ScChartObj()
462 if (pDocShell)
463 pDocShell->GetDocument()->RemoveUnoObject(*this);
466 void ScChartObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
468 //! Referenz-Update
470 if ( rHint.ISA( SfxSimpleHint ) &&
471 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
473 pDocShell = NULL; // ungueltig geworden
477 void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& rRowHeaders ) const
479 bool bFound = false;
480 ScDocument* pDoc = (pDocShell? pDocShell->GetDocument(): 0);
481 uno::Reference< embed::XEmbeddedObject > xIPObj;
482 if( pDoc )
483 xIPObj.set( pDoc->FindOleObjectByName( aChartName ), uno::UNO_QUERY );
484 if( xIPObj.is())
486 //make sure that the chart is loaded
487 svt::EmbeddedObjectRef::TryRunningState( xIPObj );
489 uno::Reference< chart2::XChartDocument > xChartDoc( xIPObj->getComponent(), uno::UNO_QUERY );
490 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
491 if( xReceiver.is() )
493 uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
494 if( xProvider.is() )
496 uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xReceiver->getUsedData() ) );
498 rtl::OUString aRanges;
499 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
500 bool bHasCategories=false;
501 bool bFirstCellAsLabel=false;
502 const beans::PropertyValue* pPropArray = aArgs.getConstArray();
503 long nPropCount = aArgs.getLength();
504 for (long i = 0; i < nPropCount; i++)
506 const beans::PropertyValue& rProp = pPropArray[i];
507 String aPropName(rProp.Name);
509 if (aPropName.EqualsAscii( "CellRangeRepresentation" ))
510 rProp.Value >>= aRanges;
511 else if (aPropName.EqualsAscii( "DataRowSource" ))
512 eDataRowSource = (chart::ChartDataRowSource)ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
513 else if (aPropName.EqualsAscii( "HasCategories" ))
514 bHasCategories = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
515 else if (aPropName.EqualsAscii( "FirstCellAsLabel" ))
516 bFirstCellAsLabel = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
519 if( chart::ChartDataRowSource_COLUMNS == eDataRowSource )
521 rColHeaders=bFirstCellAsLabel;
522 rRowHeaders=bHasCategories;
524 else
526 rColHeaders=bHasCategories;
527 rRowHeaders=bFirstCellAsLabel;
529 rRanges->Parse( aRanges, pDoc);
531 bFound = true;
534 if( !bFound )
536 rRanges = 0;
537 rColHeaders = false;
538 rRowHeaders = false;
542 void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, bool bRowHeaders )
544 if (pDocShell)
546 ScDocument* pDoc = pDocShell->GetDocument();
547 BOOL bUndo(pDoc->IsUndoEnabled());
549 if (bUndo)
551 pDocShell->GetUndoManager()->AddUndoAction(
552 new ScUndoChartData( pDocShell, aChartName, rRanges, bColHeaders, bRowHeaders, FALSE ) );
554 pDoc->UpdateChartArea( aChartName, rRanges, bColHeaders, bRowHeaders, FALSE );
558 // XTableChart
560 sal_Bool SAL_CALL ScChartObj::getHasColumnHeaders() throw(uno::RuntimeException)
562 ScUnoGuard aGuard;
563 ScRangeListRef xRanges = new ScRangeList;
564 bool bColHeaders, bRowHeaders;
565 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
566 return bColHeaders;
569 void SAL_CALL ScChartObj::setHasColumnHeaders( sal_Bool bHasColumnHeaders )
570 throw(uno::RuntimeException)
572 ScUnoGuard aGuard;
573 ScRangeListRef xRanges = new ScRangeList;
574 bool bOldColHeaders, bOldRowHeaders;
575 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
576 if ( bOldColHeaders != (bHasColumnHeaders != sal_False) )
577 Update_Impl( xRanges, bHasColumnHeaders, bOldRowHeaders );
580 sal_Bool SAL_CALL ScChartObj::getHasRowHeaders() throw(uno::RuntimeException)
582 ScUnoGuard aGuard;
583 ScRangeListRef xRanges = new ScRangeList;
584 bool bColHeaders, bRowHeaders;
585 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
586 return bRowHeaders;
589 void SAL_CALL ScChartObj::setHasRowHeaders( sal_Bool bHasRowHeaders )
590 throw(uno::RuntimeException)
592 ScUnoGuard aGuard;
593 ScRangeListRef xRanges = new ScRangeList;
594 bool bOldColHeaders, bOldRowHeaders;
595 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
596 if ( bOldRowHeaders != (bHasRowHeaders != sal_False) )
597 Update_Impl( xRanges, bOldColHeaders, bHasRowHeaders );
600 uno::Sequence<table::CellRangeAddress> SAL_CALL ScChartObj::getRanges() throw(uno::RuntimeException)
602 ScUnoGuard aGuard;
603 ScRangeListRef xRanges = new ScRangeList;
604 bool bColHeaders, bRowHeaders;
605 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
606 if ( xRanges.Is() )
608 ULONG nCount = xRanges->Count();
610 table::CellRangeAddress aRangeAddress;
611 uno::Sequence<table::CellRangeAddress> aSeq(nCount);
612 table::CellRangeAddress* pAry = aSeq.getArray();
613 for (USHORT i=0; i<nCount; i++)
615 ScRange aRange(*xRanges->GetObject(i));
617 aRangeAddress.Sheet = aRange.aStart.Tab();
618 aRangeAddress.StartColumn = aRange.aStart.Col();
619 aRangeAddress.StartRow = aRange.aStart.Row();
620 aRangeAddress.EndColumn = aRange.aEnd.Col();
621 aRangeAddress.EndRow = aRange.aEnd.Row();
623 pAry[i] = aRangeAddress;
625 return aSeq;
628 DBG_ERROR("ScChartObj::getRanges: keine Ranges");
629 return uno::Sequence<table::CellRangeAddress>();
632 void SAL_CALL ScChartObj::setRanges( const uno::Sequence<table::CellRangeAddress>& aRanges )
633 throw(uno::RuntimeException)
635 ScUnoGuard aGuard;
636 ScRangeListRef xOldRanges = new ScRangeList;
637 bool bColHeaders, bRowHeaders;
638 GetData_Impl( xOldRanges, bColHeaders, bRowHeaders );
640 ScRangeList* pList = new ScRangeList;
641 USHORT nRangeCount = (USHORT)aRanges.getLength();
642 if (nRangeCount)
644 const table::CellRangeAddress* pAry = aRanges.getConstArray();
645 for (USHORT i=0; i<nRangeCount; i++)
647 ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
648 static_cast<SCCOL>(pAry[i].EndColumn), pAry[i].EndRow, pAry[i].Sheet );
649 pList->Append( aRange );
652 ScRangeListRef xNewRanges( pList );
654 if ( !xOldRanges.Is() || *xOldRanges != *xNewRanges )
655 Update_Impl( xNewRanges, bColHeaders, bRowHeaders );
658 // XEmbeddedObjectSupplier
660 uno::Reference<lang::XComponent> SAL_CALL ScChartObj::getEmbeddedObject() throw(uno::RuntimeException)
662 ScUnoGuard aGuard;
663 SdrOle2Obj* pObject = lcl_FindChartObj( pDocShell, nTab, aChartName );
664 if ( pObject && svt::EmbeddedObjectRef::TryRunningState( pObject->GetObjRef() ) )
666 //TODO/LATER: is it OK that something is returned for *all* objects, not only own objects?
667 return uno::Reference < lang::XComponent > ( pObject->GetObjRef()->getComponent(), uno::UNO_QUERY );
670 return NULL;
673 // XNamed
675 rtl::OUString SAL_CALL ScChartObj::getName() throw(uno::RuntimeException)
677 ScUnoGuard aGuard;
678 return aChartName;
681 void SAL_CALL ScChartObj::setName( const rtl::OUString& /* aName */ ) throw(uno::RuntimeException)
683 ScUnoGuard aGuard;
684 throw uno::RuntimeException(); // name cannot be changed
687 //------------------------------------------------------------------------