Update ooo320-m1
[ooovba.git] / sc / source / ui / unoobj / chartuno.cxx
blob207c3063818ce6ea41f019b25ff101849b4ceb58
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 String sRangeStr;
259 xNewRanges->Format(sRangeStr, SCR_ABS_3D, pDoc);
261 // connect
262 if( sRangeStr.Len() )
263 xReceiver->attachDataProvider( xDataProvider );
264 else
265 sRangeStr = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( "all" ) );
267 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
268 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
270 // set arguments
271 uno::Sequence< beans::PropertyValue > aArgs( 4 );
272 aArgs[0] = beans::PropertyValue(
273 ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1,
274 uno::makeAny( ::rtl::OUString( sRangeStr )), beans::PropertyState_DIRECT_VALUE );
275 aArgs[1] = beans::PropertyValue(
276 ::rtl::OUString::createFromAscii("HasCategories"), -1,
277 uno::makeAny( bRowHeaders ), beans::PropertyState_DIRECT_VALUE );
278 aArgs[2] = beans::PropertyValue(
279 ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1,
280 uno::makeAny( bColumnHeaders ), beans::PropertyState_DIRECT_VALUE );
281 aArgs[3] = beans::PropertyValue(
282 ::rtl::OUString::createFromAscii("DataRowSource"), -1,
283 uno::makeAny( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE );
284 xReceiver->setArguments( aArgs );
287 ScChartListener* pChartListener =
288 new ScChartListener( aObjName, pDoc, xNewRanges );
289 pDoc->GetChartListenerCollection()->Insert( pChartListener );
290 pChartListener->StartListeningTo();
292 SdrOle2Obj* pObj = new SdrOle2Obj( ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ), aObjName, aInsRect );
294 // set VisArea
295 if( xObj.is())
296 xObj->setVisualAreaSize( nAspect, aSz );
298 pPage->InsertObject( pObj );
299 pModel->AddUndo( new SdrUndoInsertObj( *pObj ) ); //! Undo-Kommentar?
301 // Dies veranlaesst Chart zum sofortigen Update
302 //SvData aEmpty;
303 //aIPObj->SendDataChanged( aEmpty );
307 void SAL_CALL ScChartsObj::removeByName( const rtl::OUString& aName )
308 throw(uno::RuntimeException)
310 ScUnoGuard aGuard;
311 String aNameString(aName);
312 SdrOle2Obj* pObj = lcl_FindChartObj( pDocShell, nTab, aNameString );
313 if (pObj)
315 ScDocument* pDoc = pDocShell->GetDocument();
316 ScDrawLayer* pModel = pDoc->GetDrawLayer(); // ist nicht 0
317 SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab)); // ist nicht 0
319 pModel->AddUndo( new SdrUndoRemoveObj( *pObj ) ); //! Undo-Kommentar?
320 pPage->RemoveObject( pObj->GetOrdNum() );
322 //! Notify etc.???
326 // XEnumerationAccess
328 uno::Reference<container::XEnumeration> SAL_CALL ScChartsObj::createEnumeration()
329 throw(uno::RuntimeException)
331 ScUnoGuard aGuard;
332 return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableChartsEnumeration")));
335 // XIndexAccess
337 sal_Int32 SAL_CALL ScChartsObj::getCount() throw(uno::RuntimeException)
339 ScUnoGuard aGuard;
340 INT32 nCount = 0;
341 if ( pDocShell )
343 ScDocument* pDoc = pDocShell->GetDocument();
344 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
345 if (pDrawLayer)
347 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
348 DBG_ASSERT(pPage, "Page nicht gefunden");
349 if (pPage)
351 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
352 SdrObject* pObject = aIter.Next();
353 while (pObject)
355 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
356 ++nCount;
357 pObject = aIter.Next();
362 return nCount;
365 uno::Any SAL_CALL ScChartsObj::getByIndex( sal_Int32 nIndex )
366 throw(lang::IndexOutOfBoundsException,
367 lang::WrappedTargetException, uno::RuntimeException)
369 ScUnoGuard aGuard;
370 uno::Reference<table::XTableChart> xChart(GetObjectByIndex_Impl(nIndex));
371 if (xChart.is())
372 return uno::makeAny(xChart);
373 else
374 throw lang::IndexOutOfBoundsException();
375 // return uno::Any();
378 uno::Type SAL_CALL ScChartsObj::getElementType() throw(uno::RuntimeException)
380 ScUnoGuard aGuard;
381 return getCppuType((uno::Reference<table::XTableChart>*)0);
384 sal_Bool SAL_CALL ScChartsObj::hasElements() throw(uno::RuntimeException)
386 ScUnoGuard aGuard;
387 return getCount() != 0;
390 uno::Any SAL_CALL ScChartsObj::getByName( const rtl::OUString& aName )
391 throw(container::NoSuchElementException,
392 lang::WrappedTargetException, uno::RuntimeException)
394 ScUnoGuard aGuard;
395 uno::Reference<table::XTableChart> xChart(GetObjectByName_Impl(aName));
396 if (xChart.is())
397 return uno::makeAny(xChart);
398 else
399 throw container::NoSuchElementException();
400 // return uno::Any();
403 uno::Sequence<rtl::OUString> SAL_CALL ScChartsObj::getElementNames() throw(uno::RuntimeException)
405 ScUnoGuard aGuard;
406 if (pDocShell)
408 ScDocument* pDoc = pDocShell->GetDocument();
410 long nCount = getCount();
411 uno::Sequence<rtl::OUString> aSeq(nCount);
412 rtl::OUString* pAry = aSeq.getArray();
414 long nPos = 0;
415 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
416 if (pDrawLayer)
418 SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
419 DBG_ASSERT(pPage, "Page nicht gefunden");
420 if (pPage)
422 SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
423 SdrObject* pObject = aIter.Next();
424 while (pObject)
426 if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
428 String aName;
429 uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
430 if ( xObj.is() )
431 aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
433 DBG_ASSERT(nPos<nCount, "huch, verzaehlt?");
434 pAry[nPos++] = aName;
436 pObject = aIter.Next();
440 DBG_ASSERT(nPos==nCount, "nanu, verzaehlt?");
442 return aSeq;
444 return uno::Sequence<rtl::OUString>(0);
447 sal_Bool SAL_CALL ScChartsObj::hasByName( const rtl::OUString& aName )
448 throw(uno::RuntimeException)
450 ScUnoGuard aGuard;
451 String aNameString(aName);
452 return ( lcl_FindChartObj( pDocShell, nTab, aNameString ) != NULL );
455 //------------------------------------------------------------------------
457 ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, const String& rN) :
458 pDocShell( pDocSh ),
459 nTab( nT ),
460 aChartName( rN )
462 pDocShell->GetDocument()->AddUnoObject(*this);
465 ScChartObj::~ScChartObj()
467 if (pDocShell)
468 pDocShell->GetDocument()->RemoveUnoObject(*this);
471 void ScChartObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
473 //! Referenz-Update
475 if ( rHint.ISA( SfxSimpleHint ) &&
476 ((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
478 pDocShell = NULL; // ungueltig geworden
482 void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& rRowHeaders ) const
484 bool bFound = false;
485 ScDocument* pDoc = (pDocShell? pDocShell->GetDocument(): 0);
486 uno::Reference< embed::XEmbeddedObject > xIPObj;
487 if( pDoc )
488 xIPObj.set( pDoc->FindOleObjectByName( aChartName ), uno::UNO_QUERY );
489 if( xIPObj.is())
491 //make sure that the chart is loaded
492 svt::EmbeddedObjectRef::TryRunningState( xIPObj );
494 uno::Reference< chart2::XChartDocument > xChartDoc( xIPObj->getComponent(), uno::UNO_QUERY );
495 uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
496 if( xReceiver.is() )
498 uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
499 if( xProvider.is() )
501 uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xReceiver->getUsedData() ) );
503 rtl::OUString aRanges;
504 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
505 bool bHasCategories=false;
506 bool bFirstCellAsLabel=false;
507 const beans::PropertyValue* pPropArray = aArgs.getConstArray();
508 long nPropCount = aArgs.getLength();
509 for (long i = 0; i < nPropCount; i++)
511 const beans::PropertyValue& rProp = pPropArray[i];
512 String aPropName(rProp.Name);
514 if (aPropName.EqualsAscii( "CellRangeRepresentation" ))
515 rProp.Value >>= aRanges;
516 else if (aPropName.EqualsAscii( "DataRowSource" ))
517 eDataRowSource = (chart::ChartDataRowSource)ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
518 else if (aPropName.EqualsAscii( "HasCategories" ))
519 bHasCategories = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
520 else if (aPropName.EqualsAscii( "FirstCellAsLabel" ))
521 bFirstCellAsLabel = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
524 if( chart::ChartDataRowSource_COLUMNS == eDataRowSource )
526 rColHeaders=bFirstCellAsLabel;
527 rRowHeaders=bHasCategories;
529 else
531 rColHeaders=bHasCategories;
532 rRowHeaders=bFirstCellAsLabel;
534 rRanges->Parse( aRanges, pDoc);
536 bFound = true;
539 if( !bFound )
541 rRanges = 0;
542 rColHeaders = false;
543 rRowHeaders = false;
547 void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, bool bRowHeaders )
549 if (pDocShell)
551 ScDocument* pDoc = pDocShell->GetDocument();
552 BOOL bUndo(pDoc->IsUndoEnabled());
554 if (bUndo)
556 pDocShell->GetUndoManager()->AddUndoAction(
557 new ScUndoChartData( pDocShell, aChartName, rRanges, bColHeaders, bRowHeaders, FALSE ) );
559 pDoc->UpdateChartArea( aChartName, rRanges, bColHeaders, bRowHeaders, FALSE );
563 // XTableChart
565 sal_Bool SAL_CALL ScChartObj::getHasColumnHeaders() throw(uno::RuntimeException)
567 ScUnoGuard aGuard;
568 ScRangeListRef xRanges = new ScRangeList;
569 bool bColHeaders, bRowHeaders;
570 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
571 return bColHeaders;
574 void SAL_CALL ScChartObj::setHasColumnHeaders( sal_Bool bHasColumnHeaders )
575 throw(uno::RuntimeException)
577 ScUnoGuard aGuard;
578 ScRangeListRef xRanges = new ScRangeList;
579 bool bOldColHeaders, bOldRowHeaders;
580 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
581 if ( bOldColHeaders != (bHasColumnHeaders != sal_False) )
582 Update_Impl( xRanges, bHasColumnHeaders, bOldRowHeaders );
585 sal_Bool SAL_CALL ScChartObj::getHasRowHeaders() throw(uno::RuntimeException)
587 ScUnoGuard aGuard;
588 ScRangeListRef xRanges = new ScRangeList;
589 bool bColHeaders, bRowHeaders;
590 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
591 return bRowHeaders;
594 void SAL_CALL ScChartObj::setHasRowHeaders( sal_Bool bHasRowHeaders )
595 throw(uno::RuntimeException)
597 ScUnoGuard aGuard;
598 ScRangeListRef xRanges = new ScRangeList;
599 bool bOldColHeaders, bOldRowHeaders;
600 GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
601 if ( bOldRowHeaders != (bHasRowHeaders != sal_False) )
602 Update_Impl( xRanges, bOldColHeaders, bHasRowHeaders );
605 uno::Sequence<table::CellRangeAddress> SAL_CALL ScChartObj::getRanges() throw(uno::RuntimeException)
607 ScUnoGuard aGuard;
608 ScRangeListRef xRanges = new ScRangeList;
609 bool bColHeaders, bRowHeaders;
610 GetData_Impl( xRanges, bColHeaders, bRowHeaders );
611 if ( xRanges.Is() )
613 ULONG nCount = xRanges->Count();
615 table::CellRangeAddress aRangeAddress;
616 uno::Sequence<table::CellRangeAddress> aSeq(nCount);
617 table::CellRangeAddress* pAry = aSeq.getArray();
618 for (USHORT i=0; i<nCount; i++)
620 ScRange aRange(*xRanges->GetObject(i));
622 aRangeAddress.Sheet = aRange.aStart.Tab();
623 aRangeAddress.StartColumn = aRange.aStart.Col();
624 aRangeAddress.StartRow = aRange.aStart.Row();
625 aRangeAddress.EndColumn = aRange.aEnd.Col();
626 aRangeAddress.EndRow = aRange.aEnd.Row();
628 pAry[i] = aRangeAddress;
630 return aSeq;
633 DBG_ERROR("ScChartObj::getRanges: keine Ranges");
634 return uno::Sequence<table::CellRangeAddress>();
637 void SAL_CALL ScChartObj::setRanges( const uno::Sequence<table::CellRangeAddress>& aRanges )
638 throw(uno::RuntimeException)
640 ScUnoGuard aGuard;
641 ScRangeListRef xOldRanges = new ScRangeList;
642 bool bColHeaders, bRowHeaders;
643 GetData_Impl( xOldRanges, bColHeaders, bRowHeaders );
645 ScRangeList* pList = new ScRangeList;
646 USHORT nRangeCount = (USHORT)aRanges.getLength();
647 if (nRangeCount)
649 const table::CellRangeAddress* pAry = aRanges.getConstArray();
650 for (USHORT i=0; i<nRangeCount; i++)
652 ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
653 static_cast<SCCOL>(pAry[i].EndColumn), pAry[i].EndRow, pAry[i].Sheet );
654 pList->Append( aRange );
657 ScRangeListRef xNewRanges( pList );
659 if ( !xOldRanges.Is() || *xOldRanges != *xNewRanges )
660 Update_Impl( xNewRanges, bColHeaders, bRowHeaders );
663 // XEmbeddedObjectSupplier
665 uno::Reference<lang::XComponent> SAL_CALL ScChartObj::getEmbeddedObject() throw(uno::RuntimeException)
667 ScUnoGuard aGuard;
668 SdrOle2Obj* pObject = lcl_FindChartObj( pDocShell, nTab, aChartName );
669 if ( pObject && svt::EmbeddedObjectRef::TryRunningState( pObject->GetObjRef() ) )
671 //TODO/LATER: is it OK that something is returned for *all* objects, not only own objects?
672 return uno::Reference < lang::XComponent > ( pObject->GetObjRef()->getComponent(), uno::UNO_QUERY );
675 return NULL;
678 // XNamed
680 rtl::OUString SAL_CALL ScChartObj::getName() throw(uno::RuntimeException)
682 ScUnoGuard aGuard;
683 return aChartName;
686 void SAL_CALL ScChartObj::setName( const rtl::OUString& /* aName */ ) throw(uno::RuntimeException)
688 ScUnoGuard aGuard;
689 throw uno::RuntimeException(); // name cannot be changed
692 //------------------------------------------------------------------------