xref: /AOO41X/main/sc/source/ui/unoobj/chartuno.cxx (revision 6f0b96b455263493bb67d60b85ff598c2aa1d673)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_sc.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
26cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp>
27cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
28cdf0e10cSrcweir #include <com/sun/star/chart2/data/XDataReceiver.hpp>
29cdf0e10cSrcweir #include <com/sun/star/chart/ChartDataRowSource.hpp>
30cdf0e10cSrcweir #include <com/sun/star/chart2/XChartDocument.hpp>
31cdf0e10cSrcweir #include <com/sun/star/embed/Aspects.hpp>
32cdf0e10cSrcweir #include <com/sun/star/table/CellRangeAddress.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <svx/svditer.hxx>
35cdf0e10cSrcweir #include <svx/svdoole2.hxx>
36cdf0e10cSrcweir #include <svx/svdpage.hxx>
37cdf0e10cSrcweir #include <svx/svdundo.hxx>
38cdf0e10cSrcweir #include <sfx2/app.hxx>
39cdf0e10cSrcweir #include <unotools/moduleoptions.hxx>
40cdf0e10cSrcweir #include <sot/clsids.hxx>
41cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
42*6f0b96b4SArmin Le Grand #include <svx/charthelper.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include "chartuno.hxx"
45cdf0e10cSrcweir #include "miscuno.hxx"
46cdf0e10cSrcweir #include "docsh.hxx"
47cdf0e10cSrcweir #include "drwlayer.hxx"
48cdf0e10cSrcweir #include "undodat.hxx"
49cdf0e10cSrcweir #include "chartarr.hxx"
50cdf0e10cSrcweir #include "chartlis.hxx"
51cdf0e10cSrcweir #include "unoguard.hxx"
52cdf0e10cSrcweir #include "chart2uno.hxx"
53cdf0e10cSrcweir #include "convuno.hxx"
54cdf0e10cSrcweir 
55cdf0e10cSrcweir using namespace com::sun::star;
56cdf0e10cSrcweir 
57cdf0e10cSrcweir #define PROP_HANDLE_RELATED_CELLRANGES  1
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //------------------------------------------------------------------------
60cdf0e10cSrcweir 
61cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScChartObj, "ScChartObj", "com.sun.star.table.TableChart" )
62cdf0e10cSrcweir SC_SIMPLE_SERVICE_INFO( ScChartsObj, "ScChartsObj", "com.sun.star.table.TableCharts" )
63cdf0e10cSrcweir 
64cdf0e10cSrcweir //------------------------------------------------------------------------
65cdf0e10cSrcweir 
66cdf0e10cSrcweir SdrOle2Obj* lcl_FindChartObj( ScDocShell* pDocShell, SCTAB nTab, const String& rName )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	if (pDocShell)
69cdf0e10cSrcweir 	{
70cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
71cdf0e10cSrcweir 		ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
72cdf0e10cSrcweir 		if (pDrawLayer)
73cdf0e10cSrcweir 		{
74cdf0e10cSrcweir 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
75cdf0e10cSrcweir 			DBG_ASSERT(pPage, "Page nicht gefunden");
76cdf0e10cSrcweir 			if (pPage)
77cdf0e10cSrcweir 			{
78cdf0e10cSrcweir 				SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
79cdf0e10cSrcweir 				SdrObject* pObject = aIter.Next();
80cdf0e10cSrcweir 				while (pObject)
81cdf0e10cSrcweir 				{
82cdf0e10cSrcweir 					if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
83cdf0e10cSrcweir 					{
84cdf0e10cSrcweir                         uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
85cdf0e10cSrcweir                         if ( xObj.is() )
86cdf0e10cSrcweir 						{
87cdf0e10cSrcweir                             String aObjName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
88cdf0e10cSrcweir                             if ( aObjName == rName )
89cdf0e10cSrcweir                                 return (SdrOle2Obj*)pObject;
90cdf0e10cSrcweir 						}
91cdf0e10cSrcweir 					}
92cdf0e10cSrcweir 					pObject = aIter.Next();
93cdf0e10cSrcweir 				}
94cdf0e10cSrcweir 			}
95cdf0e10cSrcweir 		}
96cdf0e10cSrcweir 	}
97cdf0e10cSrcweir 	return NULL;
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir //------------------------------------------------------------------------
101cdf0e10cSrcweir 
102cdf0e10cSrcweir ScChartsObj::ScChartsObj(ScDocShell* pDocSh, SCTAB nT) :
103cdf0e10cSrcweir 	pDocShell( pDocSh ),
104cdf0e10cSrcweir 	nTab( nT )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	pDocShell->GetDocument()->AddUnoObject(*this);
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir ScChartsObj::~ScChartsObj()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	if (pDocShell)
112cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
113cdf0e10cSrcweir }
114cdf0e10cSrcweir 
115cdf0e10cSrcweir void ScChartsObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	//!	Referenz-Update
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) &&
120cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
121cdf0e10cSrcweir 	{
122cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
123cdf0e10cSrcweir 	}
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir ScChartObj* ScChartsObj::GetObjectByIndex_Impl(long nIndex) const
127cdf0e10cSrcweir {
128cdf0e10cSrcweir 	String aName;
129cdf0e10cSrcweir 	if ( pDocShell )
130cdf0e10cSrcweir 	{
131cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
132cdf0e10cSrcweir 		ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
133cdf0e10cSrcweir 		if (pDrawLayer)
134cdf0e10cSrcweir 		{
135cdf0e10cSrcweir 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
136cdf0e10cSrcweir 			DBG_ASSERT(pPage, "Page nicht gefunden");
137cdf0e10cSrcweir 			if (pPage)
138cdf0e10cSrcweir 			{
139cdf0e10cSrcweir 				long nPos = 0;
140cdf0e10cSrcweir 				SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
141cdf0e10cSrcweir 				SdrObject* pObject = aIter.Next();
142cdf0e10cSrcweir 				while (pObject)
143cdf0e10cSrcweir 				{
144cdf0e10cSrcweir 					if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
145cdf0e10cSrcweir 					{
146cdf0e10cSrcweir 						if ( nPos == nIndex )
147cdf0e10cSrcweir 						{
148cdf0e10cSrcweir                             uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
149cdf0e10cSrcweir                             if ( xObj.is() )
150cdf0e10cSrcweir                                 aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
151cdf0e10cSrcweir 							break;	// nicht weitersuchen
152cdf0e10cSrcweir 						}
153cdf0e10cSrcweir 						++nPos;
154cdf0e10cSrcweir 					}
155cdf0e10cSrcweir 					pObject = aIter.Next();
156cdf0e10cSrcweir 				}
157cdf0e10cSrcweir 			}
158cdf0e10cSrcweir 		}
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	if (aName.Len())
162cdf0e10cSrcweir 		return new ScChartObj( pDocShell, nTab, aName );
163cdf0e10cSrcweir 	return NULL;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir ScChartObj* ScChartsObj::GetObjectByName_Impl(const rtl::OUString& aName) const
167cdf0e10cSrcweir {
168cdf0e10cSrcweir 	String aNameString(aName);
169cdf0e10cSrcweir 	if ( lcl_FindChartObj( pDocShell, nTab, aNameString ) )
170cdf0e10cSrcweir 		return new ScChartObj( pDocShell, nTab, aNameString );
171cdf0e10cSrcweir 	return NULL;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir // XTableCharts
175cdf0e10cSrcweir 
176cdf0e10cSrcweir void SAL_CALL ScChartsObj::addNewByName( const rtl::OUString& aName,
177cdf0e10cSrcweir 										const awt::Rectangle& aRect,
178cdf0e10cSrcweir 										const uno::Sequence<table::CellRangeAddress>& aRanges,
179cdf0e10cSrcweir 										sal_Bool bColumnHeaders, sal_Bool bRowHeaders )
180cdf0e10cSrcweir 									throw(::com::sun::star::uno::RuntimeException)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir 	ScUnoGuard aGuard;
183cdf0e10cSrcweir 	if (!pDocShell)
184cdf0e10cSrcweir 		return;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	ScDocument* pDoc = pDocShell->GetDocument();
187cdf0e10cSrcweir 	ScDrawLayer* pModel = pDocShell->MakeDrawLayer();
188cdf0e10cSrcweir 	SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab));
189cdf0e10cSrcweir 	DBG_ASSERT(pPage,"addChart: keine Page");
190cdf0e10cSrcweir 	if (!pPage || !pDoc)
191cdf0e10cSrcweir 		return;
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 	//	chart can't be inserted if any ole object with that name exists on any table
194cdf0e10cSrcweir 	//	(empty string: generate valid name)
195cdf0e10cSrcweir 
196cdf0e10cSrcweir 	String aNameString(aName);
197cdf0e10cSrcweir 	SCTAB nDummy;
198cdf0e10cSrcweir 	if ( aNameString.Len() && pModel->GetNamedObject( aNameString, OBJ_OLE2, nDummy ) )
199cdf0e10cSrcweir 	{
200cdf0e10cSrcweir 		//	object exists - only RuntimeException is specified
201cdf0e10cSrcweir 		throw uno::RuntimeException();
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	ScRangeList* pList = new ScRangeList;
205cdf0e10cSrcweir 	sal_uInt16 nRangeCount = (sal_uInt16)aRanges.getLength();
206cdf0e10cSrcweir 	if (nRangeCount)
207cdf0e10cSrcweir 	{
208cdf0e10cSrcweir 		const table::CellRangeAddress* pAry = aRanges.getConstArray();
209cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<nRangeCount; i++)
210cdf0e10cSrcweir 		{
211cdf0e10cSrcweir 			ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
212cdf0e10cSrcweir 							static_cast<SCCOL>(pAry[i].EndColumn),   pAry[i].EndRow,   pAry[i].Sheet );
213cdf0e10cSrcweir 			pList->Append( aRange );
214cdf0e10cSrcweir 		}
215cdf0e10cSrcweir 	}
216cdf0e10cSrcweir 	ScRangeListRef xNewRanges( pList );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedObject > xObj;
219cdf0e10cSrcweir     ::rtl::OUString aTmp( aNameString );
220cdf0e10cSrcweir 	if ( SvtModuleOptions().IsChart() )
221cdf0e10cSrcweir         xObj = pDocShell->GetEmbeddedObjectContainer().CreateEmbeddedObject( SvGlobalName( SO3_SCH_CLASSID ).GetByteSequence(), aTmp );
222cdf0e10cSrcweir     if ( xObj.is() )
223cdf0e10cSrcweir 	{
224cdf0e10cSrcweir             String aObjName = aTmp;       // wirklich eingefuegter Name...
225cdf0e10cSrcweir 
226cdf0e10cSrcweir 			//	Rechteck anpassen
227cdf0e10cSrcweir 			//!	Fehler/Exception, wenn leer/ungueltig ???
228cdf0e10cSrcweir 			Point aRectPos( aRect.X, aRect.Y );
229cdf0e10cSrcweir             bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
230cdf0e10cSrcweir             if ( ( aRectPos.X() < 0 && !bLayoutRTL ) || ( aRectPos.X() > 0 && bLayoutRTL ) ) aRectPos.X() = 0;
231cdf0e10cSrcweir 			if (aRectPos.Y() < 0) aRectPos.Y() = 0;
232cdf0e10cSrcweir 			Size aRectSize( aRect.Width, aRect.Height );
233cdf0e10cSrcweir 			if (aRectSize.Width() <= 0) aRectSize.Width() = 5000;	// Default-Groesse
234cdf0e10cSrcweir 			if (aRectSize.Height() <= 0) aRectSize.Height() = 5000;
235cdf0e10cSrcweir 			Rectangle aInsRect( aRectPos, aRectSize );
236cdf0e10cSrcweir 
237cdf0e10cSrcweir             sal_Int64 nAspect(embed::Aspects::MSOLE_CONTENT);
238cdf0e10cSrcweir             MapUnit aMapUnit(VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( nAspect ) ));
239cdf0e10cSrcweir 			Size aSize(aInsRect.GetSize());
240cdf0e10cSrcweir             aSize = Window::LogicToLogic( aSize, MapMode( MAP_100TH_MM ), MapMode( aMapUnit ) );
241cdf0e10cSrcweir             awt::Size aSz;
242cdf0e10cSrcweir             aSz.Width = aSize.Width();
243cdf0e10cSrcweir             aSz.Height = aSize.Height();
244cdf0e10cSrcweir 
245cdf0e10cSrcweir             // Calc -> DataProvider
246cdf0e10cSrcweir             uno::Reference< chart2::data::XDataProvider > xDataProvider = new
247cdf0e10cSrcweir                 ScChart2DataProvider( pDoc );
248cdf0e10cSrcweir             // Chart -> DataReceiver
249cdf0e10cSrcweir             uno::Reference< chart2::data::XDataReceiver > xReceiver;
250cdf0e10cSrcweir             uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
251cdf0e10cSrcweir             if( xCompSupp.is())
252cdf0e10cSrcweir                 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
253cdf0e10cSrcweir             if( xReceiver.is())
254cdf0e10cSrcweir             {
255cdf0e10cSrcweir                 String sRangeStr;
256cdf0e10cSrcweir                 xNewRanges->Format(sRangeStr, SCR_ABS_3D, pDoc);
257cdf0e10cSrcweir 
258cdf0e10cSrcweir                 // connect
259cdf0e10cSrcweir                 if( sRangeStr.Len() )
260cdf0e10cSrcweir                     xReceiver->attachDataProvider( xDataProvider );
261cdf0e10cSrcweir                 else
262cdf0e10cSrcweir                     sRangeStr = String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM( "all" ) );
263cdf0e10cSrcweir 
264cdf0e10cSrcweir                 uno::Reference< util::XNumberFormatsSupplier > xNumberFormatsSupplier( pDocShell->GetModel(), uno::UNO_QUERY );
265cdf0e10cSrcweir                 xReceiver->attachNumberFormatsSupplier( xNumberFormatsSupplier );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir                 // set arguments
268cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > aArgs( 4 );
269cdf0e10cSrcweir                 aArgs[0] = beans::PropertyValue(
270cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1,
271cdf0e10cSrcweir                     uno::makeAny( ::rtl::OUString( sRangeStr )), beans::PropertyState_DIRECT_VALUE );
272cdf0e10cSrcweir                 aArgs[1] = beans::PropertyValue(
273cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii("HasCategories"), -1,
274cdf0e10cSrcweir                     uno::makeAny( bRowHeaders ), beans::PropertyState_DIRECT_VALUE );
275cdf0e10cSrcweir                 aArgs[2] = beans::PropertyValue(
276cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1,
277cdf0e10cSrcweir                     uno::makeAny( bColumnHeaders ), beans::PropertyState_DIRECT_VALUE );
278cdf0e10cSrcweir                 aArgs[3] = beans::PropertyValue(
279cdf0e10cSrcweir                     ::rtl::OUString::createFromAscii("DataRowSource"), -1,
280cdf0e10cSrcweir                     uno::makeAny( chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE );
281cdf0e10cSrcweir                 xReceiver->setArguments( aArgs );
282cdf0e10cSrcweir             }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir 			ScChartListener* pChartListener =
285cdf0e10cSrcweir 				new ScChartListener( aObjName, pDoc, xNewRanges );
286cdf0e10cSrcweir 			pDoc->GetChartListenerCollection()->Insert( pChartListener );
287cdf0e10cSrcweir 			pChartListener->StartListeningTo();
288cdf0e10cSrcweir 
289cdf0e10cSrcweir             SdrOle2Obj* pObj = new SdrOle2Obj( ::svt::EmbeddedObjectRef( xObj, embed::Aspects::MSOLE_CONTENT ), aObjName, aInsRect );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir             // set VisArea
292cdf0e10cSrcweir             if( xObj.is())
293cdf0e10cSrcweir                 xObj->setVisualAreaSize( nAspect, aSz );
294cdf0e10cSrcweir 
295*6f0b96b4SArmin Le Grand             // #121334#
296*6f0b96b4SArmin Le Grand             ChartHelper::AdaptDefaultsForChart( xObj );
297*6f0b96b4SArmin Le Grand 
298cdf0e10cSrcweir 			pPage->InsertObject( pObj );
299cdf0e10cSrcweir             pModel->AddUndo( new SdrUndoNewObj( *pObj ) );
300cdf0e10cSrcweir 
301cdf0e10cSrcweir 			// Dies veranlaesst Chart zum sofortigen Update
302cdf0e10cSrcweir 			//SvData aEmpty;
303cdf0e10cSrcweir 			//aIPObj->SendDataChanged( aEmpty );
304cdf0e10cSrcweir 	}
305cdf0e10cSrcweir }
306cdf0e10cSrcweir 
307cdf0e10cSrcweir void SAL_CALL ScChartsObj::removeByName( const rtl::OUString& aName )
308cdf0e10cSrcweir 											throw(uno::RuntimeException)
309cdf0e10cSrcweir {
310cdf0e10cSrcweir 	ScUnoGuard aGuard;
311cdf0e10cSrcweir 	String aNameString(aName);
312cdf0e10cSrcweir 	SdrOle2Obj* pObj = lcl_FindChartObj( pDocShell, nTab, aNameString );
313cdf0e10cSrcweir 	if (pObj)
314cdf0e10cSrcweir 	{
315cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
316cdf0e10cSrcweir 		ScDrawLayer* pModel = pDoc->GetDrawLayer();		// ist nicht 0
317cdf0e10cSrcweir 		SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(nTab));    // ist nicht 0
318cdf0e10cSrcweir 
319cdf0e10cSrcweir         pModel->AddUndo( new SdrUndoDelObj( *pObj ) );
320cdf0e10cSrcweir 		pPage->RemoveObject( pObj->GetOrdNum() );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 		//!	Notify etc.???
323cdf0e10cSrcweir 	}
324cdf0e10cSrcweir }
325cdf0e10cSrcweir 
326cdf0e10cSrcweir // XEnumerationAccess
327cdf0e10cSrcweir 
328cdf0e10cSrcweir uno::Reference<container::XEnumeration> SAL_CALL ScChartsObj::createEnumeration()
329cdf0e10cSrcweir 													throw(uno::RuntimeException)
330cdf0e10cSrcweir {
331cdf0e10cSrcweir 	ScUnoGuard aGuard;
332cdf0e10cSrcweir     return new ScIndexEnumeration(this, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.table.TableChartsEnumeration")));
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir // XIndexAccess
336cdf0e10cSrcweir 
337cdf0e10cSrcweir sal_Int32 SAL_CALL ScChartsObj::getCount() throw(uno::RuntimeException)
338cdf0e10cSrcweir {
339cdf0e10cSrcweir 	ScUnoGuard aGuard;
340cdf0e10cSrcweir 	sal_Int32 nCount = 0;
341cdf0e10cSrcweir 	if ( pDocShell )
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
344cdf0e10cSrcweir 		ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
345cdf0e10cSrcweir 		if (pDrawLayer)
346cdf0e10cSrcweir 		{
347cdf0e10cSrcweir 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
348cdf0e10cSrcweir 			DBG_ASSERT(pPage, "Page nicht gefunden");
349cdf0e10cSrcweir 			if (pPage)
350cdf0e10cSrcweir 			{
351cdf0e10cSrcweir 				SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
352cdf0e10cSrcweir 				SdrObject* pObject = aIter.Next();
353cdf0e10cSrcweir 				while (pObject)
354cdf0e10cSrcweir 				{
355cdf0e10cSrcweir 					if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
356cdf0e10cSrcweir 						++nCount;
357cdf0e10cSrcweir 					pObject = aIter.Next();
358cdf0e10cSrcweir 				}
359cdf0e10cSrcweir 			}
360cdf0e10cSrcweir 		}
361cdf0e10cSrcweir 	}
362cdf0e10cSrcweir 	return nCount;
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
365cdf0e10cSrcweir uno::Any SAL_CALL ScChartsObj::getByIndex( sal_Int32 nIndex )
366cdf0e10cSrcweir 							throw(lang::IndexOutOfBoundsException,
367cdf0e10cSrcweir 									lang::WrappedTargetException, uno::RuntimeException)
368cdf0e10cSrcweir {
369cdf0e10cSrcweir 	ScUnoGuard aGuard;
370cdf0e10cSrcweir 	uno::Reference<table::XTableChart> xChart(GetObjectByIndex_Impl(nIndex));
371cdf0e10cSrcweir 	if (xChart.is())
372cdf0e10cSrcweir         return uno::makeAny(xChart);
373cdf0e10cSrcweir 	else
374cdf0e10cSrcweir 		throw lang::IndexOutOfBoundsException();
375cdf0e10cSrcweir //    return uno::Any();
376cdf0e10cSrcweir }
377cdf0e10cSrcweir 
378cdf0e10cSrcweir uno::Type SAL_CALL ScChartsObj::getElementType() throw(uno::RuntimeException)
379cdf0e10cSrcweir {
380cdf0e10cSrcweir 	ScUnoGuard aGuard;
381cdf0e10cSrcweir 	return getCppuType((uno::Reference<table::XTableChart>*)0);
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir sal_Bool SAL_CALL ScChartsObj::hasElements() throw(uno::RuntimeException)
385cdf0e10cSrcweir {
386cdf0e10cSrcweir 	ScUnoGuard aGuard;
387cdf0e10cSrcweir 	return getCount() != 0;
388cdf0e10cSrcweir }
389cdf0e10cSrcweir 
390cdf0e10cSrcweir uno::Any SAL_CALL ScChartsObj::getByName( const rtl::OUString& aName )
391cdf0e10cSrcweir 			throw(container::NoSuchElementException,
392cdf0e10cSrcweir 					lang::WrappedTargetException, uno::RuntimeException)
393cdf0e10cSrcweir {
394cdf0e10cSrcweir 	ScUnoGuard aGuard;
395cdf0e10cSrcweir 	uno::Reference<table::XTableChart> xChart(GetObjectByName_Impl(aName));
396cdf0e10cSrcweir 	if (xChart.is())
397cdf0e10cSrcweir         return uno::makeAny(xChart);
398cdf0e10cSrcweir 	else
399cdf0e10cSrcweir 		throw container::NoSuchElementException();
400cdf0e10cSrcweir //    return uno::Any();
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir uno::Sequence<rtl::OUString> SAL_CALL ScChartsObj::getElementNames() throw(uno::RuntimeException)
404cdf0e10cSrcweir {
405cdf0e10cSrcweir 	ScUnoGuard aGuard;
406cdf0e10cSrcweir 	if (pDocShell)
407cdf0e10cSrcweir 	{
408cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
409cdf0e10cSrcweir 
410cdf0e10cSrcweir 		long nCount = getCount();
411cdf0e10cSrcweir 		uno::Sequence<rtl::OUString> aSeq(nCount);
412cdf0e10cSrcweir 		rtl::OUString* pAry = aSeq.getArray();
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 		long nPos = 0;
415cdf0e10cSrcweir 		ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
416cdf0e10cSrcweir 		if (pDrawLayer)
417cdf0e10cSrcweir 		{
418cdf0e10cSrcweir 			SdrPage* pPage = pDrawLayer->GetPage(static_cast<sal_uInt16>(nTab));
419cdf0e10cSrcweir 			DBG_ASSERT(pPage, "Page nicht gefunden");
420cdf0e10cSrcweir 			if (pPage)
421cdf0e10cSrcweir 			{
422cdf0e10cSrcweir 				SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
423cdf0e10cSrcweir 				SdrObject* pObject = aIter.Next();
424cdf0e10cSrcweir 				while (pObject)
425cdf0e10cSrcweir 				{
426cdf0e10cSrcweir 					if ( pObject->GetObjIdentifier() == OBJ_OLE2 && pDoc->IsChart(pObject) )
427cdf0e10cSrcweir 					{
428cdf0e10cSrcweir 						String aName;
429cdf0e10cSrcweir                         uno::Reference < embed::XEmbeddedObject > xObj = ((SdrOle2Obj*)pObject)->GetObjRef();
430cdf0e10cSrcweir                         if ( xObj.is() )
431cdf0e10cSrcweir                             aName = pDocShell->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
432cdf0e10cSrcweir 
433cdf0e10cSrcweir 						DBG_ASSERT(nPos<nCount, "huch, verzaehlt?");
434cdf0e10cSrcweir 						pAry[nPos++] = aName;
435cdf0e10cSrcweir 					}
436cdf0e10cSrcweir 					pObject = aIter.Next();
437cdf0e10cSrcweir 				}
438cdf0e10cSrcweir 			}
439cdf0e10cSrcweir 		}
440cdf0e10cSrcweir 		DBG_ASSERT(nPos==nCount, "nanu, verzaehlt?");
441cdf0e10cSrcweir 
442cdf0e10cSrcweir 		return aSeq;
443cdf0e10cSrcweir 	}
444cdf0e10cSrcweir 	return uno::Sequence<rtl::OUString>(0);
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir sal_Bool SAL_CALL ScChartsObj::hasByName( const rtl::OUString& aName )
448cdf0e10cSrcweir 										throw(uno::RuntimeException)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir 	ScUnoGuard aGuard;
451cdf0e10cSrcweir 	String aNameString(aName);
452cdf0e10cSrcweir 	return ( lcl_FindChartObj( pDocShell, nTab, aNameString ) != NULL );
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir //------------------------------------------------------------------------
456cdf0e10cSrcweir 
457cdf0e10cSrcweir ScChartObj::ScChartObj(ScDocShell* pDocSh, SCTAB nT, const String& rN)
458cdf0e10cSrcweir     :ScChartObj_Base( m_aMutex )
459cdf0e10cSrcweir     ,ScChartObj_PBase( ScChartObj_Base::rBHelper )
460cdf0e10cSrcweir 	,pDocShell( pDocSh )
461cdf0e10cSrcweir 	,nTab( nT )
462cdf0e10cSrcweir 	,aChartName( rN )
463cdf0e10cSrcweir {
464cdf0e10cSrcweir     pDocShell->GetDocument()->AddUnoObject(*this);
4657d1ce60bSWang Lei     SdrOle2Obj* pObject = lcl_FindChartObj( pDocShell, nTab, aChartName );
4667d1ce60bSWang Lei     if ( pObject && svt::EmbeddedObjectRef::TryRunningState( pObject->GetObjRef() ) )
4677d1ce60bSWang Lei         aObjectName = pObject->GetName();   // #i121178#: keep the OLE object's name
468cdf0e10cSrcweir     uno::Sequence< table::CellRangeAddress > aInitialPropValue;
469cdf0e10cSrcweir     registerPropertyNoMember( ::rtl::OUString::createFromAscii( "RelatedCellRanges" ),
470cdf0e10cSrcweir         PROP_HANDLE_RELATED_CELLRANGES, beans::PropertyAttribute::MAYBEVOID,
471cdf0e10cSrcweir         ::getCppuType( &aInitialPropValue ), &aInitialPropValue );
472cdf0e10cSrcweir }
473cdf0e10cSrcweir 
474cdf0e10cSrcweir ScChartObj::~ScChartObj()
475cdf0e10cSrcweir {
476cdf0e10cSrcweir 	if (pDocShell)
477cdf0e10cSrcweir 		pDocShell->GetDocument()->RemoveUnoObject(*this);
478cdf0e10cSrcweir }
479cdf0e10cSrcweir 
480cdf0e10cSrcweir void ScChartObj::Notify( SfxBroadcaster&, const SfxHint& rHint )
481cdf0e10cSrcweir {
482cdf0e10cSrcweir 	//!	Referenz-Update
483cdf0e10cSrcweir 
484cdf0e10cSrcweir 	if ( rHint.ISA( SfxSimpleHint ) &&
485cdf0e10cSrcweir 			((const SfxSimpleHint&)rHint).GetId() == SFX_HINT_DYING )
486cdf0e10cSrcweir 	{
487cdf0e10cSrcweir 		pDocShell = NULL;		// ungueltig geworden
488cdf0e10cSrcweir 	}
489cdf0e10cSrcweir }
490cdf0e10cSrcweir 
491cdf0e10cSrcweir void ScChartObj::GetData_Impl( ScRangeListRef& rRanges, bool& rColHeaders, bool& rRowHeaders ) const
492cdf0e10cSrcweir {
493cdf0e10cSrcweir 	bool bFound = false;
494cdf0e10cSrcweir     ScDocument* pDoc = (pDocShell? pDocShell->GetDocument(): 0);
495cdf0e10cSrcweir 
496cdf0e10cSrcweir     if( pDoc )
497cdf0e10cSrcweir     {
498cdf0e10cSrcweir         uno::Reference< chart2::XChartDocument > xChartDoc( pDoc->GetChartByName( aChartName ) );
499cdf0e10cSrcweir         if( xChartDoc.is() )
500cdf0e10cSrcweir         {
501cdf0e10cSrcweir             uno::Reference< chart2::data::XDataReceiver > xReceiver( xChartDoc, uno::UNO_QUERY );
502cdf0e10cSrcweir             uno::Reference< chart2::data::XDataProvider > xProvider = xChartDoc->getDataProvider();
503cdf0e10cSrcweir             if( xReceiver.is() && xProvider.is() )
504cdf0e10cSrcweir             {
505cdf0e10cSrcweir                 uno::Sequence< beans::PropertyValue > aArgs( xProvider->detectArguments( xReceiver->getUsedData() ) );
506cdf0e10cSrcweir 
507cdf0e10cSrcweir                 rtl::OUString aRanges;
508cdf0e10cSrcweir                 chart::ChartDataRowSource eDataRowSource = chart::ChartDataRowSource_COLUMNS;
509cdf0e10cSrcweir                 bool bHasCategories=false;
510cdf0e10cSrcweir                 bool bFirstCellAsLabel=false;
511cdf0e10cSrcweir                 const beans::PropertyValue* pPropArray = aArgs.getConstArray();
512cdf0e10cSrcweir                 long nPropCount = aArgs.getLength();
513cdf0e10cSrcweir                 for (long i = 0; i < nPropCount; i++)
514cdf0e10cSrcweir                 {
515cdf0e10cSrcweir                     const beans::PropertyValue& rProp = pPropArray[i];
516cdf0e10cSrcweir                     String aPropName(rProp.Name);
517cdf0e10cSrcweir 
518cdf0e10cSrcweir                     if (aPropName.EqualsAscii( "CellRangeRepresentation" ))
519cdf0e10cSrcweir                         rProp.Value >>= aRanges;
520cdf0e10cSrcweir                     else if (aPropName.EqualsAscii( "DataRowSource" ))
521cdf0e10cSrcweir                         eDataRowSource = (chart::ChartDataRowSource)ScUnoHelpFunctions::GetEnumFromAny( rProp.Value );
522cdf0e10cSrcweir                     else if (aPropName.EqualsAscii( "HasCategories" ))
523cdf0e10cSrcweir                         bHasCategories = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
524cdf0e10cSrcweir                     else if (aPropName.EqualsAscii( "FirstCellAsLabel" ))
525cdf0e10cSrcweir                         bFirstCellAsLabel = ScUnoHelpFunctions::GetBoolFromAny( rProp.Value );
526cdf0e10cSrcweir                 }
527cdf0e10cSrcweir 
528cdf0e10cSrcweir                 if( chart::ChartDataRowSource_COLUMNS == eDataRowSource )
529cdf0e10cSrcweir                 {
530cdf0e10cSrcweir                     rColHeaders=bFirstCellAsLabel;
531cdf0e10cSrcweir                     rRowHeaders=bHasCategories;
532cdf0e10cSrcweir                 }
533cdf0e10cSrcweir                 else
534cdf0e10cSrcweir                 {
535cdf0e10cSrcweir                     rColHeaders=bHasCategories;
536cdf0e10cSrcweir                     rRowHeaders=bFirstCellAsLabel;
537cdf0e10cSrcweir                 }
538cdf0e10cSrcweir                 rRanges->Parse( aRanges, pDoc);
539cdf0e10cSrcweir             }
540cdf0e10cSrcweir             bFound = true;
541cdf0e10cSrcweir         }
542cdf0e10cSrcweir  	}
543cdf0e10cSrcweir 	if( !bFound )
544cdf0e10cSrcweir 	{
545cdf0e10cSrcweir 		rRanges = 0;
546cdf0e10cSrcweir 		rColHeaders = false;
547cdf0e10cSrcweir 		rRowHeaders = false;
548cdf0e10cSrcweir 	}
549cdf0e10cSrcweir }
550cdf0e10cSrcweir 
551cdf0e10cSrcweir void ScChartObj::Update_Impl( const ScRangeListRef& rRanges, bool bColHeaders, bool bRowHeaders )
552cdf0e10cSrcweir {
553cdf0e10cSrcweir 	if (pDocShell)
554cdf0e10cSrcweir 	{
555cdf0e10cSrcweir 		ScDocument* pDoc = pDocShell->GetDocument();
556cdf0e10cSrcweir 		sal_Bool bUndo(pDoc->IsUndoEnabled());
557cdf0e10cSrcweir 
558cdf0e10cSrcweir 		if (bUndo)
559cdf0e10cSrcweir 		{
560cdf0e10cSrcweir 			pDocShell->GetUndoManager()->AddUndoAction(
561cdf0e10cSrcweir 				new ScUndoChartData( pDocShell, aChartName, rRanges, bColHeaders, bRowHeaders, sal_False ) );
562cdf0e10cSrcweir 		}
563cdf0e10cSrcweir 		pDoc->UpdateChartArea( aChartName, rRanges, bColHeaders, bRowHeaders, sal_False );
564cdf0e10cSrcweir 	}
565cdf0e10cSrcweir }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir // ::comphelper::OPropertySetHelper
568cdf0e10cSrcweir 
569cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& ScChartObj::getInfoHelper()
570cdf0e10cSrcweir {
571cdf0e10cSrcweir     return *ScChartObj_PABase::getArrayHelper();
572cdf0e10cSrcweir }
573cdf0e10cSrcweir 
574cdf0e10cSrcweir void ScChartObj::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const uno::Any& rValue ) throw (uno::Exception)
575cdf0e10cSrcweir {
576cdf0e10cSrcweir     switch ( nHandle )
577cdf0e10cSrcweir 	{
578cdf0e10cSrcweir         case PROP_HANDLE_RELATED_CELLRANGES:
579cdf0e10cSrcweir             {
580cdf0e10cSrcweir                 uno::Sequence< table::CellRangeAddress > aCellRanges;
581cdf0e10cSrcweir                 if ( rValue >>= aCellRanges )
582cdf0e10cSrcweir                 {
583cdf0e10cSrcweir                     ScRangeListRef rRangeList = new ScRangeList();
584cdf0e10cSrcweir                     const table::CellRangeAddress* pCellRanges = aCellRanges.getArray();
585cdf0e10cSrcweir                     sal_Int32 nCount = aCellRanges.getLength();
586cdf0e10cSrcweir                     for ( sal_Int32 i = 0; i < nCount; ++i )
587cdf0e10cSrcweir                     {
588cdf0e10cSrcweir                         table::CellRangeAddress aCellRange = pCellRanges[ i ];
589cdf0e10cSrcweir                         ScRange aRange;
590cdf0e10cSrcweir                         ScUnoConversion::FillScRange( aRange, aCellRange );
591cdf0e10cSrcweir                         rRangeList->Append( aRange );
592cdf0e10cSrcweir                     }
593cdf0e10cSrcweir                     ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL );
594cdf0e10cSrcweir                     ScChartListenerCollection* pCollection = ( pDoc ? pDoc->GetChartListenerCollection() : NULL );
595cdf0e10cSrcweir                     if ( pCollection )
596cdf0e10cSrcweir                     {
597cdf0e10cSrcweir                         pCollection->ChangeListening( aChartName, rRangeList );
598cdf0e10cSrcweir                     }
599cdf0e10cSrcweir                 }
600cdf0e10cSrcweir             }
601cdf0e10cSrcweir             break;
602cdf0e10cSrcweir         default:
603cdf0e10cSrcweir             {
604cdf0e10cSrcweir             }
605cdf0e10cSrcweir             break;
606cdf0e10cSrcweir     }
607cdf0e10cSrcweir }
608cdf0e10cSrcweir 
609cdf0e10cSrcweir void ScChartObj::getFastPropertyValue( uno::Any& rValue, sal_Int32 nHandle ) const
610cdf0e10cSrcweir {
611cdf0e10cSrcweir     switch ( nHandle )
612cdf0e10cSrcweir 	{
613cdf0e10cSrcweir         case PROP_HANDLE_RELATED_CELLRANGES:
614cdf0e10cSrcweir             {
615cdf0e10cSrcweir                 ScDocument* pDoc = ( pDocShell ? pDocShell->GetDocument() : NULL );
616cdf0e10cSrcweir                 if ( pDoc )
617cdf0e10cSrcweir                 {
618cdf0e10cSrcweir                     ScRange aEmptyRange;
619cdf0e10cSrcweir                     sal_uInt16 nIndex = 0;
620cdf0e10cSrcweir                     ScChartListener aSearcher( aChartName, pDoc, aEmptyRange );
621cdf0e10cSrcweir                     ScChartListenerCollection* pCollection = pDoc->GetChartListenerCollection();
622cdf0e10cSrcweir                     if ( pCollection && pCollection->Search( &aSearcher, nIndex ) )
623cdf0e10cSrcweir                     {
624cdf0e10cSrcweir                         ScChartListener* pListener = static_cast< ScChartListener* >( pCollection->At( nIndex ) );
625cdf0e10cSrcweir                         if ( pListener )
626cdf0e10cSrcweir                         {
627cdf0e10cSrcweir                             const ScRangeListRef& rRangeList = pListener->GetRangeList();
628cdf0e10cSrcweir                             if ( rRangeList.Is() )
629cdf0e10cSrcweir                             {
630cdf0e10cSrcweir                                 sal_uLong nCount = rRangeList->Count();
631cdf0e10cSrcweir                                 uno::Sequence< table::CellRangeAddress > aCellRanges( nCount );
632cdf0e10cSrcweir                                 table::CellRangeAddress* pCellRanges = aCellRanges.getArray();
633cdf0e10cSrcweir                                 for ( sal_uInt16 i = 0; i < nCount; ++i )
634cdf0e10cSrcweir                                 {
635cdf0e10cSrcweir                                     ScRange aRange( *rRangeList->GetObject( i ) );
636cdf0e10cSrcweir                                     table::CellRangeAddress aCellRange;
637cdf0e10cSrcweir                                     ScUnoConversion::FillApiRange( aCellRange, aRange );
638cdf0e10cSrcweir                                     pCellRanges[ i ] = aCellRange;
639cdf0e10cSrcweir                                 }
640cdf0e10cSrcweir                                 rValue <<= aCellRanges;
641cdf0e10cSrcweir                             }
642cdf0e10cSrcweir                         }
643cdf0e10cSrcweir                     }
644cdf0e10cSrcweir                 }
645cdf0e10cSrcweir             }
646cdf0e10cSrcweir             break;
647cdf0e10cSrcweir         default:
648cdf0e10cSrcweir             {
649cdf0e10cSrcweir             }
650cdf0e10cSrcweir             break;
651cdf0e10cSrcweir     }
652cdf0e10cSrcweir }
653cdf0e10cSrcweir 
654cdf0e10cSrcweir // ::comphelper::OPropertyArrayUsageHelper
655cdf0e10cSrcweir 
656cdf0e10cSrcweir ::cppu::IPropertyArrayHelper* ScChartObj::createArrayHelper() const
657cdf0e10cSrcweir {
658cdf0e10cSrcweir     uno::Sequence< beans::Property > aProps;
659cdf0e10cSrcweir     describeProperties( aProps );
660cdf0e10cSrcweir     return new ::cppu::OPropertyArrayHelper( aProps );
661cdf0e10cSrcweir }
662cdf0e10cSrcweir 
663cdf0e10cSrcweir // XInterface
664cdf0e10cSrcweir 
665cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( ScChartObj, ScChartObj_Base, ScChartObj_PBase )
666cdf0e10cSrcweir 
667cdf0e10cSrcweir // XTypeProvider
668cdf0e10cSrcweir 
669cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScChartObj, ScChartObj_Base, ScChartObj_PBase )
670cdf0e10cSrcweir 
671cdf0e10cSrcweir // XComponent
672cdf0e10cSrcweir 
673cdf0e10cSrcweir void ScChartObj::disposing()
674cdf0e10cSrcweir {
675cdf0e10cSrcweir     ScChartObj_Base::disposing();
676cdf0e10cSrcweir }
677cdf0e10cSrcweir 
678cdf0e10cSrcweir // XTableChart
679cdf0e10cSrcweir 
680cdf0e10cSrcweir sal_Bool SAL_CALL ScChartObj::getHasColumnHeaders() throw(uno::RuntimeException)
681cdf0e10cSrcweir {
682cdf0e10cSrcweir 	ScUnoGuard aGuard;
683cdf0e10cSrcweir 	ScRangeListRef xRanges = new ScRangeList;
684cdf0e10cSrcweir 	bool bColHeaders, bRowHeaders;
685cdf0e10cSrcweir 	GetData_Impl( xRanges, bColHeaders, bRowHeaders );
686cdf0e10cSrcweir 	return bColHeaders;
687cdf0e10cSrcweir }
688cdf0e10cSrcweir 
689cdf0e10cSrcweir void SAL_CALL ScChartObj::setHasColumnHeaders( sal_Bool bHasColumnHeaders )
690cdf0e10cSrcweir 												throw(uno::RuntimeException)
691cdf0e10cSrcweir {
692cdf0e10cSrcweir 	ScUnoGuard aGuard;
693cdf0e10cSrcweir 	ScRangeListRef xRanges = new ScRangeList;
694cdf0e10cSrcweir 	bool bOldColHeaders, bOldRowHeaders;
695cdf0e10cSrcweir 	GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
696cdf0e10cSrcweir 	if ( bOldColHeaders != (bHasColumnHeaders != sal_False) )
697cdf0e10cSrcweir 		Update_Impl( xRanges, bHasColumnHeaders, bOldRowHeaders );
698cdf0e10cSrcweir }
699cdf0e10cSrcweir 
700cdf0e10cSrcweir sal_Bool SAL_CALL ScChartObj::getHasRowHeaders() throw(uno::RuntimeException)
701cdf0e10cSrcweir {
702cdf0e10cSrcweir 	ScUnoGuard aGuard;
703cdf0e10cSrcweir 	ScRangeListRef xRanges = new ScRangeList;
704cdf0e10cSrcweir 	bool bColHeaders, bRowHeaders;
705cdf0e10cSrcweir 	GetData_Impl( xRanges, bColHeaders, bRowHeaders );
706cdf0e10cSrcweir 	return bRowHeaders;
707cdf0e10cSrcweir }
708cdf0e10cSrcweir 
709cdf0e10cSrcweir void SAL_CALL ScChartObj::setHasRowHeaders( sal_Bool bHasRowHeaders )
710cdf0e10cSrcweir 												throw(uno::RuntimeException)
711cdf0e10cSrcweir {
712cdf0e10cSrcweir 	ScUnoGuard aGuard;
713cdf0e10cSrcweir 	ScRangeListRef xRanges = new ScRangeList;
714cdf0e10cSrcweir 	bool bOldColHeaders, bOldRowHeaders;
715cdf0e10cSrcweir 	GetData_Impl( xRanges, bOldColHeaders, bOldRowHeaders );
716cdf0e10cSrcweir 	if ( bOldRowHeaders != (bHasRowHeaders != sal_False) )
717cdf0e10cSrcweir 		Update_Impl( xRanges, bOldColHeaders, bHasRowHeaders );
718cdf0e10cSrcweir }
719cdf0e10cSrcweir 
720cdf0e10cSrcweir uno::Sequence<table::CellRangeAddress> SAL_CALL ScChartObj::getRanges() throw(uno::RuntimeException)
721cdf0e10cSrcweir {
722cdf0e10cSrcweir 	ScUnoGuard aGuard;
723cdf0e10cSrcweir 	ScRangeListRef xRanges = new ScRangeList;
724cdf0e10cSrcweir 	bool bColHeaders, bRowHeaders;
725cdf0e10cSrcweir 	GetData_Impl( xRanges, bColHeaders, bRowHeaders );
726cdf0e10cSrcweir 	if ( xRanges.Is() )
727cdf0e10cSrcweir 	{
728cdf0e10cSrcweir 		sal_uLong nCount = xRanges->Count();
729cdf0e10cSrcweir 
730cdf0e10cSrcweir 		table::CellRangeAddress aRangeAddress;
731cdf0e10cSrcweir 		uno::Sequence<table::CellRangeAddress> aSeq(nCount);
732cdf0e10cSrcweir 		table::CellRangeAddress* pAry = aSeq.getArray();
733cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<nCount; i++)
734cdf0e10cSrcweir 		{
735cdf0e10cSrcweir 			ScRange aRange(*xRanges->GetObject(i));
736cdf0e10cSrcweir 
737cdf0e10cSrcweir 			aRangeAddress.Sheet		  = aRange.aStart.Tab();
738cdf0e10cSrcweir 			aRangeAddress.StartColumn = aRange.aStart.Col();
739cdf0e10cSrcweir 			aRangeAddress.StartRow	  = aRange.aStart.Row();
740cdf0e10cSrcweir 			aRangeAddress.EndColumn	  = aRange.aEnd.Col();
741cdf0e10cSrcweir 			aRangeAddress.EndRow	  = aRange.aEnd.Row();
742cdf0e10cSrcweir 
743cdf0e10cSrcweir 			pAry[i] = aRangeAddress;
744cdf0e10cSrcweir 		}
745cdf0e10cSrcweir 		return aSeq;
746cdf0e10cSrcweir 	}
747cdf0e10cSrcweir 
748cdf0e10cSrcweir 	DBG_ERROR("ScChartObj::getRanges: keine Ranges");
749cdf0e10cSrcweir 	return uno::Sequence<table::CellRangeAddress>();
750cdf0e10cSrcweir }
751cdf0e10cSrcweir 
752cdf0e10cSrcweir void SAL_CALL ScChartObj::setRanges( const uno::Sequence<table::CellRangeAddress>& aRanges )
753cdf0e10cSrcweir 												throw(uno::RuntimeException)
754cdf0e10cSrcweir {
755cdf0e10cSrcweir 	ScUnoGuard aGuard;
756cdf0e10cSrcweir 	ScRangeListRef xOldRanges = new ScRangeList;
757cdf0e10cSrcweir 	bool bColHeaders, bRowHeaders;
758cdf0e10cSrcweir 	GetData_Impl( xOldRanges, bColHeaders, bRowHeaders );
759cdf0e10cSrcweir 
760cdf0e10cSrcweir 	ScRangeList* pList = new ScRangeList;
761cdf0e10cSrcweir 	sal_uInt16 nRangeCount = (sal_uInt16)aRanges.getLength();
762cdf0e10cSrcweir 	if (nRangeCount)
763cdf0e10cSrcweir 	{
764cdf0e10cSrcweir 		const table::CellRangeAddress* pAry = aRanges.getConstArray();
765cdf0e10cSrcweir 		for (sal_uInt16 i=0; i<nRangeCount; i++)
766cdf0e10cSrcweir 		{
767cdf0e10cSrcweir 			ScRange aRange( static_cast<SCCOL>(pAry[i].StartColumn), pAry[i].StartRow, pAry[i].Sheet,
768cdf0e10cSrcweir 							static_cast<SCCOL>(pAry[i].EndColumn),   pAry[i].EndRow,   pAry[i].Sheet );
769cdf0e10cSrcweir 			pList->Append( aRange );
770cdf0e10cSrcweir 		}
771cdf0e10cSrcweir 	}
772cdf0e10cSrcweir 	ScRangeListRef xNewRanges( pList );
773cdf0e10cSrcweir 
774cdf0e10cSrcweir 	if ( !xOldRanges.Is() || *xOldRanges != *xNewRanges )
775cdf0e10cSrcweir 		Update_Impl( xNewRanges, bColHeaders, bRowHeaders );
776cdf0e10cSrcweir }
777cdf0e10cSrcweir 
778cdf0e10cSrcweir // XEmbeddedObjectSupplier
779cdf0e10cSrcweir 
780cdf0e10cSrcweir uno::Reference<lang::XComponent> SAL_CALL ScChartObj::getEmbeddedObject() throw(uno::RuntimeException)
781cdf0e10cSrcweir {
782cdf0e10cSrcweir 	ScUnoGuard aGuard;
783cdf0e10cSrcweir 	SdrOle2Obj* pObject = lcl_FindChartObj( pDocShell, nTab, aChartName );
784cdf0e10cSrcweir     if ( pObject && svt::EmbeddedObjectRef::TryRunningState( pObject->GetObjRef() ) )
785cdf0e10cSrcweir 	{
786cdf0e10cSrcweir         //TODO/LATER: is it OK that something is returned for *all* objects, not only own objects?
787cdf0e10cSrcweir         return uno::Reference < lang::XComponent > ( pObject->GetObjRef()->getComponent(), uno::UNO_QUERY );
788cdf0e10cSrcweir 	}
789cdf0e10cSrcweir 
790cdf0e10cSrcweir 	return NULL;
791cdf0e10cSrcweir }
792cdf0e10cSrcweir 
793cdf0e10cSrcweir // XNamed
794cdf0e10cSrcweir 
795cdf0e10cSrcweir rtl::OUString SAL_CALL ScChartObj::getName() throw(uno::RuntimeException)
796cdf0e10cSrcweir {
797cdf0e10cSrcweir 	ScUnoGuard aGuard;
798cdf0e10cSrcweir 	return aChartName;
799cdf0e10cSrcweir }
800cdf0e10cSrcweir 
801cdf0e10cSrcweir void SAL_CALL ScChartObj::setName( const rtl::OUString& /* aName */ ) throw(uno::RuntimeException)
802cdf0e10cSrcweir {
803cdf0e10cSrcweir 	ScUnoGuard aGuard;
804cdf0e10cSrcweir 	throw uno::RuntimeException();		// name cannot be changed
805cdf0e10cSrcweir }
806cdf0e10cSrcweir 
8077d1ce60bSWang Lei // XNamedEx
8087d1ce60bSWang Lei 
8097d1ce60bSWang Lei rtl::OUString SAL_CALL ScChartObj::getDisplayName() throw(uno::RuntimeException)
8107d1ce60bSWang Lei {
8117d1ce60bSWang Lei 	ScUnoGuard aGuard;
8127d1ce60bSWang Lei 	return aObjectName;
8137d1ce60bSWang Lei }
8147d1ce60bSWang Lei 
8157d1ce60bSWang Lei void SAL_CALL ScChartObj::setDisplayName( const rtl::OUString& aName ) throw(uno::RuntimeException)
8167d1ce60bSWang Lei {
8177d1ce60bSWang Lei 	ScUnoGuard aGuard;
8187d1ce60bSWang Lei 	aObjectName = aName;
8197d1ce60bSWang Lei }
8207d1ce60bSWang Lei 
821cdf0e10cSrcweir // XPropertySet
822cdf0e10cSrcweir 
823cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > ScChartObj::getPropertySetInfo() throw (uno::RuntimeException)
824cdf0e10cSrcweir {
825cdf0e10cSrcweir     return createPropertySetInfo( getInfoHelper() ) ;
826cdf0e10cSrcweir }
827cdf0e10cSrcweir 
828cdf0e10cSrcweir //------------------------------------------------------------------------
829cdf0e10cSrcweir 
830cdf0e10cSrcweir 
831cdf0e10cSrcweir 
832